rhscope.probes.mlp

Shallow MLP probe for cases where the hacking concept is not linearly separable.

Linear probes (DoMProbe and LogisticProbe) are the right default because they are cheap, easy to analyse, and work surprisingly well for the kinds of concepts rhscope targets. But a small two-layer MLP is a strictly stronger baseline worth having on hand - reviewers consistently ask for it, and on some hacking patterns that depend on non-linear feature combinations it outperforms the linear baselines by a meaningful margin. When it does not beat the linear probe, that is itself a useful observation.

The probe is a single hidden layer with tanh nonlinearity followed by a linear head. Trained with Adam + early stopping on an internal validation split carved from the fit input. Weight tensors are persisted via state_dict() and round-trip through the same SafeTensors loader as the linear probes.

class rhscope.probes.mlp.MLPProbe(metadata, *, hidden_size=None, l2=None, lr=0.001, max_epochs=200, patience=15)[source]

Bases: Probe

Binary classifier with one hidden tanh layer.

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

  • hidden_size – Width of the hidden layer. Recorded in metadata.extra for round-trip.

  • l2 – L2 penalty applied to the weight matrices (not biases).

  • lr – Adam learning rate.

  • max_epochs – Hard cap on training epochs; early stopping usually stops sooner.

  • patience – Epochs to wait for validation AUROC improvement before stopping.

Parameters:
probe_type: ClassVar[str] = 'mlp'
property hidden_size: int

Width of the hidden layer.

property l2: float

L2 penalty strength.

fit(hack_activations, clean_activations)[source]

Fit the MLP probe with Adam and internal early stopping.

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

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

Raises:

ValueError – If inputs are empty or mis-shaped.

Return type:

None

score(activations)[source]

Return pre-sigmoid logits for each activation row.

Parameters:

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

Return type:

Tensor

probabilities(activations)[source]

Sigmoid of score().

Parameters:

activations (Tensor)

Return type:

Tensor

state_dict()[source]

Return all four learned tensors keyed for SafeTensors persistence.

Return type:

dict[str, Tensor]