peal.adaptors.clarc.PClArC

class peal.adaptors.clarc.PClArC[source]

Bases: ClArC

Projective ClArC: remove the CAV direction from activations at a layer.

Inserts a CavProjection (or SimpleProjection) between the feature extractor and the downstream head, optionally fine-tunes the head with SGD on cross entropy, and saves the corrected nn.Sequential.

Parameters:

adaptor_config (PClArCConfig) – See PClArCConfig.

Methods

finetune

Fine-tune the head behind a frozen projection with cross entropy.

get_evaluation_filename

Build correction_<dataset>-dataset_<labels>_<proj>...csv.

run

Run the sweep of ClArC.run(); extra arguments are ignored.

__init__(adaptor_config)[source]
Parameters:

adaptor_config (PClArCConfig)

get_evaluation_filename(dataset_name)[source]

Build correction_<dataset>-dataset_<labels>_<proj>...csv.

Parameters:

dataset_name (str)

Return type:

str

run(*args, **kwargs)[source]

Run the sweep of ClArC.run(); extra arguments are ignored.

finetune(projection_layer, downstream_head, feature_extractor=None)[source]

Fine-tune the head behind a frozen projection with cross entropy.

Parameters:
  • projection_layer (torch.nn.Module) – Frozen CAV projection.

  • downstream_head (torch.nn.Module) – Part of the model that is trained (SGD, momentum 0.9, weight decay 1e-4, training.learning_rate).

  • feature_extractor (torch.nn.Module, optional) – Frozen prefix; None when projecting at the input.

Returns:

  • best_model (torch.nn.Module) – Deep copy of the head with the best validation avg_group_acc.

  • number_epochs_trained (int) – Epoch at which that best head was found (0 = untouched head).

Return type:

(torch.nn.Module, <class ‘int’>)

Notes

Temporarily lifts the class restriction of the train loader and re-enables it afterwards; a failing backward pass returns early.