Datasets:
File size: 5,198 Bytes
4de12e0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | # Evaluating on HandleAtlas-benchmark
A self-contained eval harness for the
[`LumeData/HandleAtlas-benchmark`](https://huggingface.co/datasets/LumeData/HandleAtlas-benchmark)
dataset. The whole protocol — splits, labels, thresholds, scoring — lives in
[`eval.yaml`](./eval.yaml); the runner in [`run_eval.py`](./run_eval.py) reads
that file, loads the dataset from the Hub, and reports the same numbers used
on the model cards.
---
## What gets measured
| metric | definition |
|---|---|
| **span-only F1** *(primary)* | label-agnostic; a prediction matches a gold span when their character-offset IoU ≥ 0.5 |
| **span+label F1** | exact match on `(start, end, label)` — only fair when models share this taxonomy |
| **latency** | wall-clock ms per record, batch=1, CPU |
Per-label P/R/F1 is also printed for diagnostic use.
---
## Setup
You only need the deps for the adapter you plan to use.
```bash
# core (always needed)
pip install datasets pyyaml
# adapter: gliner (GLiNER models, including HandleAtlas)
pip install gliner "transformers<5" torch
# + ONNX (only if you pass --onnx):
pip install onnx onnxruntime optimum "accelerate>=0.26"
# adapter: hf-pipeline (BERT/DeBERTa token-classification models)
pip install "transformers<5" torch
# Some PII models (e.g. openai/privacy-filter) require a newer transformers:
pip install "git+https://github.com/huggingface/transformers.git"
```
Recommended: use `uv` so each run gets an isolated env.
```bash
uv run --with gliner --with 'transformers<5' --with torch \
--with datasets --with pyyaml \
python run_eval.py --adapter gliner --model LumeData/HandleAtlas-166m
```
---
## Quickstart
### Evaluate HandleAtlas (PyTorch float)
```bash
python run_eval.py --adapter gliner --model LumeData/HandleAtlas-166m
```
### Evaluate the CPU (INT8 ONNX) variant
```bash
python run_eval.py \
--adapter gliner \
--model LumeData/HandleAtlas-166m-CPU \
--onnx
```
### Evaluate base GLiNER zero-shot
```bash
python run_eval.py --adapter gliner --model urchade/gliner_small-v2.1
```
### Evaluate a different-taxonomy PII model (label-agnostic only)
The span-only F1 is fair across taxonomies; the span+label F1 will read low —
that's expected.
```bash
python run_eval.py \
--adapter hf-pipeline \
--model openai/privacy-filter
```
If you want span+label to be meaningful, pass `--label-map` to translate the
model's classes into the HandleAtlas label set:
```bash
python run_eval.py \
--adapter hf-pipeline \
--model some/pii-model \
--label-map "USERNAME=generic_username,SOCIAL=instagram_username"
```
---
## CLI flags
| flag | what it does |
|---|---|
| `--adapter` | `gliner` or `hf-pipeline` (required) |
| `--model` | HF Hub id or local path; passed straight to the adapter (required) |
| `--spec` | path to `eval.yaml` (defaults to the one next to `run_eval.py`) |
| `--threshold` | override the decoding threshold from the spec |
| `--label-map` | `model_label=target_label,...` for `hf-pipeline` |
| `--onnx`, `--onnx-file` | load the ONNX file instead of the PyTorch weights (GLiNER) |
| `--threads` | CPU threads (default 8) |
| `--device` | hf-pipeline: `-1`=CPU, `0`=first GPU |
| `--limit N` | only score the first N records (smoke test) |
| `--save-predictions PATH` | write per-record predictions to JSONL |
| `--json` | also dump the metrics JSON at the end |
---
## Adding your own model
If neither built-in adapter fits, subclass `Adapter` in `run_eval.py` and
register it. The contract is one method:
```python
class MyAdapter(Adapter):
name = "mymodel"
def __init__(self, model, labels, threshold, per_label_thresholds, **_):
super().__init__(model, labels, threshold, per_label_thresholds)
# load once
self.m = my_lib.load(model)
def predict(self, text: str) -> list[dict]:
# MUST return [{"start": int, "end": int, "label": str}, ...]
# `start`/`end` are Python character offsets, end exclusive.
return [{"start": s, "end": e, "label": l}
for s, e, l in self.m.extract(text, self.labels)]
ADAPTERS["mymodel"] = MyAdapter
```
Then:
```bash
python run_eval.py --adapter mymodel --model path/or/id
```
That's it — scoring and reporting are reused.
---
## Reproducing the published numbers
The values printed by this harness on `--model LumeData/HandleAtlas-166m`
should match the baselines table in `eval.yaml`. If they don't, check:
1. **Threshold** — the spec sets `0.5` with a `0.65` override on
`generic_username`. Don't override unless you mean to.
2. **Split** — the harness only uses the `test` split; the published numbers
are on this same split with `seed=123`.
3. **Hardware** — latency was measured on a MacBook Pro M5 Pro at 8 threads.
Different hardware will give different ms numbers; F1 should not move.
---
## Files
| file | purpose |
|---|---|
| `eval.yaml` | declarative protocol — dataset, labels, thresholds, metrics, baselines |
| `run_eval.py` | runner — loads dataset, calls the adapter, scores, reports |
| `EVAL.md` | this file |
| `test.jsonl` | the actual eval data, also mirrored on the Hub |
| `README.md` | dataset card |
|