Repository navigation
Add Turkish text normalization (tr) - #547
Open
dorukdumlu wants to merge 6 commits into
Open
dorukdumlu wants to merge 6 commits into
dorukdumlu wants to merge 6 commits into
Conversation
Adds Turkish text normalization: cardinal, ordinal, decimal, fraction, money, measure (with percent), date, time,
telephone, whitelist and word.
- Suffixes written after an apostrophe are attached to the spoken number ("4'e" -> "dörde", "1990'lı" -> "bin
dokuz yüz doksanlı", "%14'ü" -> "yüzde on dördü"); "dört" softens before a vowel.
- "5." is an ordinal only before a lower-case word ("3. taksit" -> "üçüncü taksit"); at the end of a sentence it
stays a number.
- Fractions are read denominator first ("3/4" -> "dörtte üç"), dates day-month-year, the percent sign first.
Signed-off-by: Doruk Dumlu <dorukdumlu@windowslive.com>
- A multi-word whitelist expansion is emitted as one name token per word: Sparrowhawk prints name tokens as they
are, so the non-breaking space from convert_space stayed in its output ("vb." -> "ve benzeri").
- "0,50 TL" had two paths of equal weight ("elli kuruş" and "sıfır lira elli kuruş"); pynini and Sparrowhawk broke
the tie differently. The zero major path is gone when a minor part follows.
Signed-off-by: Doruk Dumlu <dorukdumlu@windowslive.com>
Suffixes after an apostrophe are rebuilt for the last word read (vowel harmony, d/t, buffer consonants, softening), so 'TL'ye' -> 'liraya', 'Aralık'a' -> 'aralığa', '%2,5'luk' -> 'yüzde iki buçukluk', '4'de' -> 'dörtte'. Adds ranges and scores, Roman numerals, ratios, dimensions, speeds, versions, codes after 'kodunuz', 'saat 17.30', and fixes amounts with kuruş plus a suffix, lower-cased currency codes and English number formats. Signed-off-by: Doruk Dumlu <dorukdumlu@windowslive.com>
Restores fraction, measure units and telephone. Only proper fractions are read denominator first; others use 'bölü' (140/90 mmHg). A unit written without a space needs two or more letters (802.11g, 5G stay names). Adds scores with zero, date and four-digit ranges, 'saatte ... km/sa', an area code before a call-centre number, and kcal, g/dl, IU/ml, nm, MP. Signed-off-by: Doruk Dumlu <dorukdumlu@windowslive.com>
- RangeFst, SerialFst and ContextFst (like en's range and serial classes) replace the context patterns that lived
in tokenize_and_classify; they read their neighbours with composed taggers and verbalizers and emit name tokens.
- "bölü" and "saatte" are morphosyntactic_features instead of text inside fields; "ile" and "nokta" are part of
the composed readings instead of injected tokens.
- Multi-word names keep plain spaces (no per-word name tokens), ISO dates rely on the Date proto field order
instead of enumerating day and month, and suffixes are attached once per fraction: the tagger goes from 1.15M to
365k states and the FAR from 39.5 MB to 16.6 MB.
- Fixes: lower-case currency codes only after an amount and never "try"; a dotted time needs a case suffix
("1.25'lik" is a decimal); the unbounded fst ** 0 in telephone groups.
- Unit tests for the suffix engine, negative tests for over-matches. A suffix after an ISO date is no longer
supported.
Signed-off-by: Doruk Dumlu <dorukdumlu@windowslive.com>
- Double quotes are left to PunctuationFst: a quote inside a name token breaks Sparrowhawk parsing; quoted cases are pytest-only (as in en). - ContextFst: saat with a time range, codes after a colon and in dash groups, capitalised fixed-phrase nouns (1. Dunya Savasi, 1. Lig). - SerialFst: three or more dash-separated groups read as a code. - Lower-case unit variants; stale docstrings fixed. Signed-off-by: Doruk Dumlu <dorukdumlu@windowslive.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Adds Turkish text normalization (
--lang=tr): cardinal, ordinal, decimal, fraction, money, measure (with percent), date, time, telephone, whitelist and word.1.250.000,-54'e,1990'larda,4'er3. taksit,II. Mehmet/Sırada 5.3,05,2,5 milyon,%2,5'luk3/4'ünü,140/90 mmHg1.250,50 TL'ye,100 TL'dir5 km'ye,120 km/sa,30x20x10 cm01.01.2027'de,31 Aralık'a,2026-03-1514:30'da,saat 17.30,09:00-18:003-5 gün,2-1,3:2,3.12.1kodunuz: 482913,12-34-560532 123 45 67'denTurkish-specific design
TL'yefor the letters "te-le",%2,5'lukfor "iki buçuk") and sometimes misspells it (4'de). The words a suffix can land on are a closed set (number words, currency, units, month names, "buçuk"), soinflection.pymaps every surface form of the common suffixes to the form each of these words takes: vowel harmony, d/t assimilation, buffer consonants and softening (dört→dördü,aralık→aralığa). The result is one string map; an unknown suffix is copied as written at a higher cost.3/4→ "dörtte üç"), ISO dates (day month year), percent (read first) and speeds ("saatte ..."). ISO dates need no reordering in the grammar: the date fields are emitted withoutpreserve_order, and the verbalizer's field order (day, month, year) puts them in spoken order, both in Python and in Sparrowhawk. Percent and speeds put the unit first and keeppreserve_order; the speed word goes inmorphosyntactic_features. Proper fractions with a named denominator (2-100 and 1000) are enumerated, since an FST cannot swap two unbounded strings; others are read "a bölü b".RangeFstandSerialFst) and emit the spoken text as one name token:RangeFst: ranges are read with "ile" (1914-1918,09.00-17.30,36,5-37,2 °C,%10-20); two numbers of up to three digits are compared, so3-5is a range but11-9and2-0'lıkare scores;30x20x10 cmis read with "çarpı".SerialFst: versions (3.12.1), ratios (3:2→ "üçe iki"), three or more dash-separated groups (12-34-56).ContextFst: a number with a dot is an ordinal only before a lower-case word or a known noun (5. sırada,1. Dünya Savaşı; at the end of a sentenceSırada 5.stays a number), in lower-cased text only before known nouns;saat 17.30is a time (otherwise a decimal); a number afterkodunuz/şifre/PINis read digit by digit.,5after a whole number,€as "euro". Letter-digit names (PS5,F1,GPT-4) are left as written.Found by the Sparrowhawk tests
convert_spaceputs into a multi-word name stays in its output (vb.gave "ve benzeri" with a non-breaking space). The Turkish name tokens therefore keep plain spaces, andVerbalizeFinalFstaccepts such names. The other languages' whitelist test files have no multi-word expansion, so they may be affected too.preserve_order, so the verbalizers treat it as optional (as en does); making it required gave empty output for percent and speeds.0,50 TLhad two paths of equal weight; pynini and Sparrowhawk broke the tie differently. The zero-major path is removed when a minor part follows."Ben) and as a punctuation token (name: """), which is what en'sPunctuationFstemits too; en does not run its punctuation cases in Sparrowhawk. The Turkish word class leaves the quote to punctuation, so pynini output is right, and the quoted-text cases run in pytest only.Testing
tests/nemo_text_processing/tr(one file per class, plus sentence-level, lower-cased and quoted-text cases); the cased ones except the quoted-text cases also pass in Sparrowhawk (export_grammars.sh --GRAMMARS=tn_grammars --LANGUAGE=tr --INPUT_CASE=cased --MODE=test: 12 test functions, OK).tr_trtest), split in half before the grammar was tuned. The held-out half (152 sentences) was run once, without changes: 84% of the sentences came out fully correct, 2% (3 sentences) had a reading that changes the meaning (802.11gread as grams,140/90 mmHgread as a mixed fraction,0212 444 0 123). Those three were fixed afterwards and are now regression tests, so the held-out score is the one before the fixes; the test half was not run again to tune on it. Most of the remaining 14% are tokens left as written (letter-digit names, rare units). I confirmed the defects the evaluation flagged.12,865), which the grammar reads as a Turkish decimal. The others:6/8as a musical meter ("altı sekizlik"),1885-6,Naked Gun 2½, an ISBN andBA-06/13. The labels were drafted with an AI assistant; I checked every row labeled wrong and a random 20 of the rows labeled correct, and agreed with all but one (the ISBN reading, left open).Not in this PR
Letter-digit names and IBANs, e-mail and URLs, identifiers whose reading depends on context (order or policy numbers), and Turkish ITN. Only deterministic normalization is implemented;
deterministic=Falsebuilds and gives the same option.Known limitations:
0-24 ayand5-3 kişiare read as scores,2024-118as a range.2026-03-15'te) is not supported.500g) is left as written, so that5Gor802.11gare not read as grams.12,865) is read as a Turkish decimal; treating every comma followed by three digits as a thousands separator would break decimals such as2,500 kg.The Jenkinsfile gets a grammar-build stage and a pytest stage with
TR_TN_CACHE; that cache folder needs to be created on the CI machine.Before your PR is "Ready for review"
Pre checks:
git commit -sto sign.pytestor (if your machine does not have GPU)pytest --cpufrom the root folder (given you marked your test cases accordingly@pytest.mark.run_only_on('CPU')).bash tools/text_processing_deployment/export_grammars.sh --MODE=test ...pytestand Sparrowhawk here.__init__.pyfor every folder and subfolder, includingdatafolder which has .TSV files?Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.to all newly added Python files?Copyright 2015 and onwards Google, Inc.. See an example here.try import: ... except: ...) if not already done.PR Type: