|
Download README.md from chcaa/ocrqa-dk-unigram: direct link, hf CLI and curl.
- Browser
- Download file 9.62 kB
-
https://huggingface.co/chcaa/ocrqa-dk-unigram/resolve/main/README.md
- Command line
-
hf download hf://chcaa/ocrqa-dk-unigram/README.md
-
curl -L -o README.md https://huggingface.co/chcaa/ocrqa-dk-unigram/resolve/main/README.md
9.62 kB
| language: | |
| - da | |
| license: other | |
| license_name: dsl-open-and-other-sources | |
| license_link: https://korpus.dsl.dk/resources/licences/dsl-open.html | |
| tags: | |
| - ocr | |
| - ocr-quality | |
| - bloom-filter | |
| - historical-text | |
| - danish | |
| # ocrqa-dk-unigram: OCR quality assessment for Danish | |
| A Danish attempt of Impresso's | |
| [OCR-quality-assessment-unigram](https://huggingface.co/impresso-project/OCR-quality-assessment-unigram). | |
| It is a Bloom filter of known Danish words, from the 1700s to today. A text's OCR quality score is the share of its distinct words that are known. | |
| Note that the filter in practice measures "unknown words", not OCR errors; so that also means not only mangled words, but also specialized vocab and (infrequent) named entities (in e.g. wikipedia) -- and non-Danish text -- will bring the score down. | |
| The file format, normalisation and score are the same as Impresso's, so Danish scores sit on the same | |
| scale as their French and German ones. | |
| ## Usage | |
| ```bash | |
| pip install cython pybloomfiltermmap3 huggingface_hub | |
| ``` | |
| ```python | |
| import unicodedata | |
| from huggingface_hub import hf_hub_download | |
| from pybloomfilter import BloomFilter | |
| known = BloomFilter.open(hf_hub_download("chcaa/ocrqa-dk-unigram", "ocrqa-dyna_v1.4.0-da.bloom")) | |
| PUNCT = "„•<>!\"#%&'’()*,./:;?[]\\~_{}\xa1\xab\xb7\xbb\xbf—^`¦§£=-" | |
| TABLE = str.maketrans({c: " " for c in PUNCT} | {d: "0" for d in "0123456789"}) | |
| def ocrqa(text): | |
| words = set(unicodedata.normalize("NFKC", text).lower().translate(TABLE).split()) | |
| return round(sum(w in known for w in words) / len(words), 3) if words else None | |
| ocrqa("Det var en mørk og stormfuld Nat, og Vinden hylede om Huset.") # 1.0 | |
| ocrqa("Dct var en rnørk og ftormfuld Nat, og Vindcn hylede om Hnset.") # 0.545 | |
| ``` | |
| ## How it was built | |
| - **Normalisation:** NFKC, lowercase, punctuation and hyphens become spaces, digits become `0`. Same as Impresso. | |
| - **Lexicons:** words that count as known whatever their frequency: | |
| - ODS full forms (1700–1950, old spelling), DDO full forms and Flexikon, all from [DSL](https://korpus.dsl.dk/resources/index.html) | |
| - COR1 / Retskrivningsordbogen 5.1 from [Dansk Sprognævn](https://ordregister.dk/) | |
| - Names: Danish place names from [Danske Stednavne](https://datafordeler.dk/) (Klimadatastyrelsen, about 156k named places), road names (Danmarks Adresseregister) and cadastral district names (Matriklen), all via Datafordeler, and from [GeoNames](https://www.geonames.org/), and given names and surnames that at least two Danish people have on [Wikidata](https://www.wikidata.org/). *Adds 81k names not already known.* | |
| Names that look like OCR errors of common words are left out: names spelled without æ/ø/å (*norre*), names of up to 3 letters unless they pass the corpus frequency rule below (*ber*), and names one typical OCR confusion away from a frequent word (*fagt* / *sagt*, *ellet* / *eller*). | |
| The dictionaries together have 1.77M distinct words. Words of 1–2 letters must also pass the frequency rule below. This keeps out abbreviations like *tl* and *mt*, which are also common OCR fragments. | |
| - **Corpus counts:** about 200M tokens from clean subsets of [Danish Dynaword](https://huggingface.co/datasets/danish-foundation-models/danish-dynaword): | |
| - Modern: `wikipedia`, `ft`, `tv2r`, `danske-taler` | |
| - Historical: `adl`, `grundtvig`, `kalliope`, `wikisource`, `gutenberg`, `jvj`, `relig`, `trykkefrihedens_skrifter` | |
| Documents in German, French or English are skipped. They are found with spaCy's stop-word lists, keeping only words that belong to one language. Examples: the 115 German and French pamphlets in Trykkefrihedens Skrifter, and 1.9k Wikipedia articles that are mostly foreign titles. | |
| A word is accepted if its count is at least `max(2, 2500 / length²)`, Impresso's v2.0.0 setting. *Adds 65k words.* | |
| - **Spelling rules:** common historical spelling variants are accepted when they map to a known word and follow the frequency rules. | |
| - **Older spellings:** a 1700s–1800s spelling is accepted when a rule maps it to a known word and it actually occurs: | |
| at least twice in the clean corpora, or 10 times in OCR'd Dynaword sets. The rules cover *kiøb → køb*, *huus → hus*, | |
| *jndhold → indhold*, *qv → kv*, *høyst → højst*, *øxe → økse*, *ph → f*, and similar. *Adds 33k words.* | |
| - **aa spellings:** every known word with *å* is also known in its pre-1948 *aa* spelling (*gård → gaard*), whether or not it is attested. *Adds 23.5k words.* | |
| - **Storage:** the 1,990,494 words are stored as a Bloom filter (5 MB, read with `pybloomfiltermmap3`). It answers only "is this word known?" and cannot be read back as a word list. It never misses a known word, and wrongly accepts about 1 in 20,000 unknown words. | |
| Build parameters are in `ocrqa-dyna_v1.4.0-da.bloom.json`. | |
| ## Evaluation | |
| Scores below are on 3000-character chunks of held-out documents. Every 20th document was left out for testing. | |
| Only Danish documents are scored. German, French and English ones are left out. | |
|  | |
| The gain on modern text is partly because Folketinget, TV 2 and Danske Taler are among the training sources: the test documents are held out, but other documents from the same sources are in the word counts. The OCR/HTR sets are not used for the word counts at all. The main result is the historical rows, where a Wikipedia-only list mistakes old spelling for OCR errors. | |
| | Text | Wikipedia only (Impresso's frequency rule) | This model | | |
| |---|---|---| | |
| | Clean modern text | 0.88–0.94 | 0.93–0.99 | | |
| | Clean historical text (1700s–1900s) | 0.70–0.84 | 0.93–0.98 | | |
| | Enevældens Nyheder, 1660–1849 (OCR/HTR) | 0.71 | 0.91 | | |
| | Danmarks Breve (uncorrected OCR) | 0.75 | 0.90 | | |
| With simulated OCR errors added to clean historical text, the score falls steadily with the character error rate. | |
| The simulated errors include Danish and Fraktur confusions: æ/œ, ø/ö, å/aa, ſ/f, e/c, rn/m, dropped letters and split words. | |
|  | |
| | Character error rate | 0% | 1% | 2% | 5% | 10% | 30% | | |
| |---|---|---|---|---|---|---| | |
| | Score | 0.95 | 0.90 | 0.86 | 0.75 | 0.64 | 0.43 | | |
| The scores in these tables are means over 3000-character chunks. For long texts, such as whole novels, score 3000-character chunks and average them. The score is sensitive to document length. | |
| ## Limitations | |
| - **Some 1700s–early 1800s spellings are still missing.** Clean 1700s text scores 0.95, against 0.97 for modern text. The spelling rules only cover forms that occur in the corpora. | |
| - **The model is for Danish.** German, French or English text scores low (German: about 0.4) whatever its OCR quality. | |
| - **Norwegian text scores lower**, whatever its OCR quality. | |
| - **Rare names and foreign words count as unknown.** Common Danish person names (Wikidata) and place names (Danske Stednavne, GeoNames) are covered, but text full of rarer names, such as advertisements or lists, still scores somewhat lower. | |
| - **No exclusion list of known OCR errors yet.** Impresso uses one. | |
| ## Versions | |
| - **1.4.0** (current): adds aa spellings of all å-words, Danish place and road names (Danske Stednavne, Danmarks Adresseregister, Matriklen, GeoNames) and person names from Wikidata (leaving out names that look like OCR errors of common words), and no longer counts words from `historical-danish-handwriting`, which has transcription errors. *Suggested by Johan Heinsen (AAU).* | |
| - **1.3.1:** German, French and English documents are skipped when counting words, so foreign words such as *daß* and *avoit* are no longer known. Danish scores are unchanged; German text now scores about 0.4 instead of 0.65. | |
| - **1.2.0:** first release. | |
| ## Credits | |
| Ordlisten bygger bl.a. på tre af Det Danske Sprog- og Litteraturselskabs åbne sprogressourcer: fuldformslisterne fra | |
| hhv. Den Danske Ordbog og Ordbog over det danske Sprog samt FLEXIKON – Fuldformsleksikon med bøjningsoplysninger | |
| (alle tilgængelige fra [korpus.dsl.dk](https://korpus.dsl.dk)). Det Danske Sprog- og Litteraturselskab har ikke | |
| deltaget i udviklingen af OCR-kvalitetsmodellen ocrqa-dk-unigram. | |
| *In English:* the word list is built partly on three of the Society for Danish Language and Literature's (DSL) open | |
| language resources: the full-form lists of Den Danske Ordbog and Ordbog over det danske Sprog, and FLEXIKON. All are | |
| available from korpus.dsl.dk under the [DSL open licence](https://korpus.dsl.dk/resources/licences/dsl-open.html). | |
| DSL did not take part in developing this model. | |
| Other sources: | |
| - Method and normalisation: the [Impresso project](https://huggingface.co/impresso-project/OCR-quality-assessment-unigram). | |
| - COR1 (Retskrivningsordbogen 5.1): Dansk Sprognævn, [ordregister.dk](https://ordregister.dk/). | |
| - Place names: [GeoNames](https://www.geonames.org/), under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). | |
| - Person names: [Wikidata](https://www.wikidata.org/) (CC0). | |
| - Place, road and cadastral names: Klimadatastyrelsen, Danske Stednavne, Danmarks Adresseregister (DAR) and Matriklen, [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). | |
| - Word counts: [Danish Dynaword](https://huggingface.co/datasets/danish-foundation-models/danish-dynaword) | |
| (Danish Foundation Models) and the original sources listed in its dataset cards. | |
| ## Licence | |
| The parts built from DSL data are used under the [DSL open licence](https://korpus.dsl.dk/resources/licences/dsl-open.html); follow its terms when you use this model. | |
| --- | |
| Made by Pascale Feldkamp (CHC, Aarhus University). | |