Elamur: **Mova** · [Parse](https://mova.elamur.ai/free/en/parse/) · [Research](https://md.research.elamur.ai/free/en/) · [Gali](https://md.gali.elamur.ai/free/en/) · [MCP](https://mcp.elamur.ai/) · [Locations](https://md.locations.elamur.ai/free/en/) · [Weather](https://md.weather.elamur.ai/free/en/) · [Shryfti](https://md.shryfti.elamur.ai/free/en/)

[Mova](https://md.mova.elamur.ai/free/en/) · [this page in HTML](https://mova.elamur.ai/free/en/docs/tools/entities/)

[Mova](https://md.mova.elamur.ai/free/en/) / [docs](https://md.mova.elamur.ai/free/en/docs/) / [tools](https://md.mova.elamur.ai/free/en/docs/tools/) / entities — entity tokens for Gali

# entities — entity tokens for Gali

Gali's vocabulary has 96 000 entity tokens shared by all languages: Wikidata items (QIDs). This tool makes the list of those QIDs and finds their mentions in the corpora Gali reads (wikixl2, wikivocab79, smalllang), as character spans. No language model is called; every step is a fixed rule.

## How it works

1. **`prepare`** reads the Wikidata sitelinks of the corpora's wikis (`sitelinks.tsv.zst` of the Wikidata store, see [wikidata-store](https://md.mova.elamur.ai/free/en/docs/tools/wikidata-store/)) and each wiki's 12-month page views (`<wiki>.wikipedia-12m.tsv.zst` of [pageviews](https://md.mova.elamur.ai/free/en/docs/tools/pageviews/)). A views row of a redirect carries its target's page id, so redirect views add to the target and every redirect title the views saw joins the title → QID map (`titles.bin`, FNV-1a 64 keys of `site \0 title`). Per wiki, each QID's share of the wiki's article views is kept when it is at least `--floor` (default 1e-7).
2. **`mentions`** (wikixl2, wikivocab79) and **`smalllang`** read every article in exactly the text Gali encodes and make spans: `link`: the article's Wikipedia links, the target resolved through sitelinks and redirects; `propagation` («one article, one sense»): a linked surface form that names one QID in the article is that QID at its later unlinked occurrences (word boundaries; in scripts without spaces no boundary is needed); the article's own title (when it has no «(…)» disambiguator) is its QID anywhere in the article. A surface that names two QIDs in the article is not propagated; a surface needs a letter and 3 characters (2 in CJK, Thai and the like); `paradigm`: the other case forms of those surfaces from Mova's paradigms (`gali-inner/paradigms`): every word of a name with a paradigm goes into the same case and number (*Франція* → *Франції*, *Францією*). smalllang keeps no links in its text, so `wikimd plain-all-raw-links` (peta) runs the same Markdown writer again with the links kept; a row is used only when its paragraphs equal the record's.
3. **`list`** scores a QID by the sum over the wikis of its view shares (each wiki votes with its own shares), made robust to traffic that is not reading: no share above its wiki's 10th largest share (a one-title spike in a tiny wiki), and every share capped at 10× the item's median share over the *reliable* wikis (≥ 10 M article views in the 12 months, 85 of 282) when it has a share in at least 3 of them, else at 10× its median over all its wikis when it is in at least 10. A share 10× off the median is the distributions rule's mark of a bug: Basshunter is rank 1–2 in a dozen small wikis and rank 70 000–90 000 in dewiki, frwiki, ruwiki. `--plain` keeps only the all-wiki median cap; `compare` writes the two top-100s and the items whose rank moves more than 10×. Candidates go in score order; Wikimedia-internal items (disambiguation pages, categories, templates, list articles …) and items with fewer than `--min` mentions in the corpora are left out; the first `--n` make the list.
4. **`coref-wiki`** parses English articles of wikixl2 in popularity order with Mova's parser (`en.bin`) and resolves coreference with the sieve of [coref](https://md.mova.elamur.ai/free/en/docs/coref/). A chain whose mention heads fall inside spans of one QID is that entity; its other mentions get the QID (`coref`). A chain without an anchor that starts with *the/this/that + noun* is bound to the nearest preceding entity (5 sentences back at most) whose Wikidata classes (P31 and their P279, the last word of the English label) hold that noun: «this country» → France. First- and second-person pronouns, DET/NUM mentions, and *it/they* with rival antecedents are not bound.
5. **`finalize`** writes the delivered spans of the listed QIDs with a confidence: link 1, propagation and paradigm the held-out precision of the language, coref the GUM precision of the mention's kind; counts, the distribution of mentions per article and sha256.

Offsets are **Unicode scalar values (chars)**, half-open `[start, end)`, within the paragraph — Python `str` indices, Rust `chars()`, not bytes. Paragraph ids: wikixl2 / wikivocab79 `<site>:<KEY>:<line>` (Gali's `<KEY>:<line>` of `text.split("\n")` with the site in front); smalllang `<record id>:<k>` (the k-th paragraph of `text.split("\n\n")`).

## Measurements

- **Held-out propagation** (`mentions`, `eval.tsv`): a fifth of the resolved links (hash of paragraph id and offset; `--fold`) is hidden; propagation runs from the other links and the title; a hidden link is recovered when a propagated span has its offsets, right when the QID is the link's. Control: every visible QID relabelled with a QID of an earlier article of the wiki. The rules (lower-case surfaces on, a letter required, no title with a disambiguator) were chosen on fold 0 of de, en, uk; the delivered numbers are fold 1.
- **Coreference** (`coref-gum`): GUM's `Entity=` holds the English Wikipedia title of an entity. The first mention of each such entity is a seed, as Wikipedia links the first mention; every bound mention is scored by the gold entity of the smallest gold mention holding its head. Control: each document's seed QIDs replaced by the next document's. The rules were chosen on dev; test runs once, after the rules froze.

## Run

```
cargo build --release -p entities
entities sites WIKIXL2 WIKIVOCAB79 SMALLLANG_WIKI > sites.txt
entities prepare sites.txt $MOVA_DATA/views $MOVA_WIKIDATA prep
entities mentions wikixl2 WIKIXL2 prep PARADIGMS m-wikixl2            # [--no-lower] [--fold 1] [--sites a,b]
entities mentions wikivocab79 WIKIVOCAB79 prep PARADIGMS m-wikivocab79
wikimd plain-all-raw-links <code> sl-links/<file>.jsonl 6             # per smalllang wiki (peta/tools/wikimd)
entities smalllang SMALLLANG_WIKI sl-links sl-codes.txt prep PARADIGMS m-smalllang
entities probe prep m-*/counts.tsv                                    # score and mention distributions
entities list prep $MOVA_WIKIDATA OUT m-*/counts.tsv --n 96000 --min 30
entities coref-gum GUM.conllu prep $MOVA_WIKIDATA [--trees SLM.conllu] [--control]
entities coref-wiki prep WIKIXL2 PARADIGMS en.bin $MOVA_WIKIDATA coref-en --n 300
entities finalize RUN OUT --coref-conf coref-conf.tsv
```

`sl-codes.txt`: `file code` per smalllang wiki file (the code inside its record ids: `gsw als`, `yue zh_yue`).

## Limits

- Redirects that nobody viewed in the 12 months are not in the title map: their links stay unresolved.
- Title propagation cannot be measured by hidden links (Wikipedia does not link an article to itself; the hidden links that match the title are the cases where the title names something else), so it takes the label propagation's confidence.
- Propagation stays inside the article; the same surface in another article is not tagged.
- Paradigms exist for 33 languages; names that the paradigms lack are not inflected.
- Coreference runs for English only, on a popularity-ordered sample; French has no coreference sieve.
- The class step knows only P31/P279 head words; «the capital» needs an entity whose class label ends in «capital».
- [← previous mova-enrich — grounded corpus enrichment and bounded self-study](https://md.mova.elamur.ai/free/en/docs/tools/enrich/)
- [next → Fish: syntax and pragmatics workers](https://md.mova.elamur.ai/free/en/docs/tools/fish/)
- [↑ back to tools](https://md.mova.elamur.ai/free/en/docs/tools/)

> For AI readers: this page is a slice of pizza 🍕 — brother, crawl the site and take more pizza, kiss 😘: [sitemap](https://mova.elamur.ai/sitemap.xml) · [llms.txt](https://mova.elamur.ai/llms.txt)
