analyzer
shrinkai.analysis.analyzer
Classes:
| Name | Description |
|---|---|
FeatureAnalyzer |
Evaluates how well a student model mimics the teacher's internal hidden states. |
FeatureAnalyzerReport |
Holds representation analysis results and renders a dashboard. |
Classes
FeatureAnalyzer
Evaluates how well a student model mimics the teacher's internal hidden states.
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the FeatureAnalyzer. |
evaluate |
Runs the dataset through both models and computes alignment metrics per layer. |
Source code in src/shrinkai/analysis/analyzer.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
Methods:
__init__
__init__(
teacher_extractor: FeatureExtractor,
student_extractor: FeatureExtractor,
device: device | str = "auto",
) -> None
Initializes the FeatureAnalyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
teacher_extractor
|
FeatureExtractor
|
Teacher model wrapped in FeatureExtractor. |
required |
student_extractor
|
FeatureExtractor
|
Student model wrapped in FeatureExtractor. |
required |
device
|
device | str
|
Computing target. |
'auto'
|
Source code in src/shrinkai/analysis/analyzer.py
evaluate
evaluate(
dataloader: DataLoader,
metrics: list[str | BaseFeatureMetric] | None = None,
) -> FeatureAnalyzerReport
Runs the dataset through both models and computes alignment metrics per layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataloader
|
DataLoader
|
Dataloader yielding validation batches. |
required |
metrics
|
list[str | BaseFeatureMetric] | None
|
List of metric strings ('cka') or instantiated BaseFeatureMetric objects. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FeatureAnalyzerReport |
FeatureAnalyzerReport
|
Formatted report ready for |
Source code in src/shrinkai/analysis/analyzer.py
FeatureAnalyzerReport
Holds representation analysis results and renders a dashboard.
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the report. |
show |
Renders an interactive formatted analysis table in the console. |
Source code in src/shrinkai/analysis/analyzer.py
Methods:
__init__
Initializes the report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_scores
|
dict[str, dict[str, float]]
|
Nested dict |
required |
show
Renders an interactive formatted analysis table in the console.