Evaluator
High-level evaluation coordinator bound to a trainer.
This class owns an EncoderEvaluator and DecoderEvaluator and exposes convenience methods that pass the trainer through. It can also hold a Visualizer instance for evaluation-related plots.
Subclasses can override evaluation or plotting methods to customize caching, metrics, or visualization behavior.
Source code in gradiend/evaluator/evaluator.py
_visualizer_class
instance-attribute
_visualizer_class = visualizer_class if visualizer_class is not None else _default_visualizer_class()
_delegate_to_visualizer
Source code in gradiend/evaluator/evaluator.py
_get_visualizer
evaluate
Run encoder and decoder evaluation and return a combined result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs_encoder
|
dict
|
Optional dict of keyword arguments forwarded to evaluate_encoder. |
None
|
kwargs_decoder
|
dict
|
Optional dict of keyword arguments forwarded to evaluate_decoder. |
None
|
**kwargs
|
Any
|
Extra kwargs applied to both encoder and decoder evaluations (e.g., shared eval data settings). |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with: |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Source code in gradiend/evaluator/evaluator.py
evaluate_decoder
evaluate_decoder(model_with_gradiend=None, feature_factors=None, lrs=None, use_cache=None, split='test', max_size=None, max_size_training_like=None, max_size_neutral=None, eval_batch_size=None, training_like_df=None, neutral_df=None, selector=None, summary_extractor=None, summary_metrics=None, target_class=None, increase_target_probabilities=True, plot=False, show=None, plot_kwargs=None)
Run decoder grid evaluation and return summary + grid for one direction (strengthen or weaken).
Only the dataset and feature-factor combinations required for the requested direction are computed. Use increase_target_probabilities=True (default) for strengthen, False for weaken.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_with_gradiend
|
Any
|
Optional ModelWithGradiend (or path) to evaluate. If None, the trainer's model is used. |
None
|
feature_factors
|
Optional[list]
|
Optional list of feature factors to test. If None, derived from direction and target classes. |
None
|
lrs
|
Optional[list]
|
Optional list of learning rates to test. If None, defaults are used. |
None
|
use_cache
|
Optional[bool]
|
If True, cached decoder grid results are reused when available under the trainer's experiment_dir. If None, defaults come from trainer training args. |
None
|
split
|
Optional[Any]
|
Dataset split used for training-like decoder evaluation rows.
Defaults to |
'test'
|
max_size
|
Optional[int]
|
Shared evaluation-size alias. If set and explicit decoder caps are omitted, caps both training-like decoder rows and neutral/LMS rows. |
None
|
max_size_training_like
|
Optional[int]
|
Maximum size for generated training-like eval data. |
None
|
max_size_neutral
|
Optional[int]
|
Maximum size for generated neutral eval data (and LMS text cap). |
None
|
eval_batch_size
|
Optional[int]
|
Common eval batch size used for LMS. |
None
|
training_like_df
|
Optional[Any]
|
Optional explicit training-like DataFrame. |
None
|
neutral_df
|
Optional[Any]
|
Optional explicit neutral DataFrame. |
None
|
selector
|
Optional[Any]
|
Optional SelectionPolicy for choosing best candidate per metric (e.g. LMSThresholdPolicy). |
None
|
summary_extractor
|
Optional[Any]
|
Optional callable(results) -> (candidates, ctx). Use to add derived metrics (e.g. bpi, fpi, mpi) to candidates; then pass summary_metrics. |
None
|
summary_metrics
|
Optional[Any]
|
Optional list of metric names to summarize (e.g. ["bpi", "fpi", "mpi"]). |
None
|
target_class
|
Optional[Any]
|
If set (str or list of str), evaluate only for this target class (or classes). Restricts feature factors and datasets for efficiency. When None, evaluates for all target classes. |
None
|
increase_target_probabilities
|
bool
|
If True (default), compute strengthen summaries only (keys e.g. "3SG"). If False, compute weaken summaries only (keys e.g. "3SG_weaken"). Only required combinations are evaluated. |
True
|
plot
|
bool
|
If True, after selection run any missing dataset evaluations for plotting, update cache, then plot. |
False
|
show
|
Optional[bool]
|
If True, display the plot; if False, only save. When None and plot=True, defaults to True. |
None
|
plot_kwargs
|
Optional[Dict[str, Any]]
|
Optional dict of options forwarded to plot_probability_shifts when plot=True. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Flat dict: for strengthen, keys like result['3SG']; for weaken, keys like result['3SG_weaken']. |
Dict[str, Any]
|
Each entry has value, feature_factor, learning_rate, id, strengthen, lms, base_lms. Plus 'grid'. |
Dict[str, Any]
|
When plot=True, also 'plot_paths' and 'plot_path'. |
Source code in gradiend/evaluator/evaluator.py
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 | |
evaluate_encoder
evaluate_encoder(encoder_df=None, eval_data=None, use_cache=None, split=None, max_size=None, **kwargs)
Run encoder evaluation and return encoding/correlation metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_df
|
Optional[Union[Any, Dict[str, Any]]]
|
Optional DataFrame or dict with "encoder_df" key. If provided, skips encoding and computes metrics from this data. Use evaluate_encoder(return_df=True) to get such a dict. |
None
|
eval_data
|
Any
|
Optional pre-computed GradientTrainingDataset. If None and encoder_df is None, the trainer creates eval data via create_eval_data. |
None
|
use_cache
|
Optional[bool]
|
If True, reuse cached JSON result under experiment_dir when available. If None, defaults come from trainer training args. |
None
|
split
|
Optional[str]
|
Dataset split for eval data creation. Default: "test". |
None
|
max_size
|
Optional[int]
|
Maximum samples per variant for eval data creation. |
None
|
**kwargs
|
Any
|
Forwarded to create_eval_data when encoder_df and eval_data are None. |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with keys: correlation, mean_by_class, mean_by_type, n_samples, |
Dict[str, Any]
|
all_data, training_only, target_classes_only, boundaries; optionally |
Dict[str, Any]
|
neutral_mean_by_type, mean_by_feature_class, label_value_to_class_name. |
Source code in gradiend/evaluator/evaluator.py
plot_encoder_by_target
plot_encoder_by_target(encoder_df=None, *, plot_style='strip', title=None, output=None, show=True, figsize=None, jitter=0.25, dodge=True, point_size=1.5, interactive=False, height=520, legend_loc='upper right', highlight_non_convergence=None, **kwargs)
Plot encoder values grouped by target token within feature class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_df
|
Optional[DataFrame]
|
Optional encoder-evaluation DataFrame. |
None
|
plot_style
|
Literal['strip', 'box', 'violin']
|
Plot style: |
'strip'
|
title
|
Optional[str]
|
Optional plot title. |
None
|
output
|
Optional[str]
|
Optional explicit output file path. |
None
|
show
|
bool
|
Whether to display the plot. |
True
|
figsize
|
Optional[Tuple[float, float]]
|
Optional Matplotlib figure size for static plots. |
None
|
jitter
|
float
|
Horizontal jitter for strip points. |
0.25
|
dodge
|
bool
|
If True, separate split hues within each target. |
True
|
point_size
|
float
|
Marker size for strip plots. |
1.5
|
interactive
|
bool
|
If True, create the interactive Plotly strip variant. |
False
|
height
|
int
|
Plotly height in pixels for interactive plots. |
520
|
legend_loc
|
str
|
Static Matplotlib legend location. |
'upper right'
|
highlight_non_convergence
|
Optional[bool]
|
Override non-convergence markers in title. |
None
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to the visualizer. |
{}
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Output path when saved, otherwise visualizer-specific result. |
Source code in gradiend/evaluator/evaluator.py
plot_encoder_distributions
plot_encoder_distributions(encoder_df=None, *, output=None, output_dir=None, show=True, title=True, target_and_neutral_only=True, split_plot_mode='facet', include_neutral=False, figsize=None, img_format='png', dpi=None, highlight_non_convergence=None, return_fig_ax=False, **kwargs)
Plot encoder value distributions for target and optional neutral rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_df
|
Optional[DataFrame]
|
Optional encoder-evaluation DataFrame. When omitted, the visualizer loads or computes the trainer's encoder analysis data. |
None
|
output
|
Optional[str]
|
Optional explicit output file path. |
None
|
output_dir
|
Optional[str]
|
Optional output directory used when |
None
|
show
|
bool
|
Whether to display the figure interactively. |
True
|
title
|
Union[str, bool]
|
Plot title. |
True
|
target_and_neutral_only
|
bool
|
If True, omit identity/auxiliary training rows. |
True
|
split_plot_mode
|
str
|
How split-aware data is shown, e.g. |
'facet'
|
include_neutral
|
bool
|
If True, include neutral evaluation rows when present. |
False
|
figsize
|
Optional[Tuple[float, float]]
|
Optional Matplotlib figure size. |
None
|
img_format
|
str
|
File format used for generated output paths. |
'png'
|
dpi
|
Optional[int]
|
Optional figure DPI. |
None
|
highlight_non_convergence
|
Optional[bool]
|
Override whether non-convergent runs are
marked in titles/labels. |
None
|
return_fig_ax
|
bool
|
If True, return Matplotlib |
False
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to the visualizer. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Visualizer-specific result, usually an output path or |
Source code in gradiend/evaluator/evaluator.py
plot_encoder_scatter
plot_encoder_scatter(encoder_df=None, *, color_by='label', x_col=None, label_name_mapping=None, max_points=None, show=True, title=None, height=500, split='test', highlight_non_convergence=None, **kwargs)
Create an interactive Plotly scatter plot for encoder outlier inspection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_df
|
Optional[DataFrame]
|
Optional encoder-evaluation DataFrame. When omitted, the visualizer loads or computes encoder analysis data. |
None
|
color_by
|
str
|
Column used for point color, commonly |
'label'
|
x_col
|
Optional[str]
|
Column used for the categorical x-axis. |
None
|
label_name_mapping
|
Optional[dict]
|
Optional mapping from raw labels to display names. |
None
|
max_points
|
Optional[int]
|
Optional cap on plotted rows. |
None
|
show
|
bool
|
Whether to display the Plotly figure. |
True
|
title
|
Optional[str]
|
Optional plot title. |
None
|
height
|
int
|
Plot height in pixels. |
500
|
split
|
str
|
Split to evaluate/load when |
'test'
|
highlight_non_convergence
|
Optional[bool]
|
Override non-convergence markers in title. |
None
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to the visualizer. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Visualizer-specific result, typically an HTML path or Plotly figure. |
Source code in gradiend/evaluator/evaluator.py
plot_encoder_strip_by_split
plot_encoder_strip_by_split(encoder_df=None, *, include_neutral=False, title=None, output=None, show=True, figsize=None, jitter=0.08, dodge=True, point_size=5.0, label_points=False, highlight_non_convergence=None, **kwargs)
Plot encoder values as a strip plot grouped by data split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_df
|
Optional[DataFrame]
|
Optional encoder-evaluation DataFrame. |
None
|
include_neutral
|
bool
|
If True, include neutral rows when available. |
False
|
title
|
Optional[str]
|
Optional plot title. |
None
|
output
|
Optional[str]
|
Optional explicit output file path. |
None
|
show
|
bool
|
Whether to display the Matplotlib figure. |
True
|
figsize
|
Optional[Tuple[float, float]]
|
Optional Matplotlib figure size. |
None
|
jitter
|
float
|
Horizontal jitter for points. |
0.08
|
dodge
|
bool
|
If True, separate split hues within each group. |
True
|
point_size
|
float
|
Marker size. |
5.0
|
label_points
|
Union[bool, Literal['outliers', 'outliers+sample', 'sample'], str]
|
Whether and how to label points. Supported values are
visualizer-defined, including |
False
|
highlight_non_convergence
|
Optional[bool]
|
Override non-convergence markers in title. |
None
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to the visualizer. |
{}
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Output path when saved, otherwise visualizer-specific result. |
Source code in gradiend/evaluator/evaluator.py
plot_probability_shifts
plot_probability_shifts(decoder_results=None, class_ids=None, target_class=None, increase_target_probabilities=True, use_cache=None, *, output=None, show=True, figsize=None, highlight_non_convergence=None, return_fig_ax=False, **kwargs)
Plot decoder probability shifts over learning-rate/grid candidates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decoder_results
|
Optional[Dict[str, Any]]
|
Optional result from |
None
|
class_ids
|
Optional[List[str]]
|
Optional class ids to include in the plot. |
None
|
target_class
|
Optional[str]
|
Optional single target class to plot. |
None
|
increase_target_probabilities
|
bool
|
True for strengthen plots, False for weaken plots. |
True
|
use_cache
|
Optional[bool]
|
Whether the visualizer may use cached decoder results. |
None
|
output
|
Optional[str]
|
Optional explicit output file path. |
None
|
show
|
bool
|
Whether to display the Matplotlib figure. |
True
|
figsize
|
Optional[Tuple[float, float]]
|
Optional Matplotlib figure size. |
None
|
highlight_non_convergence
|
Optional[bool]
|
Override non-convergence markers in title. |
None
|
return_fig_ax
|
bool
|
If True, return Matplotlib |
False
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to the visualizer. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Visualizer-specific result, usually an output path or |
Source code in gradiend/evaluator/evaluator.py
plot_training_convergence
plot_training_convergence(*, plot_mean_by_class=True, plot_mean_by_feature_class=None, plot_correlation=True, class_spread=None, output=None, show=True, title=True, figsize=None, img_format='png', dpi=None, highlight_non_convergence=None, return_fig_ax=False, **kwargs)
Plot convergence statistics collected during GRADIEND training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plot_mean_by_class
|
bool
|
Plot mean encoder values by label class. |
True
|
plot_mean_by_feature_class
|
Optional[bool]
|
Plot means grouped by feature class.
|
None
|
plot_correlation
|
bool
|
Plot correlation over training steps. |
True
|
class_spread
|
Optional[Literal['minmax', 'iqr', 'ci95']]
|
Optional spread band behind class means.
|
None
|
output
|
Optional[str]
|
Optional explicit output file path. |
None
|
show
|
bool
|
Whether to display the figure interactively. |
True
|
title
|
Union[str, bool]
|
Plot title. |
True
|
figsize
|
Optional[Tuple[float, float]]
|
Optional Matplotlib figure size. |
None
|
img_format
|
str
|
File format used for generated output paths. |
'png'
|
dpi
|
Optional[int]
|
Optional figure DPI. |
None
|
highlight_non_convergence
|
Optional[bool]
|
Override whether non-convergent runs are
marked in titles/labels. |
None
|
return_fig_ax
|
bool
|
If True, return Matplotlib |
False
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to the visualizer. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Visualizer-specific result, usually an output path or |