Probes
steerability.algorithms.core.internals.probes
Probes: calibrated affine readouts over model internals.
Probe is model-free feature math with canonical polarity (a score at or above zero means
present). fit_probe and calibrate_bias fit and calibrate probes from contrastive pairs;
ProbeSet scores many probes in one read-only forward and returns a ProbeReadings;
ProbeSetFit defers fitting to the model a pipeline provides at steer time.
CalibrationSpec = Literal['max_f1', 'midpoint'] | tuple[Literal['target_fpr'], float]
module-attribute
Probe
dataclass
Calibrated affine readout of a concept from pooled hidden states.
A probe scores pooled per-layer features as sum_l features[l] @ weights[l] + bias, and its
decision is score >= 0 (ties open). Polarity is canonical, i.e., positives score at or
above zero, and the operating threshold is folded into bias at calibration time, so no
comparator or threshold field exists. Weights are stored in raw activation coordinates (any
standardization used during fitting is folded into the weights), so scoring needs no
activation statistics.
The class is model-free feature math. It runs no forwards and registers no hooks; batched
reads over a live model go through ProbeSet.
Attributes:
| Name | Type | Description |
|---|---|---|
model_type |
str
|
HuggingFace |
location |
str
|
Residual-stream boundary the weights were fitted at ( |
pooling |
Literal['mean', 'last']
|
Token aggregation the probe expects ( |
layer_ids |
list[int]
|
Layers whose features the decision function consumes. |
weights |
dict[int, Tensor]
|
Per-layer weight vectors, |
bias |
float
|
Calibrated offset; the decision is |
meta |
dict
|
Provenance record (fit method, sample counts, calibration record, layer sweep, fingerprints, package version, polarity marker). May be empty for hand-constructed probes, which disarms all fingerprint checks. |
Source code in steerability/algorithms/core/internals/probes/probe.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 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 244 245 | |
bias
instance-attribute
layer_ids
instance-attribute
location
instance-attribute
meta = field(default_factory=dict)
class-attribute
instance-attribute
model_type
instance-attribute
pooling
instance-attribute
weights
instance-attribute
as_gate(*, allow_model_mismatch=False)
A steering gate reproducing this probe's decision, for gated interventions.
The gate reads the probe's layers at the probe's pooling, scores each pooled state against the probe's weights, and opens where the summed contributions plus the calibrated bias are at or above zero (ties open). The decision is evaluated on the prompt and holds for the whole generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allow_model_mismatch
|
bool
|
When True, the intervention's model-identity check for this probe is disarmed. |
False
|
Returns:
| Type | Description |
|---|---|
Gate
|
A |
Source code in steerability/algorithms/core/internals/probes/probe.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
decision_function(features)
Signed decision scores for pooled features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Mapping[int, Tensor]
|
Mapping from layer id to pooled features of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Float32 tensor of shape |
Tensor
|
plus |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a layer in |
Source code in steerability/algorithms/core/internals/probes/probe.py
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 | |
load(dir_path)
classmethod
Load a probe saved by save.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_path
|
str | Path
|
Directory containing the safetensors file and JSON sidecar. |
required |
Returns:
| Type | Description |
|---|---|
'Probe'
|
The loaded |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the artifact-format version is unsupported or the recorded polarity marker is not canonical. |
Source code in steerability/algorithms/core/internals/probes/probe.py
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 | |
predict(features)
Boolean decisions for pooled features: decision_function(features) >= 0 (ties open).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Mapping[int, Tensor]
|
Mapping from layer id to pooled features of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Bool tensor of shape |
Source code in steerability/algorithms/core/internals/probes/probe.py
108 109 110 111 112 113 114 115 116 117 | |
save(dir_path)
Save the probe to a directory (safetensors for weights, JSON sidecar for metadata).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_path
|
str | Path
|
Directory to write to; created if missing. |
required |
Source code in steerability/algorithms/core/internals/probes/probe.py
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 | |
score_hidden(hidden, prompt_mask=None)
Pool per-layer hidden states and apply the decision function.
Each layer's [B, T, H] tensor is aggregated to [B, H] per self.pooling using the
mask, so "last" selects the last real (non-pad) token per row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden
|
Mapping[int, Tensor]
|
Mapping from layer id to hidden states of shape |
required |
prompt_mask
|
Tensor | None
|
Attention mask of shape |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Float32 tensor of signed decision scores, shape |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a layer in |
Source code in steerability/algorithms/core/internals/probes/probe.py
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 | |
ProbeEvaluation
dataclass
Held-out scores of a probe on labeled data.
Attributes:
| Name | Type | Description |
|---|---|---|
positive_scores |
Tensor
|
Signed decision scores of the positive class, shape |
negative_scores |
Tensor
|
Signed decision scores of the negative class, shape |
accuracy |
float
|
Fraction correct at the calibrated point ( |
f1 |
float
|
F1 of the same decision. |
Source code in steerability/algorithms/core/internals/probes/fitting.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
accuracy
instance-attribute
f1
instance-attribute
negative_scores
instance-attribute
positive_scores
instance-attribute
ProbeFitSpec
dataclass
Configuration for fitting a Probe from contrastive pairs.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
Literal['lda', 'mean_diff', 'logreg', 'fisher']
|
Direction estimation method. |
pooling |
Literal['mean', 'last']
|
Token aggregation for feature extraction ( |
location |
str
|
Residual-stream boundary features are captured at. |
prompt_format |
PromptFormat
|
How pairs are rendered into model-ready text before tokenization. |
candidate_layers |
Sequence[int] | None
|
Explicit layer ids to sweep. None sweeps all decoder layers, optionally
windowed by |
layer_range |
tuple[float, float] | None
|
Fractional-depth window |
calibration |
CalibrationSpec
|
Operating-point rule folded into the bias (see |
C |
float
|
Inverse regularization strength for |
seed |
int
|
Random seed forwarded to |
Source code in steerability/algorithms/core/internals/probes/fitting.py
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 | |
C = 1.0
class-attribute
instance-attribute
calibration = 'max_f1'
class-attribute
instance-attribute
candidate_layers = None
class-attribute
instance-attribute
layer_range = None
class-attribute
instance-attribute
location = 'layer_input'
class-attribute
instance-attribute
method = 'lda'
class-attribute
instance-attribute
pooling = 'last'
class-attribute
instance-attribute
prompt_format = 'chat_prompt'
class-attribute
instance-attribute
seed = 0
class-attribute
instance-attribute
ProbeReadings
dataclass
One ProbeSet.read() call's result.
Attributes:
| Name | Type | Description |
|---|---|---|
scores |
dict[str, Tensor]
|
Mapping from probe name to signed decision scores, |
decisions |
dict[str, Tensor]
|
Mapping from probe name to boolean decisions, |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
21 22 23 24 25 26 27 28 29 30 31 32 | |
decisions
instance-attribute
scores
instance-attribute
ProbeSet
Named probes scored on a batch of prompts in one read-only forward.
All probes must share one model_type and one capture location, since a single forward
supplies every probe's features. read() registers forward pre-hooks on the union of the
probes' layers (the layer_input boundary), runs one forward, and returns per-probe signed
scores and decisions. The call is self-contained, i.e., it registers no standing hooks and
never edits hidden states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probes
|
Mapping[str, Probe]
|
Mapping from probe name to a fitted |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
probes |
dict[str, Probe]
|
The probes, keyed by name. |
names |
tuple[str, ...]
|
The probe names, in mapping order. |
layer_ids |
list[int]
|
Sorted union of the probes' layers. |
latest |
ProbeReadings | None
|
The most recent |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
latest = None
instance-attribute
layer_ids = sorted({lid for probe in self.probes.values() for lid in probe.layer_ids})
instance-attribute
location
property
The shared capture boundary of the probes.
model_type
property
The shared model_type of the probes.
names = tuple(self.probes)
instance-attribute
probes = dict(probes)
instance-attribute
fit(model, tokenizer, *, data, spec=None, stats=None, calibration_data=None, session=None)
classmethod
Fit one probe per name and return the set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel | None
|
Model the probes are fitted on. |
required |
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer for rendering and encoding the pairs. |
required |
data
|
Mapping[str, ContrastivePairs]
|
Mapping from probe name to the contrastive pairs it is fitted on. |
required |
spec
|
ProbeFitSpec | Mapping[str, ProbeFitSpec] | None
|
A shared |
None
|
stats
|
ActivationStats | None
|
Ambient activation statistics for methods that require them. |
None
|
calibration_data
|
Mapping[str, ContrastivePairs] | None
|
Optional mapping from probe name to calibration pairs. |
None
|
Returns:
| Type | Description |
|---|---|
ProbeSet
|
The fitted |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
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 | |
read(model, input_ids, attention_mask=None, session=None)
Score a batch of prompts against every probe in one read-only forward.
Registers one forward pre-hook per layer in the union (the layer_input boundary, the
only boundary read() serves), runs a single forward under torch.no_grad() with
use_cache=False wrapped in auxiliary_pass(aligned=True), removes the hooks, then
pools each probe's layers per its pooling with the attention mask and applies its
decision function. The auxiliary marking means co-resident state controls' condition
scorers, gates, and position counters ignore the pass, while "all"-scoped behavior
transforms still apply, so scores measure the stream as deployed. A set fitted at
"layer_output" raises, since a pre-hook capture would score features one block away
from where those probes were fitted; score such probes offline via
layerwise_tokenwise_hidden and Probe.score_hidden.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel | None
|
The model to read (must match the probes' |
required |
input_ids
|
Tensor
|
Prompt token ids of shape |
required |
attention_mask
|
Tensor | None
|
Prompt attention mask matching |
None
|
Returns:
| Type | Description |
|---|---|
ProbeReadings
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the model's |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
summary()
Per-probe diagnostic table.
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
Mapping from probe name to a dict with keys |
dict[str, dict]
|
|
dict[str, dict]
|
|
Source code in steerability/algorithms/core/internals/probes/probe_set.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
ProbeSetFit
dataclass
Deferred fitting recipe; holds every fitting input except the model.
fit(model, tokenizer) estimates stats first when it is a StatsSpec, fits one probe
per name, and returns a ProbeSet. RoutedDecoding.steer() calls fit on the model the
pipeline provides, so pipelines whose structural controls produce the final weights fit on
those weights, and ProbeFitSpec fields stay grid-searchable through ControlSpec.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Mapping[str, ContrastivePairs]
|
Mapping from probe name to the contrastive pairs it is fitted on. |
spec |
ProbeFitSpec | Mapping[str, ProbeFitSpec]
|
A shared |
stats |
ActivationStats | StatsSpec | None
|
Ambient activation statistics, or a |
calibration_data |
Mapping[str, ContrastivePairs] | None
|
Optional mapping from probe name to calibration pairs; names absent from the mapping calibrate on their fit pairs. |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 | |
calibration_data = None
class-attribute
instance-attribute
data
instance-attribute
names
property
The probe names, available before fitting so routing rules validate at construction.
spec = field(default_factory=ProbeFitSpec)
class-attribute
instance-attribute
stats = None
class-attribute
instance-attribute
fit(model, tokenizer, session=None)
Fit the recipe on model, resolving a StatsSpec on it first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel | None
|
Model the probes are fitted on. |
required |
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer for rendering and encoding the pairs. |
required |
Returns:
| Type | Description |
|---|---|
ProbeSet
|
The fitted |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
calibrate_bias(pos_scores, neg_scores, calibration='max_f1')
Bias placing the operating point of raw_score + bias >= 0 at the chosen threshold.
The returned bias equals the negated threshold. "midpoint" places the threshold halfway
between the class score means; "max_f1" picks the F1-maximizing threshold over the midpoints
of consecutive distinct observed scores, breaking F1 ties toward the largest symmetric margin
min(pos.min() - t, t - neg.max()) (predictions score >= threshold; a single distinct
observed score is used as the threshold directly);
("target_fpr", x) places it at the (1 - x)-quantile of the negative scores. Calibration
never repairs polarity; inverted inputs raise instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_scores
|
Tensor
|
Raw scores of positive examples, shape |
required |
neg_scores
|
Tensor
|
Raw scores of negative examples, shape |
required |
calibration
|
CalibrationSpec
|
The operating-point rule. |
'max_f1'
|
Returns:
| Type | Description |
|---|---|
float
|
The bias |
Raises:
| Type | Description |
|---|---|
ValueError
|
If either score tensor is empty, |
Source code in steerability/algorithms/core/internals/probes/fitting.py
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 | |
evaluate_probe(probe, model, tokenizer, data, *, prompt_format='raw', batch_size=8, max_length=None, session=None)
Score labeled data against a fitted probe in the probe's recorded space.
Renders data per prompt_format, captures at the probe's location, pools per the probe's
pooling over the probe's layers, and applies probe.decision_function. The probe is not
refitted or recalibrated; the decision uses the probe's calibrated bias, so score >= 0 is
positive at the calibrated point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probe
|
Probe
|
The fitted |
required |
model
|
PreTrainedModel | None
|
Model whose activations are captured, or None when a capture-capable |
required |
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer for rendering and encoding the data. |
required |
data
|
ContrastivePairs | LabeledExamples
|
Contrastive pairs or unpaired labeled examples to score. The positives are scored as the positive class and the negatives as the negative class. |
required |
prompt_format
|
PromptFormat
|
How the data is rendered before tokenization. Must match the format the probe was fitted under for the scores to be comparable. |
'raw'
|
batch_size
|
int
|
Chunk size for feature extraction. |
8
|
max_length
|
int | None
|
Tokenization truncation bound. None truncates to the tokenizer's model maximum. |
None
|
session
|
Optional capture-capable session used in place of a live model. |
None
|
Returns:
| Type | Description |
|---|---|
ProbeEvaluation
|
A |
Source code in steerability/algorithms/core/internals/probes/fitting.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
fit_probe(model, tokenizer, *, data, spec=ProbeFitSpec(), stats=None, calibration_data=None, allow_model_mismatch=False, batch_size=8, max_length=None, session=None)
Fit a calibrated single-layer Probe from contrastive data.
The data is rendered per spec.prompt_format, tokenized, captured at spec.location
(inside auxiliary_pass(aligned=True)), and pooled per spec.pooling. Extraction runs in
chunks of batch_size, pooling each chunk immediately and retaining features only for the
candidate layers, so memory holds pooled [N, H] features rather than per-token states.
Candidate layers are swept; for each, a direction is fitted per spec.method, oriented on
fit-set scores (weights are negated when the mean positive score falls below the mean
negative score, which can occur only for "logreg", since for "mean_diff", "lda", and
"fisher" the fit-set score gap is nonnegative by construction), and the bias is
calibrated via calibrate_bias. The layer with the best F1 at the calibrated point is
kept, with the calibration score gap in pooled within-class standard deviations as
tie-break, and the full sweep is recorded in probe.meta["layer_sweep"].
Calibration scores come from calibration_data when supplied, else from data. The split
lets the contrast be fitted on discriminative pairs while the operating point is calibrated
on a covering set; orientation is never re-evaluated on calibration_data, and a calibration
set whose scores contradict the fit is caught by the inversion raise in calibrate_bias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel | None
|
Model whose activations are captured. |
required |
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer for rendering and encoding the data. |
required |
data
|
ContrastivePairs | LabeledExamples
|
Contrastive pairs or unpaired labeled examples the direction is fitted on.
Unpaired classes require |
required |
spec
|
ProbeFitSpec
|
Fitting configuration. |
ProbeFitSpec()
|
stats
|
ActivationStats | None
|
Ambient activation statistics, required by |
None
|
calibration_data
|
ContrastivePairs | LabeledExamples | None
|
Optional data the operating point is calibrated on. |
None
|
allow_model_mismatch
|
bool
|
When True, a |
False
|
batch_size
|
int
|
Chunk size for feature extraction. |
8
|
max_length
|
int | None
|
Tokenization truncation bound for feature extraction. None truncates to the tokenizer's model maximum length. |
None
|
Returns:
| Type | Description |
|---|---|
Probe
|
A fitted |
Probe
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the method requires |
Source code in steerability/algorithms/core/internals/probes/fitting.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
fitting
Probe fitting: contrastive feature extraction, direction estimation, and bias calibration.
CalibrationSpec = Literal['max_f1', 'midpoint'] | tuple[Literal['target_fpr'], float]
module-attribute
logger = logging.getLogger(__name__)
module-attribute
ProbeEvaluation
dataclass
Held-out scores of a probe on labeled data.
Attributes:
| Name | Type | Description |
|---|---|---|
positive_scores |
Tensor
|
Signed decision scores of the positive class, shape |
negative_scores |
Tensor
|
Signed decision scores of the negative class, shape |
accuracy |
float
|
Fraction correct at the calibrated point ( |
f1 |
float
|
F1 of the same decision. |
Source code in steerability/algorithms/core/internals/probes/fitting.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
accuracy
instance-attribute
f1
instance-attribute
negative_scores
instance-attribute
positive_scores
instance-attribute
ProbeFitSpec
dataclass
Configuration for fitting a Probe from contrastive pairs.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
Literal['lda', 'mean_diff', 'logreg', 'fisher']
|
Direction estimation method. |
pooling |
Literal['mean', 'last']
|
Token aggregation for feature extraction ( |
location |
str
|
Residual-stream boundary features are captured at. |
prompt_format |
PromptFormat
|
How pairs are rendered into model-ready text before tokenization. |
candidate_layers |
Sequence[int] | None
|
Explicit layer ids to sweep. None sweeps all decoder layers, optionally
windowed by |
layer_range |
tuple[float, float] | None
|
Fractional-depth window |
calibration |
CalibrationSpec
|
Operating-point rule folded into the bias (see |
C |
float
|
Inverse regularization strength for |
seed |
int
|
Random seed forwarded to |
Source code in steerability/algorithms/core/internals/probes/fitting.py
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 | |
C = 1.0
class-attribute
instance-attribute
calibration = 'max_f1'
class-attribute
instance-attribute
candidate_layers = None
class-attribute
instance-attribute
layer_range = None
class-attribute
instance-attribute
location = 'layer_input'
class-attribute
instance-attribute
method = 'lda'
class-attribute
instance-attribute
pooling = 'last'
class-attribute
instance-attribute
prompt_format = 'chat_prompt'
class-attribute
instance-attribute
seed = 0
class-attribute
instance-attribute
calibrate_bias(pos_scores, neg_scores, calibration='max_f1')
Bias placing the operating point of raw_score + bias >= 0 at the chosen threshold.
The returned bias equals the negated threshold. "midpoint" places the threshold halfway
between the class score means; "max_f1" picks the F1-maximizing threshold over the midpoints
of consecutive distinct observed scores, breaking F1 ties toward the largest symmetric margin
min(pos.min() - t, t - neg.max()) (predictions score >= threshold; a single distinct
observed score is used as the threshold directly);
("target_fpr", x) places it at the (1 - x)-quantile of the negative scores. Calibration
never repairs polarity; inverted inputs raise instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos_scores
|
Tensor
|
Raw scores of positive examples, shape |
required |
neg_scores
|
Tensor
|
Raw scores of negative examples, shape |
required |
calibration
|
CalibrationSpec
|
The operating-point rule. |
'max_f1'
|
Returns:
| Type | Description |
|---|---|
float
|
The bias |
Raises:
| Type | Description |
|---|---|
ValueError
|
If either score tensor is empty, |
Source code in steerability/algorithms/core/internals/probes/fitting.py
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 | |
evaluate_probe(probe, model, tokenizer, data, *, prompt_format='raw', batch_size=8, max_length=None, session=None)
Score labeled data against a fitted probe in the probe's recorded space.
Renders data per prompt_format, captures at the probe's location, pools per the probe's
pooling over the probe's layers, and applies probe.decision_function. The probe is not
refitted or recalibrated; the decision uses the probe's calibrated bias, so score >= 0 is
positive at the calibrated point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probe
|
Probe
|
The fitted |
required |
model
|
PreTrainedModel | None
|
Model whose activations are captured, or None when a capture-capable |
required |
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer for rendering and encoding the data. |
required |
data
|
ContrastivePairs | LabeledExamples
|
Contrastive pairs or unpaired labeled examples to score. The positives are scored as the positive class and the negatives as the negative class. |
required |
prompt_format
|
PromptFormat
|
How the data is rendered before tokenization. Must match the format the probe was fitted under for the scores to be comparable. |
'raw'
|
batch_size
|
int
|
Chunk size for feature extraction. |
8
|
max_length
|
int | None
|
Tokenization truncation bound. None truncates to the tokenizer's model maximum. |
None
|
session
|
Optional capture-capable session used in place of a live model. |
None
|
Returns:
| Type | Description |
|---|---|
ProbeEvaluation
|
A |
Source code in steerability/algorithms/core/internals/probes/fitting.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
fit_probe(model, tokenizer, *, data, spec=ProbeFitSpec(), stats=None, calibration_data=None, allow_model_mismatch=False, batch_size=8, max_length=None, session=None)
Fit a calibrated single-layer Probe from contrastive data.
The data is rendered per spec.prompt_format, tokenized, captured at spec.location
(inside auxiliary_pass(aligned=True)), and pooled per spec.pooling. Extraction runs in
chunks of batch_size, pooling each chunk immediately and retaining features only for the
candidate layers, so memory holds pooled [N, H] features rather than per-token states.
Candidate layers are swept; for each, a direction is fitted per spec.method, oriented on
fit-set scores (weights are negated when the mean positive score falls below the mean
negative score, which can occur only for "logreg", since for "mean_diff", "lda", and
"fisher" the fit-set score gap is nonnegative by construction), and the bias is
calibrated via calibrate_bias. The layer with the best F1 at the calibrated point is
kept, with the calibration score gap in pooled within-class standard deviations as
tie-break, and the full sweep is recorded in probe.meta["layer_sweep"].
Calibration scores come from calibration_data when supplied, else from data. The split
lets the contrast be fitted on discriminative pairs while the operating point is calibrated
on a covering set; orientation is never re-evaluated on calibration_data, and a calibration
set whose scores contradict the fit is caught by the inversion raise in calibrate_bias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel | None
|
Model whose activations are captured. |
required |
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer for rendering and encoding the data. |
required |
data
|
ContrastivePairs | LabeledExamples
|
Contrastive pairs or unpaired labeled examples the direction is fitted on.
Unpaired classes require |
required |
spec
|
ProbeFitSpec
|
Fitting configuration. |
ProbeFitSpec()
|
stats
|
ActivationStats | None
|
Ambient activation statistics, required by |
None
|
calibration_data
|
ContrastivePairs | LabeledExamples | None
|
Optional data the operating point is calibrated on. |
None
|
allow_model_mismatch
|
bool
|
When True, a |
False
|
batch_size
|
int
|
Chunk size for feature extraction. |
8
|
max_length
|
int | None
|
Tokenization truncation bound for feature extraction. None truncates to the tokenizer's model maximum length. |
None
|
Returns:
| Type | Description |
|---|---|
Probe
|
A fitted |
Probe
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the method requires |
Source code in steerability/algorithms/core/internals/probes/fitting.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
probe
A calibrated linear probe on the pooled hidden states with scores oriented in a consistent direction.
POLARITY_MARKER = 'positives_high'
module-attribute
PROBE_FORMAT_VERSION = 1
module-attribute
logger = logging.getLogger(__name__)
module-attribute
Probe
dataclass
Calibrated affine readout of a concept from pooled hidden states.
A probe scores pooled per-layer features as sum_l features[l] @ weights[l] + bias, and its
decision is score >= 0 (ties open). Polarity is canonical, i.e., positives score at or
above zero, and the operating threshold is folded into bias at calibration time, so no
comparator or threshold field exists. Weights are stored in raw activation coordinates (any
standardization used during fitting is folded into the weights), so scoring needs no
activation statistics.
The class is model-free feature math. It runs no forwards and registers no hooks; batched
reads over a live model go through ProbeSet.
Attributes:
| Name | Type | Description |
|---|---|---|
model_type |
str
|
HuggingFace |
location |
str
|
Residual-stream boundary the weights were fitted at ( |
pooling |
Literal['mean', 'last']
|
Token aggregation the probe expects ( |
layer_ids |
list[int]
|
Layers whose features the decision function consumes. |
weights |
dict[int, Tensor]
|
Per-layer weight vectors, |
bias |
float
|
Calibrated offset; the decision is |
meta |
dict
|
Provenance record (fit method, sample counts, calibration record, layer sweep, fingerprints, package version, polarity marker). May be empty for hand-constructed probes, which disarms all fingerprint checks. |
Source code in steerability/algorithms/core/internals/probes/probe.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 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 244 245 | |
bias
instance-attribute
layer_ids
instance-attribute
location
instance-attribute
meta = field(default_factory=dict)
class-attribute
instance-attribute
model_type
instance-attribute
pooling
instance-attribute
weights
instance-attribute
as_gate(*, allow_model_mismatch=False)
A steering gate reproducing this probe's decision, for gated interventions.
The gate reads the probe's layers at the probe's pooling, scores each pooled state against the probe's weights, and opens where the summed contributions plus the calibrated bias are at or above zero (ties open). The decision is evaluated on the prompt and holds for the whole generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allow_model_mismatch
|
bool
|
When True, the intervention's model-identity check for this probe is disarmed. |
False
|
Returns:
| Type | Description |
|---|---|
Gate
|
A |
Source code in steerability/algorithms/core/internals/probes/probe.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
decision_function(features)
Signed decision scores for pooled features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Mapping[int, Tensor]
|
Mapping from layer id to pooled features of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Float32 tensor of shape |
Tensor
|
plus |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a layer in |
Source code in steerability/algorithms/core/internals/probes/probe.py
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 | |
load(dir_path)
classmethod
Load a probe saved by save.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_path
|
str | Path
|
Directory containing the safetensors file and JSON sidecar. |
required |
Returns:
| Type | Description |
|---|---|
'Probe'
|
The loaded |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the artifact-format version is unsupported or the recorded polarity marker is not canonical. |
Source code in steerability/algorithms/core/internals/probes/probe.py
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 | |
predict(features)
Boolean decisions for pooled features: decision_function(features) >= 0 (ties open).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Mapping[int, Tensor]
|
Mapping from layer id to pooled features of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Bool tensor of shape |
Source code in steerability/algorithms/core/internals/probes/probe.py
108 109 110 111 112 113 114 115 116 117 | |
save(dir_path)
Save the probe to a directory (safetensors for weights, JSON sidecar for metadata).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_path
|
str | Path
|
Directory to write to; created if missing. |
required |
Source code in steerability/algorithms/core/internals/probes/probe.py
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 | |
score_hidden(hidden, prompt_mask=None)
Pool per-layer hidden states and apply the decision function.
Each layer's [B, T, H] tensor is aggregated to [B, H] per self.pooling using the
mask, so "last" selects the last real (non-pad) token per row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden
|
Mapping[int, Tensor]
|
Mapping from layer id to hidden states of shape |
required |
prompt_mask
|
Tensor | None
|
Attention mask of shape |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Float32 tensor of signed decision scores, shape |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a layer in |
Source code in steerability/algorithms/core/internals/probes/probe.py
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 | |
probe_set
Score all probes in a batch with a read-only forward pass.
logger = logging.getLogger(__name__)
module-attribute
ProbeReadings
dataclass
One ProbeSet.read() call's result.
Attributes:
| Name | Type | Description |
|---|---|---|
scores |
dict[str, Tensor]
|
Mapping from probe name to signed decision scores, |
decisions |
dict[str, Tensor]
|
Mapping from probe name to boolean decisions, |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
21 22 23 24 25 26 27 28 29 30 31 32 | |
decisions
instance-attribute
scores
instance-attribute
ProbeSet
Named probes scored on a batch of prompts in one read-only forward.
All probes must share one model_type and one capture location, since a single forward
supplies every probe's features. read() registers forward pre-hooks on the union of the
probes' layers (the layer_input boundary), runs one forward, and returns per-probe signed
scores and decisions. The call is self-contained, i.e., it registers no standing hooks and
never edits hidden states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probes
|
Mapping[str, Probe]
|
Mapping from probe name to a fitted |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
probes |
dict[str, Probe]
|
The probes, keyed by name. |
names |
tuple[str, ...]
|
The probe names, in mapping order. |
layer_ids |
list[int]
|
Sorted union of the probes' layers. |
latest |
ProbeReadings | None
|
The most recent |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
latest = None
instance-attribute
layer_ids = sorted({lid for probe in self.probes.values() for lid in probe.layer_ids})
instance-attribute
location
property
The shared capture boundary of the probes.
model_type
property
The shared model_type of the probes.
names = tuple(self.probes)
instance-attribute
probes = dict(probes)
instance-attribute
fit(model, tokenizer, *, data, spec=None, stats=None, calibration_data=None, session=None)
classmethod
Fit one probe per name and return the set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel | None
|
Model the probes are fitted on. |
required |
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer for rendering and encoding the pairs. |
required |
data
|
Mapping[str, ContrastivePairs]
|
Mapping from probe name to the contrastive pairs it is fitted on. |
required |
spec
|
ProbeFitSpec | Mapping[str, ProbeFitSpec] | None
|
A shared |
None
|
stats
|
ActivationStats | None
|
Ambient activation statistics for methods that require them. |
None
|
calibration_data
|
Mapping[str, ContrastivePairs] | None
|
Optional mapping from probe name to calibration pairs. |
None
|
Returns:
| Type | Description |
|---|---|
ProbeSet
|
The fitted |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
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 | |
read(model, input_ids, attention_mask=None, session=None)
Score a batch of prompts against every probe in one read-only forward.
Registers one forward pre-hook per layer in the union (the layer_input boundary, the
only boundary read() serves), runs a single forward under torch.no_grad() with
use_cache=False wrapped in auxiliary_pass(aligned=True), removes the hooks, then
pools each probe's layers per its pooling with the attention mask and applies its
decision function. The auxiliary marking means co-resident state controls' condition
scorers, gates, and position counters ignore the pass, while "all"-scoped behavior
transforms still apply, so scores measure the stream as deployed. A set fitted at
"layer_output" raises, since a pre-hook capture would score features one block away
from where those probes were fitted; score such probes offline via
layerwise_tokenwise_hidden and Probe.score_hidden.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel | None
|
The model to read (must match the probes' |
required |
input_ids
|
Tensor
|
Prompt token ids of shape |
required |
attention_mask
|
Tensor | None
|
Prompt attention mask matching |
None
|
Returns:
| Type | Description |
|---|---|
ProbeReadings
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the model's |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
summary()
Per-probe diagnostic table.
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
Mapping from probe name to a dict with keys |
dict[str, dict]
|
|
dict[str, dict]
|
|
Source code in steerability/algorithms/core/internals/probes/probe_set.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
ProbeSetFit
dataclass
Deferred fitting recipe; holds every fitting input except the model.
fit(model, tokenizer) estimates stats first when it is a StatsSpec, fits one probe
per name, and returns a ProbeSet. RoutedDecoding.steer() calls fit on the model the
pipeline provides, so pipelines whose structural controls produce the final weights fit on
those weights, and ProbeFitSpec fields stay grid-searchable through ControlSpec.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Mapping[str, ContrastivePairs]
|
Mapping from probe name to the contrastive pairs it is fitted on. |
spec |
ProbeFitSpec | Mapping[str, ProbeFitSpec]
|
A shared |
stats |
ActivationStats | StatsSpec | None
|
Ambient activation statistics, or a |
calibration_data |
Mapping[str, ContrastivePairs] | None
|
Optional mapping from probe name to calibration pairs; names absent from the mapping calibrate on their fit pairs. |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 | |
calibration_data = None
class-attribute
instance-attribute
data
instance-attribute
names
property
The probe names, available before fitting so routing rules validate at construction.
spec = field(default_factory=ProbeFitSpec)
class-attribute
instance-attribute
stats = None
class-attribute
instance-attribute
fit(model, tokenizer, session=None)
Fit the recipe on model, resolving a StatsSpec on it first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel | None
|
Model the probes are fitted on. |
required |
tokenizer
|
PreTrainedTokenizerBase
|
Tokenizer for rendering and encoding the pairs. |
required |
Returns:
| Type | Description |
|---|---|
ProbeSet
|
The fitted |
Source code in steerability/algorithms/core/internals/probes/probe_set.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |