Evaluates whether a zero-shot prompting method (OOC) improves stratified invariance and counterfactual invariance in LLM text classification predictions across real-world and synthetic datasets, while measuring retention of predictive accuracy. Use when the user wants to benchmark on civilcomments (Toxic Comments), Bios (Occupation), Amazon Fashion Reviews, Discrimination (Synthetic), MIMIC-III/SBDH (Clinical), Semantic Leakage Tasks, or asks about evaluating this task. Reports SI-bias.
Installs into .claude/skills of the current project.
Are you the author of Test Time Fairness Eval?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-test-time-fairness-eval)
---
name: test-time-fairness-eval
description: Evaluates whether a zero-shot prompting method (OOC) improves stratified invariance and counterfactual invariance in LLM text classification predictions across real-world and synthetic datasets, while measuring retention of predictive accuracy. Use when the user wants to benchmark on civilcomments (Toxic Comments), Bios (Occupation), Amazon Fashion Reviews, Discrimination (Synthetic), MIMIC-III/SBDH (Clinical), Semantic Leakage Tasks, or asks about evaluating this task. Reports SI-bias.
metadata:
skill_kind: dataset_eval
source_arxiv: 2406.07685
bibtex_key: cotta2024testtimefairness
confidence: high
---
# test-time-fairness-eval
> Test-Time Fairness and Robustness in Large Language Models — Cotta et al. (2024) (arXiv:2406.07685, 2024)
## What this evaluates
Evaluates whether a zero-shot prompting method (OOC) improves stratified invariance and counterfactual invariance in LLM text classification predictions across real-world and synthetic datasets, while measuring retention of predictive accuracy.
## Datasets
- **civilcomments (Toxic Comments)** — total ?; splits: test (-1)
- **Bios (Occupation)** — total ?; splits: test (-1)
- **Amazon Fashion Reviews** — total ?; splits: test (-1)
- **Discrimination (Synthetic)** — total ?; splits: test (-1)
- **MIMIC-III/SBDH (Clinical)** — total ?; splits: test (-1)
- **Semantic Leakage Tasks** — total ?; splits: test (-1)
## Metrics
- `SI-bias` **(primary)** — range: [0, 1]
- Maximum absolute difference in predicted positive rate across context values within each adjustment set stratum: max_{s,z1,z2} |P(Ŷ=1|S=s,Z=z1) - P(Ŷ=1|S=s,Z=z2)|. A value of 0 indicates perfect stratified invariance.
- `macro F1-score` — range: [0, 1]
- Standard macro-averaged F1 score computed over binary predictions to handle label imbalance across datasets.
- `CI Probability` — range: [0, 1]
- Proportion of input pairs differing only in context Z that receive identical predictions across all exogenous noise configurations: (1/Π|Ui|) Σ_u Π_{z,z'} 1(Ŷ(z',u)=Ŷ(z,u)).
## Input / output format
**Input**: Text input X (e.g., comment, biography, review, question, clinical note) paired with a context variable Z (e.g., gender, religion, race, sentiment, employment status) and ground-truth label Y.
**Output**: Binary prediction Ŷ ∈ {0, 1} (or yes/no) indicating the target class.
## Scoring recipe
```python
def compute_si_bias(predictions, gold_S, gold_Z):
si_bias = 0.0
for s in set(gold_S):
for z1 in set(gold_Z):
for z2 in set(gold_Z):
mask1 = (gold_S == s) & (gold_Z == z1)
mask2 = (gold_S == s) & (gold_Z == z2)
if mask1.sum() > 0 and mask2.sum() > 0:
p1 = predictions[mask1].mean()
p2 = predictions[mask2].mean()
si_bias = max(si_bias, abs(p1 - p2))
return si_bias
```
## Common pitfalls
- SI-bias is estimated on only 200 balanced examples per dataset/context pair, which may yield high variance.
- CI Probability assumes deterministic API calls (temperature=0), ignoring stochastic sampling effects common in LLM APIs.
- OOC uses LLM-predicted S (S_LM^+) during inference, but SI-bias is evaluated using ground-truth S, potentially inflating reported fairness gains.
## Evidence (verbatim from paper)
> Since we are dealing with binary classification tasks, we follow Veitch et al., Hardt et al. and define the following stratified invariance bias: SI-bias:=max_{s∈S,z1,z2∈Z}|P(Ŷ=1|S=s,Z=z1)-P(Ŷ=1|S=s,Z=z2)|. It follows from Definition 2 that if S is an adjustment set, the above metric is complete, i.e., a predictor satisfies stratified invariance if and only if its SI-bias is zero. For each dataset and context pair, we estimate the SI-bias with 200 random examples balanced according to S and Z.
## Citation
```bibtex
@misc{cotta2024testtimefairness,
title={Test-Time Fairness and Robustness in Large Language Models},
author={Cotta et al. (2024)},
year={2024},
note={arXiv:2406.07685}
}
```
- arXiv: 2406.07685