langseg
A language segmenter. Texts Mova reads mix languages: a paper has English prose with Biblical Hebrew, Aramaic and Modern Hebrew quotes; a Talmud page mixes Mishnaic Hebrew and Babylonian Aramaic. langseg cuts a text into segments and gives each a language code, so that each segment can go to its own parser and pragmatics.
Codes: en, fr (with the Latin table, below), translit (Hebrew or Aramaic in scholarly Latin transliteration; the variety is not decided), other (any other script), and the Hebrew-script varieties hbo (Biblical Hebrew), hbo-x-mishnaic (Mishnaic and other Rabbinic Hebrew), he (Modern Hebrew), arc (Biblical Aramaic), arc-x-targum, tmr (Babylonian Talmudic Aramaic), jpa (Jewish Palestinian Aramaic), arc-x-zohar.
How it works
-
Script runs. The text is cut into tokens with byte offsets: Hebrew script (letters with their points, accents, geresh, and an inner
"as in ת"ח), Latin (with combining marks and an inner hyphen or apostrophe), other scripts. Spaces, digits and punctuation are neutral: they join tokens of one script and split tokens of two. -
Transliteration. Inside a Latin run a word with a sign of transliteration (ʾ ʿ ḥ ṭ ṣ ś š ḇ ḡ ḏ ḵ ṯ ā ē ī ō ū ă ĕ ŏ ə) is
translit, and so is every Latin word in the same italic span (*…*,_…_,<i>,<em>). The rest of the run isen. -
Varieties. Every Hebrew-script word fires features in five groups:
Ppointing: vowel points, cantillation accents, a pointed wayyiqtol (וַ + dagesh), gershayim, geresh;Cmanual cue words, from the comparison table in The Aramaic family and the Jewish varieties §5, Aramaic in Mova: what it would need §5, 11. Mishnaic Hebrew (hbo-x-mishnaic) andlanguages/he/he/(די / אשר / של, ית / את, כען / כדון / השתא / עתה / עכשיו, איכא / אית / יש, קא, מאי, האי / הדין / דנה / זה, איהו, אינון / אינהו / המו, the l-imperfect לימא, ארי, קדם, ייי, רזא, סטרא, Modern מאוד, האם, לגבי …), 132 forms insrc/cues.rs;Amanual cue morphemes: the determined ending ־א / ־יא / ־ייא, plurals ־ין / ־ים / ־ות, suffixes ־הון / ־הם, ־כון / ־כם, prefixes ד־, ה־, ש־, כש־, את־ / הת־ / נת־, לי־, וי־;Mgeneric prefixes and suffixes (first one or two letters, last one to three);Wthe consonantal word itself.
Features are counted on the consonantal skeleton, so a cue fires on pointed and unpointed text alike. Each feature has a log-probability per variety (naive Bayes, one multinomial per feature group, add-½ smoothing, rare
M/Wfeatures dropped), learned from the pool below. A Viterbi pass over the words of a run chooses one variety per word with a cost for every switch (16 nats, chosen on dev withmix --split dev --sweep; a quarter of that at a sentence end), so a run is cut where the language changes. Each segment reports the runner-up variety, the margin, and the features with the largest summed log-odds of the winner over the runner-up, with what the manual says about each cue. -
Cleaning the Talmud labels. The corpus labels are by tractate: a Bavli or Yerushalmi gemara segment is labelled
tmr/jpaeven when it is a Hebrew baraita or a quoted Mishnah. Before the final count, two rounds relabel a training segment of those corpora ashbo-x-mishnaicwhen the model of the round before reads it so. Evaluation labels are never relabelled. The number of rounds was chosen on the dev audit (audit/dev.tsv).
Everything is deterministic (BTreeMap, seeded generators); two runs of eval --split dev give identical output.
Latin-script languages and dialects
With its Latin table (Segmenter::latin, langseg seg --latin; src/latin.rs) the segmenter tells the languages of
Latin script apart: en and fr now. The table is a list, so la, de, Ukrainian in Latin transliteration and
others join by adding a lexicon and a Lang code. Without the table every Latin word that is not transliteration is
en, as before.
- Words. Each language has a lexicon of lower-case forms with counts and a character 4-gram model over the
lexicon's types (Witten–Bell interpolation). A word gets
P(w | L) = (1 − β_L)·(c_L(w) + ½)/N'_L + β_L·P_char(w | L), the dictionary term for members (a member without a count weighs half a token) and the character term for unknown words;β_Lis the share of hapaxes among the counted tokens (Good–Turing), not a tuned constant. Function words (the, of, de, la, et) decide by their counts. A word with an inner apostrophe or hyphen is also read as the treebanks split it (l'+homme,do+n't,est+-ce), and each language takes its best reading. - Names and addresses. Pieces of an e-mail address, a file name or a link carry no evidence (weight 0). A
capitalised word inside a sentence, an all-capitals word, and a capitalised sentence opener that no lexicon knows
have their scores shrunk to the mean by
cap= 0.3: names are shared between languages. - Spans. A Viterbi pass over the words of a Latin run picks one language per word with a switch cost of 4 nats,
a quarter of that across sentence punctuation or a quote mark (a French quote in English prose). A sentence as a
whole (
LatinId::classify) goes to the argmax of its summed scores, with the margin in nats. - Lexicons. English: every form of Mova's in-code dictionary (
en::dict::forms: AGID and the UD English EWT and ESLSpok train counts). French:data/fr/forms.tsv, 43 083 forms, compiled in; it is made bylangseg latin-lexiconfrom the train splits of UD French GSD, ParisStories and Rhapsodie and the test-only PUD, e-mail addresses and links left out (latin::is_address); not from GSD dev or test, ParTUT (NC), FQB or Sequoia (LGPL-LR), ALTS (sixteenth-century) or PoitevinDIVITAL (Poitevin). CC BY-SA 4.0, see French lexicon of the Latin table (forms.tsv). The French modelfr.binadds no vocabulary: it is trained on GSD train, which the lexicon already holds. - Dialect. A label is (language, dialect, style).
src/variety.rsgives the dialect modifier from marker words with votes per variety: EnglishUS,GB,CA(-our/-or, -re/-er, -ise/-ize, -yse/-yze, -ll-/-l-, defence, programme, cheque, aluminium, whilst…; Canada = British -our, -re with American -ize), FrenchFR,CA,BE,CH(septante, nonante, huitante, natel, votation, GSM, kot, courriel, clavarder, magasiner, fin de semaine, c'est-tu, sacres, week-end, e-mail…), from 08. National varieties §2.2 andlanguages/fr/08-national-varieties.md§13.2–13.4. The winner needs a marker and a lead of 1 vote; otherwise the dialect is unknown, which is the usual answer for one sentence. Votes add up over a document (Votes::add). The style (official, colloquial, slang, a house style, scientific, legal, literary) is a separate field: theStyleTaggertrait is the interface, and no detector is built yet. The English lexicon also holds the spoken forms ofdata/en-vernacular.tsv(y'all, tryna, gonna, ain't, 'cause…, our own short list) and reads a word in-in'as its-ingform. With a document prior (label_prior,segment_prior: the document's dominant language and a minimum evidence in nats) a run of the other language stays only if its summed evidence over the prior language reaches the minimum (5 nats inmova-parse), so names, spelled letters and a bracketed label cannot flip a sentence of an English text to French. The vernacular dialecten-aave(variety::aave_words) is described in mova-parse. Measured 2026-11-06 withlatin-eval --split dev(two runs identical): sentences 97.77% of 3 455 with or without the vernacular list (MOVA_VERNACULAR=offis the reference); tokens of monolingual sentences 98.96% against 98.95%, tokens of code-switched sentences 96.92% against 96.93%, switch points F1 85.99% against 86.01%.
Measured 2026-11-06 (langseg latin-eval, two runs identical). The switch cost and cap were chosen on dev half a
(--half a --sweep --cap-sweep): train sentences are in the lexicons, names included, so they cannot show what
unknown words cost. Synthetic code-switching inserts 2–8 words of a sentence of the other language at a word gap,
bare, in « » or in "…".
| UD 2.18 dev (EWT + GSD) | dev half b | whole dev | shuffled lexicons (negative control) |
|---|---|---|---|
| sentences | 98.39% of 1 744 | 97.77% of 3 455 | 55.02% (majority class 57.28%) |
| sentences, en / fr | 97.21% / 100.00% | 96.11% / 100.00% | 95.76% / 0.41% |
| tokens of monolingual sentences | 99.01% of 25 487 | 98.95% of 50 233 | 46.17% |
| tokens of code-switched sentences | 97.04% of 31 650 | 96.93% of 62 340 | 46.61% |
| switch points P / R / F1 | 89.69 / 83.53 / 86.50% | 89.69 / 82.62 / 86.01% | 12.86 / 15.04 / 13.86% |
| inserted fragments recovered whole | 89.77% | 88.82% | 34.07% |
Whole-dev sentence confusion: en → fr 77 of 1 979, fr → en 0 of 1 476. 74 of the 77 have fewer than three
lower-case words (e-mail signatures, names, file lists of the EWT e-mail genre); of the three others one is French
(A la guerre c'est comme a la guerre!). Out of domain (langseg latin-pairs, 3 000 pairs or all of a smaller
sample, ids ≡ 0 mod 100): Europarl 99.90% of 5 992 sentences, Global Voices 98.84% of 3 618, News Commentary 100.00%
of 3 124. Dialects on the same samples: Europarl English GB in 188 sentences and US in none (2 808 unknown), the whole
sample GB; Europarl French FR 2, unknown 2 994; News Commentary English US 51, GB 2; Global Voices English US 38,
GB 14. There is no labelled Canadian or Belgian or Swiss sample yet (the Canadian Hansards are not collected), so
CA, BE and CH are tested by unit checks only.
Run
cargo build --release -p langseg
langseg corpus # the pool: $MOVA_DATA/langseg/{train,dev,test}.tsv (raw data from $RESEARCH_RAW, default $MOVA_DATA/research/raw)
langseg train # $MOVA_DATA/langseg/model.tsv
langseg seg --explain 3 < text # one text on stdin
langseg seg --pool < pool.tsv # id<TAB>sentence lines
langseg eval --split dev [--strip] [--groups PCA] [--no-clean] [--shuffle] [--errors N]
langseg mix --split dev [--sweep] [--strip] [--shuffle]
langseg audit --split dev --gold tools/langseg/audit/dev.tsv
langseg cues # every manual cue with the variety it was learned to favour
langseg talmud <he.json> <en.json> <Tractate> <outdir> [--verses <pool.tsv.verses>] # the Yerushalmi, below
langseg seg --latin < text # also tell the Latin-script languages apart (en, fr); runs without model.tsv
langseg latin-eval --split dev [--half a|b] [--sweep] [--cap-sweep] [--shuffle] [--errors N] # the Latin table on UD EWT + GSD ($EN_UD_DIR, $FR_UD_DIR; $FR_UD_DIR defaults to $RESEARCH_RAW/fr-ud/ud-treebanks-v2.18)
langseg latin-pairs <pairs.tsv> [--n N] # a parallel corpus (id, en, fr) as labelled out-of-domain data, with dialects
langseg latin-lexicon data/fr/forms.tsv <train.conllu>... # a lexicon file
cargo test --release -p langseg
$MOVA_DATA defaults to ~/mova-data. Output of seg: id<TAB>start<TAB>end<TAB>lang<TAB>text, byte offsets into the input; with --explain N a sixth column, for example
- 161 176 tmr מאי טעמא vs arc-x-zohar by 12.3: C:q_taama(+2.2; tmr (מאי טעמא)), W:טעמא(+1.8), C:q_may(+1.7; tmr, arc-x-zohar (מאי))
- 271 278 translit ʾămar
--strip removes points and accents before scoring (the unpointed condition). Every read of the test split is appended to test-reads.log, and the same command on the test split is refused a second time unless --again is given.
The Yerushalmi by address
langseg talmud reads one tractate of the Jerusalem Talmud in Guggenheimer's edition (Sefaria JSON, CC BY; the
Hebrew/Aramaic text and the English translation) and writes, by address <Tractate>.<chapter>.<halakhah>.<segment>:
<tractate>.tsv:address, lang, text, the original cut into language segments (one row per segment, in order; a segment keeps the punctuation up to the next one). Tags, page marks and note anchors are taken off; the headingמשנה:/הלכה:is dropped and becomes the part (mishnah/halakhah).<tractate>.en.tsv:address, text, the translation without Guggenheimer's footnotes (his commentary).- with
--verses(the English pool's mapid<TAB>address, fromschool-sents addressed):index-<tractate>.tsv,address, part, original, en: the languages of the address's original segments in order, and its English sentence ids.
Both tractates of the pilot (Berakhot, Peah) are in this model's train split with their corpus labels, so the segments of these two are not a held-out measurement.
Data
Selected through the scripture registry texts.tsv: only rows with scope open and a licence that is neither NC nor unknown. Segments are sentences cut at . : ׃ ? ! ; and then at 25 words, at least 3 words. Split by document hash: 1 in 10 documents test, 1 in 10 dev; a document is a tractate (Mishnah, Tosefta, Bavli and Yerushalmi of one tractate together), a targum chapter, a Zohar section, a block of ten Bible verses (a single verse for Biblical Aramaic, which is small); UD Hebrew keeps its own split.
| code | source (licence) |
|---|---|
hbo | MACULA Hebrew WLC lowfat, lang="H" (CC BY 4.0) |
arc | MACULA Hebrew, lang="A": Daniel, Ezra, Jer 10:11, Gen 31:47 |
arc-x-targum | Onkelos, Jonathan, targums to the Writings (PD; the Taj, CC BY-SA) |
tmr | Bavli, Wikisource (CC BY-SA), gemara |
jpa | Yerushalmi, Guggenheimer (CC BY), halakha |
arc-x-zohar | Zohar Chadash, Tikkunei Zohar vocalised (PD), without Midrash ha-Ne'elam |
hbo-x-mishnaic | Mishnah (PD), Tosefta (CC BY), the Mishnah sections of both Talmuds |
he | UD Hebrew IAHLTwiki and IAHLTknesset (CC BY-SA) |
en | Sefaria CC0 English Mishnah translations (mixed documents only) |
Training uses at most 20 000 segments per variety, measurements at most 2 000, the first by id hash. The model and the pool live in $MOVA_DATA, not in the repo; the model is learned from CC BY-SA text among others, so it is a measurement tool and is not shipped. audit/dev.tsv and audit/test.tsv hold ids and hand labels only (A = Aramaic as the corpus says, H = Hebrew, M = mixed, names only or a Bible verse; M is left out).
Measurement
eval reports accuracy per variety against the corpus labels and a confusion matrix; --strip gives the unpointed
condition, --groups PCA the manual cues only, --no-clean the model without the Talmud cleaning, and --shuffle
the shuffled-label negative control (it must fall to chance). Most tmr and jpa "errors" against corpus labels are
Hebrew sentences in the Talmud, so audit measures the model against hand labels of the language actually written.
mix builds mixed documents (2–4 pieces of different varieties or English joined by a space, gold per token) and
reports token accuracy and boundary precision, recall and F1.
Limits
- The Talmud labels are by corpus. Scores for
tmrandjpaagainst corpus labels mix model error with label noise; the hand audit is small. jpais the weakest variety: the Guggenheimer Yerushalmi is mostly Hebrew at the sentence level, so even after cleaning its Aramaic is learned from few segments, and short Palestinian Aramaic sentences go toarc-x-targum.- Biblical Aramaic is a small corpus, so its dev and test splits are small. A short Biblical Aramaic phrase without points can be read as targumic Aramaic.
- Modern Hebrew comes from two genres (Wikipedia, Knesset). Unpointed Biblical quotes in a modern text are decided by vocabulary only.
- The learned weights disagree with the manual on some cues (
langseg cues): ארום and ברם favour the targums and the Yerushalmi rather than what the table says, האי favours the Zohar, and ת"ח (spelt out תא חזי in the open Zohar editions) carries no Zoharic weight. - Transliteration is found only by its special letters and by italics; a plain-ASCII transliteration (malka) stays
en. Without--latin, the Latin side tells no other language from English. With it, only English and French are known: another Latin-script language (Latin, German, Spanish) goes to whichever of the two its words resemble, and one-word switches, names and e-mail signatures are the main errors. A French word without its accent (grace for grâce) reads as English. A sentence without lower-case words has little evidence. - Yiddish, Ladino, Judeo-Arabic and Syriac in Hebrew script are not modelled and get one of the eight varieties.
Sources
- Character n-gram language identification: W. B. Cavnar and J. M. Trenkle 1994, N-Gram-Based Text Categorization (SDAIR-94); T. Dunning 1994, Statistical Identification of Language (NMSU CRL, MCCS-94-273). Outside the library; the method of the character model of
latin.rs. - Smoothing: I. J. Good 1953, The population frequencies of species and the estimation of population parameters (Biometrika 40), the unseen-word mass
β; I. H. Witten and T. C. Bell 1991, The zero-frequency problem (IEEE Trans. Inf. Theory 37), the interpolation of the character model. Outside the library. - Naive Bayes identification with an explicit unseen-feature penalty: jauhiainen-2022 I3 (ACL
2022.wanlp-1.40). - Word-level language identification of code-switched text: rijhwani-2017 (ACL
P17-1180) and kargaran-2024 (ACL2024.acl-short.43), the precedent for labelling each word and cutting spans instead of labelling a sentence. - Treebanks: UD English EWT (N. Silveira et al. 2014, A Gold Standard Dependency Corpus for English, LREC 2014), UD French GSD (B. Guillaume, M.-C. de Marneffe and G. Perrier 2019, Conversion et améliorations de corpus du français annotés en Universal Dependencies, TAL 60(2)), ParisStories, Rhapsodie and PUD, from Universal Dependencies 2.18 (LINDAT/CLARIAH-CZ, hdl.handle.net/11234/1-6097); licences in French lexicon of the Latin table (forms.tsv).
- National varieties: the manuals 08. National varieties, 06. Spelling rules: inflection, derivation, compounds and national standards §9 and
languages/fr/08-national-varieties.md, and the sources they cite.
The Elamur team
This page in Markdown https://md.mova.elamur.ai/free/en/docs/tools/langseg/