# Zeyrek and Zemberek Zeyrek is a port of [Zemberek](https://github.com/ahmetaa/zemberek-nlp) 0.21.0, the Java library for Turkish. It uses Zemberek's dictionaries, its morphotactics and its disambiguation model, and it gives the same analyses for almost every word. This page says where it doesn't, why, and which answer the annotated corpora support. ## How the two were compared Every word of five annotated corpora, about 500,000 words, went through zeyrek and through Zemberek 0.21.0. For each word, two things were compared: the set of analyses, and the analysis each disambiguator chooses in the sentence. The corpora are the test sets of TrMor2016 and TrMor2006 and of UD Turkish BOUN and IMST, which people annotated by hand, and TrMor2018, which was annotated semi-automatically. | Corpus | Words | Same analyses | Same choice | |---|---:|---:|---:| | TrMor2016 test | 19,262 | 99.97% | 99.70% | | TrMor2006 test | 862 | 100.00% | 99.77% | | UD Turkish BOUN test | 12,015 | 99.96% | 99.73% | | UD Turkish IMST test | 9,750 | 99.97% | 99.90% | | TrMor2018 | 460,669 | 99.98% | 99.78% | Zeyrek's Python and Rust analyzers give the same answer for every one of these words, so everything below is true of both. Where the two choose differently, the annotations agree with zeyrek more often: | Corpus | Only zeyrek right | Only Zemberek right | |---|---:|---:| | TrMor2016 and TrMor2006 tests | 37 | 4 | | TrMor2018 | 634 | 167 | The annotations have limits. UD gives only the lemma, which can't tell an accusative from a possessive, or a proper noun from a common noun with the same lemma. TrMor2018 is about 95.6% correct overall, but much less on exactly the words where zeyrek and Zemberek disagree: in a hand check of 60 of them, its tag was wrong about one time in three. So the verdicts below lean on the hand-annotated TrMor2016 and TrMor2006 sentences, and on reading TrMor2018's sentences where its tags and the grammar disagree. ## What's the same The analyses come from the same dictionaries and the same morphotactic graph, so a word gets the same analyses in both, with the exceptions below. The disambiguator is the same model. Without zeyrek's rules, its search picks Zemberek's analysis for every word of the corpora but four. In those four sentences, Zemberek's own answer depends on what it analyzed before. Its disambiguator numbers each lemma and its groups as it meets them, and caches scores by that number. After 16,384 numbers, it makes new ones from a hash, and those can collide, so a candidate can get another one's cached score. Run on their own, those sentences get zeyrek's answers. ## Rules on top of the model Zemberek's model scores each word with the two words before it. Some choices in Turkish depend on words further away, and the model also never learned what a capital letter means. Zeyrek corrects it with a few rules, first added in [Correct the disambiguator with rules for genitives, participles and case - #63](https://github.com/obulat/zeyrek/pull/63). Most of the differences in choice come from them. When a rule changes a word, zeyrek searches the sentence again to pick among that word's corrected readings, with every other word kept as the model chose it. ### A word written in lowercase isn't a proper noun Zemberek lowercases words before it analyzes them, so in its training data every proper noun was lowercase, and the model can't use case. When a word written in lowercase has a common reading, zeyrek drops its proper-noun readings. It only does this in sentences that have capital letters, since in all-lowercase text case says nothing. > Kadınlar hafif **nazdan** hoşlanırlar, zor olanı severler. Zemberek reads *nazdan* as the name *Naz*; zeyrek reads it as *naz*, coyness, which is right. In "Sanki **elif** elif uzuyordu, inceliyordu", *elif* is the letter alif, not the name Elif, as Zemberek has it. Where the two differ, zeyrek is right 16 times in the hand-annotated sentences and Zemberek never, and in TrMor2018, zeyrek 290 times and Zemberek never. The one kind of sentence it can't get right is one that writes a name in lowercase. In "Şimdi yaşadığım **batının** verimli bölgelerinden doğduğum yörelere her gidişimde…", the annotators read *batı* as the region, the West, and gave the lemma *Batı*. ### A genitive needs a possessed word A genitive, such as *cironun*, is followed by a possessed word, such as *doları*. When that word is several words further on, the model, which looks only two words back, often reads its -I as the accusative. Zeyrek reads an -I word as possessive when its clause has a third-person genitive that no other word has taken. > Demek ki bu **cironun** 40 milyon **doları** Avrupa'ya ihraç edilen Lassa lastiklerden, > 55 milyon doları da Brisa'nın Bridgestone'a ihracatından oluşuyor. Here *doları* is "its dollars", the possessive, as zeyrek reads it. Zemberek reads it as the object. A genitive is taken by a possessive word right after it, even with *da* or *de* in between, as in "bankacıların da önerisiyle", and by a verb made a noun with a possessive, such as *olması*. Three more cases keep the accusative: - A possessive genitive takes the genitive before it and is free itself, so a chain counts once. In "8 futbolcunun sözleşmesinin bitecek olması **yönetimi** şimdiden düşündürmeye başladı", *olması* takes the chain, and *yönetimi* is the object. - When the next word is a verb made a noun with a possessive, the genitive is its subject and the -I word its object: "Öğrencilerin bu **kitabı** okumaları", "AB'nin gruba yeni **üyeleri** dahil etmesi". *olmak* and *bulunmak* take no object, so "Türkiye'nin en önemli **şehri** olduğunu" stays possessive. - A name with -I after an apostrophe, such as *Serkan'ı* or *Filistin'i*, is an accusative. In the hand-annotated sentences, zeyrek is right 19 times where Zemberek isn't, and Zemberek 4 times. #### Where the rule is inconsistent The rule decides by where words stand, not by what the grammar says, so the same construction can get a different answer when an unrelated word comes between. In Turkish, what usually decides it is the verb the -I word belongs to: a verb that takes no object, such as *durmak*, *sertleşmek*, *olmak* or a passive, can't have an accusative, so the -I word is possessive, its subject; a verb that takes one, such as *bulmak*, *almak* or *götürmek*, usually has the -I word as its object. The rule looks at the verb only to exempt *olmak* and *bulunmak*. - **A possessed word counts only right after its genitive.** In "Vatandaşların yardımı ile kurtarılan bazı **yaralıları** hastaneye götürdü", *yardımı* takes the genitive, and *yaralıları* is the object, as it should be. With one word more, "Vatandaşların bize yardımı ile …", *yardımı* no longer counts, and *yaralıları* becomes possessive. The same thing makes "**Bunların** bize yıllık **geliri** en kötü şartlarda 28 milyon **doları** bulacak" wrong: *doları* is the object of *bulacak*, but zeyrek reads it as possessive. - **The same holds for coordination, in the other direction.** In "hata değerinin olası nedenleri ve **çözümleri** gösterilmiştir", *çözümleri* is possessive, which is right, but only because *olası* keeps *nedenleri* from counting. Without *olası*, "hata değerinin nedenleri ve çözümleri gösterilmiştir", *nedenleri* takes the genitive and *çözümleri* becomes an accusative, though *gösterilmiştir* is passive and takes no object. - **A verb made a noun counts only right after the -I word, whatever the verb.** In "Öğrencilerin bu **kitabı** okumaları", that makes *kitabı* the object of *okumaları*, which is right. But "onların her yıl belli bir miktarda **lastiği** bizden satın almalarını" has *bizden* between, so *lastiği* becomes possessive. And the rule doesn't check that the verb takes an object: in "Annesinin bu sözler üzerine **yüzü** sertleşmesi", it makes *yüzü* an accusative, though *sertleşmek*, to harden, takes none. - **Names are an exception by spelling.** A name with -I after an apostrophe, such as *Serkan'ı*, is always accusative, because that was right in 31 of 33 cases. A common noun in the same place goes through the rule. The obvious fixes for these trade one error for others. Counting every possessive word as taking a genitive made 68 right choices wrong in TrMor2018 and one wrong choice right, because several words can share a genitive, as *nedenleri* and *çözümleri* do. Taking any verb made a noun later in the clause as the genitive's was right only 5 times in 8 in a sample. Tracking the genitives in the model's search, instead of after it, was worse on every corpus. Looking at whether the verb takes an object would address all of these, but it needs a list of which verbs do, which the dictionaries don't have. ### A participle before a verb is a noun A participle such as *yaptıkları* is an adjective when it modifies the noun after it, and a noun when it's the object or subject of the verb after it. The model often reads it as an adjective either way. Zeyrek makes it a noun when a verb follows. > OSD ve TAYSAD yetkililerinin … bir şov niteliğinde olması için çaba > **harcadıkları** ifade ediliyor. Here *harcadıkları* is what *ifade ediliyor* reports, and zeyrek is right. The next word only counts as a verb if it can't be anything else, so in "Kopyalamak üzere **seçtiğiniz** alan…", where *alan* is the noun "field", and in "Osmanlı resim sanatının doruğa **ulaştığı** yıllardı", the participle stays an adjective. Nor does a participle that modifies the same noun count: in "kullanmak **istediğiniz** varolan konsolu açın", both *istediğiniz* and *varolan* modify *konsolu*. TrMor2018 tags most of the remaining differences against zeyrek, but for a reason that isn't about this rule: it tags a participle that stands for a noun as an adjective, as in "Sonunda **dediğim** oldu" and "Hiç … birşeyler **denediğiniz** oldu mu?", where zeyrek's noun is the grammatical reading. ## Dictionary and graph changes Zeyrek's dictionaries add a few words and readings that Zemberek doesn't have: - *içişleri*, internal affairs, as in "İçişleri Bakanı'nın imzasıyla". Zemberek reads it as a form of the verb *içmek*, drinking. - *içeri* as a postposition, as in "kapıdan içeri girdi", as *dışarı* already is. - *yapıştırıcı*, as in "etiket yapıştırıcısı", and readings without voicing of *müteahhit*, *beraat*, *emlak* and *istirahat*: *müteahhiti*, *beraatı*. - *öbürü* and *umum* as quantifying pronouns, as in "öbürü de" and "umumun menfaati". Zemberek's graph also has a rule for the demonstrative *o* in words like *onsuz*, but it looks the item up under an id that doesn't exist, so the rule never applies. Zeyrek's applies it, and the annotations agree: "Sen, **onsuz** tamamlanmamış olacaktın" has the demonstrative. Like Zemberek, zeyrek has no pronoun *topu*, as in "hepi topu", all in all. The graph names one, but TrMor2018's annotators tagged *topu* as the noun *top* in all 24 of its sentences, including the one with "hepi topu": "Acemi olduğu için hepi **topu** bir masası var." ## Numbers Turkish separates thousands with dots. Zeyrek reads *1.000* as the number "bin", a cardinal, and its suffixes follow, as in *1.000'den*. Zemberek reads it as a real number, one point zero zero zero, and gives no analysis to *24.950.000*. In "Maçı da 58.008 kişi izledi", the annotations agree with zeyrek, as they do for all 19 such numbers in the corpora. ## Apostrophes inside words In Ottoman words such as *Mün'im*, *te'lif* or *san'at*, the apostrophe stands for a letter, not for the start of a suffix. When nothing else analyzes a word with an apostrophe inside it, zeyrek analyzes it without the apostrophe, if the stem goes on for at least two letters after it. Zemberek gives such words no analysis. Names such as *Matt'in* and *Levi's*, where only a suffix follows the apostrophe, get no analysis in either. ## Formats The CoNLL-U, Apertium, UniMorph, strict Oflazer and segmented formatters write what Zemberek's write, compared on words that between them have every feature and tag Zemberek writes for the 10,000 most frequent words, with one difference: informal morphemes, as in "geliyom", get the tags of the formal morphemes they stand for, as they do in zeyrek's other formatters. Zemberek's formatters don't know the informal morphemes, so they leave out their tense and person. Zemberek's CoNLL-U formatter also writes whole sentences, splitting a copula or "-ki" off its word as a multiword token, and its Apertium formatter writes a sentence as a stream of `^word/analysis$` units. Zeyrek's formatters write one analysis at a time, as its other formatters do. Zemberek's `SegmentedSurfaceFormatter` also writes Leipzig glosses. Zeyrek's `"leipzig"` formatter writes its own, with a gloss for every morpheme. ## Ottoman compounds Ottoman Turkish joins nouns with the Persian izafet, as in "bakiye-i ömür", and with the Arabic article, as in "Şeyh-ül İslam", written after a hyphen. Zemberek has no analysis for such a word. Zeyrek analyzes the noun before the hyphen, so *bakiye-i* and *devlet-i* get the analyses of *bakiye* and *devlet*. ## Circumflexes A circumflex tells apart words that are otherwise spelled the same: *hâlâ*, still, and *hala*, aunt. Like Zemberek, zeyrek keeps only the analyses whose stem has the word's circumflexes, so *hâlâ* is only the adverb. Zemberek keeps nothing when no analysis has them. The dictionaries write many words without their circumflex, so a correctly written word can go without an analysis: "**Usûl** böyledir." gets none from Zemberek, as the dictionary has only *usul*. Zeyrek keeps every analysis then. Of the 40 TrMor2018 words with a circumflex that the two analyze differently, zeyrek's way chooses the right analysis for 27, and Zemberek's for 18. ## Restoring Turkish letters `LatticeDeasciifier` scores words with Zemberek's model and gets their candidate spellings from zeyrek's analyses. It was compared with Zemberek's `LatticeDeasciifier` on 871 texts: news paragraphs, sentences with and without their Turkish letters and in uppercase, and random strings of letters, digits, emoji and punctuation. Each text was restored with `deasciify` in each circumflex mode and with `deasciify_known_words`, and zeyrek gives Zemberek's text every time, in Python and in Rust. The tests check 197 of those texts, in `tests/data/lattice-deasciifier-zemberek.tsv`. Restoring the words above that the two analyze differently, such as *içişleri*, *onsuz* and *usul*, gives Zemberek's text too. ## Spelling suggestions The spell checker suggests the same words as Zemberek's `TurkishSpellChecker`, and ranks them the same way: `suggest` as Zemberek's `suggestForWord(word)`, with its unigram model, and `suggest_in_context` as `suggestForWord(word, left, right, lm)` with its bigram model, `lm.2gram.slm.gz`. Words with exactly the same score can come in another order, since each implementation finds them in its own order. Zemberek's bigram model keeps a 16-bit fingerprint of each word pair instead of the pair, so about one pair in 65,000 that the model doesn't have matches the fingerprint of one it has, and gets its probability. Zeyrek's copy of the model has those pairs too, so that it ranks every pair as Zemberek does. ## Normalizing noisy text `SentenceNormalizer` builds each sentence's candidates with zeyrek's analyzer, tokenizer, `LatticeDeasciifier` and bigram model, and chooses among them with Zemberek's model. It was compared with Zemberek's `TurkishSentenceNormalizer` on 56,316 sentences: the sentences of Zemberek's sentence boundary test text and of its normalizer tests and examples, each as it is and typed without Turkish letters, informally, with typos, with words split and joined, in other casings and as on social media. Zeyrek gives Zemberek's sentence for all but 11 of them, in Python and in Rust. The tests check 468 of them, in `tests/data/sentence-normalizer-zemberek.tsv`. The other 11 differ because zeyrek's analyzer does, as described above: - zeyrek's dictionary has the pronoun *öbürü*, which changes the candidates of "oburu": "ne o ne oburu" stays as it is, where Zemberek writes "ne o ne öbürü". - zeyrek's dictionary has a variant of *beraat*, acquittal, without voicing, as it has for *emlak* and *istirahat*, so "beraatina" becomes "beraatına", where Zemberek writes "beraatine". - zeyrek analyzes the noun of an Ottoman compound such as *devlet-i*, so it keeps "devlet-i Aliyye", where Zemberek, with no analysis, writes "devleti Aliyye". For the same reason it writes the title "Âfâk-ı Irak" as "âfâk-ı Irak". - zeyrek keeps the analyses of a word whose circumflex no stem has, so it knows the names in "ebû tâlib" and "fâtıma", and capitalizes them.