Skip to content
Skillpedia
Machine learning5.8k Β· #14672

auditing-subgroup-fairness

What it does

This skill checks whether a clinical language model performs worse for some demographic groups than others, such as in finding personal details. It is for teams reviewing a model's fairness before it is used on real patients.

When to use it

  • βœ“When you want per-group recall and leakage numbers for a de-identification or NER model.
  • βœ“When you suspect one patient group has more personal details exposed than another.
  • βœ“When a clinical AI governance review needs documented disparity figures.

Skill link

https://github.com/maziyarpanahi/openmed/blob/master/skills/auditing-subgroup-fairness/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/maziyarpanahi/openmed/blob/master/skills/auditing-subgroup-fairness/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œCheck whether our de-identification model misses more personal details for some age groups than others, and show the gap.”

5 new skills a week. 1 minute to read.

How it works

The agent groups the gold-standard test spans by demographic tags, measures recall and leakage for each group, and reports the largest disparity and the worst-performing group.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Auditing Subgroup Fairness

An aggregate pass can hide a group the model fails. For de-identification that failure has a name: under-protection β€” PHI that leaks more often for one demographic group than another. openmed.eval.fairness_report slices leakage and recall by gold-span group so disparities surface before deployment, not after a breach.

When to use this skill

  • You want per-subgroup recall and leakage for a de-id or NER model.
  • You suspect (or must rule out) that one group is under-protected.
  • You need disparity numbers for a clinical AI governance review.
  • You need to document which subgroups you couldn't evaluate (the data gap).

What it measures

For each surrogate group fairness_report returns:

  • leakage_rate β€” fraction of that group's gold PHI characters left exposed (the de-id harm metric).
  • recall β€” fraction of that group's gold spans detected.
  • leakage_disparity β€” max - min leakage across groups (the gap to close).
  • worst_group / worst_group_leakage β€” the most-failed group.

Group membership comes from a group tag in each gold span's metadata (keys group, demographic_group, or surrogate_group); ungrouped spans fall into unspecified.

Quick start

from openmed.eval import fairness_report

# Gold fixtures must tag spans with a surrogate group, e.g.
#   {"start": 4, "end": 12, "label": "PERSON", "metadata": {"group": "female"}}
fair = fairness_report(
    "OpenMed/Privacy-PII-Detection",
    "golden",                 # named suite, or pass a list of fixtures
    device="cpu",
)

print("leakage disparity:", fair.leakage_disparity)
print("worst group      :", fair.worst_group, fair.worst_group_leakage)
for group, m in sorted(fair.per_group.items()):
    print(f"  {group:14s} recall={m.recall:.3f}  leakage={m.leakage_rate:.4f}")

# Under-protection alarm: any group leaking more than the rest.
LEAKAGE_GAP_LIMIT = 0.0       # leakage-first: ideally zero leakage everywhere
assert fair.leakage_disparity <= LEAKAGE_GAP_LIMIT or fair.worst_group_leakage == 0

FairnessReport.to_dict() is JSON-ready and PHI-free β€” drop it straight into a model card.

Workflow

  1. Tag the gold corpus by group. Add a synthetic group to each PHI span's metadata (sex, age band, race/ethnicity surrogate). Use synthetic surrogates, not real protected attributes (see building-gold-corpus).
  2. Run fairness_report on the model + suite.
  3. Read leakage first, recall second. For de-id, a group with higher leakage is under-protected β€” that is the headline finding.
  4. Compute the disparity (leakage_disparity) and locate worst_group. Equalized-odds framing: equal true-positive (recall) and equal leakage across groups.
  5. Document the gap. If race/ethnicity surrogates are absent, report that the audit could not cover them β€” most clinical NLP studies omit race entirely, so silence is the default failure mode, not equity.
  6. Feed it forward. Put per-group numbers and the gap into the model card and the governance review.

Hand-off to / from OpenMed

  • From building-gold-corpus: supplies group-tagged synthetic fixtures.
  • From evaluating-with-leakage-gates: an aggregate RELEASABLE decision should be paired with this audit β€” overall pass, subgroup fail is exactly the trap this catches.
  • To authoring-model-cards: FairnessReport.to_dict() fills the quantitative-analysis / subgroup section.
  • Pairs with benchmarking-clinical-ner: same run, different slice (label vs group).

Edge cases & gotchas

  • Under-protection is the de-id harm; lead with leakage. A group with equal recall but higher leakage is still failed.
  • The race documentation gap is the norm. Most clinical NLP corpora don't record race/ethnicity, so most fairness audits silently can't measure it. Report the absence explicitly β€” don't let missing data read as parity.
  • unspecified is not a real group. A pile of spans in unspecified means your gold isn't tagged; fix the corpus before trusting the disparity.
  • Small groups give noisy rates. Report span counts (span_count, total_chars) alongside rates; a 1-of-2 leak isn't a 50% population rate.
  • Synthetic surrogates only. Never store real protected attributes in eval fixtures; use fabricated group labels for slicing.
  • Disparity β‰ˆ 0 with high leakage everywhere is not "fair". Equal failure is still failure β€” chec
FAQ

What if my data has no group labels?

Unlabeled spans fall into an unspecified group, and the report shows that data gap.

What does leakage mean here?

It is the share of a group's personal details that remains exposed after de-identification.

Does it fix the model?

No. It measures disparities so they can be addressed before deployment.

Details

Original description by the author

Audit an OpenMed NER or de-identification model for performance disparities across demographic subgroups (sex, age band, race/ethnicity when available) using openmed.eval.fairness_report. Use when the user wants per-subgroup recall and leakage, wants to check whether de-identification under-protects a group, wants to surface a documentation gap where subgroup data is missing, or needs equalized-odds-style disparity numbers for a clinical model. Trigger on \"fairness\", \"subgroup\", \"bias audit\", \"disparity\", \"equalized odds\", \"under-protected group\", \"per-group recall\", or \"STANDIN

repo: maziyarpanahi/openmed

Popularity

GitHub stars
5.8k
Ranking position
#14672
License
Apache-2.0
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills