EncoderEvaluator
Encoder evaluation: encode gradients on eval data and compute label correlation. Uses trainer for model and create_eval_data; subclasses can override to customize behavior (caching, metrics).
evaluate_encoder
evaluate_encoder(trainer, encoder_df=None, eval_data=None, use_cache=None, split=None, max_size=None, **kwargs)
Evaluate encoder on eval data: encode gradients and compute unified encoder metrics.
Uses get_encoder_metrics_from_dataframe as single source of truth for all metrics. When encoder_df is provided, skips encoding and computes metrics directly from it. When experiment_dir is set, encoder metrics are written to the same path as the encoder analysis CSV but with .json extension (e.g. encoded_values_max_size_500_split_test.json). When use_cache=True and experiment_dir is set, loads from that path when the file exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trainer
|
Any
|
Trainer (or protocol) with get_model() and create_eval_data(). |
required |
encoder_df
|
Optional[DataFrame]
|
Optional DataFrame with encoded values. If provided, skips encoding and computes metrics from this DataFrame. Use when you already have encoder outputs (e.g. from evaluate_encoder(return_df=True)). |
None
|
eval_data
|
Any
|
Optional pre-computed GradientTrainingDataset. If None and encoder_df is None, created via trainer.create_eval_data. |
None
|
use_cache
|
Optional[bool]
|
If True, use cached encoder evaluation result when available (requires experiment_dir). |
None
|
split
|
Optional[str]
|
Dataset split for create_eval_data. Default: "test". |
None
|
max_size
|
Optional[int]
|
Maximum samples per variant for create_eval_data. |
None
|
**kwargs
|
Any
|
Passed to trainer.create_eval_data when eval_data and encoder_df are None. |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with keys from get_encoder_metrics_from_dataframe: n_samples, sample_counts, |
Dict[str, Any]
|
all_data, training_only, target_classes_only, boundaries, correlation, |
Dict[str, Any]
|
mean_by_class, mean_by_type; optionally neutral_mean_by_type, mean_by_feature_class, |
Dict[str, Any]
|
label_value_to_class_name. |
Source code in gradiend/evaluator/encoder.py
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |