Download ocr_metadata/ocr_metadata.md from chcaa/kb-books: direct link, hf CLI and curl.
- Browser
- Download file 15.9 kB
-
https://huggingface.co/datasets/chcaa/kb-books/resolve/main/ocr_metadata/ocr_metadata.md
- Command line
-
hf download hf://datasets/chcaa/kb-books/ocr_metadata/ocr_metadata.md
-
curl -L -o ocr_metadata.md https://huggingface.co/datasets/chcaa/kb-books/resolve/main/ocr_metadata/ocr_metadata.md
OCR Meta Data
OCR quality the legibility of scans might not always easy to analyze in a corpus of this magnitude. Especially knowing there are historic texts and at least two different font types present in the original scans.
For assessing the current state of the text data in the corpus and identifying documents which require to be re-processed from the scan a relatively quick, low-resource, rough estimation was used by comparing text meta data to the meta data of external references.
The before comparing to the reference, the pages, that are likely to be noise and/or non-representative to the overall quality of the document, were filtered out.
The meta data of the OCR (and thus text quality) the scripts related to their attainment are available here
The meta data of the texts and the scripts related to their attainment are detailed here
Data Fields
An entry in the ocr_meta_data.json consists of the following fields:
filename(str): A unique identifier for each document.above_ref_line(float): Bounded at [0,1], a numerical representation of quality. The bigger the number, the higher the ratio of pages surpassing the reference line derived from external texts.processed(bool): Whether the meta data was successfully compared to the reference line.problem(str): Flagged errors during the comparison process:no: The document was processed, the comparison process ran as expectedsmall_doc: The document was processed, but the document has less than 10 pages. Low page numbers can influence the outcome of the de-noising.no_mix: The document was processed, but no pages were identified as noisy or non-representative of the whole document. As books usually have at least some empty- or title pages, this level of homogeneity is unexpected.low_prop: The document was processed, but after filtering, the remaining pages were less than half the size of the original document. As books usually have a main type of page, which dominates its majority, (e.g.: pages of full text) this level of variety is unexpected.empty: The document was not processed, the ocr is missing.
Results and Recommendations
Banded quality values by year
Ratio and number of documents for each year, if quality is banded into 0.2 chunks based on the above_ref_line variable. The dotted line marks 1848
The plots show a gradual increase in quality of the texts throughout the 19th century. This change in ocr quality likely corresponds to the shift from fraktur to antiqua fonts in book printing. OCR technology available at the time of scanning probably had issues with fraktur based texts. The sudden drop in the number of high-quality OCRs in the early 20th century are simply due to the public domain filtering which removed a lot of documents of ambiguous status before assembling and publishing the corpus itself.
Since the method for determining quality is not without faults (the plots indicate some high-quality OCRs even in the 1750's, which are almost all guaranteed to be in fraktur) the year 1848 seems to be an adequate dividing line.
Documents published from this year onward with a high above_ref_line value should be of acceptable quality, while the rest might require either some text restoration or more OCR methods. But as the examples show, all documents should be approached cautiously.
Pre 1848 excerpts with above_ref_line of 1:
Disse Rigers Fortrin i Lyksali... (1752)
1te Crearur, fi>m hav formeeret Naturens Rige med et L iv , har Ud rettet meere end de, som ikke ere S tore uden ved Adeleggelse. Forend Throner og M e re bleve besmittede med B lo d ; forend Hyklerie og Overtros bragte den Lårdom ind, at M agten ikke var bundet ril Viisdom s Lov, da i den lyksalige Alder saae man de adel- modige Helte at bane sig Vey til et ubodeligt N avn ved at vare det menneskelige Kions Lovgivere, Velgiorere og Beskyttere: A t giore Jorden frugtbar, sormeere Landet med S tader og Indbyggere, be fordre mange Familiers Velstand ved Handel og Konster, og giore deres Lyksalighed sikker og bestandig ved Love var den eeneste V ey til DLre og Udsdelighed: D e forte ikke S v a rd e t, uden for at hanthave de viise Love, som de selv havde givet, og fo ra t stadfaste Folket i en ro lig Besiddelse a f den Lyksalighed, hvortil de selv vare forste Aarsag og S tifte re .Et ringe Bryllups-Digt, da Bru... (1753)
O ! et lyksaligt P a r, hvor Venskab saa kand fryde, Hvor ZEgte-Folk ey Tab paa noget godt stal nyde, Hvor parret P ar sin Fryd ey finder uden der, Hvor deres Hjemme - Sted i TEgte-Pagten er. Men er det saa, saa er'vel den, der ugift bliver, Ey saa lyksalig, som ben Mand, der sig hengiver T>'l stig en Engle- V en, og faaer den Mage, der Fornoyer, elsker og ham årer med l?lsiler. V or B r u d g o m har ved sit eomxali ven Havn tiltragtet Han fem Aars S oe-fart mod sligt Haab har lidet ag tet/ Som Soe-Mand bcrr han P riis, nu Reysen vel er endt, V or erdle Brudgom ^ oredi Sorg til Trsst blev sendt.Kort Samtale imellem en Landma...(1760)
Deres Hoygrevelige Excellencer, Hr. Johan Ludvig von HMlil, Greve til Detln-aborg, Ridder a f Dlepkanten, Geheime Raad t det Geheime < I!onleil, Cammerherre, Ober-8eeret3ir i det Danffe (dancellie, krLlidi Udi d!o!legio de Ourlu D vangelu promovendo, (Jeneral-KirkednlpeLkori, og krXddi i det Kongelige Viden skabernes 8oeietXt udi Kiobenhavn rc.Excerpts from 1848 with above_ref_line of 1:
Kongens Svar og dets Følger
^ndskjondt vi ikke tröste os til ved Ordet at gribe ind i Be givenhedernes Gang, saa ville vi dog ikke svigte det Hverv at oplyse Veien for Villien, der aldrig behover mere Lys end naar Folelsen stcerkt opliver den. Kongen har talt; og hver dansk Mand slutter sig nu til ham. Kongens Svar til det tydffe Parties Assendinge er i Alles Mund, — og, hvilke Anskuelser man end iovrigt hvlder, saa vil Enhver tilstaae, at der er Forstand med Kraft i den Tale.Pastor Hieronimus Laubs Efterm...
3S aaudrig, talentfuld og begavet Religionslærer; en tw Hyrde for den ham anbetroede Hjord, der ikke plejede denne med menneskelig Viisdoms svulstige Ord, men prcedikede som' en sand Herrens Apostel Guds Ord reent og pnurt, og agtede hverken sig selv eller Menigheden at vide Andet til Salighed end Jesum Christum, og ham korsfæstet; hvorfor han og kunde sige sig selv med Apostelen: „Det er min Roes, min Samvittigheds Vidnesbyrd, at jeg har vandret for Gud i Oprigtighed og Hjertets Retsindighed".Sørgetale ved Kong Christian d...
Kongernes Konge, Du Herrernes Herre! Dybt boie vi os for Dig, som holder Almagtens Scepter i DinHaand; men i det vi boie os for Dig med dybeste LErefrygt, hceve vi ogsaa Blikket til Dig med den barnligste Tillid, fordi vi vide, at Du, paa hvis Vink Troner henveires og Herskerspire knuses, er Algodhedens Gud, som Du er Alvceldens. Men derfor tor vi ogsaa for Dig, barmhjertige Fader, udtale vore Klager,Methods
The processes for estimating quality are detailed below
Reference Data and Comparison
For reference, 10k documents were sampled from the Enevaldens nyheder dataset from the Danish Dynaword. That dataset is assumed to have similar linguistic and stylistic contents, as it is also a collection historic Danish writings, dating back multiple centuries.
The Danish Dynaword in addition, has an automatic labeling process, which can assess text quality.
Only documents with the "good" label were chosen, to try and assemble a reference dataset.
The 10k documents were processed in the same way as the meta data of this corpus. The texts were tokenized, and tokens were matched to entries in the reference dictionary.
The text_rel_a_words (float) variables were extracted, which are all These are all bounded [0,1]. These values formed a reference distribution, with each value in it representing the ratio of identifiable danish words and all words in a single text from an allegedly good quality historic Danish dataset. The median of this distribution was chosen as the reference line.
To determine the ocr quality of the documents of this corpus, the text_rel_a_words values for each document were also extracted from the metadata and compared to the reference line.
The comparison resulted in the above_ref_line(float) variable bounded [0,1], which represents the proportion of pages in the document, that were above the reference line. A value of 1 would therefore mean a document in which all pages had a greater proportion of ( tokens found within the dictionary / all alphabetical tokens ) than the reference line. This would probably indicate a document with a high high-quality OCR.
Values around 0.5 would indicate ambiguous, but possibly similar quality to the historic texts, and values of 0 would indicate worse quality.
Relevant scripts for producing the reference values are available here.
Relevant scripts for comparison to the reference values are available here.
Removing Noise
The exact contents of the documents are also quite important and can influence the results. The reference distribution contains values derived from only text, while a page in this scanned corpus might be empty, might have pictures or only a small amount of tokens. For example, because of this, a picture book with perfectly legible, high-quality OCR scan danish text, which is above the reference line but only on every odd page, because even pages have pictures and therefore 0 alphabetical tokens, would have a final value of 0.5. This could prove problematic and lead to false estimations in the OCR quality of some documents. Also, if one thinks of books, they usually have empty pages in the front, back and between chapters, or might have title pages with only named entities, etc. These would all lower the estimated quality, therefore there needs to be a way to separate the relevant pages of every document. The pages which hold the majority of text contents and therefore would be the best indication of quality.
Conjugate prior based poisson mixture estimation
A non parametric conjugate-prior based mixture estimation was used to determine which pages are representative for each document.
If a book is a collection of different page types, e.g. pages with only text, pages with half text, title and empty pages, it could modelled as a mixture of discrete distributions, where each discrete value corresponds to the number of tokens on a page. These distributions are supposed to be clearly separable when ordered, and there should be minimal overlap between the drawn values.
Therefore a poisson mixture model could probably clearly separate the underlying page types for each document, but to avoid the use of more complex modeling techniques, the pages were simply ordered and treated as individual draws from poisson distributions, while a gamma distribution, which is the conjugate prior for the poisson, was calculated after every observation. This way, the gamma distribution gives the expected values for the lambda value of the poisson. In case the new value will be much higher than expected, the expectations of the gamma distribution will greatly update, and this signals that these are now drawn from a new poisson distribution. It is important for this to work, that the pages are ordered by the number of words on them in an increasing fashion.
The method is crude and might not be as precise as a mixture model estimation, but at least, it is fast and the only essential external library for running it is numpy.
Then after mixture boundaries were identified, the number of pages belonging to each category were counted, and the one with the most pages in it was deemed the representative distribution for that document. Other noisy or non-related pages were filter out before comparing the documents to the reference line.
Relevant scripts for filtering the pages is available here.
Error logs during filtering are available here
Mixture Separation Example
There is a 100 page document which is a mixture of draws from 3 poisson distributions.
| Distributions | # draws | ||
|---|---|---|---|
| lambda noise | 10 | 5 | |
| lambda picture | 80 | 15 | |
| lambda text | 200 | 80 |
If the pages are ordered, the first 5 will be from a poisson with lambda noise. Let these values be [ 8, 8, 12, 13, 15 ].
The gamma distribution is the conjugate prior of the poisson, meaning, after each nth draw of x from a poisson, the expected possible lambda n+1 values can be modelled as:
So after page 1 (page 1 here refers not to original page 1, but the one with the least words on it after ordering)
After page 2:
And so on...
But after page 5, there is a big change, because the currently expected gamma has a mean of 56/5 = 11.2 but we know in this case the next 15 pages are drawn from lambda picture, which is 80.
While the conjugate prior gamma for lambda was slowly homing on the value 10, now it will have a large update.
Let's say that x6 = 63
This is an observable difference. The mean of this distribution is 19.83. Then the conjugate prior estimated lambda values for the second distribution will "clump" together again, until x21 is reached, where there will be another big leap in the expected possible values for lambda 22.
To automatically identify the leaps, the second derivative of the means of the gamma distributions were taken. This way, large changes will emerge as outlier positive numbers. For example:
To make this a non parametric estimation, outliers in this list are treated as borders between different distributions. Preferably, values above the mean by 3 standard deviation were treated as outliers.
In the case of this simulated example, it successfully identified the 3 different distributions, but with smaller difference between the lambdas, or too small overall document size,this method might struggle.