Skip to content
Back to skills

Counterfactual Rep Eval

ASecurity

Evaluates how well counterfactual representations (CFRs) in high-dimensional embedding space mimic true text counterfactuals, measuring prediction consistency, probability alignment, and downstream fairness improvements across synthetic and real-world biased datasets. Use when the user wants to benchmark on EEEC+, BiasInBios, or asks about evaluating this task. Reports PIP.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 11, 2026
researchpythongit

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add qhjqhj00/research-skills-pool --skill counterfactual-rep-eval --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Counterfactual Rep Eval?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Counterfactual Rep Eval
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qhjqhj00-counterfactual-rep-eval/badge)](https://www.skillsdirectory.com/skills/qhjqhj00-counterfactual-rep-eval)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: counterfactual-rep-eval
description: Evaluates how well counterfactual representations (CFRs) in high-dimensional embedding space mimic true text counterfactuals, measuring prediction consistency, probability alignment, and downstream fairness improvements across synthetic and real-world biased datasets. Use when the user wants to benchmark on EEEC+, BiasInBios, or asks about evaluating this task. Reports PIP.
metadata:
  skill_kind: dataset_eval
  source_arxiv: 2402.00711
  bibtex_key: [REDACTED]
  confidence: high
---

# counterfactual-rep-eval

> Explaining Text Classifiers with Counterfactual Representations — Lemberger et al. (2024) (arXiv:2402.00711, 2024)

## What this evaluates

Evaluates how well counterfactual representations (CFRs) in high-dimensional embedding space mimic true text counterfactuals, measuring prediction consistency, probability alignment, and downstream fairness improvements across synthetic and real-world biased datasets.

## Datasets

- **EEEC+** — total ?; splits: test (-1); repo http://github.com/toinesayan/counterfactual-representations-for-explanation
- **BiasInBios** — total ?; splits: test (-1)

## Metrics

- `PIP` **(primary)** — range: [0, 1]
  - Proportion of Identical Predictions. Measures the fraction of instances where the classifier's prediction on the original representation matches its prediction on the counterfactual representation. Range [0, 1], higher is better.
- `ATV` — range: [0, 1]
  - Average Total Variation distance. Measures the average L1 distance (divided by 2) between the predicted probability distributions of the original and counterfactual representations. Range [0, 1], lower is better.
- `TPR-Gap` — range: other
  - True Positive Rate Gap. Defined as P[Ŷ=y|Z=z, Y=y] - P[Ŷ=y|Z=¬z, Y=y]. Measures the disparity in true positive rates across sensitive attribute values for a given class. Lower values indicate better fairness.

## Input / output format

**Input**: Text document s, sensitive attribute value z (e.g., gender/race), ground-truth label y, and classifier predictions/probabilities on original embedding X(s) and intervened counterfactual embedding X(s)_{Z←z}.

**Output**: Classifier predictions Ŷ, probability distributions p_Ŷ, and derived metric values (PIP, ATV, ATE, TPR-Gap, Π̂).

## Scoring recipe

```python
def compute_PIP(pred_orig, pred_cf):
    return np.mean(pred_orig == pred_cf)

def compute_ATV(probs_orig, probs_cf):
    return np.mean(0.5 * np.sum(np.abs(probs_orig - probs_cf), axis=1))

def compute_TPR_Gap(y_true, y_pred, z_attr, class_label):
    mask_z = (z_attr == 'z')
    mask_not_z = (z_attr == 'not_z')
    tp_z = np.mean((y_true[mask_z] == class_label) & (y_pred[mask_z] == class_label))
    tp_not_z = np.mean((y_true[mask_not_z] == class_label) & (y_pred[mask_not_z] == class_label))
    return tp_z - tp_not_z
```

## Common pitfalls

- Swapping only the gender attribute in BiasInBios ignores other correlated factors, making ground-truth counterfactuals imperfect.
- CFRs may poorly substitute true counterfactuals for a small fraction of observations, skewing ATE estimates if not filtered by TV distance.
- Stochastic CFRs accounting for variance in the parallel component do not significantly improve evaluation results over deterministic versions.

## Evidence (verbatim from paper)

> One possible metric for this evaluation is the proportion of observations for which predictions coincide. For a finer analysis, we can also evaluate the average distance in total variation between the probability distributions predicted by the classifiers Y_hat and Z_hat. Let S:={(s_i,z_i)} be a set of couples of text documents s_i and of CF values z_i≠Z(s_i). Define the proportion of identical predictions (PIP) by PIP_Y_hat[S] := (1/|S|) Σ 1[Y_hat(X(s_{Z←z})) = Y_hat(X(s)_{Z←z})]. The range of the PIP metric is [0,1], closer to 1 being better.

## Citation

```bibtex
@misc{lemberger2024counterfactual,
  title={Explaining Text Classifiers with Counterfactual Representations},
  author={Lemberger et al. (2024)},
  year={2024},
  note={arXiv:2402.00711}
}
```

- arXiv: 2402.00711

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.