Tetrak
GitHub ↗
Progress

Classical spelling, Russian notes and a cursive italic: two releases of the Armenian recogniser

Much of an Armenian library is printed in a spelling our recogniser had never been shown, and Yerevan's scholarly editions quote Russian it had no letters for. v7 reads both, and v8 reads an italic that v7 could not. One register still goes to another engine by a distance, and finding out why led us to the transcripts we score against

In 1991 a press in Beirut printed the memoirs of Alexander Khatisian, who was mayor of Tiflis before he was prime minister of the first Republic of Armenia, and who died in exile in Paris. Three years later a press in Yerevan printed the fifth volume of the complete works of Hovhannes Tumanyan, his stories and tales. The two men were contemporaries, and the two books are near neighbours in date. To an OCR model they are different worlds.

The Yerevan volume is in the spelling adopted in Soviet Armenia in 1922, and its editors’ notes quote Russian. The Beirut one is in the classical spelling the diaspora never gave up, down to its title: the title page prints Քաղաքապետի մը յիշատակները (Memoirs of a mayor), where Armenian Wikisource files the book under the reformed հիշատակները. It is also set almost throughout in a heavy cursive italic.

Until this month our Armenian recogniser read the first of those books well, apart from every Russian word in it, and the second badly. This article covers the two releases that changed that, v7 and v8, what each cost, and the register another engine still reads much better than we do.

Two things the model had never seen

v6, the model we wrote about in October, led most of the registers we measured it on. Every one of those registers was in reformed spelling. Two kinds of text that sit on the same shelves were outside anything it had been trained on.

Classical spelling. Everything printed in Armenian before 1922, and nearly everything the diaspora has printed since, uses the older orthography. We have written about telling the two apart. The reform was a respelling, and both spellings draw on the same letters, so nothing here needed a new alphabet. What changes is how often each letter turns up and where: ւ standing on its own and not only inside ու, and եւ set as two letters where reformed print sets the ligature և. A recogniser learns those habits along with the shapes, and ours had learnt the reformed ones. The classical books brought exactly one printed character the model had no class for, the apostrophe of elision ՚.

Russian. Yerevan’s scholarly editions mix Russian into Armenian pages: bibliographies, titles, quotations in the notes. v6 had no Cyrillic letters at all, so those words could not be read however well the rest of the page went, and every training line that contained one had been thrown away. The Russian arrives as scattered words and short runs inside Armenian lines, so what has to be learnt is the change of alphabet in the middle of a line.

The recogniser’s output is a fixed list of characters in a fixed order, and a change to that list is a new model. The trainer already owed its next run a new list for a handful of symbols, so the next model was going to be trained from scratch whatever else it did. We put the Russian alphabet and the classical books into the same run.

What went into v7

A pre-train on synthetic lines and then a fine-tune on real ones, as before. Three things were new.

The dictionary that went backwards

The first fine-tune was better than v6 on every classical register, and it read Russian for the first time. It was worse on one register, the Armenian–English dictionary, and our first explanation was wrong.

We assumed lookalikes. Cyrillic and Latin share several shapes (а and a, р and p, с and c), and a model that has just learnt Cyrillic might well spell poor as роог. It did, a handful of times. But when we went through the English words v6 had read and the new model had not, nearly all of them were ordinary misreadings in Latin letters: genlle for gentle, Ietter for letter. The cause was in what the pre-train had been fed. To teach the model Russian we had rendered many times more lines containing Cyrillic than lines of Latin alone, and its English had gone unpractised.

Two fixes followed. A fourth synthetic set, English lines from public-domain novels, went into a second fine-tune, and the dictionary came back. And the script fold in the library, which already turned a Latin h inside an Armenian word back into հ, learnt a third script. A token with no Armenian letter is now written in whichever of Latin or Cyrillic its unambiguous letters belong to, and a token made only of shared shapes follows the text around it. The English set was not free: it took a little off the classical gain, and we kept it.

Two word lists, because a spelling is not a mistake

The recogniser has no language model, so since v6 a word list has sat behind it. A word whose reading is not in the list takes a listed reading from the recogniser’s own alternatives, when one is nearly as probable. That list was counted from reformed text. Run over a classical page, it would do what a well-meaning modern proofreader might do, and respell the page one word at a time.

So there are two lists now: one counted from the reformed books, and one from the classical books together with the Nayiri Armenian Lexicon. There is one rule. A word found in either list is accepted as written and is never rewritten into the other’s spelling. եւ and և count as the same word. Before shipping the cure we measured the harm we had feared: on held-out crops from the classical books, the reformed list alone broke more words than it fixed, and the two lists together fixed many more than they broke.

What v7 cost

We had set v7 a gate: no worse than v6 on any of the eight older registers. It did not meet it. Through the full pipeline, several of the older registers lost a little word recall.

The same losses, the same size, show in the recogniser’s raw output, with no word lists, no fold and no layout step behind it. We had promised ourselves a comparison of that kind before publishing, because the run changed two things at once. It says that the recogniser itself gave up a little on the reformed registers in order to learn the rest, and that the post-processing is neither causing the loss nor hiding a larger one.

We shipped v7 on 16 November knowing that. The losses are small and the classical gains are not, and the model card records them as a known defect. v8 has since recovered some of the ground; a few of the older registers are still a little below v6.

The engine we measured last

Calfa’s hye-paddle is the strongest other Armenian engine we have measured. The model we run is paddle-calfa-tiny, version 1.0.0. Calfa has since published a larger one in the same repository, which we have not yet run, so read “hye-paddle” below as the smaller model. We have published a comparison without it before. We did it again, and not by choice. Its first run over the classical registers failed on every page within two minutes. A routine dependency update in Tetrak had quietly resolved the Paddle packages back to a version that cannot load Calfa’s model. v7’s model card went up with a comparison against the other three engines, and by that comparison v7 led nearly all of the classical registers.

That evening, with the dependency pinned, hye-paddle ran. v7 kept the lead on mean word recall, but hye-paddle took several of the classical registers from it, two of them by a wide margin. We corrected the card the same night.

The two were Khatisian’s memoirs and the first volume of Khachatur Abovyan’s complete works, a Yerevan edition of 1948. They turned out to fail for different reasons, and neither was the reason we would have guessed.

Khatisian: a typeface the harvester could not see

Nine of Khatisian’s ten evaluation pages are set in the cursive italic and one is in upright type. The upright page was the only one of the ten on which v7 beat hye-paddle.

We ruled out the scan first. Thinning the strokes, blurring the pages and lowering their resolution left recall the same or worse. We ruled out vocabulary: fewer of this book’s words fall outside the word lists than any other classical register’s. What was left was the cut of the type. The errors were of a kind no other register shows: ռ read as ո, and ւ, which this italic draws as a small tick, read as a colon.

The model had barely seen the face, and the reason is built into how we collect training data. Real crops come from running the current model over a scanned page and keeping the lines whose reading can be aligned with the transcript. A typeface the current model reads badly aligns badly, so it contributes few crops, so the next model reads it badly too. Khatisian’s book had supplied a fraction of one per cent of v7’s real crops. Italic as a style was not the problem: v7 read the italics we render with exactly as well as the upright faces. It was this older cursive cut, which the diaspora presses used and none of our typefaces imitates.

The loop does loosen with each model. v7 could align far more of the book than v6 could, so we harvested every proofread page of it with v7 and got many times the crops. v8 is v7 fine-tuned with a share of each batch given to those crops and to crops from two other books set in italics.

Beside it we trained a control: the same number of extra iterations on v7’s own recipe, with no new material. The control barely moved, so the gain belongs to the crops and not to the extra training. We had learnt to want that a few hours earlier, from a first attempt that changed several things at once. It gained on Khatisian, lost on two other registers, and could not say which change was to blame. The run we shipped changes one thing.

v8 went out on 18 November. Its price is in the Russian. The italic books contain almost none, and v8 reads a few fewer of the Russian words in Tumanyan’s notes than v7 did. We published knowing that as well, and the model card gives the count.

Abovyan: a photograph, and then a transcript

The Abovyan pages are verse in Grabar, the classical language itself, set in a light italic. The recogniser copes with the face. What marks the book out is the photography: its ink is pale grey on grey paper, where every other book we hold at that resolution is black on white.

Stretching the contrast before reading helped at once, and that became a rule in the pipeline, measured on every register before it shipped. A page whose darkest ink is still pale is stretched to full contrast before detection, and every other page reaches the detector untouched. The rule looks at the ink and not at the paper, because one register of black ink on toned paper read slightly worse when stretched. The engines page has the threshold.

That closed part of the gap. To close the rest we did the obvious thing and harvested the rest of the edition: several times the Abovyan crops, some of them stretched exactly as the pipeline stretches a page. It did nothing. The fine-tune with all the new material moved the register no further than a control with none of it.

So we asked a question we should have asked earlier: are the transcripts right? The pages are marked as proofread on Wikisource, which means one contributor has read the page against the scan. On one of the worst-scoring pages we took every word where our model and hye-paddle read the same thing and the transcript said another, and checked each against the scan. The two engines are built on different architectures by different people, so when they agree against the transcript it is worth looking. Every one of those words was an error in the transcript. Reading the rest of the page line by line found more, about one word in seven in all. The scanned file carries a text layer from some earlier OCR, and the transcript had that layer’s mistakes word for word.

