A Practical Method for Generating String Counterfactuals

Matan Avitan, Ryan Cotterell, Yoav Goldberg, Shauli Ravfogel

Introduction

In the field of AI interpretability, "representation surgery" has emerged as a powerful technique for modifying a model's internal state to steer or erase specific concepts, such as gender or sentiment. However, these interventions typically occur within a high-dimensional "black box" of embedding vectors. Without a mechanism to translate these modified vectors back into natural language, researchers remain "blind" to the semantic nuances of their interventions. This paper introduces a "counterfactual lens" that bridges this gap by inverting surgically altered representations into readable text.

Methodology: The Counterfactual Lens

The proposed pipeline integrates two distinct processes: Representation Surgery and Representation Inversion.

1. Representation Surgery

The authors employ three primary techniques to manipulate the internal vectors:

  • LEACE: A linear erasure method designed to remove all information about a target concept from the representation.
  • MiMiC: A method that shifts a representation from one class (e.g., Male) to another (e.g., Female) by matching the statistical moments of the target group.
  • MiMiC+: An extension that pushes representations further toward the target group's centroid to ensure a more definitive conceptual shift.

2. Representation Inversion (Vec2Text)

To transform these modified vectors back into strings, the researchers utilize a Vec2Text approach. They train a dedicated inversion model (based on GTR-base) that iteratively refines a text string until its embedding closely matches the target modified vector.

The Counterfactual Lens Pipeline: Encoding a source string, performing representation surgery on the vector, and inverting the result back into a counterfactual string.

Experimental Setup

The primary evaluation is conducted on the BiasBios dataset, which consists of professional biographies annotated with gender and profession. This dataset serves as a benchmark for analyzing how gendered language influences career classification.

Insights: Surfacing Hidden Stereotypes

The "counterfactual lens" reveals that a model's internal concept of gender is deeply entangled with professional identity. When steering a male doctor's biography toward a female representation, the model does more than swap pronouns; it often alters professional titles (e.g., changing "Dr." to "Ms.") or introduces stereotypically feminine descriptors.

By analyzing Pointwise Mutual Information (PMI), the authors identified words most likely to appear after an intervention. Shifting toward "Female" increased the prevalence of words like "maternal," "domestic," and "nurturing," even when absent from the original text. This demonstrates that the lens can act as a "meta-interpretability" tool, exposing the latent biases inherent in the model's representation space.

Results and Bias Mitigation

The generated counterfactuals were evaluated for fluency and effectiveness. Perplexity scores indicated that the reconstructed text was as fluent as, or even more fluent than, the original biographies. Human evaluation confirmed that MiMiC (M → F) interventions successfully changed the perceived gender in 86% of cases.

Crucially, these string counterfactuals were used for Data Augmentation. By training classifiers on a combination of original and counterfactual biographies, the researchers significantly reduced algorithmic bias.

Bias Mitigation Results: Performance metrics for career classification across different data settings, showing the reduction in gender gap.

As shown in the table above, the True Positive Rate (TPR) Gender Gap—a key measure of unfairness—was reduced from 14.27 to 10.59 using MiMiC+ counterfactuals, while maintaining high overall accuracy and F1 scores.

Conclusion and Limitations

While the "counterfactual lens" provides a powerful tool for transparency, the authors note limitations such as "inversion noise," where the Vec2Text process occasionally alters unrelated details like dates or locations. Additionally, the current study focuses on binary gender labels, which does not capture the full spectrum of gender identity. Future work aims to extend this method to non-binary attributes and more complex stylistic concepts.

Summary updated

BibTeX
@inproceedings{avitan2025practical,
  author = {Matan Avitan and Ryan Cotterell and Yoav Goldberg and Shauli Ravfogel},
  title = {{A Practical Method for Generating String Counterfactuals}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.findings-naacl.180},
}
Figure