peal.adaptors.clarc.CavProjection¶
- class peal.adaptors.clarc.CavProjection[source]¶
Bases:
ModuleLayer that projects the CAV direction out of its input.
Computes
x - x cav cav^T + zwherezis the projection of the mean non-artifact activation onto the CAV, followed by a ReLU. With acav_modethe projection coefficient is computed on spatially pooled activations and broadcast overH, 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 bycorrection_strength.cav_mode (
str, optional) – None (flat input),"cavs_max"or"cavs_mean".correction_strength (
float, default1.0) – Multiplier of the CAV; values other than 1 give a partial correction.
Methods
Project the CAV direction out of
xand apply ReLU.- __init__(activations, annotations, cav, cav_mode=None, correction_strength=1.0)[source]¶
- Parameters:
activations (torch.Tensor)
annotations (torch.Tensor)
cav (torch.Tensor)
cav_mode (str)
correction_strength (float)
- forward(x)[source]¶
Project the CAV direction out of
xand apply ReLU.- Raises:
NotImplementedError – For an unknown
cav_mode.