Skip to the content.

Learning Fair Representations (LFR)

Overview

Learning Fair Representations (LFR) is a preprocessing technique for achieving fairness in machine learning models. It works by transforming the original input features into a new representation that preserves the information needed for the main prediction task while removing information about sensitive attributes.

What Problem Does It Solve?

LFR addresses the challenge of creating fair classifiers by learning a new representation of the data that:

  1. Encodes the training data as well as possible;
  2. Obfuscates information about protected attributes;
  3. Preserves enough information to predict the target variable accurately.

This approach allows any standard machine learning algorithm to be applied to the transformed data without explicitly incorporating fairness constraints.

Key Concepts

How It Works

  1. Neural Network Architecture:
    • Encoder: Transforms input features into a fair latent representation;
    • Decoder: Reconstructs original features from the latent representation;
    • Classifier: Predicts the target variable from the latent representation.
  2. Training Process:
    • The model is trained to minimize a weighted combination of three losses:
      • Reconstruction loss: Measures how well the original features can be reconstructed;
      • Fairness loss: Measures statistical disparity between protected groups in the latent space;
      • Classification loss: Measures prediction accuracy on the target variable.
  3. Hyperparameters:
    • alpha_x: Weight for the reconstruction loss component;
    • alpha_y: Weight for the classification loss component;
    • alpha_z: Weight for the fairness loss component;
    • latent_dim: Dimension of the fair representation (smaller than input dimension).

Implementation Details

The FairLib implementation uses PyTorch and includes:

Usage Example

import torch
from fairlib.preprocessing.lfr import LFR
from sklearn.model_selection import train_test_split

dataset, X_train, X_test, y_train, y_test = ...

# Initialize LFR model
lfr = LFR(
    input_dim=dataset.shape[1],  # Number of input features
    latent_dim=8,                # Dimension of fair representation
    output_dim=dataset.shape[1], # Same as input for reconstruction
    alpha_z=1.0,                 # Weight for fairness loss
    alpha_x=1.0,                 # Weight for reconstruction loss
    alpha_y=1.0                  # Weight for classification loss
)

# Train the model
lfr.fit(dataset, epochs=100)

# Transform data to fair representation
X_train_fair = lfr.transform(X_train)
X_test_fair = lfr.transform(X_test)

# Use transformed data with any classifier
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression()
clf.fit(X_train_fair, y_train)
predictions = clf.predict(X_test_fair)

Advantages and Limitations

Advantages

Limitations

References

R. Zemel, Y. Wu, K. Swersky, T. Pitassi, and C. Dwork, “Learning Fair Representations.” International Conference on Machine Learning, 2013.