rhscope.probes.logistic

L2-regularized logistic regression probe over pooled activations.

Trained with torch-native L-BFGS; converges quickly for the probe sizes we care about (hidden dims up to ~8k, dataset sizes up to ~50k). The score method returns raw logits; apply metrics.sigmoid to get calibrated-ish probabilities for ECE and Brier.

class rhscope.probes.logistic.LogisticProbe(metadata, *, l2=1.0, max_iter=200)[source]

Bases: Probe

Binary logistic-regression probe with L2 regularization.

Variables:
  • probe_type (ClassVar[str]) – Discriminator used by the Probe registry.

  • l2 – Strength of the L2 penalty on weights (not bias). Recorded in metadata.extra for round-trip.

Parameters:
probe_type: ClassVar[str] = 'logistic'
property weights: Tensor

Learned weight vector of shape (hidden_dim,).

property bias: Tensor

Learned scalar bias stored as a 1-element tensor.

property l2: float

Active L2 penalty coefficient applied to weights during fit.

fit(hack_activations, clean_activations)[source]

Fit the logistic probe with L-BFGS.

Parameters:
  • hack_activations (Tensor) – Shape (N_hack, hidden_dim).

  • clean_activations (Tensor) – Shape (N_clean, hidden_dim).

Raises:

ValueError – If inputs are empty, mis-shaped, or mis-dimensioned.

Return type:

None

score(activations)[source]

Return logits (not probabilities) for each activation.

Parameters:

activations (Tensor) – (N, hidden_dim) or (hidden_dim,).

Returns:

Logit tensor. Apply torch.sigmoid or metrics.sigmoid for probabilities.

Return type:

Tensor

probabilities(activations)[source]

Sigmoid of score - convenience wrapper.

Parameters:

activations (Tensor)

Return type:

Tensor

state_dict()[source]

Return the learned weights and bias tensors.

Return type:

dict[str, Tensor]