Folio Swedish Newspaper OCR
Transcribe a line of nineteenth-century Swedish newspaper print on a CPU. The 1.31-million-parameter reader aims to preserve diplomatic spelling, including long s (ſ), accents and punctuation. It also reads the verified rectangles on 101 original newspaper scans from Kungliga biblioteket.
To read a full page, install the FP32 page-crop reader and its Swedish language data together. The command finds the lines and prints their transcriptions.
python -m pip install https://huggingface.co/foliokestrel/folio-swedish-newspaper-ocr/resolve/main/python/folio_swedish_newspaper_ocr-0.2.0-py3-none-any.whl
folio-swedish-ocr page newspaper.jpg
For a cropped line that slopes across the scan, try folio-swedish-ocr line --straighten line.png. On registered early newspaper rectangles it reduced character errors from 4.91% to 3.01%. The later sample went from 8.85% to 8.97%. Try a real crop and compare results
Run folio-swedish-ocr example to try the included historical crop. Line images, multipage TIFF, JSON output and source package
On 2,888 line crops from seven held-out newspaper titles, the Swedish reader made 7,185 edits in 165,877 reference characters (4.33% CER). Swedish Fraktur Kraken made 14,729 edits (8.88%) on the same crops. The Swedish reader’s CER ranged from 1.63% to 15.53% across the seven titles. Per-title and per-page results
A 1.33 MB download is also available for CPU and WebAssembly inference. It made 9.63% character errors on 624 later newspaper lines and 4.35% on the original seven-title test, compared with 9.68% and 4.33% for the 5.26 MB model. Run the compact model and inspect changed readings
For lines cropped directly from newspaper scans, the optional page-crops reader reduced character error from 5.54% to 4.91% on 2,888 verified rectangles. It improved on each of the seven held-out titles. With the same Tesseract line detections on 22 pages, known-line character error fell from 7.95% to 7.18%, counting missed lines as deletions. To try it, run python folio_fraktur.py --model-dir page-crops page-crops/examples/line.png. Page-crop reader, full-page command and later-newspaper results
The optional CPU model used 24.6% and 24.5% less time than FP32 to transcribe 192 cropped lines in two single-thread CPU runs. Including page layout and the rest of the full-page command, the six-scan comparison saved 4.6% of elapsed time. The graph occupies 2.05 MB. The FP32 graph occupies 5.26 MB. Run the CPU comparison on your own lines
You can also make a searchable PDF from your own newspaper JPEGs, PNGs or multipage TIFFs. The scanned pages stay visible and the text can be searched and copied. Offline command and two-page example
Read one line
Download the repository once with hf download foliokestrel/folio-swedish-newspaper-ocr --local-dir swedish-reader. Run these commands in that directory with Python 3.10 or newer.
python -m pip install -r requirements.txt
python folio_fraktur.py examples/line.png

The released model reads this validation example as “ffn fullſtändigt inredd byggnad, innehål=”. The original reference, source page and row number accompany the image. Example provenance
To read your own line, pass a cropped PNG or JPEG. Multiple paths are accepted in one command. In Python, load the reader once and reuse it.
from PIL import Image
from folio_fraktur import FrakturReader
reader = FrakturReader(".", threads=2)
with Image.open("line.png") as line:
print(reader(line))
Read an original newspaper page
For an entire newspaper scan, you can review the least certain lines and merge your edits into the full page transcript. Try the seven-line example or prepare your own scan
Download a JPEG from the Swedish Newspaper Lines browser. The reader identifies it by SHA-256 digest and automatically locates every verified rectangle on that page. Output records preserve the source row index, page ID and box alongside the prediction. Use a new output filename. Swedish Newspaper Lines
python read_page_lines.py original.jpg predictions.jsonl
To include upstream reference text or read a subset, pass a JSONL exported by the browser or the provenance dataset. The reader verifies each row and rectangle against the original scan. The single-line command above also works with material outside this collection. Swedish Fraktur line provenance
python read_page_lines.py original.jpg compared.jsonl --lines page-lines.jsonl
On the same 2,888 test locations, reading rectangles directly from the original JPEGs produced 9,188 edits (5.54% CER) and 869 exact lines. The original Riksarkivet line crops mask background and neighboring print. Both measurements start with known locations. Page-box results
Held-out line recognition
Seven publications contributed 22 test pages containing 26,228 reference words. All four recognizers received the same grayscale Riksarkivet crops. CER and WER are total character and word edits divided by the respective reference totals. Mean title CER weights each title equally.
| Recognizer | Character edits | CER | WER | Exact lines | Mean title CER |
|---|---|---|---|---|---|
| Folio Swedish newspaper | 7,185 | 4.33% | 18.96% | 962 | 5.36% |
| Swedish Fraktur Kraken | 14,729 | 8.88% | 29.37% | 447 | 11.62% |
| Folio Finnish newspaper | 22,753 | 13.72% | 51.10% | 87 | 14.87% |
| Mannheim frak2021 RAW_LINE | 25,763 | 15.53% | 49.12% | 120 | 17.33% |
| Newspaper | Lines | Folio Swedish CER | Swedish Kraken CER |
|---|---|---|---|
| Carlscronas Wekoblad | 368 | 2.77% | 5.91% |
| Dagligt Allehanda | 445 | 1.63% | 3.17% |
| Gefleborgs Läns Tidning | 219 | 15.53% | 42.47% |
| Götheborgs Allehanda | 223 | 4.01% | 6.13% |
| Hvad Nytt | 253 | 4.55% | 5.94% |
| Najaden | 693 | 2.21% | 5.82% |
| Stockholms Dagblad | 687 | 6.79% | 11.89% |
The Swedish reader trained on other titles in this newspaper collection. The Kraken model’s published Swedish training corpus covers earlier print from 1626–1816. A prior pilot sampled 384 rows from this same newspaper collection. Those rows and their image duplicates were excluded from adaptation and test folds. Titles and pages in the pilot can also occur in the new folds. These scores describe registered, nonblank lines from this collection. Ornate type, unfamiliar publications, short fragments and page layout can produce different results. Comparison protocol and replay commands · Swedish Kraken model
Training and availability
Folio Kestrel initialized the Swedish reader from the Finnish newspaper model, extended its character alphabet using Swedish training labels, and fine-tuned for 24 epochs. Validation used six titles entirely separate from the 26 training titles and the seven test titles. Epoch 11 had the lowest mean validation title CER (1.72%). The CPU ONNX export agreed with PyTorch on 5,635 of 5,639 validation transcriptions. All test numbers above use CPU inference. Training instructions and folds · CPU export comparison
The repository contains ONNX for inference, safetensors weights for training, and the data preparation, scoring and replay scripts. The weights use CC BY-SA 4.0, evaluation data and the bundled scan crop use CC BY 4.0, and the code uses Apache-2.0. Source credits and licenses