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).
- visual (
visual.rs): UTS #39 confusable classes (every member of a prototype's class with every other) and intentional pairs, one-level canonical decompositions (a letter and its accented forms), and glyph neighbours at cosine ≥ 0.95 of the 32×32 rasters (glyphs/similarity.tsv). Both sides must be Latin, Greek, Cyrillic, ASCII digits or signs. Every relation is symmetric. In a word, each kind present gets an equal share of the choice, so the many accented forms do not crowd out the homoglyphs. - phonetic (
phon.rs): letters are aligned with sounds from the language's Wiktionary IPA (one broad transcription per word, General American first for English): graphemes of 1–3 letters against 0–2 PanPhon segments, hard EM started from words with as many letters as segments. Two sounds are close when PanPhon's unweighted distance (Σ|a−b|/2 over 24 features ÷ 24) is at most--tau(1/24: one feature). An edit replaces a grapheme by a usual spelling (P ≥ 0.05, seen ≥ 20 times) of the same sound (city → sity, weight 1) or of a close sound (dog → doc, voicing; weight ½). A word outside the IPA lexicon gets each letter's most usual sound. - translit (
translit.rs): Cyrillic letters aligned with their Latin spellings in the Rusyn wiki's word pairs (CLDR Cyrillic-Latin, run by ICU4X intransliteration/), giving three tables:cldr(щ → ŝ),ascii(marks taken off by the canonical decompositions: щ → s) andchat(cldrwith the digraph convention of chat and passport romanisation: č ch, š sh, ž zh, ŝ shch, c ts, the iotated vowels y + vowel). For English the noise writes a word in Cyrillic letter by letter (the invertedasciitable, longest match); for Ukrainian it writes a word in Latin.
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:
- visual: one substitution of the visual table anywhere in the token (cost
--edit), or every foreign letter folded to its look-alike at once (--foldper letter); - phonetic: one grapheme replaced by a grapheme of the same or a close sound (
--edit); - translit: the whole token read through the transliteration table into the language's script, a beam over each
letter's spellings pruned by the lexicon's prefixes (
--translit-costplus each letter's −ln share).
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.
- The table (
data/keyboard/keyboards.tsv, built into the crate; sources and licence in Licence of the keyboard data) is written bynoisy keyboard-extract(xkb.rs): libxkbcommon (loaded at run time) compiles the default variant of each language's layout from the system's xkb symbols and gives the keysyms of the 48 main keys at the base and Shift levels, punctuation positions included (ЙЦУКЕН «.» is «ю», «,» is «б», «?» is Shift+7). 59 native layouts: Cyrillic (uk, ru, be, bg, sr, mk, kk, ky, tg, mn, tt, ba, cv, sah, udm, kv, os), el, he, hy, ka, Arabic script (ar, fa, ur, ps, ckb, sd, ug), syc, dv, Indic (hi, mr, ne, bn, gu, pa, or, ta, te, kn, ml, si), th, lo, km, my, bo, am, QWERTZ (de, cs, sk, hu, sl, hr, bs, sq), AZERTY (fr); and en-US, en-GB. Korean comes from the KS X 5002 2-set assignment, stated inhangul.rs(--unicode-dataadds it to the table), because xkb'skris US QWERTY plus the Hangul toggle keys. - The swap (
keyboard.rs):native_on_enanden_on_native, longest match per key text; where a character sits on two keys the base level wins and the ISO key left of Z comes last. Korean goes through the 2-set automaton (hangul.rs: the Unicode syllable arithmetic, finals carried to the next syllable before a vowel, compound vowels and finals from the jongseong names of UnicodeData, the seven complex vowels stated as facts): 안녕하세요 ↔ dkssudgktpdy. - ime-latin (
ime.rs), its own class: for ja and zh, forgetting to switch the input method on gives romaji or pinyin. Chinese: each character's first UnihankMandarinreading, tones off, ü as v. Japanese: the word's UniDic reading in wāpuro romaji (Hepburn out, folded to Kunrei for lookup, so either typing is found). The detector looks the Latin token up in a romanization index of the lexicon (the most frequent word per key).
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.
- Evidence: a token invalid as it is (unknown in the text's languages; a single letter only when that letter is rare
there, and then capped) whose reading is a known word seen at least
min_evidencetimes; a token known as it is gives evidence only for a cross-script readingknown_gain(in ln) more frequent. A reading that turns an outer letter into punctuation (Tom → To;) or changes only punctuation (ID: → ID^) is no reading. - Runs: a run ends at its first and last token of evidence or of plausible reading (invalid as is, read into letters the target lexicon uses); inside it, a token known as it is and a token without letters stay. Punctuation inside a whitespace token is read with it, and each token also gets the reading that keeps its outer punctuation, so a token split or joined by a swapped punctuation key is read both ways.
- Protected, never changed: URLs, e-mail addresses, anything with a digit (codes, part numbers, HS codes, numbers with units), and a short token right after a number (its unit).
- Confidence: a softmax over the path scores of the distinct readings (the best path, as is, each state over the whole text); a relative weight, not a calibrated probability.
- Homoglyphs: the letters of a minority script inside a mixed-script word (a Latin «а» inside a Cyrillic word), counted per text, with the tokens.
langgiven: the text's language decides what is valid as is, and only its pair (or, for en, every pair) is read;langnone: every loaded lexicon.
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
- One edit per word; the noise never splits or joins tokens, and the bench runs on gold tokens, so tokenisation errors on dirty text are not measured.
- Real-word errors are out of reach: a noisy form that is itself a known word (form → from, on → in) is never suspicious. Many as-heard edits of short words are such words.
- The phonetic model knows one broad transcription per word and single-segment sounds; diphthongs and silent letters are not substituted.
- The chat table's digraphs are a rule of this crate, not a table of gali-inner (the Mongolian BGN rows there carry Mongolian values); real chat spelling varies more (x for х, w for в, 4 for ч).
- The lexicon is the treebanks' forms and the dictionary: a correct rare word that only the noise reaches is missed, and a frequent word one edit away from a genuine unknown word can take its place.
- The normalizer reads one token at a time with its two neighbours; it does not rescore with the parser.
- The layout reader knows words only through the lexicon: an unseen inflection inside a run is carried as plausible, a whole query of unseen words is not read, and a swapped form that is itself a word of the text's language (or of any loaded language, with no language given) is never evidence. The UD train forms are a small lexicon for inflected languages.
- English typed on the Korean 2-set loses its case (Shift gives the same or the doubled jamo), and on the phonetic Cyrillic layouts (sr, mk) a swap reads like a transliteration, so names and loanwords in Cyrillic can read as English when the text is declared English.
- Separate punctuation tokens are never changed; a swapped punctuation key is restored only inside a whitespace token. The Ethiopic layout (am) types syllables through dead keys, which the table leaves out.
- ime-latin knows one reading per Chinese character and one per Japanese word: homophones are resolved by frequency only (型 or 性 for xing), and an IME's conversion model is out of reach.
This page in Markdown https://md.mova.elamur.ai/free/en/docs/tools/noisy/