peal.adaptors.clarc.CavProjection

class peal.adaptors.clarc.CavProjection[source]

Bases: Module

Layer that projects the CAV direction out of its input.

Computes x - x cav cav^T + z where z is the projection of the mean non-artifact activation onto the CAV, followed by a ReLU. With a cav_mode the projection coefficient is computed on spatially pooled activations and broadcast over H, W.

Parameters:
  • activations (torch.Tensor) – Shape (N, D) activations used for the clean mean.

  • annotations (torch.Tensor) – Shape (N,); samples with label 0 define the clean mean.

  • cav (torch.Tensor) – CAV, reshaped to (D, 1) and scaled by correction_strength.

  • cav_mode (str, optional) – None (flat input), "cavs_max" or "cavs_mean".

  • correction_strength (float, default 1.0) – Multiplier of the CAV; values other than 1 give a partial correction.

Methods

forward

Project the CAV direction out of x and apply ReLU.

__init__(activations, annotations, cav, cav_mode=None, correction_strength=1.0)[source]
Parameters:
forward(x)[source]

Project the CAV direction out of x and apply ReLU.

Raises:

NotImplementedError – For an unknown cav_mode.