Mova0.6 pre-release

translate — Mova's translator through a meta-world

translate is Mova's own deterministic translator, and its hard test. A text is read down the standard stack of its language into a world, read from there into a meta-world that belongs to no language and no author, and written out of the meta-world by the standard encoder of the target language with the target author's delta. The standard stack of that language then takes it down to the text. The test is byte for byte. Whole blocks of verse-aligned Bibles must come back exactly: runs of chapters up to 2 500 words, with their layout (blocks.rs). What that takes, the residual, is measured in bits per block, per 1 000 words and per verse, by stage and by class. No large model translates or teaches here: every table is counted from the texts, and every choice says why.

How it works

source text ─► tokens ─► UD tree ─► frames ─► world            (the standard stack of the source: tools/roundtrip)
                                      │
                         reader into the meta-world             (the interlingua lexicon; for Hebrew, the Hebrew reader)
                                      ▼
                                 meta-world                     (concepts, coarse grammar, tree: no author, no language)
                                      │
               standard encoder of the target language + the author's delta
                                      ▼
target words ─► UD tree ─► tokens ─► text                       (the standard stack of the target, with the encoder's
                                                                 order and forms as hints)

The meta-world

The meta-world of a verse is a graph of meta tokens. Each token has a concept, the coarse grammar the standard parse gives it (PTB tag), its head and its relation. With --meta-rel coarse the relation is a frame role (subject, object, oblique, a noun's modifier, a verb's modifier, a clause link, a function word, punctuation, root), and a punctuation mark hangs on the token before it. With --clauses flat a sentence's root and every coordinated or paratactic predicate hang on the top of the verse, so how an author joins clauses («…, and he said» or «…. He said») is not in the meta-world's tree.

Function words between two authors (fwt.rs, --fwt on) are the one part learned per author pair. For each trained pair, a small table holds the function tokens of the source the target drops in a context, and the runs of function tokens it inserts between two source tokens. A rule is kept with at least 3 cases and half of its context's. The table is applied to the source's meta-world before the target's encoder. Each token also keeps the source words it was read from, so an encoder can learn how an author writes it. What belongs to one author is left out:

The interlingua lexicon (meta.rs) is learned once, for all authors, on the training verses of pairs of authors. The pairs are around two hubs: JPS–KJV, KJV–WEB and KJV–ASV, and with --hub2 on also JPS–ASV and ASV–WEB. JPS↔WEB is never paired. For each pair:

  1. Each verse is read as a sequence of reading keys: the lemma in lower case; a punctuation mark as written; LORD and GOD (the divine name in capitals) in capitals.
  2. The longest common subsequence of the two key sequences anchors the verse. The gaps between anchors are the places where the two authors differ.
  3. Gap pairs of one to four keys on each side give word and phrase pairs. A word next to punctuation does not form a pair.
  4. A pair is a candidate when it holds for at least 3 occurrences, 20% of the word's differing places and 2% of all its occurrences.
  5. Each candidate is judged by the residual it moves (--lexicon judged, the default). What a merge saves the reader is measured (--judge measured): the reader's bits on up to 12 sampled training verse pairs where the two differ, with the merge and without it, times the merge's count (without the flag: an assumed 17 bits a word for every differing place it makes equal). With --judge-pairs on, a merge must also not cost any author pair more than it saves that pair's reader. A pair's cost counts its two authors' occurrences whose member the author and the tag no longer tell. It costs the encoder 17 bits a word for every occurrence, in all the judged corpora, whose member its context no longer tells: author, tag and relation for a word, author alone for a phrase. Candidates go in order of their counts, and a cluster's cost is recomputed as it grows. A merge is kept when it saves at least 51 bits more than it costs. --lexicon mutual is the alternative rule: each must be the other's most frequent partner, with 5 occurrences, 30% and 5%.

The concept is named after the most frequent member. The reader reads a verse with the longest known phrase first, then the word. A phrase's tree position is that of its word whose head lies outside it.

