Upload folder using huggingface_hub
Browse filesFiles changed (4)
- .gitattributes+2
- README.mdAdded+123
- figures/by_source.pngAdded
- figures/noise_curve.pngAdded
33 unmodified lines343536373833 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textocrqa-dyna_v1.2.0-da.bloom filter=lfs diff=lfs merge=lfs -textfigures/by_source.png filter=lfs diff=lfs merge=lfs -textfigures/noise_curve.png filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123---language:- dalicense: otherlicense_name: dsl-open-and-other-sourceslicense_link: https://korpus.dsl.dk/resources/licences/dsl-open.htmltags:- 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 distinctwords that are known. The file format, normalisation and score are the same as Impresso's, so Danish scores sit on the samescale as their French and German ones.
## Usage
```bashpip install cython pybloomfiltermmap3 huggingface_hub```
```pythonimport unicodedatafrom huggingface_hub import hf_hub_downloadfrom pybloomfilter import BloomFilter
known = BloomFilter.open(hf_hub_download("chcaa/ocrqa-dk-unigram", "ocrqa-dyna_v1.2.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.0ocrqa("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/)
Together that's 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`, `historical-danish-handwriting`, `trykkefrihedens_skrifter`
A word is accepted if its count is at least `max(2, 2500 / length²)`, Impresso's v2.0.0 setting. This adds 68k words.- **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. This adds 32.5k words.- **Storage:** the 1,873,757 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.2.0-da.bloom.json`.
## Evaluation
Scores below are on 3000-character chunks of held-out documents. Every 20th document was left out for testing.

| Text | Wikipedia-only list | This model ||---|---|---|| Clean modern text | 0.88–0.94 | 0.93–0.99 || Clean historical text (1700s–1900s) | 0.67–0.84 | 0.93–0.98 || Enevældens Nyheder, 1660–1849 (OCR/HTR) | 0.71 | 0.91 || Danmarks Breve (uncorrected OCR) | 0.74 | 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
- **1700s–early 1800s spellings are still partly missing**, so text from that period scores slightly lower (clean 1700s text: 0.93, modern: 0.97). The spelling rules only cover forms that occur in the corpora.- **Norwegian text scores lower**, whatever its OCR quality.- **Names and foreign words count as unknown** unless they are frequent.- **No exclusion list of known OCR errors yet.** Impresso uses one.
## Versions
- **1.2.0:** adds attested older spellings via rules (Enevældens Nyheder 0.89 → 0.91)- **1.1.0:** 1–2 letter lexicon words must pass the frequency rule- **1.0.0:** first build
## Credits
Ordlisten bygger bl.a. på tre af Det Danske Sprog- og Litteraturselskabs åbne sprogressourcer: fuldformslisterne frahhv. 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 ikkedeltaget 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) openlanguage resources: the full-form lists of Den Danske Ordbog and Ordbog over det danske Sprog, and FLEXIKON. All areavailable 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/).- 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..gitattributes+2
README.mdAdded+123
figures/by_source.pngAdded

Large File Pointer Details
- SHA256: 14d26826723f5bf7228ffacb7a322e89b7fd49250d2b51fe7f3ac856d0bd9c4f
- Pointer size: 131 Bytes
- Size of remote file: 212 kB
figures/noise_curve.pngAdded

Large File Pointer Details
- SHA256: e272aab769fc09f8ede3982d277bc783c3197a1b028a6c7cd1999163c9960cef
- Pointer size: 131 Bytes
- Size of remote file: 124 kB