iris-names / README.md
aneesahammed's picture
Rewrite the model card, correct the notices, add an example and a rebuild script
c1ca102 verified
|
Raw History Blame Contribute Delete
9.76 kB
---
license: other
license_name: apache-2.0-and-mit
license_link: https://huggingface.co/iris-hq/iris-names/blob/main/LICENSES.md
language:
- en
library_name: onnx
pipeline_tag: token-classification
base_model:
- fastino/gliner2.5-base-v1
- Xenova/DeBERTa-v3-base-mnli-fever-anli
base_model_relation: quantized
tags:
- onnx
- onnxruntime
- named-entity-recognition
- zero-shot
- natural-language-inference
- gliner2
- deberta-v3
- on-device
- iris
---
# iris-names
Two existing open models, converted or repackaged as ONNX files so an app can find names in text on the CPU, without sending the text anywhere:
| Folder | What it does | Upstream model | What was changed here |
|---|---|---|---|
| `gliner25/` | Finds spans of text for labels you choose | [fastino/gliner2.5-base-v1](https://huggingface.co/fastino/gliner2.5-base-v1), by Fastino AI (Apache-2.0) | Exported to ONNX in FP32, entity spans only; tokenizer files edited |
| `deberta-nli/` | Scores whether a sentence supports a statement | [MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli](https://huggingface.co/MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli), by Moritz Laurer (MIT), from the [Xenova ONNX conversion](https://huggingface.co/Xenova/DeBERTa-v3-base-mnli-fever-anli) (`model_q4f16.onnx`) | Weights moved to a separate data file; tokenizer files edited |
**Nothing was trained or fine-tuned here, and this repository did no quantisation.** The Q4F16 quantisation is Xenova's. `base_model_relation: quantized` is the Hub's nearest category for a conversion; the GLiNER files are FP32. Credit for the models belongs to their authors. This repository adds the export, the packaging, a rebuild script and an example.
[Iris](https://huggingface.co/iris-hq), a personal knowledge app, downloads these files at commit `d179d4a5a599fa8541dd0da17d0aea89096039fc`. The model files are the same at every commit of this repository so far.
## Use it
You need [uv](https://docs.astral.sh/uv/) and about 1 GB of free disk space.
```bash
uvx hf download iris-hq/iris-names --local-dir iris-names
uv run iris-names/examples/extract.py --model-dir iris-names --check "Ada Lovelace worked with Charles Babbage in London."
```
Or with pip, in a virtual environment:
```bash
pip install onnxruntime==1.23.2 tokenizers==0.22.2 "huggingface_hub>=1.0" "numpy>=2.0"
hf download iris-hq/iris-names --local-dir iris-names
python iris-names/examples/extract.py --model-dir iris-names --check "Ada Lovelace worked with Charles Babbage in London."
```
Output, shortened (`score` is GLiNER's, `check` is DeBERTa's):
```json
[
{"text": "Ada Lovelace", "label": "person", "start": 0, "end": 12, "score": 0.995, "check": 0.9979},
{"text": "Charles Babbage", "label": "person", "start": 25, "end": 40, "score": 0.9727, "check": 0.9932},
{"text": "London", "label": "location", "start": 44, "end": 50, "score": 0.9972, "check": 0.9799}
]
```
Choose labels with `--labels person,city`. `--self-test` checks an installation. Once the files are downloaded, `--model-dir` makes no network request.
Load the tokenizers with `tokenizers.Tokenizer.from_file`, as the example does. `transformers.AutoTokenizer` (4.57.6) fails on `gliner25/`.
The example is a plain reference for the two models. It is not Iris's extraction pipeline, which adds its own filtering, so its results differ from Iris's.
## How it works
1. **Split.** Text becomes lowercased words with their positions, by GLiNER2's word pattern.
2. **Prompt.** The example reads one line at a time. Labels and words become one sequence of at most 512 tokens: `( [P] entities ( [E] label … ) ) [SEP_TEXT] words…`. There is no outer `[CLS]` or `[SEP]`. A longer line is read in windows that do not overlap.
3. **Encode.** `gliner25/encoder/model.onnx` gives a 768-wide vector per token. Each word uses its first token, and each label uses its `[E]` token.
4. **Find spans.** `gliner25/boundary_head.onnx` scores up to 192 candidate spans per label, plus a score that the label is absent.
5. **Decode.** Labels whose absent score is over 0.5 are dropped, spans under the threshold are dropped, and the best set of non-overlapping spans is kept for each label. Different labels may overlap.
6. **Check (optional).** `deberta-nli/model.onnx` reads `[CLS] premise [SEP] hypothesis [SEP]`, such as a sentence and "London is a location.", and gives the probability that the first supports the second. The wording in the example is illustrative.
| File | Inputs | Outputs |
|---|---|---|
| `gliner25/encoder/model.onnx` (opset 18) | `input_ids`, `attention_mask`: int64 `[batch, seq]` | `last_hidden_state`: float32 `[batch, seq, 768]` |
| `gliner25/boundary_head.onnx` (opset 18) | `token_states` float32 `[batch, words, 768]`, `text_mask` bool `[batch, words]`, `query_states` float32 `[batch, queries, 768]`, `query_mask` bool `[batch, queries]` | `indices` int64 `[batch, queries, 192, 2]` (first word, end word), `pair_logits` float32 and `valid_mask` bool `[batch, queries, 192]`, `null_logits` float32 `[batch, queries]` |
| `deberta-nli/model.onnx` (opset 12, and `com.microsoft` `MatMulNBits`, so it needs ONNX Runtime) | `input_ids`, `attention_mask`: int64 `[batch, seq]` | `logits`: float32 `[batch, 3]` (entailment, neutral, contradiction) |
**Tokenizer edits.** In both folders `tokenizer_class` is `XLMRobertaTokenizer`, and added tokens missing from the Unigram vocabulary are appended to it, so that [swift-transformers](https://github.com/huggingface/swift-transformers) 1.4.0 can load them. Token IDs do not change.
## Hardware
- **Disk:** 1,015,584,754 bytes (969 MiB) of model files.
- **CPU only.** No GPU was used or tested.
- **Measured** on one Apple M4 Pro with 64 GB, macOS 27.0.1, Python 3.13.11, 4 threads, with the example script, including start-up:
| Run | Time | Peak resident memory |
|---|---:|---:|
| One sentence, GLiNER only | 0.9 s | 837 MB |
| One sentence, with `--check` | 1.2 s | 834 MB |
| 60 lines, 480 words, with `--check` (180 names found) | 10 s | 834 MB |
Each is a single run, so treat them as a rough guide. Allow at least 1 GB of free memory. Linux, Windows, Intel Macs and phones are untested.
## Rebuild it
`scripts/build_bundle.py` downloads both upstream models at fixed commits (about 1 GB), rebuilds all 11 model files and compares them with `SHA256SUMS`.
```bash
uv run iris-names/scripts/build_bundle.py rebuilt
```
| Source | Commit |
|---|---|
| `fastino/gliner2.5-base-v1` | `07d99c0ba5d15cb3b24e0a236fa99bdd4ef87a5c` |
| `Xenova/DeBERTa-v3-base-mnli-fever-anli` | `72a1ce83a0144efaf828b3c3844320a61197a53d` |
On 2026-11-24 it rebuilt 11 of 11 files byte for byte on the Mac above. Another platform may give different bytes.
GLiNER's boundary head needs four small changes to `gliner2==2.1.0` before it exports. They are in the script, with the reasons. Package versions are pinned at the top of the script.
To check a download:
```bash
cd iris-names && shasum -a 256 -c SHA256SUMS
```
## Checks
Run on 2026-11-24 and 25 against commit `d179d4a5a599fa8541dd0da17d0aea89096039fc`:
- **Same spans as PyTorch.** On 27 short texts with 5 labels at threshold 0.5, the example found the same 113 spans as unmodified `gliner2==2.1.0`, with scores within 0.0001. All texts fitted in one 512-token window. Longer text can differ, because this example cuts it into windows.
- **Python.** The self-test passes on 3.11, 3.12 and 3.13.
These show that the conversion is faithful. They do not measure accuracy.
**No accuracy results are published.** Iris has measured its own pipeline, but those numbers include filtering that is not in this repository, so they would not describe these files. See the upstream cards for their authors' results, and test on your own text.
## Limits
- **English.** Both models are English. A Japanese sentence gave no names; other languages were not evaluated.
- **Common words are reported as names.** "He met the teacher at the store on Monday." gives teacher (person), store (location) and Monday (event). Expect to filter.
- **Wrong types and boundaries.** "My dog Biscuit likes the park." gives Biscuit (product). "The Soviet official praised The Beatles and the Newark Bay project." gives Beatles (location), while "The Beatles played in Hamburg." is read correctly.
- **Case is ignored** by the word splitter, so capital letters are no signal.
- **Crowded text loses names.** The GLiNER 2.5 head keeps the 32 best start points and 32 best end points per label and window. In a test with 48 names in one paragraph, PyTorch and this ONNX export both found 31. Pass short texts: sentences, lines or paragraphs.
- **Long lines** are cut into windows, and a name on a window edge can be missed. Every label shortens the window.
- **NLI scores are not calibrated probabilities**, depend on the wording of the hypothesis, and are no guarantee. Pairs over 512 tokens are not checked.
- **Entity spans only.** GLiNER 2.5's relations, classification and structured output were not exported.
- **Bias.** Upstream training data can carry social and geographic bias. Do not use this alone for decisions about people.
- Finding names in documents is processing personal data. Running locally does not change your duties under privacy law.
## Licences
`gliner25/` is Apache-2.0 and `deberta-nli/` is MIT. The second model was trained partly on ANLI, a dataset under CC BY-NC 4.0, so check your position before commercial use. The scripts here are Apache-2.0. Full notices are in [LICENSES.md](LICENSES.md).
## Cite
Please cite the original authors: [GLiNER2](https://arxiv.org/abs/2507.18546) (Zaratiana et al., 2025), and the [DeBERTa-v3 NLI model](https://huggingface.co/MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli), whose card gives its citation.