| # 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 | |
|
|