ignite icon indicating copy to clipboard operation
ignite copied to clipboard

Add fairness and bias metrics

Open TahaZahid05 opened this issue 9 months ago • 2 comments

🚀 Feature

Description I propose adding fairness metrics to ignite.metrics (or creating a dedicated ignite.metrics.fairness module).

These metrics would accept (y_pred, y, group_labels) as input during the update step. A simple example could be SubgroupAccuracyDifference:

from ignite.metrics import Metric

class SubgroupAccuracyDifference(Metric):
    # Expects predictions, targets, and the subgroup identifier
    required_output_keys = ("y_pred", "y", "group_labels")

    def reset(self):
        self._correct_per_group = {}
        self._total_per_group = {}

    def update(self, output):
        y_pred, y, groups = output[0].detach(), output[1].detach(), output[2].detach()
        # Segment predictions into group buckets...

    def compute(self):
        # Calculate metric per bucket, then return max difference between any two groups...

Other metrics in this suite could include:

  • DemographicParityDifference: Measures the difference in selection rates (positive predictions) between different demographic groups, regardless of the true label.
  • EqualizedOddsDifference: Measures the maximum difference in true positive rates or false positive rates between different subgroups.
  • MaxSubgroupError: Returns the worst-performing metric value across any monitored subgroup (useful for Minimax fairness).

Motivation Currently, Ignite has a ton of great classification and regression metrics, but it doesn't seem to have any metrics designed for evaluating algorithmic fairness or subgroup bias (like measuring accuracy differences between demographic groups or data sources).

In our recent project (SemEval 2026), my team had to track a complex metric called "content effect bias." This required evaluating our model across two overlapping subgroups simultaneously: the logical "validity" of a statement, and the real-world "plausibility" of that statement.

To compute the final metric, we had to slice the predictions into four intersectional subgroups (Valid-Plausible, Valid-Implausible, Invalid-Plausible, Invalid-Implausible) and calculate the difference in both accuracy and confidence scores between those specific slices.

Because we needed to dynamically map predictions to these specific subgroups during the validation epoch, we found that we needed to write custom tracking logic.

Evaluating fairness and subgroup disparities like this is becoming a standard requirement for many ML pipelines. Currently, users have to log all predictions and sensitive features to evaluate disparity metrics using secondary libraries like fairlearn (e.g., fairlearn.metrics.demographic_parity_difference) after the epoch ends. Adding these directly to Ignite would be highly beneficial.

Alternatives Calculating these offline with libraries like fairlearn (which specializes in metrics requiring a sensitive_features argument) or custom scikit-learn wrappers after pulling all the predictions out of the engine. However, this breaks the real-time logging (e.g., to TensorBoard/WandB) that makes Ignite's event system so useful.

Additional Context I already have working PyTorch implementations for some of these from our project. I'd be happy to adapt them to the ignite.metrics.Metric standard, add the DDP support, and open a PR if interested!

TahaZahid05 avatar Mar 01 '26 18:03 TahaZahid05

@TahaZahid05 thanks for proposing these metrics. If you would like to drive this development, it is OK to me.

vfdev-5 avatar Mar 02 '26 10:03 vfdev-5

@vfdev-5 Best! I'll work on it, and would update as necessary.

TahaZahid05 avatar Mar 02 '26 14:03 TahaZahid05