Mova0.6 pre-release

noisy — reading dirty text

noisy plants errors with known ground truth into CoNLL-U files, measures how the parsers break on them, and normalizes dirty text back with a reason for every change. It adapts the idea of Gali's inner languages (a neural model that learns letters, sounds, glyphs and typical errors) to Mova's way: the same correspondences are kept as tables, every random choice is a seeded hash, and every decision is a comparison of counts that can be printed. No model is called.

cargo build --release -p noisy
noisy ipa-extract --langs en,uk OUT.tsv              # the IPA rows of a few languages, for fast loading
noisy tables [common]                                # table sizes and sample edits of each model
noisy corrupt [common] --model M --rate R [--seed S] IN.conllu OUT.conllu CHANGES.tsv
noisy score GOLD PRED [NOISY]                        # UAS, LAS, UPOS on all words and on the changed ones
noisy normalize [common] [--control shuffled] IN OUT DECISIONS.tsv
noisy nscore CLEAN NOISY NORM                        # planted, restored, wrong, missed, false corrections
noisy tune [common] [--rate R] TUNE.conllu           # the normalizer's parameter grid on a tuning file
noisy bench [common] --gold DEV --out DIR --en BIN --en-model FILE --gparse BIN --gparse-model DIR \
            [--models visual,phonetic,translit,layout] [--rates 0,0.05,0.1,0.2,0.4] [--seed S] [--parsers en,gparse] \
            [--layout X] [--lex L=FILE]
noisy keyboard-extract [--unicode-data UnicodeData.txt] [--xkb-version V] OUT.tsv   # the keyboard table, from xkb
noisy keyboard [WORD ...]                            # every language's pair with en: sizes, conflicts, examples
noisy layout-eval --lang L --swap X --lex L=FILE ... [--spans word=.4,start=.3,after=.1,line=.2] [--rate R] \
            [--unihan FILE] DEV OUT_DIR             # one pair: planted spans, controls, query slices
noisy query --lex L=FILE ... [--lang L] [--controls FILE] [TEXT ...]   # the reader on texts (or stdin lines)

Common options: --lang en|uk; --gali DIR (Gali's inner-language tables, default gali-inner, read only); --ipa FILE (the rows ipa-extract wrote, else the whole table); the lexicon: --conllu FILE (forms and bigrams, repeatable), --counts FILE (word|UPOS<TAB>count rows, repeatable), --ipa-words (the language's Wiktionary IPA headwords, each counted as a dictionary form, --dict-floor times); --table chat|ascii|cldr (the transliteration used for noise); the normalizer's --edit, --fold, --translit-cost, --keep, --rare, --margin, --beta, --foreign, --names off.

The noise models

Each model is built from Gali's tables at load time; each change it makes is written to CHANGES.tsv with the clean form, the noisy form and why (o (U+006F) → ο (U+03BF), visual confusable, UTS39 confusables.txt 18.0.0, prototype o).

A word is chosen when unit(h(seed, sentence, word, 1)) < rate (a word line outside multiword tokens, with a letter in it), so the words of a lower rate are a subset of those of a higher one; the edit is chosen by h(seed, sentence, word, 2), the same at every rate. One edit per word (translit rewrites the whole word). Rate 0 writes the input back byte for byte: the bench checks the file and both parses against the clean ones.

The bench

noisy bench parses the gold file, then for each model and rate the corrupted file, with en annotate (en.bin) and gparse annotate (CPU, GP_CPU=1), on gold tokens, and scores both the same way: UAS, LAS (the universal relation) and UPOS over every word, and over the changed words. It runs the normalizer on the clean file (false corrections, and the parse of the normalized clean file) and on every noisy file, with the real tables and with the shuffled control, and parses the normalized files. Outputs: bench.tsv, normalize.tsv, and every file and decision list under --out.

The normalizer

normalize.rs. A token is suspicious when it has a letter of another script than the language's, or the lexicon does not know it (seen fewer than 2 times; for English also not an en dictionary form, en::morph::known_form). Candidates come from inverting the noise models, and each must be a known word written in the language's script:

Score of a candidate c between the words p and n: ln(1 + count c) + β·(ln(1 + count p c) + ln(1 + count c n)) − cost. Keeping the token scores the same with no cost, plus --keep, minus --rare for each letter the lexicon's text almost never uses (share below 10⁻⁵: a planted look-alike has them, a genuine word seldom does), and minus --foreign when the token has a letter of another script (0 by default; 2 for Ukrainian, chosen on a tuning file: Latin words inside Ukrainian text are mostly transliteration, inside English text Cyrillic is rare anyway). The best candidate replaces the token, in the token's case pattern, only when it leads every other score, keeping included, by --margin; otherwise the token stays and is flagged with its candidates. A name-like token (all capitals, or a capital inside the sentence) written only in common letters of the language is left alone and flagged (--names off turns this off): an unknown name is not an error, and in-script edits turn names into words. Each decision is a row of DECISIONS.tsv: action, form, output, reason with its count and margin, the three best candidates.

The defaults were chosen on a tuning file, never on the bench file (noisy tune, Params::default in normalize.rs).

Controls: the clean file (false corrections, and whether its parse changes), and --control shuffled: the same normalizer with the visual table's right sides permuted, each grapheme's phonetic alternatives taken from another grapheme and the transliteration's letters rotated; its recall must collapse.

Keyboard layouts and the layout reader

The commonest layout error is forgetting to switch between the native layout and the English one, in either direction: native text typed while the English layout is on (привіт → ghbdsn), or English typed while the native layout is on (hello → руддщ). So every language is a pair with English, by key position and level, not every layout with every other.

Noise (--model layout, --model ime-latin in layout-eval): the whole word retyped. Per word at a rate (the bench), or by spans (--spans): a chosen sentence (unit(h(seed, s, 0, 3)) < rate) gets one span of a sampled kind — word, start (the first 1–3 words), after (1–3 words after a foreign term: a token in another script, else a proper noun) or line — and every token in it is retyped, punctuation keys too. The span kind is in the change row.

The reader (query.rs), one library call: Reader::normalize(text, lang) → [(candidate, confidence, reason)], Reader::read → the readings, every change with its reason (layout uk-on-en: ghbdsn→привіт (score 4.63, xkb ua ↔ us); run of 1 tokens, margin 5.13), the protected tokens and the homoglyph count, and read_batch for a list or a page. It is a run detector over the tokens: each token has a reading in every state (as is; X-on-en and en-on-X for each pair; ime-latin for ja and zh), Viterbi finds the best path (entering or leaving a swapped state costs switch, two layouts in a row two switches, a swapped token per_token), and a run is kept only when it beats the same path read as is by margin.

noisy bench --models layout runs the reader before the normalizer on the clean, noisy and shuffled-control files. layout-eval measures one pair: the clean file (false corrections), planted spans with the real and the shuffled tables (Swap::shuffled: the English side of the letter pairs permuted; the ime control rotates the romanization index), and query-like slices of 1–4 words, all retyped, read with the language given and with none (exact slices, token precision and recall, changed clean slices, the time per slice). query --controls data/keyboard/controls.tsv reads the negative control set (names, codes, URLs, e-mail addresses, numbers with units, clean text in en, uk, ru), each line with its own language and with none; every line must come out unchanged. The reader's defaults were chosen on tuning files (GUM dev, UD Ukrainian-IU dev), not on the measured ones (Params::default in query.rs).

Limits

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