--- pretty_name: mGENRE title trie + Wikidata QID lookup + QID attributes (impresso NEL assets) license: cc-by-nc-4.0 language: - multilingual - af - am - ar - as - az - be - bg - bm - bn - br - bs - ca - cs - cy - da - de - el - en - eo - es - et - eu - fa - ff - fi - fr - fy - ga - gd - gl - gn - gu - ha - he - hi - hr - ht - hu - hy - id - ig - is - it - ja - jv - ka - kg - kk - km - kn - ko - ku - ky - la - lg - ln - lo - lt - lv - mg - mk - ml - mn - mr - ms - my - ne - nl - no - om - or - pa - pl - ps - pt - qu - ro - ru - sa - sd - si - sk - sl - so - sq - sr - ss - su - sv - sw - ta - te - th - ti - tl - tn - tr - uk - ur - uz - vi - wo - xh - yo - zh task_categories: - text-retrieval tags: - entity-linking - named-entity-linking - entity-disambiguation - text2text-generation - mgenre - marisa-trie - wikidata - constrained-decoding - impresso size_categories: - 10M> lang` token-id sequences (105 languages, redirects included). Drives constrained beam search via a `prefix_allowed_tokens_fn` callback. | | `lang_title2wikidataID-normalized_with_redirect.marisa` | ~200 MB | `marisa_trie.BytesTrie` | Maps `f"{lang}\x1f{title}"` → the lex-smallest Wikidata QID (ASCII). Resolves generated titles to QIDs offline. | | `qid2attrs.marisa` | ~70 MB | `marisa_trie.RecordTrie` (fmt `"> xx"`: - The **trie** restricts generation to valid titles at every decoder step (prevents hallucinated pages). - The **lookup** turns the generated `(title, lang)` into a Wikidata QID without any live Wikipedia/Wikidata HTTP calls — suitable for offline / batch inference. In `impresso-inference`, the NEL task auto-downloads whichever file is missing from this dataset on first launch. See that repo's `src/impresso_inference/tasks/nel/` for the full pipeline. ## How to load ```python import marisa_trie # Title trie — constrained decoding trie = marisa_trie.Trie() trie.mmap("titles_lang_all105_marisa_trie_with_redirect.marisa") # (lang, title) -> QID lookup lookup = marisa_trie.BytesTrie() lookup.mmap("lang_title2wikidataID-normalized_with_redirect.marisa") qid = lookup[f"en\x1fGermany"][0].decode("ascii") # -> "Q183" # QID -> (class, birthdate) attributes from datetime import date, timedelta CLASS = {0: "other", 1: "org", 2: "loc", 3: "person", 4: "disambiguation"} BIRTH_NONE, EPOCH = -2**31, date(1, 1, 1) attrs = marisa_trie.RecordTrie(" (3, 712657) cls = CLASS[class_code] # -> "person" birth = None if birth_days == BIRTH_NONE else EPOCH + timedelta(days=birth_days) # -> 1952-03-11 ``` **Token-id encoding (trie only).** marisa-trie stores keys as UTF-8 strings, so mGENRE token ids are encoded per character as `chr(t)` for `t < 55000` and `chr(t + 10000)` otherwise — a 10 000-codepoint shift that skips the UTF-16 surrogate range. This matches the upstream GENRE byte layout; any consumer of the trie must apply the same shift when decoding allowed-token sets. Keys are `Title >> lang` token sequences. ## Licensing Released under **CC BY-NC 4.0 (non-commercial)**, inherited from the upstream [facebookresearch/GENRE](https://github.com/facebookresearch/GENRE) data the trie and lookup are derived from. The underlying knowledge base is public: Wikidata identifiers are **CC0**, and Wikipedia titles are **CC BY-SA**. Use for non-commercial research consistent with the GENRE license. `qid2attrs.marisa` contains only **Wikidata facts** (`P31`/`P279`/`P569`), which are **CC0**; its QID selection follows the GENRE-derived lookup above, so it is distributed here under the same non-commercial terms for consistency. ## Citation The trie and lookup originate from mGENRE: ```bibtex @article{de-cao-etal-2022-multilingual, title = "Multilingual Autoregressive Entity Linking", author = "De Cao, Nicola and Wu, Ledell and Popat, Kashyap and Artetxe, Mikel and Goyal, Naman and Plekhanov, Mikhail and Zettlemoyer, Luke and Cancedda, Nicola and Riedel, Sebastian and Petroni, Fabio", journal = "Transactions of the Association for Computational Linguistics", volume = "10", year = "2022", address = "Cambridge, MA", publisher = "MIT Press", url = "https://aclanthology.org/2022.tacl-1.16", doi = "10.1162/tacl_a_00460", pages = "274--290" } ``` ## Acknowledgements Repackaged for historical-newspaper entity linking by the [Impresso project](https://impresso-project.ch) — an interdisciplinary effort on historical media analysis across languages, time, and modalities. Funded by the Swiss National Science Foundation ([CRSII5_173719](http://p3.snf.ch/project-173719), [CRSII5_213585](https://data.snf.ch/grants/grant/213585)) and the Luxembourg National Research Fund (grant No. 17498891). - Model: [`impresso-project/nel-mgenre-multilingual`](https://huggingface.co/impresso-project/nel-mgenre-multilingual) - Code: [`impresso/impresso-inference`](https://github.com/impresso/impresso-inference) - Upstream data: [facebookresearch/GENRE](https://github.com/facebookresearch/GENRE)