# IdRef Alignment — Evaluation Script `eval_idref_alignment.py` is a self-contained [uv](https://docs.astral.sh/uv/) script that benchmarks the **Humatheque IdRef-Qualinka alignment API** against a golden dataset of person → IdRef PPN mappings. - **API under test:** [`idref-linker.smartbiblia.fr`](https://idref-linker.smartbiblia.fr/docs) (source: [gegedenice/humatheque-idref-qualinka-api](https://github.com/gegedenice/humatheque-idref-qualinka-api)) - **Evaluation dataset:** [`Geraldine/humatheque-vlm-sudoc-grounded-idref`](https://huggingface.co/datasets/Geraldine/humatheque-vlm-sudoc-grounded-idref) - **Endpoint:** `POST /align/person` --- ## What it does For every row of the dataset: 1. **Build the document context** from the `sudoc_record_templated` column: `title`, `subtitle`, `discipline`, `institution` (`granting_institution`), `doctoral_school`, `degree_type`, `year` (`defense_year`). 2. **Read the golden truth** from the `idref_persname_ppns` column — a list of `{ "Firstname Lastname": "PPN" }` pairs. 3. For **each person**, POST the name + context to `/align/person` and compare the returned PPN against the golden PPN. The request body mirrors the API's `AlignPersonRequest` (see `build_align_payload`), including the embedding model used for semantic similarity. --- ## Metrics | Metric | Definition | |---|---| | **Accepted & correct** | `status == "accepted"` **and** `best_ppn == gold` — the production decision is right | | **Accepted decisions** | rows where the API returned `status == "accepted"` (regardless of correctness) | | **Top-1 correct** | `best_candidate.ppn == gold` — ranking quality, ignoring the accept threshold | | **Candidate recall** | gold PPN appears anywhere in the returned `candidates[]` — recall of the candidate search | | **Precision / Recall / F1** | of the "accepted" decision | | **Status breakdown** | counts of `accepted` / `ambiguous` / `low_confidence` / `not_found` / `error` | Each person also gets a `gold_rank` (1-based position of the gold PPN in the ranked candidate list, or `null` if absent). --- ## Usage Run directly from the Hub (no clone needed): ```bash uv run https://huggingface.co/datasets/Geraldine/uv-scripts/resolve/main/idref-alignment/eval_idref_alignment.py ``` Or locally: ```bash uv run eval_idref_alignment.py # full dataset, default settings uv run eval_idref_alignment.py --limit 10 --concurrency 4 uv run eval_idref_alignment.py --embedding-model "" # lexical similarity instead of embeddings IDREF_API_KEY=xxx uv run eval_idref_alignment.py # if the API requires an X-API-Key ``` ### Key options | Flag | Default | Description | |---|---|---| | `--api-base` | `https://idref-linker.smartbiblia.fr` | Base URL of the alignment API | | `--dataset` | `Geraldine/humatheque-vlm-sudoc-grounded-idref` | HF dataset id | | `--split` | `train` | Dataset split | | `--embedding-model` | `sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2` | Embedding model (empty string ⇒ lexical similarity) | | `--max-candidates` | `20` | Max IdRef candidates per name | | `--max-docs-per-role` | `20` | Max reference docs per role | | `--reference-top-k` | `3` | Top-k references used as evidence | | `--limit` | `0` (all) | Evaluate only the first N documents | | `--concurrency` | `4` | Max concurrent API requests | | `--request-timeout` | `90.0` | Per-request HTTP timeout (s) | | `--out` | `idref_eval_results.jsonl` | Per-person JSONL output | | `--summary-out` | `idref_eval_summary.json` | Aggregate summary JSON | The API key and base URL can also be set via the `IDREF_API_KEY` / `IDREF_API_BASE` environment variables. The deployed API is currently open (no key required). --- ## Outputs - **`idref_eval_results.jsonl`** — one record per person with `name`, `gold_ppn`, `status`, `best_ppn`, `top1_ppn`, `top1_score`, `candidate_ppns`, `gold_rank`, and the correctness flags (`accepted_correct`, `top1_correct`, `topk_correct`). - **`idref_eval_summary.json`** — aggregate metrics + status breakdown. - A formatted summary table is also printed to the console. --- ## Notes - The script follows the API's HTTP→HTTPS redirect automatically and retries failed requests with backoff. - The dataset `thumbnail` (image) column is dropped on load to avoid an unnecessary Pillow dependency. - Embedding-based requests are heavier server-side; for a quick smoke test use `--limit` and/or `--embedding-model ""`.