Exploring and Leveraging Class Vectors for Classifier Editing

Jaeik Kim, Jaeyoung Do

Abstract

Modern deep learning models are often "rigid," making post-training modifications difficult without extensive retraining or risking collateral damage to unrelated knowledge. This paper explores Class Vectors, a simple yet powerful mechanism for "editing" image classifiers. By capturing how specific classes shift in a model's latent space during fine-tuning, these vectors allow for surgical operations—such as unlearning specific categories or adapting to environmental noise—using basic vector arithmetic. We demonstrate that Class Vectors provide a highly efficient, training-free or low-parameter alternative to traditional model editing, maintaining high performance across diverse benchmarks including ImageNet, EuroSAT, and BERT-based NLP tasks.

1. Introduction

Once a Vision Transformer (ViT) or a ResNet is fully trained, altering its behavior typically requires significant resources. If a model consistently misidentifies objects under specific conditions (e.g., buses as snowplows in winter) or needs to "forget" a class for privacy reasons, practitioners are often forced to choose between expensive retraining or complex model editing tools that may not generalize well to visual data.

The core challenge lies in modifying individual classes without causing "collateral damage" to the rest of the model's knowledge. While "task vectors" have been used to modify entire tasks, they lack the granularity required for class-level interventions. This work introduces Class Vectors to bridge this gap.

2. Methodology

The fundamental innovation is the Class Vector ($\kappa_c$), which represents the semantic shift of a specific class between two states of a model.

2.1 Definition and Arithmetic

A Class Vector is calculated as the difference between the average representation (centroid) of a class in a fine-tuned model versus its representation in a pre-trained model. Because these vectors represent specific semantic shifts, they can be manipulated using arithmetic:

  • Unlearning: To remove a class's influence, one can subtract its corresponding Class Vector.
  • Environmental Adaptation: To adapt to a new environment (e.g., snow), a "noise" vector can be calculated and subtracted from the representation to "see through" the environmental interference.

2.2 Editing Modes

The authors propose two primary modes for applying these edits:

  1. Latent-space Injection: A training-free approach where internal features are steered during inference.
  2. Weight-space Mapping: A permanent modification where a tiny fraction of the model's parameters (e.g., LayerNorm or final MLP layers) are trained to bake the edit into the weights. This process is remarkably efficient, often completing in under 1.5 seconds using a single data sample.

3. Theoretical Foundations

The effectiveness of Class Vectors relies on two key observations:

  • Linearity of Learning: Fine-tuning often follows surprisingly linear paths in latent space, allowing model behavior to be "slid" along a vector with predictable results.
  • Neural Collapse: In deep models, class representations tend to become nearly orthogonal. This independence allows for the modification of one class vector without significantly impacting others, ensuring surgical precision.

4. Experimental Evaluation

The approach was validated across a broad spectrum of benchmarks:

  • Standard Classification: MNIST, EuroSAT, GTSRB, RESISC45, DTD, and SVHN.
  • Robustness and Attacks: Snowy ImageNet for environmental adaptation and typography attacks (e.g., misleading text labels on images).
  • Cross-Modal Application: The method was also tested on NLP tasks (AG-NEWS, DBPedia-14) using BERT-Base, confirming its utility beyond computer vision.

5. Key Results

  • Surgical Unlearning: Class Vectors achieved near 0% accuracy on targeted "forgotten" classes while maintaining over 90% accuracy on the remaining classes, outperforming standard gradient ascent (NegGrad) methods.
  • Robustness: In snowy scenes, the method provided a 10–20% accuracy boost by effectively subtracting the "snow" component from image features.
  • Defense: The method successfully neutralized typography attacks, restoring model accuracy to clean-image levels.
  • Efficiency: Weight-space mapping proved to be orders of magnitude faster than traditional retraining, requiring only ~1.5K parameters and completing in under 1.5 seconds.

6. Discussion and Limitations

While powerful, the Class Vector approach assumes that class representations are well-structured and linearly separable. It may face challenges with high intra-class variance or extremely long-tailed distributions. Additionally, the current framework focuses on single-label classification; extending this to multi-label or hierarchical contexts remains an open area for research. Finally, weight-mapping requires access to internal model layers, which may limit its application in restricted "black-box" API environments.

7. Conclusion

Class Vectors offer a promising path toward efficient and precise model editing. By leveraging the linear properties of latent spaces and the phenomenon of neural collapse, researchers can now perform complex behavioral adjustments with the simplicity of vector arithmetic. Future work will explore the application of these techniques to Generative AI and Large Language Models (LLMs) to steer content generation.

Summary updated

BibTeX
@inproceedings{kim2025exploring,
  author = {Jaeik Kim and Jaeyoung Do},
  title = {{Exploring and Leveraging Class Vectors for Classifier Editing}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=jWrDyknUZ8},
}
Figure