We corrected the page on Wikisource against the scan, as any proofreader there would, and scored it again. Both engines went up. The gap between them did not close, so the bad transcript had been hiding a real difference and not manufacturing one. Most of what remains sits in a few pages that are out of focus as well as faint, and blur is not something more crops of the same typeface will teach.

Two changes to the trainer came out of it.

The tables below still score Abovyan against the uncorrected page, and its other nine pages have not been checked. We will regenerate the row when the register has been read through.

Registertetrak-hy v8 (ours)hye-calfa-nhye-paddlemarkertesseract-hye
Totovents, Works0.9690.9410.9410.8070.739
Medical encyclopedia0.9600.8290.9330.9140.877
Khrimian, Works0.9580.9380.9430.8880.798
Otyan, Works0.9580.9290.9340.8370.727
Baronian, Works0.9450.9110.9180.7870.744
Toranian, Erkirner ew marder0.9430.8380.9090.8860.901
Aram Manukyan, Documents0.9410.9240.9410.9120.801
Tumanyan (academic edition)0.9350.9040.9130.7080.713
Armenian printing (Teodik)0.9330.8940.8990.6750.637
Faustus of Byzantium (1968)0.9140.9140.9220.8600.716
Kajaznuni, Azg ew hayrenik0.9110.8520.8860.5720.604
Encyclopedia (ASE vol. 2)0.9090.8430.8650.8360.773
Baronian, Azgayin jojer0.9010.8530.8940.6850.611
Abovyan, Works vol. 10.8560.8710.9100.8060.607
Khatisian, Memoirs0.8380.7480.8560.6170.387
Aghbalyan, Criticism0.8240.8010.8460.7000.586
Dictionary (hy–en)0.7080.1090.4570.6780.046
Mean over registers0.9060.8290.8800.7750.663

Word recall — order-insensitive, so it measures recognition almost independently of layout. Generated from evaluation/ocr/registers.csv at build time. Bold marks the best engine per register. Only engines measured on every register appear.

Registertetrak-hy v8 (ours)hye-calfa-nhye-paddlemarkertesseract-hye
Totovents, Works0.9880.9840.9850.8140.938
Medical encyclopedia0.9550.9750.3020.8880.973
Khrimian, Works0.9830.9830.9850.9160.945
Otyan, Works0.9870.9780.9810.9200.923
Baronian, Works0.9870.9820.9830.8640.943
Toranian, Erkirner ew marder0.9710.9740.9840.9720.983
Aram Manukyan, Documents0.9610.9600.9630.9420.933
Tumanyan (academic edition)0.9760.9500.9700.6580.889
Armenian printing (Teodik)0.9820.9710.9760.7320.899
Faustus of Byzantium (1968)0.9700.9760.9270.9190.929
Kajaznuni, Azg ew hayrenik0.9780.9570.9760.6660.877
Encyclopedia (ASE vol. 2)0.9750.9600.3340.5260.946
Baronian, Azgayin jojer0.9830.9680.9810.7400.876
Abovyan, Works vol. 10.9300.9200.9460.9030.832
Khatisian, Memoirs0.9660.9000.9780.7140.757
Aghbalyan, Criticism0.8980.8630.8960.7710.800
Dictionary (hy–en)0.8390.4010.4350.6630.339
Mean over registers0.9600.9240.8590.8000.870

Character similarity — order-sensitive, so it collapses where the reading order is wrong. Generated from evaluation/ocr/registers.csv at build time. Bold marks the best engine per register. Only engines measured on every register appear.

Where we still lose, and why

v8 leads both means, and most registers by word recall. The bilingual dictionary flatters our mean, because Calfa’s models are Armenian-only and read its English badly; without that register the lead on the mean narrows and stays. Where we do not lead:

Calfa’s two models are licensed CC BY-NC 4.0, so we can measure them and nobody can ship them in a commercial pipeline. Ours can be shipped: the code and weights are Apache 2.0, and the word lists are CC BY-SA 4.0, as the sources they are counted from require. That difference is a reason to keep building ours. It is not a reason to describe theirs as anything but the better reader of those books.

What we would tell ourselves a month ago

Run every engine before writing the claim. We knew this, and wrote it down in September. The claim on v7’s card stood for less than a day, and only because we went back that evening.

A harvest made with your own model inherits its blind spots. A source that yields few crops is not a small source. It is a source the model cannot read, which is the one that most needs crops. We now look at yield by source before deciding what a run is missing.

Change one thing and train a control beside it. The run that changed several things cost a night and answered nothing. The control costs the same hours every time. Once it told us a gain was real, and once that a gain we were pleased with was only more training.

When more data does nothing, check the labels. Two unrelated engines agreeing against the ground truth is cheap to compute. On the one page where we checked every case by eye, it was right every time.

Further reading

How the recogniser works

Ground truth and scan quality

Armenian print, spelling and the other engines