The Hebrew reader (hebrew.rs) is also learned, not written. It reads the Leningrad Codex as MACULA's UD trees.

  1. It learns on two kinds of training verse pairs:
    • Hebrew with the meta-world read from JPS 1917, cut at the Hebrew verse numbers. Meta tokens align to Hebrew words by IBM Model 1. MACULA's English glosses act as a prior: 2 pseudo-counts per gloss word in each of 5 iterations. A place prior favours words at the same relative position.
    • Hebrew with the meta-world read from the KJV, where its verse numbers are the Hebrew ones (--strong <eng-kjv>). eBible's KJV writes each translated word with the Strong's number of the Hebrew word it renders, and MACULA writes the same numbers on the Hebrew words (strong.rs). A meta token with a number aligns to the Hebrew word with that number; the rest align by IBM Model 1.
  2. The meta tokens aligned to a Hebrew word, and the unaligned tokens after them, form that word's chunk: וַיְהִי reads as it come_to_pass, and אֵת reads as nothing.
  3. A Hebrew word reads as its most frequent chunk, in the most specific context seen at least twice: lemma, part of speech, verb type, person and number; then lemma, part of speech and verb type; then the lemma alone.
  4. A lemma never seen reads as MACULA's gloss through the lexicon.
  5. Chunk heads hang on the chunk of their Hebrew head.
  6. With --heb-grammar on (grammar_plan), the reader also writes what Hebrew says by structure and English by words:
    • an of before a construct dependent;
    • a the before a construct head whose chain is definite;
    • each possessive suffix as a possessive before its noun;
    • a subject that follows its verb, moved before the verb.

The Hebrew world level uses MACULA's verbs and their frame arguments (Frame=A0/A1/A2), and the negation of macula prag.

The standard encoder and the authors

The standard encoder (profile.rs) is learned on all the English we have:

Each text is read into the meta-world, and each meta token is seen next to the chunk of words written for it. The sentence capital is taken off, because it is the stack's rule. To encode a token, the standard takes the most specific context that was seen often enough and writes its most frequent chunk. The contexts, from most to least specific, are:

  1. concept, tag and both neighbours;
  2. concept, tag and relation;
  3. concept and tag;
  4. the concept alone.

A concept never seen gets its bare form: the concept inflected by morph from its tag.

An author is a delta over the standard: a sparse set of overrides, learned only from what the standard gets wrong on that author's training text. The overrides are learned from the coarsest context to the finest. An override «in this context write this chunk» is kept only when both of these hold:

A finer override wins over a coarser one. Where the delta says nothing, the standard decides. «Author» can be any style. Here there are eight: JPS 1917, KJV, WEB, ASV, the school's book lines (school-plain: explain, fact), its conversational test questions (school-talk: the voice that is half slang), its formal exam questions (school-exam), and the tales.

Exact mode: the split code and the gate

For each target verse, the residual is split by stage (measure.rs):

The decoder runs the stages down: meta-world, encoder, parse, script, tree decoder, text. The gate compares the meta-world, the tree, the tokens and the text on the way. The direct code is gated too: it sends the target from the translation's own normal-mode output, with a tree script and the stack, the way the baselines are measured.

Classes are roundtrip's, in six groups:

Bits follow roundtrip's fixed rules: a dictionary lemma is 17 bits, a function word 8, a mark 5, a position log2(n+1).

Normal mode

In normal mode the encoder with the target author's delta writes the source's meta-world, with no residual. The output is scored against the target verse by exact match, chrF, and roundtrip's divergence classes on the parsed output.

Data

How to run

