peal.adaptors.clarc¶
Class Artifact Compensation (ClArC) adaptors for removing known shortcuts.
ClArC (Anders et al.) corrects a classifier that relies on an artifact (a spurious “confounder” feature) by estimating a Concept Activation Vector (CAV) for the artifact from group-annotated activations and then either
projecting the artifact direction out of the activations at a chosen layer (
PClArC, optionally followed by fine-tuning the downstream head), orfine-tuning the downstream head with a right-for-the-right-reasons penalty that pushes the input gradient orthogonal to the CAV (
RRClArC).
Both are PEAL adaptors driven by a ClArCConfig: they load a trained
predictor, sweep layer_index x correction_strength, evaluate group
accuracies on the validation (and optionally an unpoisoned test) split, write
one csv per evaluation dataset plus best_model_result.txt into
base_dir and save every corrected model as *.cpl. Module-level helpers
split a model into feature extractor / head and compute pattern or SVM CAVs.
Module attributes
Memo of the CAV estimated for one layer: |
Functions
Dispatch to |
|
Pattern CAV: covariance of activations with the +-1 artifact label. |
|
CAV from the normal of a balanced |
|
Flatten nested |
|
Return the dotted name of the child at 1-based |
|
Split a model into |
Classes
Memo of the CAV estimated for one layer: |
|
Layer that projects the CAV direction out of its input. |
|
Base class of the ClArC adaptors: data setup, sweep loop and evaluation. |
|
Configuration shared by the ClArC adaptors. |
|
Projective ClArC: remove the CAV direction from activations at a layer. |
|
Config of |
|
Right-for-the-right-reasons ClArC. |
|
Config of |
|
Layer that subtracts the mean artifact minus non-artifact activation. |