Spaces:
Sleeping
Sleeping
Add Performance & citation tab; single ISAAC paper citation
Browse files- README.md +77 -8
- app.py +10 -4
- generalization.py +9 -2
- moralization.py +7 -1
- performance.py +488 -0
- relevance.py +11 -2
README.md
CHANGED
|
@@ -8,6 +8,25 @@ sdk_version: 6.9.0
|
|
| 8 |
python_version: "3.10"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
# ISAAC Text Classifiers
|
|
@@ -18,12 +37,17 @@ Use is subject to [terms](https://github.com/BabakHemmatian/Illinois_Social_Atti
|
|
| 18 |
|
| 19 |
- **Relevance** — is a text relevant to a given social group distinction (ability, age,
|
| 20 |
race, sexuality, skin tone, weight)? Six fine-tuned RoBERTa classifiers behind a
|
| 21 |
-
distinction dropdown
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
- **Generalization** — clause segmentation plus per-clause labels for linguistic
|
| 24 |
features that make for more, or less, generalized statements
|
| 25 |
(genericity, eventivity, boundedness/habituality; 18 combinations).
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
Each task has a **Single text** tab and a **Multiple texts (file)** tab that
|
| 29 |
accepts a `.txt` (one text per line) or `.csv` (text in the first column) and
|
|
@@ -32,12 +56,46 @@ returns a labeled results CSV.
|
|
| 32 |
For **race** and **skin tone** relevance, a 0.6 confidence threshold is applied to the
|
| 33 |
"relevant" class, matching the ISAAC pipeline (`filter_relevance.py`).
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
## Layout
|
| 36 |
|
| 37 |
| File | Contents |
|
| 38 |
| --- | --- |
|
| 39 |
-
| `app.py` |
|
| 40 |
| `common.py` | Device/token resolution, model-path resolution, file I/O, GPU-duration helpers. |
|
|
|
|
| 41 |
| `relevance.py` | Six relevance classifiers, thresholding, UI. |
|
| 42 |
| `moralization.py` | Moralization classifier and UI. |
|
| 43 |
| `generalization.py` | Segmenter + clause classifier, aggregation, pie charts, UI. |
|
|
@@ -61,6 +119,8 @@ ZeroGPU charges each visitor's daily quota against the duration a call
|
|
| 61 |
than a flat worst case. Overrunning a request kills the call, so the estimates
|
| 62 |
assume a cold model load every time.
|
| 63 |
|
|
|
|
|
|
|
| 64 |
## Memory behavior
|
| 65 |
|
| 66 |
Every model is loaded lazily and cached, so only the task(s) actually used are
|
|
@@ -80,14 +140,18 @@ Each model resolves local-first with a Hugging Face Hub fallback
|
|
| 80 |
|
| 81 |
| Task | Local path under `models/` | Hub default | Env override |
|
| 82 |
| --- | --- | --- | --- |
|
| 83 |
-
| Relevance | `filter_relevance_<group>` | `
|
| 84 |
-
| Moralization | `label_moralization` | `
|
| 85 |
-
| Generalization (segmenter) | `label_generalization/label_generalization_segmentation` | `
|
| 86 |
-
| Generalization (classifier) | `label_generalization/label_generalization` | `
|
| 87 |
|
| 88 |
The same code therefore runs locally against the project's `models/` directory
|
| 89 |
and on Hugging Face against the published model repos.
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
## Local testing
|
| 92 |
|
| 93 |
```bash
|
|
@@ -96,3 +160,8 @@ pip install -r requirements.txt
|
|
| 96 |
export ISAAC_MODELS_DIR=/path/to/Illinois_Social_Attitudes/models
|
| 97 |
python app.py
|
| 98 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
python_version: "3.10"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
+
license: other
|
| 12 |
+
license_name: isaac-data-use-agreement
|
| 13 |
+
license_link: https://github.com/BabakHemmatian/Illinois_Social_Attitudes/blob/main/Data_Use_Agreement.md
|
| 14 |
+
models:
|
| 15 |
+
- ISAAC-corpus/isaac-relevance-ability
|
| 16 |
+
- ISAAC-corpus/isaac-relevance-age
|
| 17 |
+
- ISAAC-corpus/isaac-relevance-race
|
| 18 |
+
- ISAAC-corpus/isaac-relevance-sexuality
|
| 19 |
+
- ISAAC-corpus/isaac-relevance-skin_tone
|
| 20 |
+
- ISAAC-corpus/isaac-relevance-weight
|
| 21 |
+
- ISAAC-corpus/isaac-moralization
|
| 22 |
+
- ISAAC-corpus/isaac-generalization
|
| 23 |
+
- ISAAC-corpus/isaac-generalization-segmentation
|
| 24 |
+
tags:
|
| 25 |
+
- social-science
|
| 26 |
+
- reddit
|
| 27 |
+
- content-classification
|
| 28 |
+
- moralization
|
| 29 |
+
- generalization
|
| 30 |
---
|
| 31 |
|
| 32 |
# ISAAC Text Classifiers
|
|
|
|
| 37 |
|
| 38 |
- **Relevance** — is a text relevant to a given social group distinction (ability, age,
|
| 39 |
race, sexuality, skin tone, weight)? Six fine-tuned RoBERTa classifiers behind a
|
| 40 |
+
distinction dropdown (`roberta-large` for five distinctions; `roberta-base` for
|
| 41 |
+
skin tone).
|
| 42 |
+
- **Moralization** — does a text frame its subject in moral terms? Fine-tuned binary
|
| 43 |
+
`bert-base-uncased` classifier.
|
| 44 |
- **Generalization** — clause segmentation plus per-clause labels for linguistic
|
| 45 |
features that make for more, or less, generalized statements
|
| 46 |
(genericity, eventivity, boundedness/habituality; 18 combinations).
|
| 47 |
+
The released weights are the DiSCo RoBERTa models (see
|
| 48 |
+
[segmenter](https://huggingface.co/BabakScrapes/disco-clause-segmenter) and
|
| 49 |
+
[classifier](https://huggingface.co/BabakScrapes/disco-se-classifier)),
|
| 50 |
+
re-published under ISAAC-facing repo names.
|
| 51 |
|
| 52 |
Each task has a **Single text** tab and a **Multiple texts (file)** tab that
|
| 53 |
accepts a `.txt` (one text per line) or `.csv` (text in the first column) and
|
|
|
|
| 56 |
For **race** and **skin tone** relevance, a 0.6 confidence threshold is applied to the
|
| 57 |
"relevant" class, matching the ISAAC pipeline (`filter_relevance.py`).
|
| 58 |
|
| 59 |
+
## Performance
|
| 60 |
+
|
| 61 |
+
Reported in full in the app's **Performance & citation** tab, which is rendered
|
| 62 |
+
from `performance.py` — the single source of truth for every metric this project
|
| 63 |
+
publishes, including the nine model cards. Summary:
|
| 64 |
+
|
| 65 |
+
| Model | Base | Eval *k* | Headline | Residual irrelevance | Decision rule |
|
| 66 |
+
| --- | --- | --- | --- | --- | --- |
|
| 67 |
+
| Relevance — ability | `roberta-large` | 148 | .846 | 6.0% | argmax |
|
| 68 |
+
| Relevance — age | `roberta-large` | 149 | .886 | 3.0% | argmax |
|
| 69 |
+
| Relevance — race | `roberta-large` | 150 | .862 | 8.0% | P(rel) > 0.6 |
|
| 70 |
+
| Relevance — sexuality | `roberta-large` | 150 | .955 | 5.0% | argmax |
|
| 71 |
+
| Relevance — skin tone | `roberta-base` | 189 | .788 | 9.3% | P(rel) > 0.6 |
|
| 72 |
+
| Relevance — body weight | `roberta-large` | 148 | .987 | 4.0% | argmax |
|
| 73 |
+
| Moralization | `bert-base-uncased` | 2,682 | macro F1 .755 | — | argmax |
|
| 74 |
+
| Generalization (18-way) | `roberta-base` | 2,357 | acc. .737, macro F1 .514 | — | argmax |
|
| 75 |
+
| Generalization (segmenter) | `roberta-base` | — | 95.5% clause-span coverage | — | argmax |
|
| 76 |
+
|
| 77 |
+
"Headline" is held-out F1 for the relevance models. "Residual irrelevance" is the
|
| 78 |
+
stringent-rule rate in the finished corpus after all four filtering stages, from
|
| 79 |
+
the double-rated human audit — the figure to quote for corpus quality. The
|
| 80 |
+
collapsed generalization features (genericity .852, eventivity .879,
|
| 81 |
+
boundedness/habituality .804 macro F1) are what ISAAC reports and are stronger
|
| 82 |
+
than the 18-way figure.
|
| 83 |
+
|
| 84 |
+
Every published number lives in `performance.py` and is rendered from there into
|
| 85 |
+
(a) the collapsed accordion inside each task tab, (b) the **Performance &
|
| 86 |
+
citation** tab, and (c) the table above. To regenerate the table after any edit:
|
| 87 |
+
|
| 88 |
+
```bash
|
| 89 |
+
python performance.py --readme
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
## Layout
|
| 93 |
|
| 94 |
| File | Contents |
|
| 95 |
| --- | --- |
|
| 96 |
+
| `app.py` | four top-level tabs |
|
| 97 |
| `common.py` | Device/token resolution, model-path resolution, file I/O, GPU-duration helpers. |
|
| 98 |
+
| `performance.py` | Every published metric, as data, plus the markdown renderers for the app, this README, and the model cards. |
|
| 99 |
| `relevance.py` | Six relevance classifiers, thresholding, UI. |
|
| 100 |
| `moralization.py` | Moralization classifier and UI. |
|
| 101 |
| `generalization.py` | Segmenter + clause classifier, aggregation, pie charts, UI. |
|
|
|
|
| 119 |
than a flat worst case. Overrunning a request kills the call, so the estimates
|
| 120 |
assume a cold model load every time.
|
| 121 |
|
| 122 |
+
The **Performance & citation** tab is static markdown and holds no GPU.
|
| 123 |
+
|
| 124 |
## Memory behavior
|
| 125 |
|
| 126 |
Every model is loaded lazily and cached, so only the task(s) actually used are
|
|
|
|
| 140 |
|
| 141 |
| Task | Local path under `models/` | Hub default | Env override |
|
| 142 |
| --- | --- | --- | --- |
|
| 143 |
+
| Relevance | `filter_relevance_<group>` | `ISAAC-corpus/isaac-relevance-<group>` | `ISAAC_RELEVANCE_REPO_PREFIX` |
|
| 144 |
+
| Moralization | `label_moralization` | `ISAAC-corpus/isaac-moralization` | `ISAAC_MORALIZATION_REPO` |
|
| 145 |
+
| Generalization (segmenter) | `label_generalization/label_generalization_segmentation` | `ISAAC-corpus/isaac-generalization-segmentation` | `ISAAC_GENERALIZATION_SEG_REPO` |
|
| 146 |
+
| Generalization (classifier) | `label_generalization/label_generalization` | `ISAAC-corpus/isaac-generalization` | `ISAAC_GENERALIZATION_REPO` |
|
| 147 |
|
| 148 |
The same code therefore runs locally against the project's `models/` directory
|
| 149 |
and on Hugging Face against the published model repos.
|
| 150 |
|
| 151 |
+
The nine model repos are gated behind the project Data Use Agreement. Add a read
|
| 152 |
+
token as a Space secret named `HF_TOKEN` (Settings → Variables and secrets) so
|
| 153 |
+
the Space can load them.
|
| 154 |
+
|
| 155 |
## Local testing
|
| 156 |
|
| 157 |
```bash
|
|
|
|
| 160 |
export ISAAC_MODELS_DIR=/path/to/Illinois_Social_Attitudes/models
|
| 161 |
python app.py
|
| 162 |
```
|
| 163 |
+
|
| 164 |
+
## Citation
|
| 165 |
+
|
| 166 |
+
See the **Performance & citation** tab, or the
|
| 167 |
+
[project repository](https://github.com/BabakHemmatian/Illinois_Social_Attitudes).
|
app.py
CHANGED
|
@@ -8,20 +8,24 @@ import gradio as gr
|
|
| 8 |
|
| 9 |
import generalization
|
| 10 |
import moralization
|
|
|
|
| 11 |
import relevance
|
| 12 |
|
| 13 |
DESCRIPTION = """
|
| 14 |
# ISAAC Text Classifiers
|
| 15 |
|
| 16 |
-
Coding-free demos for
|
| 17 |
-
|
| 18 |
-
Pick a task below; each one loads its fine-tuned model on
|
| 19 |
demand and offers a single-text tab and a bulk file tab.
|
| 20 |
|
| 21 |
-
* **Relevance** — is a text about a given social
|
| 22 |
sexuality, skin tone, weight)?
|
| 23 |
* **Moralization** — does a text frame its subject in moral terms?
|
| 24 |
* **Generalization** — how generalized vs. anecdotal is the language, clause by clause?
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
"""
|
| 26 |
|
| 27 |
with gr.Blocks(title="ISAAC Text Classifiers") as demo:
|
|
@@ -34,6 +38,8 @@ with gr.Blocks(title="ISAAC Text Classifiers") as demo:
|
|
| 34 |
moralization.build_ui()
|
| 35 |
with gr.Tab("Generalization"):
|
| 36 |
generalization.build_ui()
|
|
|
|
|
|
|
| 37 |
|
| 38 |
gr.Markdown(common.FOOTER)
|
| 39 |
|
|
|
|
| 8 |
|
| 9 |
import generalization
|
| 10 |
import moralization
|
| 11 |
+
import performance
|
| 12 |
import relevance
|
| 13 |
|
| 14 |
DESCRIPTION = """
|
| 15 |
# ISAAC Text Classifiers
|
| 16 |
|
| 17 |
+
Coding-free demos for the classifiers built for the **Illinois Social Attitudes
|
| 18 |
+
(ISAAC)** project. Pick a task below; each one loads its fine-tuned model on
|
|
|
|
| 19 |
demand and offers a single-text tab and a bulk file tab.
|
| 20 |
|
| 21 |
+
* **Relevance** — is a text about a given social distinction (ability, age, race,
|
| 22 |
sexuality, skin tone, weight)?
|
| 23 |
* **Moralization** — does a text frame its subject in moral terms?
|
| 24 |
* **Generalization** — how generalized vs. anecdotal is the language, clause by clause?
|
| 25 |
+
|
| 26 |
+
Held-out performance for every model is reported under
|
| 27 |
+
**Performance & citation**, and each task tab repeats the figures for the model
|
| 28 |
+
it runs.
|
| 29 |
"""
|
| 30 |
|
| 31 |
with gr.Blocks(title="ISAAC Text Classifiers") as demo:
|
|
|
|
| 38 |
moralization.build_ui()
|
| 39 |
with gr.Tab("Generalization"):
|
| 40 |
generalization.build_ui()
|
| 41 |
+
with gr.Tab("Performance & citation"):
|
| 42 |
+
gr.Markdown(performance.full_report_md())
|
| 43 |
|
| 44 |
gr.Markdown(common.FOOTER)
|
| 45 |
|
generalization.py
CHANGED
|
@@ -12,6 +12,7 @@ import matplotlib
|
|
| 12 |
matplotlib.use("Agg") # headless backend for Spaces / servers
|
| 13 |
import matplotlib.pyplot as plt
|
| 14 |
import numpy as np
|
|
|
|
| 15 |
import re
|
| 16 |
import spaces
|
| 17 |
import torch
|
|
@@ -46,10 +47,10 @@ SEG_SUBDIR = "label_generalization/label_generalization_segmentation"
|
|
| 46 |
CLF_SUBDIR = "label_generalization/label_generalization"
|
| 47 |
|
| 48 |
HUB_SEG = os.environ.get(
|
| 49 |
-
"ISAAC_GENERALIZATION_SEG_REPO", "
|
| 50 |
)
|
| 51 |
HUB_CLF = os.environ.get(
|
| 52 |
-
"ISAAC_GENERALIZATION_REPO", "
|
| 53 |
)
|
| 54 |
|
| 55 |
MAX_WORDS_PER_SNIPPET = 200
|
|
@@ -465,6 +466,12 @@ SINGLE_EXAMPLES = [
|
|
| 465 |
def build_ui():
|
| 466 |
gr.Markdown(DESCRIPTION)
|
| 467 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
# Explicit gr.Tabs: these sit inside a top-level task tab in app.py, so the
|
| 469 |
# implicit grouping Gradio applies to bare sibling gr.Tab blocks is not
|
| 470 |
# something to rely on here.
|
|
|
|
| 12 |
matplotlib.use("Agg") # headless backend for Spaces / servers
|
| 13 |
import matplotlib.pyplot as plt
|
| 14 |
import numpy as np
|
| 15 |
+
import performance
|
| 16 |
import re
|
| 17 |
import spaces
|
| 18 |
import torch
|
|
|
|
| 47 |
CLF_SUBDIR = "label_generalization/label_generalization"
|
| 48 |
|
| 49 |
HUB_SEG = os.environ.get(
|
| 50 |
+
"ISAAC_GENERALIZATION_SEG_REPO", "ISAAC-corpus/isaac-generalization-segmentation"
|
| 51 |
)
|
| 52 |
HUB_CLF = os.environ.get(
|
| 53 |
+
"ISAAC_GENERALIZATION_REPO", "ISAAC-corpus/isaac-generalization"
|
| 54 |
)
|
| 55 |
|
| 56 |
MAX_WORDS_PER_SNIPPET = 200
|
|
|
|
| 466 |
def build_ui():
|
| 467 |
gr.Markdown(DESCRIPTION)
|
| 468 |
|
| 469 |
+
# Held-out performance for both models in the chain, collapsed by default;
|
| 470 |
+
# text comes from performance.py, the single source of truth for every
|
| 471 |
+
# published metric.
|
| 472 |
+
with gr.Accordion("Performance for these classifiers", open=False):
|
| 473 |
+
gr.Markdown(performance.generalization_summary_md())
|
| 474 |
+
|
| 475 |
# Explicit gr.Tabs: these sit inside a top-level task tab in app.py, so the
|
| 476 |
# implicit grouping Gradio applies to bare sibling gr.Tab blocks is not
|
| 477 |
# something to rely on here.
|
moralization.py
CHANGED
|
@@ -6,6 +6,7 @@ from pathlib import Path
|
|
| 6 |
|
| 7 |
import common # imports `spaces` before torch; see common.py
|
| 8 |
import gradio as gr
|
|
|
|
| 9 |
import spaces
|
| 10 |
import torch
|
| 11 |
from common import (
|
|
@@ -24,7 +25,7 @@ from common import (
|
|
| 24 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 25 |
|
| 26 |
LOCAL_DIRNAME = "label_moralization"
|
| 27 |
-
HUB_ID = os.environ.get("ISAAC_MORALIZATION_REPO", "
|
| 28 |
|
| 29 |
MAX_LENGTH = 512
|
| 30 |
BATCH_SIZE = 16
|
|
@@ -142,6 +143,11 @@ SINGLE_EXAMPLES = [
|
|
| 142 |
def build_ui():
|
| 143 |
gr.Markdown(DESCRIPTION)
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
# Explicit gr.Tabs: these sit inside a top-level task tab in app.py, so the
|
| 146 |
# implicit grouping Gradio applies to bare sibling gr.Tab blocks is not
|
| 147 |
# something to rely on here.
|
|
|
|
| 6 |
|
| 7 |
import common # imports `spaces` before torch; see common.py
|
| 8 |
import gradio as gr
|
| 9 |
+
import performance
|
| 10 |
import spaces
|
| 11 |
import torch
|
| 12 |
from common import (
|
|
|
|
| 25 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 26 |
|
| 27 |
LOCAL_DIRNAME = "label_moralization"
|
| 28 |
+
HUB_ID = os.environ.get("ISAAC_MORALIZATION_REPO", "ISAAC-corpus/isaac-moralization")
|
| 29 |
|
| 30 |
MAX_LENGTH = 512
|
| 31 |
BATCH_SIZE = 16
|
|
|
|
| 143 |
def build_ui():
|
| 144 |
gr.Markdown(DESCRIPTION)
|
| 145 |
|
| 146 |
+
# Held-out performance, collapsed by default; text comes from
|
| 147 |
+
# performance.py, the single source of truth for every published metric.
|
| 148 |
+
with gr.Accordion("Performance for this classifier", open=False):
|
| 149 |
+
gr.Markdown(performance.moralization_summary_md())
|
| 150 |
+
|
| 151 |
# Explicit gr.Tabs: these sit inside a top-level task tab in app.py, so the
|
| 152 |
# implicit grouping Gradio applies to bare sibling gr.Tab blocks is not
|
| 153 |
# something to rely on here.
|
performance.py
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Single source of truth for every performance number this project publishes.
|
| 2 |
+
|
| 3 |
+
Everything the Space displays, everything the Space README states, and the
|
| 4 |
+
"Evaluation" block of every Hugging Face model card is rendered from the data
|
| 5 |
+
structures below. Nothing here is duplicated by hand anywhere else, so a metric
|
| 6 |
+
cannot drift between the app, the README, and the nine model repos.
|
| 7 |
+
|
| 8 |
+
All figures are the final, released-checkpoint values reported in:
|
| 9 |
+
|
| 10 |
+
Hemmatian, B., Hadjarab, S., Chen, J., & Kurdi, B. (2026).
|
| 11 |
+
The Illinois Social Attitudes Aggregate Corpus (ISAAC).
|
| 12 |
+
|
| 13 |
+
Table 3 Residual irrelevance in the final corpus (double-rated audit)
|
| 14 |
+
Table 5 Label-classifier performance
|
| 15 |
+
Table C1 Interrater agreement on relevance training samples
|
| 16 |
+
Table C2 Relevance classifier performance on held-out slices
|
| 17 |
+
|
| 18 |
+
Run this file directly to regenerate the derived markdown:
|
| 19 |
+
|
| 20 |
+
python performance.py --readme # Space README section
|
| 21 |
+
python performance.py --card isaac-relevance-race
|
| 22 |
+
python performance.py --card isaac-moralization
|
| 23 |
+
python performance.py --card isaac-generalization
|
| 24 |
+
python performance.py --card isaac-generalization-segmentation
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
from __future__ import annotations
|
| 28 |
+
|
| 29 |
+
import sys
|
| 30 |
+
|
| 31 |
+
# ---------------------------------------------------------------------------
|
| 32 |
+
# Shared constants
|
| 33 |
+
# ---------------------------------------------------------------------------
|
| 34 |
+
|
| 35 |
+
PAPER_CITE = (
|
| 36 |
+
"Hemmatian, B., Hadjarab, S., Chen, J., & Kurdi, B. (2026). "
|
| 37 |
+
"*The Illinois Social Attitudes Aggregate Corpus (ISAAC): An Open Tool and "
|
| 38 |
+
"Reproducible Pipeline for Analyzing Social Group Discourse at Scale.*"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
REPO_URL = "https://github.com/BabakHemmatian/Illinois_Social_Attitudes"
|
| 42 |
+
DUA_URL = f"{REPO_URL}/blob/main/Data_Use_Agreement.md"
|
| 43 |
+
SITE_URL = "https://isaac.psychology.illinois.edu/"
|
| 44 |
+
SPACE_URL = "https://huggingface.co/spaces/BabakScrapes/isaac-classifiers"
|
| 45 |
+
|
| 46 |
+
GROUP_LABELS = {
|
| 47 |
+
"ability": "Ability (abled vs. disabled)",
|
| 48 |
+
"age": "Age (young vs. old)",
|
| 49 |
+
"race": "Race (White vs. Black)",
|
| 50 |
+
"sexuality": "Sexuality (straight vs. gay)",
|
| 51 |
+
"skin_tone": "Skin tone (light vs. dark)",
|
| 52 |
+
"weight": "Body weight (thin vs. fat)",
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
# ---------------------------------------------------------------------------
|
| 56 |
+
# Relevance classifiers (six repos)
|
| 57 |
+
#
|
| 58 |
+
# `heldout` lists the evaluation slices reported for the *released* checkpoint.
|
| 59 |
+
# Race and skin tone shipped retrained checkpoints, which the manuscript
|
| 60 |
+
# evaluates on two slices; the other four shipped their initial checkpoint,
|
| 61 |
+
# evaluated on one.
|
| 62 |
+
# ---------------------------------------------------------------------------
|
| 63 |
+
|
| 64 |
+
RELEVANCE = {
|
| 65 |
+
"ability": {
|
| 66 |
+
"base_model": "FacebookAI/roberta-large",
|
| 67 |
+
"threshold": None,
|
| 68 |
+
"heldout": [
|
| 69 |
+
{"slice": "Held-out 10% of the rated training sample", "k": 148,
|
| 70 |
+
"precision": .815, "recall": .880, "f1": .846},
|
| 71 |
+
],
|
| 72 |
+
"interrater": {"k": 1476, "raw_agreement": .982, "kappa": .960},
|
| 73 |
+
"residual": {"k": 100, "stringent": .060, "lenient": .030,
|
| 74 |
+
"kappa": .651, "raw_agreement": .970, "submissions": .040},
|
| 75 |
+
},
|
| 76 |
+
"age": {
|
| 77 |
+
"base_model": "FacebookAI/roberta-large",
|
| 78 |
+
"threshold": None,
|
| 79 |
+
"heldout": [
|
| 80 |
+
{"slice": "Held-out 10% of the rated training sample", "k": 149,
|
| 81 |
+
"precision": .853, "recall": .921, "f1": .886},
|
| 82 |
+
],
|
| 83 |
+
"interrater": {"k": 1485, "raw_agreement": .906, "kappa": .812},
|
| 84 |
+
"residual": {"k": 100, "stringent": .030, "lenient": .000,
|
| 85 |
+
"kappa": None, "raw_agreement": .970, "submissions": .020},
|
| 86 |
+
},
|
| 87 |
+
"race": {
|
| 88 |
+
"base_model": "FacebookAI/roberta-large",
|
| 89 |
+
"threshold": .6,
|
| 90 |
+
"heldout": [
|
| 91 |
+
{"slice": "Held-out 10% of the retraining sample", "k": 40,
|
| 92 |
+
"precision": .786, "recall": .917, "f1": .846},
|
| 93 |
+
{"slice": "Held-out 10% of the initial training sample", "k": 150,
|
| 94 |
+
"precision": 1.000, "recall": .757, "f1": .862},
|
| 95 |
+
],
|
| 96 |
+
"interrater": {"k": 1498, "raw_agreement": .926, "kappa": .784},
|
| 97 |
+
"residual": {"k": 150, "stringent": .080, "lenient": .053,
|
| 98 |
+
"kappa": .786, "raw_agreement": .973, "submissions": .040},
|
| 99 |
+
},
|
| 100 |
+
"sexuality": {
|
| 101 |
+
"base_model": "FacebookAI/roberta-large",
|
| 102 |
+
"threshold": None,
|
| 103 |
+
"heldout": [
|
| 104 |
+
{"slice": "Held-out 10% of the rated training sample", "k": 150,
|
| 105 |
+
"precision": .962, "recall": .949, "f1": .955},
|
| 106 |
+
],
|
| 107 |
+
"interrater": {"k": 1493, "raw_agreement": .936, "kappa": .871},
|
| 108 |
+
"residual": {"k": 100, "stringent": .050, "lenient": .020,
|
| 109 |
+
"kappa": .556, "raw_agreement": .970, "submissions": .050},
|
| 110 |
+
},
|
| 111 |
+
"skin_tone": {
|
| 112 |
+
"base_model": "FacebookAI/roberta-base",
|
| 113 |
+
"threshold": .6,
|
| 114 |
+
"heldout": [
|
| 115 |
+
{"slice": "Held-out 10% of the retraining sample", "k": 40,
|
| 116 |
+
"precision": .875, "recall": .840, "f1": .857},
|
| 117 |
+
{"slice": "Held-out 10% of the initial training sample", "k": 189,
|
| 118 |
+
"precision": .839, "recall": .743, "f1": .788},
|
| 119 |
+
],
|
| 120 |
+
"interrater": {"k": 1885, "raw_agreement": .934, "kappa": .725},
|
| 121 |
+
"residual": {"k": 150, "stringent": .093, "lenient": .047,
|
| 122 |
+
"kappa": .643, "raw_agreement": .953, "submissions": .090},
|
| 123 |
+
},
|
| 124 |
+
"weight": {
|
| 125 |
+
"base_model": "FacebookAI/roberta-large",
|
| 126 |
+
"threshold": None,
|
| 127 |
+
"heldout": [
|
| 128 |
+
{"slice": "Held-out 10% of the rated training sample", "k": 148,
|
| 129 |
+
"precision": .975, "recall": 1.000, "f1": .987},
|
| 130 |
+
],
|
| 131 |
+
"interrater": {"k": 1475, "raw_agreement": .896, "kappa": .690},
|
| 132 |
+
"residual": {"k": 100, "stringent": .040, "lenient": .030,
|
| 133 |
+
"kappa": .852, "raw_agreement": .990, "submissions": .020},
|
| 134 |
+
},
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
RESIDUAL_POOLED = {"k": 700, "stringent": .063, "lenient": .033, "submissions": .043}
|
| 138 |
+
|
| 139 |
+
# ---------------------------------------------------------------------------
|
| 140 |
+
# Moralization (one repo)
|
| 141 |
+
# ---------------------------------------------------------------------------
|
| 142 |
+
|
| 143 |
+
MORALIZATION = {
|
| 144 |
+
"base_model": "google-bert/bert-base-uncased",
|
| 145 |
+
"eval_set": "Held-out 10% of the Moral Foundations Reddit Corpus (MFRC)",
|
| 146 |
+
"k": 2682,
|
| 147 |
+
"positive_rate": .491,
|
| 148 |
+
"moralized_precision": .733,
|
| 149 |
+
"moralized_recall": .788,
|
| 150 |
+
"moralized_f1": .760,
|
| 151 |
+
"accuracy": .755,
|
| 152 |
+
"macro_f1": .755,
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
# ---------------------------------------------------------------------------
|
| 156 |
+
# Generalization (two repos; identical weights to the public DiSCo release)
|
| 157 |
+
# ---------------------------------------------------------------------------
|
| 158 |
+
|
| 159 |
+
GENERALIZATION = {
|
| 160 |
+
"base_model": "FacebookAI/roberta-base",
|
| 161 |
+
"eval_set": "Held-out 10% of the DiSCo gold corpus",
|
| 162 |
+
"k": 2357,
|
| 163 |
+
"situation_entity": {"n_classes": 18, "accuracy": .737, "macro_f1": .514},
|
| 164 |
+
"features": [
|
| 165 |
+
{"name": "Genericity", "n_classes": 2, "macro_f1": .852, "accuracy": .860},
|
| 166 |
+
{"name": "Eventivity", "n_classes": 2, "macro_f1": .879, "accuracy": .894},
|
| 167 |
+
{"name": "Boundedness / habituality", "n_classes": 4,
|
| 168 |
+
"macro_f1": .804, "accuracy": .850},
|
| 169 |
+
],
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
SEGMENTATION = {
|
| 173 |
+
"base_model": "FacebookAI/roberta-base",
|
| 174 |
+
"coverage": .955,
|
| 175 |
+
"coverage_note": (
|
| 176 |
+
"The segmenter covered most of the target clause span for 95.5% of "
|
| 177 |
+
"human-verified clauses."
|
| 178 |
+
),
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
DISCO_SEG_URL = "https://huggingface.co/BabakScrapes/disco-clause-segmenter"
|
| 182 |
+
DISCO_CLF_URL = "https://huggingface.co/BabakScrapes/disco-se-classifier"
|
| 183 |
+
|
| 184 |
+
# ---------------------------------------------------------------------------
|
| 185 |
+
# Formatting helpers
|
| 186 |
+
#
|
| 187 |
+
# Metrics are printed in the manuscript's leading-dot style (.846) so the app,
|
| 188 |
+
# the README, the cards, and the paper are visually comparable.
|
| 189 |
+
# ---------------------------------------------------------------------------
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def m(value: float | None) -> str:
|
| 193 |
+
"""Format a 0-1 metric as the manuscript does: .846, 1.000, or an em dash."""
|
| 194 |
+
if value is None:
|
| 195 |
+
return "—"
|
| 196 |
+
text = f"{value:.3f}"
|
| 197 |
+
return text[1:] if text.startswith("0.") else text
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def pct(value: float | None) -> str:
|
| 201 |
+
if value is None:
|
| 202 |
+
return "—"
|
| 203 |
+
return f"{value * 100:.1f}%"
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
# ---------------------------------------------------------------------------
|
| 207 |
+
# Per-task summaries -- rendered into the collapsed accordion inside each task
|
| 208 |
+
# tab, next to the controls that actually run the model.
|
| 209 |
+
# ---------------------------------------------------------------------------
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def relevance_summary_md(group: str, heading: bool = True) -> str:
|
| 213 |
+
spec = RELEVANCE[group]
|
| 214 |
+
rows = "\n".join(
|
| 215 |
+
f"| {row['slice']} | {row['k']} | {m(row['precision'])} | "
|
| 216 |
+
f"{m(row['recall'])} | {m(row['f1'])} |"
|
| 217 |
+
for row in spec["heldout"]
|
| 218 |
+
)
|
| 219 |
+
residual = spec["residual"]
|
| 220 |
+
inter = spec["interrater"]
|
| 221 |
+
|
| 222 |
+
threshold_note = ""
|
| 223 |
+
if spec["threshold"] is not None:
|
| 224 |
+
threshold_note = (
|
| 225 |
+
f"\n**This classifier applies a P(relevant) > {spec['threshold']} "
|
| 226 |
+
"decision threshold** and was trained with an asymmetric penalty on "
|
| 227 |
+
"false positives, so it is deliberately more conservative than a "
|
| 228 |
+
"plain argmax classifier. Scoring the same text with `argmax` will "
|
| 229 |
+
"not reproduce the ISAAC corpus.\n"
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
title = f"**{GROUP_LABELS[group]}** — b" if heading else "B"
|
| 233 |
+
|
| 234 |
+
return f"""
|
| 235 |
+
{title}ase model `{spec['base_model']}`.
|
| 236 |
+
|
| 237 |
+
| Evaluation slice | *k* | Precision | Recall | F1 |
|
| 238 |
+
| --- | --- | --- | --- | --- |
|
| 239 |
+
{rows}
|
| 240 |
+
{threshold_note}
|
| 241 |
+
**Human agreement on the training data.** Two trained annotators rated
|
| 242 |
+
*k* = {inter['k']:,} posts: {pct(inter['raw_agreement'])} raw agreement,
|
| 243 |
+
Cohen's κ = {m(inter['kappa'])}.
|
| 244 |
+
|
| 245 |
+
**What the full filter delivers.** Held-out precision describes this model in
|
| 246 |
+
isolation. In the released corpus this classifier is one of four filtering
|
| 247 |
+
stages, and a double-rated audit of the finished
|
| 248 |
+
{GROUP_LABELS[group].split(' (')[0].lower()} data (*k* = {residual['k']})
|
| 249 |
+
found {pct(residual['stringent'])} of comments irrelevant under the stringent
|
| 250 |
+
rule and {pct(residual['lenient'])} under the lenient rule
|
| 251 |
+
({pct(residual['submissions'])} for submissions). That end-to-end figure, not
|
| 252 |
+
the F1 above, is the number to quote when describing corpus quality.
|
| 253 |
+
"""
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def moralization_summary_md() -> str:
|
| 257 |
+
d = MORALIZATION
|
| 258 |
+
return f"""
|
| 259 |
+
Base model `{d['base_model']}`, fine-tuned on the Moral Foundations Reddit
|
| 260 |
+
Corpus (MFRC; Trager et al., 2022) reduced to a binary moralized / non-moralized
|
| 261 |
+
target.
|
| 262 |
+
|
| 263 |
+
| Evaluation slice | *k* | Metric | Value |
|
| 264 |
+
| --- | --- | --- | --- |
|
| 265 |
+
| {d['eval_set']} | {d['k']:,} | Precision (moralized) | {m(d['moralized_precision'])} |
|
| 266 |
+
| | | Recall (moralized) | {m(d['moralized_recall'])} |
|
| 267 |
+
| | | F1 (moralized) | {m(d['moralized_f1'])} |
|
| 268 |
+
| | | Accuracy | {m(d['accuracy'])} |
|
| 269 |
+
| | | Macro F1 | {m(d['macro_f1'])} |
|
| 270 |
+
|
| 271 |
+
The evaluation slice is {pct(d['positive_rate'])} moralized, so accuracy is
|
| 272 |
+
interpretable against a ~50% baseline.
|
| 273 |
+
|
| 274 |
+
**Binary by design.** Per-foundation classification performance in the published
|
| 275 |
+
literature is highly uneven, and a binary moralization construct commands
|
| 276 |
+
broader theoretical agreement than the individual foundations. This model
|
| 277 |
+
therefore does not return moral-foundation labels.
|
| 278 |
+
"""
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def generalization_summary_md() -> str:
|
| 282 |
+
d = GENERALIZATION
|
| 283 |
+
se = d["situation_entity"]
|
| 284 |
+
feature_rows = "\n".join(
|
| 285 |
+
f"| {f['name']} ({f['n_classes']}-way) | {m(f['macro_f1'])} | {m(f['accuracy'])} |"
|
| 286 |
+
for f in d["features"]
|
| 287 |
+
)
|
| 288 |
+
return f"""
|
| 289 |
+
Two `{d['base_model']}` models run in sequence: a clause segmenter, then a
|
| 290 |
+
{se['n_classes']}-way situation-entity classifier. Both are the same weights as
|
| 291 |
+
the public DiSCo release — see the
|
| 292 |
+
[clause segmenter]({DISCO_SEG_URL}) and
|
| 293 |
+
[situation-entity classifier]({DISCO_CLF_URL}) cards for the full model
|
| 294 |
+
description and the corpus they were trained on.
|
| 295 |
+
|
| 296 |
+
**Segmentation.** {SEGMENTATION['coverage_note']}
|
| 297 |
+
|
| 298 |
+
**Classification**, on the {d['eval_set'].lower()} (*k* ≈ {d['k']:,}):
|
| 299 |
+
|
| 300 |
+
| Target | Macro F1 | Accuracy |
|
| 301 |
+
| --- | --- | --- |
|
| 302 |
+
| Full situation entity ({se['n_classes']}-way) | {m(se['macro_f1'])} | {m(se['accuracy'])} |
|
| 303 |
+
{feature_rows}
|
| 304 |
+
|
| 305 |
+
The {se['n_classes']}-way macro F1 of {m(se['macro_f1'])} is held down by heavy
|
| 306 |
+
label imbalance across the rarer situation-entity types. The three collapsed
|
| 307 |
+
features are what ISAAC actually reports, and they are the numbers to rely on.
|
| 308 |
+
"""
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
# ---------------------------------------------------------------------------
|
| 312 |
+
# Full report -- rendered into the top-level "Performance & citation" tab.
|
| 313 |
+
# ---------------------------------------------------------------------------
|
| 314 |
+
|
| 315 |
+
FRAMING = f"""
|
| 316 |
+
# Model performance
|
| 317 |
+
|
| 318 |
+
Every classifier in this Space was evaluated on data held out from its own
|
| 319 |
+
training set. The numbers below are the final, released-checkpoint values
|
| 320 |
+
reported in the ISAAC manuscript; nothing here is estimated or approximate.
|
| 321 |
+
|
| 322 |
+
Two things are worth reading before you use any of these numbers in a write-up:
|
| 323 |
+
|
| 324 |
+
1. **Held-out performance describes a model, not the corpus.** For the relevance
|
| 325 |
+
classifiers especially, the model is one stage in a four-stage filter. The
|
| 326 |
+
end-to-end residual irrelevance rate from the human audit of the finished
|
| 327 |
+
corpus is reported alongside each classifier, and it is the more meaningful
|
| 328 |
+
figure for most claims about data quality.
|
| 329 |
+
2. **Race and skin tone are thresholded.** Both apply a P(relevant) > 0.6
|
| 330 |
+
decision rule rather than plain argmax. This Space reproduces that rule. If
|
| 331 |
+
you load the weights yourself and take an argmax, you will get a more
|
| 332 |
+
permissive classifier than the one that built ISAAC.
|
| 333 |
+
|
| 334 |
+
Full methodological detail, including the annotation protocol and the
|
| 335 |
+
stage-by-stage audit, is in the manuscript and its Appendix C.
|
| 336 |
+
"""
|
| 337 |
+
|
| 338 |
+
CITATION_MD = f"""
|
| 339 |
+
## Citation
|
| 340 |
+
|
| 341 |
+
If you use these classifiers, please cite the ISAAC paper. **One citation covers
|
| 342 |
+
the whole project** — the corpus, the pipeline, and every model. Please do not
|
| 343 |
+
cite the models or the repository separately.
|
| 344 |
+
|
| 345 |
+
**APA**
|
| 346 |
+
|
| 347 |
+
> {PAPER_CITE.replace('*', '')}
|
| 348 |
+
|
| 349 |
+
**BibTeX**
|
| 350 |
+
|
| 351 |
+
```bibtex
|
| 352 |
+
@article{{hemmatian2026isaac,
|
| 353 |
+
author = {{Hemmatian, Babak and Hadjarab, Sarah and Chen, Jessica and Kurdi, Benedek}},
|
| 354 |
+
title = {{The {{Illinois}} Social Attitudes Aggregate Corpus ({{ISAAC}}): An Open Tool and Reproducible Pipeline for Analyzing Social Group Discourse at Scale}},
|
| 355 |
+
year = {{2026}},
|
| 356 |
+
note = {{Manuscript submitted for publication}}
|
| 357 |
+
}}
|
| 358 |
+
```
|
| 359 |
+
|
| 360 |
+
## Terms
|
| 361 |
+
|
| 362 |
+
The classifiers exposed here are released under a Creative Commons Attribution
|
| 363 |
+
4.0 International License. The ISAAC corpus itself is governed separately by the
|
| 364 |
+
project [Data Use Agreement]({DUA_URL}).
|
| 365 |
+
|
| 366 |
+
## Elsewhere
|
| 367 |
+
|
| 368 |
+
* Corpus, samples, and SQL playground: <{SITE_URL}>
|
| 369 |
+
* Pipeline source, keyword lists, and pattern sets: <{REPO_URL}>
|
| 370 |
+
"""
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def full_report_md() -> str:
|
| 374 |
+
parts = [FRAMING, "\n## Relevance classifiers\n"]
|
| 375 |
+
for group in RELEVANCE:
|
| 376 |
+
parts.append(f"\n### {GROUP_LABELS[group]}\n")
|
| 377 |
+
parts.append(relevance_summary_md(group, heading=False))
|
| 378 |
+
|
| 379 |
+
parts.append(f"""
|
| 380 |
+
### Residual irrelevance across all six distinctions
|
| 381 |
+
|
| 382 |
+
The design target was under 10% irrelevant content in the finished corpus, for
|
| 383 |
+
every distinction and both post types. A final double-rated audit of stratified
|
| 384 |
+
random samples (*k* = {RESIDUAL_POOLED['k']} comments pooled) confirmed it.
|
| 385 |
+
|
| 386 |
+
| Distinction | *k* | Comments, stringent | Comments, lenient | κ | Raw agreement | Submissions |
|
| 387 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 388 |
+
""")
|
| 389 |
+
for group, spec in RELEVANCE.items():
|
| 390 |
+
r = spec["residual"]
|
| 391 |
+
kappa = "≈ 0" if r["kappa"] is None else m(r["kappa"])
|
| 392 |
+
parts.append(
|
| 393 |
+
f"| {GROUP_LABELS[group].split(' (')[0]} | {r['k']} | "
|
| 394 |
+
f"{pct(r['stringent'])} | {pct(r['lenient'])} | {kappa} | "
|
| 395 |
+
f"{pct(r['raw_agreement'])} | {pct(r['submissions'])} |\n"
|
| 396 |
+
)
|
| 397 |
+
p = RESIDUAL_POOLED
|
| 398 |
+
parts.append(
|
| 399 |
+
f"| **Pooled** | **{p['k']}** | **{pct(p['stringent'])}** | "
|
| 400 |
+
f"**{pct(p['lenient'])}** | — | — | **{pct(p['submissions'])}** |\n"
|
| 401 |
+
)
|
| 402 |
+
parts.append(
|
| 403 |
+
"\nThe stringent rule counts a post as irrelevant if *either* annotator "
|
| 404 |
+
"judged it so; the lenient rule requires both.\n"
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
parts.append("\n## Moralization classifier\n")
|
| 408 |
+
parts.append(moralization_summary_md())
|
| 409 |
+
parts.append("\n## Generalization classifiers\n")
|
| 410 |
+
parts.append(generalization_summary_md())
|
| 411 |
+
|
| 412 |
+
parts.append(f"""
|
| 413 |
+
## A note on the off-the-shelf labels
|
| 414 |
+
|
| 415 |
+
ISAAC also carries sentiment (VADER, TextBlob, Stanza) and emotion
|
| 416 |
+
(emotion-english-distilroberta-base, roberta-base-go_emotions, EmoBERTa) labels.
|
| 417 |
+
Those models are not in-house and are not served by this Space; their published
|
| 418 |
+
benchmarks and ISAAC's ensemble-agreement analyses are reported in the
|
| 419 |
+
manuscript.
|
| 420 |
+
""")
|
| 421 |
+
|
| 422 |
+
parts.append(CITATION_MD)
|
| 423 |
+
return "".join(parts)
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
# ---------------------------------------------------------------------------
|
| 427 |
+
# Derived-artifact rendering
|
| 428 |
+
# ---------------------------------------------------------------------------
|
| 429 |
+
|
| 430 |
+
_CARD_RENDERERS = {
|
| 431 |
+
"isaac-moralization": moralization_summary_md,
|
| 432 |
+
"isaac-generalization": generalization_summary_md,
|
| 433 |
+
"isaac-generalization-segmentation": generalization_summary_md,
|
| 434 |
+
**{
|
| 435 |
+
f"isaac-relevance-{g}": (lambda g=g: relevance_summary_md(g))
|
| 436 |
+
for g in RELEVANCE
|
| 437 |
+
},
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
def readme_section_md() -> str:
|
| 442 |
+
"""The block pasted into the Space README under '## Performance'."""
|
| 443 |
+
rows = []
|
| 444 |
+
for group, spec in RELEVANCE.items():
|
| 445 |
+
# Summarize with the largest evaluation slice available for the released
|
| 446 |
+
# checkpoint; the smaller retraining slices are shown in full in-app.
|
| 447 |
+
best = max(spec["heldout"], key=lambda row: row["k"])
|
| 448 |
+
thr = "P(rel) > 0.6" if spec["threshold"] else "argmax"
|
| 449 |
+
rows.append(
|
| 450 |
+
f"| Relevance — {GROUP_LABELS[group].split(' (')[0].lower()} | "
|
| 451 |
+
f"`{spec['base_model'].split('/')[-1]}` | {best['k']} | "
|
| 452 |
+
f"{m(best['f1'])} | {pct(spec['residual']['stringent'])} | {thr} |"
|
| 453 |
+
)
|
| 454 |
+
d, se = MORALIZATION, GENERALIZATION["situation_entity"]
|
| 455 |
+
return f"""## Performance
|
| 456 |
+
|
| 457 |
+
Reported in full in the app's **Performance & citation** tab, which is rendered
|
| 458 |
+
from `performance.py` — the single source of truth for every metric this project
|
| 459 |
+
publishes, including the nine model cards. Summary:
|
| 460 |
+
|
| 461 |
+
| Model | Base | Eval *k* | Headline | Residual irrelevance | Decision rule |
|
| 462 |
+
| --- | --- | --- | --- | --- | --- |
|
| 463 |
+
{chr(10).join(rows)}
|
| 464 |
+
| Moralization | `{d['base_model'].split('/')[-1]}` | {d['k']:,} | macro F1 {m(d['macro_f1'])} | — | argmax |
|
| 465 |
+
| Generalization (18-way) | `{GENERALIZATION['base_model'].split('/')[-1]}` | {GENERALIZATION['k']:,} | acc. {m(se['accuracy'])}, macro F1 {m(se['macro_f1'])} | — | argmax |
|
| 466 |
+
| Generalization (segmenter) | `{SEGMENTATION['base_model'].split('/')[-1]}` | — | {pct(SEGMENTATION['coverage'])} clause-span coverage | — | argmax |
|
| 467 |
+
|
| 468 |
+
"Headline" is held-out F1 for the relevance models. "Residual irrelevance" is the
|
| 469 |
+
stringent-rule rate in the finished corpus after all four filtering stages, from
|
| 470 |
+
the double-rated human audit — the figure to quote for corpus quality. The
|
| 471 |
+
collapsed generalization features (genericity {m(GENERALIZATION['features'][0]['macro_f1'])},
|
| 472 |
+
eventivity {m(GENERALIZATION['features'][1]['macro_f1'])},
|
| 473 |
+
boundedness/habituality {m(GENERALIZATION['features'][2]['macro_f1'])} macro F1)
|
| 474 |
+
are what ISAAC reports and are stronger than the 18-way figure.
|
| 475 |
+
"""
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
if __name__ == "__main__":
|
| 479 |
+
args = sys.argv[1:]
|
| 480 |
+
if args[:1] == ["--readme"]:
|
| 481 |
+
print(readme_section_md())
|
| 482 |
+
elif args[:1] == ["--card"] and len(args) == 2:
|
| 483 |
+
renderer = _CARD_RENDERERS.get(args[1])
|
| 484 |
+
if renderer is None:
|
| 485 |
+
sys.exit(f"unknown repo: {args[1]}\nknown: {', '.join(_CARD_RENDERERS)}")
|
| 486 |
+
print(renderer())
|
| 487 |
+
else:
|
| 488 |
+
print(full_report_md())
|
relevance.py
CHANGED
|
@@ -6,6 +6,7 @@ from pathlib import Path
|
|
| 6 |
|
| 7 |
import common # imports `spaces` before torch; see common.py
|
| 8 |
import gradio as gr
|
|
|
|
| 9 |
import spaces
|
| 10 |
import torch
|
| 11 |
from common import (
|
|
@@ -32,9 +33,9 @@ from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
| 32 |
|
| 33 |
GROUPS = ["ability", "age", "race", "sexuality", "skin_tone", "weight"]
|
| 34 |
|
| 35 |
-
# Released model-repo naming: prefix + group, e.g. "
|
| 36 |
HUB_PREFIX = os.environ.get(
|
| 37 |
-
"ISAAC_RELEVANCE_REPO_PREFIX", "
|
| 38 |
)
|
| 39 |
|
| 40 |
# Number of distinction models kept resident simultaneously.
|
|
@@ -190,6 +191,14 @@ def build_ui():
|
|
| 190 |
info="Which fine-tuned relevance classifier to apply.",
|
| 191 |
)
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
# Explicit gr.Tabs: these sit inside a top-level task tab in app.py, so the
|
| 194 |
# implicit grouping Gradio applies to bare sibling gr.Tab blocks is not
|
| 195 |
# something to rely on here.
|
|
|
|
| 6 |
|
| 7 |
import common # imports `spaces` before torch; see common.py
|
| 8 |
import gradio as gr
|
| 9 |
+
import performance
|
| 10 |
import spaces
|
| 11 |
import torch
|
| 12 |
from common import (
|
|
|
|
| 33 |
|
| 34 |
GROUPS = ["ability", "age", "race", "sexuality", "skin_tone", "weight"]
|
| 35 |
|
| 36 |
+
# Released model-repo naming: prefix + group, e.g. "ISAAC-corpus/isaac-relevance-race".
|
| 37 |
HUB_PREFIX = os.environ.get(
|
| 38 |
+
"ISAAC_RELEVANCE_REPO_PREFIX", "ISAAC-corpus/isaac-relevance-"
|
| 39 |
)
|
| 40 |
|
| 41 |
# Number of distinction models kept resident simultaneously.
|
|
|
|
| 191 |
info="Which fine-tuned relevance classifier to apply.",
|
| 192 |
)
|
| 193 |
|
| 194 |
+
# Held-out performance for the selected distinction, collapsed by default.
|
| 195 |
+
# Kept in this tab rather than only under "Performance & citation" so the
|
| 196 |
+
# thresholding caveat sits next to the control that triggers it. Text comes
|
| 197 |
+
# from performance.py, the single source of truth for every published metric.
|
| 198 |
+
with gr.Accordion("Performance for this classifier", open=False):
|
| 199 |
+
perf_md = gr.Markdown(performance.relevance_summary_md(GROUPS[0]))
|
| 200 |
+
group_dd.change(performance.relevance_summary_md, inputs=group_dd, outputs=perf_md)
|
| 201 |
+
|
| 202 |
# Explicit gr.Tabs: these sit inside a top-level task tab in app.py, so the
|
| 203 |
# implicit grouping Gradio applies to bare sibling gr.Tab blocks is not
|
| 204 |
# something to rely on here.
|