cargo build --release -p school-sents -p translate -p jobs
E=$RESEARCH_RAW/scripture/4-translations/ebible
P=$MOVA_DATA/runs/translate-<date>/pools
OT=GEN,EXO,LEV,NUM,DEU,JOS,JDG,RUT,1SA,2SA,1KI,2KI,1CH,2CH,EZR,NEH,EST,JOB,PSA,PRO,ECC,SNG,ISA,JER,LAM,EZK,DAN,HOS,JOL,AMO,OBA,JON,MIC,NAM,HAB,ZEP,HAG,ZEC,MAL
for a in jps:engjps kjv:eng-kjv web:eng-web asv:eng-asv; do
  target/release/school-sents usfm $E/${a#*:} $P/${a%%:*}.tsv ${a%%:*} $OT; done
target/release/school-sents usfm $E/engjps $P/jps-heb.tsv jps $OT --hebrew-verses
J=$MOVA_BIG/corpora/judaism
target/release/jobs run --name translate --mem-gb 14 -- target/release/translate eval \
  --pools $P --wlc $J/text/tanakh-wlc-macula --prag $J/parsedb-hbo/prag.tsv \
  --school $MOVA_DATA/school/courses --tales <corpus-0.3>/treebanks/mova-tales-silver-en.conllu \
  --talmud <talmud pool>/talmud.tsv \
  --strong $RESEARCH_RAW/scripture/4-translations/ebible/eng-kjv \
  --meta-rel coarse --judge measured --lb on --judge-pairs on --hub2 on --clauses flat --fwt on --heb-grammar on \
  --own-words 0.8 --typo on \
  --usfm $RESEARCH_RAW/scripture/4-translations/ebible \
  --out $MOVA_DATA/runs/translate-<date>/run1 --split dev --threads 10
# alternatives, off by default: --lexicon mutual, --feats on, --meta-tree frames, --fw on, --clauses on|joined, --lattice on, --std-vote corpus|context, --reorder on
# --sample N (default 5): one in N of the school's held-out lessons is measured
cargo test --release -p translate

The flags above are the current system. A run writes report.md (every table of the run), examples.md (verses with the reason of every choice), numbers.tsv, lexicon.tsv (each concept's members and the pair that linked them) and deltas.tsv (every override with its counts). Two runs of the same flags give byte-identical files. The test split runs with --split test, once per release; decisions are made on dev.

Each run reports normal mode (chrF and exact match per block and per verse), exact mode (bits per block, per 1 000 words and per verse, split and direct code), the residual by class, the reader stage alone, world-level agreement, and each author's delta on its held-out text. Baselines are measured beside every system: copying the source, a word-by-word table trained on the pair, and, from Hebrew, MACULA's glosses word by word. The dev books cut into blocks by roundtrip blocks' rule (roundtrip::blocks::group); this crate's own maker and roundtrip::blocks::jps must give the same runs, which every run checks.

Options

Controls

Every run measures its negative controls beside the systems: the gate control (a corrupted residual must fail), verses shuffled inside each block, the Hebrew reader learned on shuffled verse pairs, the wrong author's delta, a delta trained on shuffled units, the null delta, the lexicon learned on shuffled verse pairs, and the function-word, joining and reorder tables learned on shuffled verses.

Limits of normal mode

  1. Quotes across verses. The quote state is kept per verse, not per block, so a quote that opens in one verse and closes in another comes out the wrong way round.
  2. Swaps for pairs never trained. The swap tables exist only for trained pairs; they are not composed through the hub (JPS→KJV→WEB), so JPS→WEB keeps unto, thy and thou.
  3. Own words do not yield to a finer context the author has seen (KJV's stand where it writes standest after thou), and the share is flat.
  4. The Hebrew clause order inside quotes and objects, and the of: an inserted article can still meet a chunk's of.
  5. The one-reader block code has no position code that names the verse first.

The parallel Tanakh as site pages, both ways (--pages)

The Tanakh corpus pages of the site (corpora/<part>/<BOOK>.<c>.<v>/: a verse in Hebrew with its MACULA tree, its pragmatics, its Targum and links to its English; corpora/<part>/jps/<BOOK>.<n>/: a JPS sentence with its tree and frames) are translated as page blocks, Hebrew pages → meta-world → English pages and English pages → meta-world → Hebrew pages (pages.rs). A chapter is its verse pages on one side and the sentence pages that begin in it on the other; the blocks are the JPS's chapter runs of roundtrip blocks (blocks::jps, blocks::group, 2,500 words), the other side cut the same (blocks::like).

A target page block costs the translation of its texts — each Hebrew verse, or each English unit (the JPS sentences that begin in a verse), with the split code (reader, encoder, stack) — and the page around them: the target pages through roundtrip blocks' site decoder (roundtrip::blocks::site_md) with the translated texts and the source's own texts given (site_md::give, class given), so the markup, the other prose, the trees and tables it writes from the layers, and the Targum are what is left.

English → Hebrew (heb_enc.rs). The Hebrew encoder is the Hebrew reader turned round, learned on the same training verse pairs: the reader's alignment gives each meta token to a Hebrew word (its chunk); the first token of a word's chunk emits the word (lemma, UPOS, XPOS, FEATS, relation), the others nothing; to encode, each meta token emits what it emitted most often in the most specific context seen twice (profile::ctx_keys), and a word hangs on the word its meta head's chain emitted first. The split code onto a Hebrew verse: reader — the script from the meta-world read from the English to the one the Hebrew reader reads from the target verse; encoder — the Hebrew tree script from what the encoder writes for the target's own meta-world to MACULA's words (roundtrip::mixed::heb::frames_encode), with the words out of place; stack — the words to their forms by the lookup generator of the training books' trees, a form looked up with the word before it in its written word (Lookup::from_conllu_ctx, --heb-forms ctx: the dagesh after וַ, the article's vowel), and the written words to the verse (mixed::heb::tree_encode, tokens_up); a verse whose written words are not its tree's (a paragraph mark glued to a word) stores its text. The gate decodes the meta-world, the words, the written words and the verse. A Hebrew encoder learned on shuffled pairs is the control.

Run

roundtrip site-learn --site-md $S --site-target 1000 --out $L --model <en.bin> --lin-every 2   # tools/roundtrip README
jobs run --name translate --mem-gb 16 -- translate eval … (the current system's flags) \
  --pages $S --site-dict $L/markup.tsv --site-heb $L/hebrew.tsv --site-english $L/english.tsv --heb-forms ctx \
  --model $L/en-lin.bin --out <dir> --split dev

--site-english adds the site's train pages' English (english.tsv; the Tanakh's held-out books left out) to the standard encoder's training text. The adapted order (en-lin.bin) changes no translation stage (the encoder's order is the stack's hint); it applies to the pages' prose. The run appends «The parallel Tanakh as pages, both ways» to report.md and writes pages.tsv (a row per block and direction: verses, words, gate, the bits of each stage and of the page). The test split needs a higher --mem-gb than dev while it writes the pages.

Limits. English → Hebrew has no Hebrew generator of pointing from lemma, binyan and prefix, and no model of the accents as a layer of the verse's syntax. The Hebrew encoder emits no word for what no meta token stands for (אֵת, prefixes, suffix pronouns). The page's template is not derived from the page id.

Many translations, each in its own world (translate many)

translate many (many.rs, logic.rs) takes every English translation eBible has, gives each its own world, and links the worlds through the meta-world. It is the same design as above, scaled from four authors to every English edition, and measured block by block.

How it works

Data

All eng* folders of ebible. The library packs every USFM book of 64 KiB or more as seekable zstd; school-sents usfm, blocks::read_layout and strong::read read .usfm.zst as well as .usfm, and the pools are the same bytes either way.

How to run

cargo build --release -p school-sents -p translate -p jobs
E=$RESEARCH_RAW/scripture/4-translations/ebible
P=$MOVA_DATA/runs/bible-many/pools
for d in $E/eng*; do target/release/school-sents usfm $d $P/$(basename $d).tsv $(basename $d) -; done
target/release/jobs run --name bible-many --mem-gb 8 -- target/release/translate many --pools $P \
  --lexicon-from <a translate eval run>/lexicon.tsv --ebible $E --out $MOVA_DATA/runs/bible-many/<run> \
  --threads 10 --train-every 4 --max-len 1 --extend on [--shuffled-lexicon on]
# the meta-world of the whole canon outside the test books (size and memory only):
target/release/translate many --pools $P --lexicon-from <run>/lexicon.tsv --out <dir> --threads 10 --canon on

Other options of translate many (defaults in brackets): --near N (3) pairs each learning translation with the hubs and its N nearest by the baseline's concept agreement on the training blocks; --hubs a,b (eng-kjv,eng-web) names the hubs; --hold-every N (5) holds every N-th measured translation (not a hub) out of the lexicon (0: none); --reference NAME (eng-kjv) is the versification every other translation is aligned to; --max-words N (2500) caps a block; --learn on|off (on) learns the lexicon from the pairs; --distinct on|off (on) refuses a learned pair whose two sides share a word; --parallel-only on (off) measures only on the Tanakh's dev blocks and only translations that have all of them, on the verses every measured translation has; --rules on writes the residual rules below; --rules-limit N (0: all) takes only the first N ordered pairs of --rules on, for timing; --model <en.bin> overrides the default model. --shuffled-lexicon on adds the lexicon learned on shuffled verse pairs as a control; the verses shuffled inside each block are the other control.

A run writes:

translate many does not change translate eval: the same eval flags give the same files with and without the many code.

Residual rules (--rules on)

For every ordered pair, rules.rs turns the reader's script from the source's meta-world to the target's into candidate rules:

Each rule is learned on one half of the dev blocks (by the block's parity) and measured on the other. It is measured again with the verses paired by the wrong number inside the block (the control). The rules are then joined greedily, each next one measured on top of those before it. This is transformation-based learning (Brill 1995) on meta-worlds. rules.tsv has each pair's list; rules.md has the rules that gain most over all the pairs and, per pair, the share of the reader's bits they remove.

Limits of translate many

Greek, Latin, Hebrew: sources and gaps

A non-English text plugs in the way the Hebrew one does (hebrew.rs): its own world, from its own parse, and a reader learned into the same meta-world on verse pairs, aligned by IBM Model 1 and, where a text has them, by Strong's numbers. In the library:

Limits

This page in Markdown https://md.mova.elamur.ai/free/en/docs/tools/translate/