Skip to content

feat(extract): opt-in multilingual NER model; never download a model in Tor mode - #152

Merged
JordanCoin merged 3 commits into
mainfrom
claude/open-prs-merge-review-e6z0ep
Nov 19, 2026
Merged

JordanCoin merged 3 commits into
mainfrom
claude/open-prs-merge-review-e6z0ep

Conversation

@JordanCoin

Copy link
Copy Markdown
Owner

Tier-2 entity extraction uses urchade/gliner_medium-v2.1, which only reads English. This PR adds an opt-in multilingual model. The default doesn't change. It also closes a Tor leak in how models are downloaded.

Follows the benchmark in #147 / #119.

Multilingual model (opt-in)

  • Which model: fastino/gliner2-multi-v1 (Apache-2.0). It was the most accurate on every test set, including the only clean English spans (strict F1 0.94). The other candidate, gliner_multi-v2.1, found fewer names, was worse on English and is a bigger download.
  • How to turn it on:
    • Install with openfoia install-extras ner-multilingual (gliner2[local], about 6 MB on top of torch).
    • Select it with analyze extract --ner-model multilingual, OPENFOIA_NER_MODEL=multilingual, or "entities": {"ner_model": "multilingual"} in config.
  • Missing extra: if multilingual is selected but gliner2 isn't installed, it says so once and uses the next tier. It deliberately doesn't fall back to the English model, which could start a 1.6 GB download nobody asked for.
  • Non-English hint: when the English model is selected and a document is mostly in a non-Latin script, or clearly not in English, analyze extract prints one notice suggesting the multilingual model. The agent's extract_entities result carries the same hint. It never switches or downloads anything by itself.
  • Provenance: analyze runs names the model that produced each run.
  • Portable mode: model caches stay on the stick for every entry point (CLI, agent, MCP, web).

Measured (13-language news set, 68 names)

English (default) Multilingual
Names found exactly 35/68 (F1 0.60) 54/68 (F1 0.87)
Hindi + Bengali 0/11 9/11
Peak RAM 2.0 GB 3.0 GB
Time per page 1× 1.30–1.36×
  • Latin and Cyrillic text: the English model already finds 32 of 35 names. The gain there is precision and cleaner spans.
  • Chinese: neither model finds names exactly, because Chinese is written without spaces and the text is split into words wrongly.
  • Caveat on the test set: the sentences were written by an AI model and need review by native speakers. docs/benchmarks/gliner2.md says so, and the raw output is in gliner2-news-raw.json.
  • Why the default stays English: the multilingual model needs about 1 GB more RAM, which matters on a $300 laptop.

Fixed: no model download in Tor mode (added on review)

The first extraction downloaded an uncached model straight from huggingface.co, not through Tor, even with network.tor on. That showed the user's real IP. This applied to the existing English model as well as the new one.

The loaders now refuse that download. The GLiNER tier says so once and the run continues with the other tiers; regex always runs. The message explains how to get the model: download it once with Tor off, or copy the Hugging Face cache over. A test checks that only the cache is tried, and that the test fails without the fix. Threat model and guide updated.

Checks

  • 25 tests in tests/test_ner_model_choice.py, with models stubbed so they run without torch.
  • The subagent that built this also broke the code on purpose 19 ways (mutation checks); every break was caught by a test.
  • The Tor fix's test fails without the fix.
  • Full gate on top of main: ruff clean, 1337 passed, 8 skipped.

Generated by Claude Code

english (urchade/gliner_medium-v2.1, the default) or multilingual
(fastino/gliner2-multi-v1, new extra ner-multilingual). Env
OPENFOIA_NER_MODEL, analyze extract --ner-model. Runs record the model id
that ran; a non-English hint suggests the switch without making it. The
benchmark gains --ner-model and a 26-sentence news set in 13 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
…language news set

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
Hugging Face downloads go straight to huggingface.co, not through Tor, so a
first extraction in Tor mode showed the user's real IP. The loaders now raise
ModelDownloadRefused when network.tor is on and the model is not cached; the
GLiNER tier prints that once and the run continues with the other tiers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
@JordanCoin
JordanCoin merged commit 3cc921f into main Nov 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants