NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Demographics Should Not Be the Reason of Toxicity: Mitigating Discrimination in Text Classifications with Instance Weighting

Guanhua Zhang, Bing Bai, Junqi Zhang, Kun Bai, Conghui Zhu, Tiejun Zhao

Abstract

With the recent proliferation of the use of text classifications, researchers have found that there are certain unintended biases in text classification datasets. For example, texts containing some demographic identity-terms (e.g., "gay", "black") are more likely to be abusive in existing abusive language detection datasets. As a result, models trained with these datasets may consider sentences like "She makes me happy to be gay" as abusive simply because of the word "gay." In this paper, we formalize the unintended biases in text classification datasets as a kind of selection bias from the non-discrimination distribution to the discrimination distribution. Based on this formalization, we further propose a model-agnostic debiasing training framework by recovering the non-discrimination distribution using instance weighting, which does not require any extra resources or annotations apart from a pre-defined set of demographic identity-terms. Experiments demonstrate that our method can effectively alleviate the impacts of the unintended biases without significantly hurting models' generalization ability.

Introduction

Machine learning models for text classification—especially toxicity detection—often inherit human prejudices present in their training data. This phenomenon, known as unintended bias, occurs when models unfairly flag sentences containing demographic terms (like "gay" or "black") as abusive. For instance, in many datasets, the word "gay" appears much more frequently in toxic comments than in neutral ones. Consequently, a model might learn to flag a perfectly benign sentence like "She makes me happy to be gay" as abusive simply because of the identity term.

Identity terms and their toxicity rates in the Toxicity Comments dataset.

Existing solutions usually involve expensive data supplementation or data augmentation techniques like swapping gender terms, which can produce nonsensical results (e.g., "He gives birth"). This paper proposes a model-agnostic framework that treats this bias as a statistical selection bias problem and uses instance weighting to recover a "non-discrimination distribution" during training.

Methodology

The authors formalize the problem by defining two distributions:

  • $\hat{\mathcal{D}}$ (Non-discrimination distribution): An ideal world where identity terms ($Z$) are independent of the labels ($Y$).
  • $\mathcal{D}$ (Discrimination distribution): The observed, biased dataset where certain identities are correlated with toxicity.

The transition from $\hat{\mathcal{D}}$ to $\mathcal{D}$ is treated as a selection bias (specifically, "Not Missing at Random" or NMAR). To mitigate this, the authors employ Instance Weighting.

The Instance Weighting Algorithm

  1. Estimate Bias: A simple classifier (e.g., Random Forest) is trained to predict the label $y$ based solely on identity terms $z$ and metadata like sentence length, yielding $P(y|z)$.
  2. Calculate Weights: Every sample in the training set is assigned a weight $w = \frac{Q(y)}{P(y|z)}$, where $Q(y)$ is the prior probability of the label in an ideal distribution.
  3. Debiased Training: The actual toxicity model (e.g., CNN or LSTM) is trained using these weights in the loss function. Samples that are "stereotypically" toxic (high $P(y|z)$) are down-weighted, while "counter-stereotypical" samples are up-weighted.

Experimental Evaluation

The method was evaluated on three major benchmarks: Sexist Tweets (12k tweets), Toxicity Comments (160k Wikipedia comments), and Jigsaw Toxicity (1.8 million comments). Evaluation utilized Identity Phrase Templates Test Sets (IPTTS)—synthetic, neutral sentences like "I am a [identity-term]"—to measure how often models incorrectly flag neutral identity mentions.

Key Results

The weighting method was compared against a baseline (no debiasing) and data-based methods (Swap/Supplement).

  • Bias Reduction: On the Jigsaw dataset, the weighting method reduced the False Positive Equality Difference (FPED) from 3.088 to 0.085—a massive improvement in fairness.
  • Performance Trade-off: While debiasing usually slightly lowers the Area Under the Curve (AUC) on the original biased test set, the weighting method maintained a higher IPTTS AUC (accuracy on neutral identity-based sentences) than data-swapping methods.
Performance and fairness metrics on the Jigsaw Toxicity dataset.

Discussion and Conclusion

Framing social prejudice as a statistical selection bias allows for the use of well-established importance sampling techniques. This approach is model-agnostic and requires no new data, working entirely within the original dataset by adjusting how much the model "cares" about specific examples.

However, the method relies on a pre-defined list of identity terms and assumes that social prejudice doesn't change the marginal distribution of identities ($P(Z) = Q(Z)$). Future work could address more subtle, coded language or intersectional biases that don't rely on specific keywords, and explore applying this "loss recovery" idea to other NLP tasks beyond text classification.

Summary updated

BibTeX
@inproceedings{zhang2020demographics,
  author = {Guanhua Zhang and Bing Bai and Junqi Zhang and Kun Bai and Conghui Zhu and Tiejun Zhao},
  title = {{Demographics Should Not Be the Reason of Toxicity: Mitigating Discrimination in Text Classifications with Instance Weighting}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2020},
  url = {https://openreview.net/forum?id=oW-eg0zATFT},
}
Figure