File size: 2,461 Bytes
1fa5a85 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Inference with a compatible classifier
Run commands from a local copy of this repository with the packages listed in requirements.txt. The demo uses synthetic tensors and a deterministic seed. The research numbers in the paper were computed separately on held-out datasets.
The target is a BGE-small, BGE-base or DINOv2-small encoder followed by the study's normalized CLS readout and an affine classifier. Use features.static(backbone, key) to construct the fixed projection and selected channels. Run the shared frozen backbone in evaluation mode and call features.capture(backbone, key, inputs, static_state) to obtain a triple (k, a, s) for each batch. Here k is the projected block input, a holds selected preactivations, and s is the residual stream before final normalization. Keep class IDs aligned between versions.
Each endpoint is expressed relative to that same base in six tensors: inc [r,m], inbias [m], out [m,d], outbias [d], head [C,d], and bias [C]. The reference implementation uses r=48 and m=128. Generic updates outside this family require an adapter. target.init(static_state,C) creates zero residuals and an empty head. target.logits(triple,patch,static_state) evaluates a patch. target.physical(base,key,patch,static_state) writes both internal affine maps into a copy of the base. Keep patch['head'] and patch['bias'] as the classifier, and apply the normalized CLS readout in target.full_logits. Applying the patch to an already edited base would double-count the changes.
~~~python
from inference import Editor
from fixture import example
o,u,st,s,y,f,fy,g,q = example()
patch,anchor = Editor().propose(o,u,st,s,y,f,fy,g)
~~~
The support and validation sets must be disjoint and cover every class. The Boolean vector g identifies the newly emphasized group. The proposed patch is selected on validation before test examples are scored. The predictor is optional for this operation.
The CSV records balanced accuracy and decision agreement as fractions. The paper first averages within each held dataset and then gives all four datasets equal weight. Seeds share test examples. Data sources: [MASSIVE](https://huggingface.co/datasets/AmazonScience/massive), [Banking77](https://huggingface.co/datasets/PolyAI/banking77), [CLINC150](https://github.com/clinc/oos-eval), [Flowers102](https://www.robots.ox.ac.uk/~vgg/data/flowers/102/) and [FGVC-Aircraft](https://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/).
|