An Attention-based Framework for Fair Contrastive Learning

Stefan K. Nielsen, Tan M. NguyenarXiv 2024 · DOI

Abstract

Learning unbiased data representations is a critical challenge in machine learning, particularly when dealing with complex or continuous sensitive attributes. This paper introduces FARE (Fairness-Aware Attention), a framework that leverages attention mechanisms to dynamically identify and ignore bias-inducing samples during contrastive learning. To address computational scalability, we propose SparseFARE, which integrates Locality-Sensitive Hashing (LSH) to reduce complexity to $O(b \log b)$. Our approach outperforms existing state-of-the-art methods in both fairness metrics and predictive accuracy across diverse datasets, including ColorMNIST and CelebA.

Introduction

Machine learning models frequently inherit and amplify societal biases present in training data, leading to disparate performance across demographic groups. Fair Representation Learning seeks to mitigate this by producing embeddings that retain task-relevant information while discarding sensitive attributes such as race, gender, or age. Contrastive learning has emerged as a powerful paradigm for this task, yet traditional "fair" variants often rely on restrictive binary assumptions for sensitive attributes. These methods struggle with high-cardinality or continuous attributes (e.g., skin tone or age), often resorting to computationally expensive kernel-based approximations that lack flexibility.

Methodology

The proposed framework introduces two key innovations to overcome these hurdles:

1. FARE: Fairness-Aware Attention

Instead of relying on fixed mathematical kernels to define sample similarity, FARE employs a learned attention mechanism. This allows the model to adaptively weight negative samples in the contrastive loss function. By focusing on "bias-reducing" samples—those that help distinguish objects without relying on sensitive features—and down-weighting "bias-causing" ones, the model learns a more robust and fair representation. This is formalized in the FAREContrast loss function.

2. SparseFARE: Efficient Scalability

Standard attention mechanisms scale quadratically with batch size ($O(b^2)$). To make fair contrastive learning viable for large-scale datasets, we introduce SparseFARE. This variant utilizes Locality-Sensitive Hashing (LSH) to partition samples into "buckets" of similarity.

Overview of the SparseFARE attention mechanism using Locality-Sensitive Hashing (LSH) to group similar samples into buckets for efficient computation.

As illustrated in Figure 1, the model attends within buckets and across neighboring buckets, discarding extreme outliers before attention computation. This optimization reduces complexity to $O(b \log b)$, significantly outperforming previous $O(b^3)$ kernel-based methods.

Experimental Evaluation

We evaluated FARE and SparseFARE on two benchmark datasets:

  • ColorMNIST: A synthetic dataset where digits are overlaid on backgrounds with continuous RGB colors. The objective is to classify the digit while remaining invariant to the background color.
  • CelebA: A large-scale facial attribute dataset. We target "Attractiveness" prediction while treating "Male" and "Young" as protected sensitive attributes.

Results and Discussion

Our experiments demonstrate that FARE effectively breaks the traditional trade-off between fairness and accuracy.

Performance comparison on the ColorMNIST dataset, showing SparseFARE's superior accuracy and bias removal capabilities.

As shown in Figure 2, SparseFARE achieves a state-of-the-art Bias Removal score of 74.0 on ColorMNIST, a significant improvement over the 64.9 achieved by Fair-InfoNCE. Crucially, this fairness gain does not come at the cost of performance; SparseFARE also achieves the highest accuracy (86.4%) among all tested models.

On the more complex CelebA dataset, SparseFARE achieved the best fairness score with an Equalized Odds (EO) of 18.7 (lower is better), surpassing the best kernel-based baseline (20.8) while maintaining competitive classification accuracy.

Conclusion and Future Work

FARE provides a flexible and efficient framework for fair representation learning by treating attention as a learned kernel. By selectively weighting samples, it effectively "bleaches" bias from embeddings. Future research will explore the integration of multi-head attention to capture more nuanced bias interactions and investigate the framework's performance across a broader range of downstream tasks.

Summary updated

BibTeX
@misc{nielsen2024attention,
  author = {Stefan K. Nielsen and Tan M. Nguyen},
  title = {{An Attention-based Framework for Fair Contrastive Learning}},
  year = {2024},
  eprint = {2411.14765},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.14765},
}
Figure