SAVRN
Search Contact SAVRN

Open-weight model · Image to text

trocr-base-handwritten-hist-swe-2

by Swedish National Archives, AI-lab and Data Services Riksarkivet/trocr-base-handwritten-hist-swe-2

An HTR model for historical Swedish developed by the Swedish National Archives in collaboration with the Stockholm City Archives, the Finnish National Archives and Jämtlands Fornskriftsällskap.

Parameters385M
Context
Weights1.5 GB
Licenseapache-2.0
AccessOpen weights
Monthly Downloads98.1k

Runs On

What it takes to serve trocr-base-handwritten-hist-swe-2 (385M parameters): the memory its weights need at each precision, and the cheapest way to rent enough data-center GPUs to hold them.

PrecisionWeightsMemory neededCheapest setupPer hourAlso fits
16-bit 0.8 GB 0.9 GB 1x MI300X (192 GB)
Vultr
$1.85 1x H100 $1.99 · 1x MI325X $2.00
8-bit 0.4 GB 0.5 GB 1x MI300X (192 GB)
Vultr
$1.85 1x H100 $1.99 · 1x MI325X $2.00
4-bit 0.2 GB 0.2 GB 1x MI300X (192 GB)
Vultr
$1.85 1x H100 $1.99 · 1x MI325X $2.00

Memory is the weights at that precision plus 20% for the runtime and a short context; a long context needs more. Prices are the lowest on-demand hourly rates in the SAVRN Index, read Sep 18, 2026.

Model Card

By Swedish National Archives, AI-lab and Data Services, published under apache-2.0, revision aa79fcb1850b.

An HTR model for historical Swedish developed by the Swedish National Archives in collaboration with the Stockholm City Archives, the Finnish National Archives and Jämtlands Fornskriftsällskap. The model is trained on Swedish handwriting from the period 1600-1900. The model is trained on Swedish running-text handwriting dating from the start of the 17th century to the end of the 19th century. Like most current HTR models it operates on a text-line level, so its intended use is within an HTR pipeline that segments the text into text lines, which are transcribed by the model. The model can be used without fine-tuning on all handwriting but performs best on the type of handwriting it was…

Read Swedish National Archives, AI-lab and Data Services's full model card

Swedish Lion Libre

An HTR model for historical Swedish developed by the Swedish National Archives in collaboration with the Stockholm City Archives, the Finnish National Archives and Jämtlands Fornskriftsällskap. The model is trained on Swedish handwriting from the period 1600-1900.

Model Details

Model Description

  • Developed by: The Swedish National Archives
  • Model type: TrOCR base handwritten
  • Language(s) (NLP): Historical Swedish handwriting
  • License: apache-2.0
  • Finetuned from model: trocr-base-handwritten

Uses

The model is trained on Swedish running-text handwriting dating from the start of the 17th century to the end of the 19th century. Like most current HTR models it operates on a text-line level, so its intended use is within an HTR pipeline that segments the text into text lines, which are transcribed by the model.

Direct Use

The model can be used without fine-tuning on all handwriting but performs best on the type of handwriting it was trained on, which is Swedish handwriting from 1600-1900. See below for detailed test and evaluation results.

Downstream Use

The model can be fine-tuned on other types of handwriting, or if you plan to use it to transcribe some specific material that is within it's domain but not included in the training data, for instance if you got a large letter collection dating from the 17th century, it can be fine-tuned on a small amount of manually transcribed in-domain data, say 20-50 letters, and then used to transcribe the entire collection.

Out-of-Scope Use

The model won't work well out-of-the-box for other languages than Swedish, and it won't work well for printed text.

How to Get Started with the Model

Use the code below to get started with the model, but bear in mind that the image has to be a single text line.

from transformers import TrOCRProcessor, VisionEncoderDecoderModel
from PIL import Image
import requests

img_path = 'path/to/image'
image = Image.open(img_path)

processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
model = VisionEncoderDecoderModel.from_pretrained('Riksarkivet/trocr-base-handwritten-hist-swe-2')
pixel_values = processor(images=image, return_tensors="pt").pixel_values

generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]

If you want to transcribe entire pages, consider using HTRflow, a package developed by the Swedish National Archives and intended for streamlining large and small scale HTR/OCR-projects. Install the package, write a pipeline config yaml, where you specify the models to use by their huggingface id, add preprocessing or post-processing steps, and then run the pipeline with htrflow pipeline <path/to/yaml> <path/to/image>. A .yaml file for an entire pipeline, transcribing full pages, could look like this:

```yaml

Demo pipeline for running text

steps:

Region segmentation

  • step: Segmentation settings: model: yolo model_settings: model: Riksarkivet/yolov9-regions-1 generation_settings: conf: 0.3 batch_size: 32

Line segmentation

  • step: Segmentation settings: model: yolo model_settings: model: Riksarkivet/yolov9-lines-within-regions-1 generation_settings: conf: 0.3 batch_size: 16

  • step: TextRecognition settings: model: WordLevelTrocr model_settings: model: Riksarkivet/trocr-base-handwritten-hist-swe-2 generation_settings: batch_size: 16 num_beams: 1

  • step: ReadingOrderMarginalia settings: two_page: always

Export to Alto and Page XML

  • step: Export settings: dest: outputs/alto format: alto

  • step: Export settings: dest: outputs/page format: page ```

See the documentation for the HTRflow package for further instructions on specific steps and customizations.

Training Details

Training Data

We cannot publically release all data the model was trained on, since we ourselves haven't created all the data, but below are links to the datasets we can release publically:

Göteborgs poliskammare 1850-1900
Krigshovrättens domböcker
Svea hovrätt
Bergskollegium
Frihetstidens utskottshandlingar
Carl-Fredrik Påhlmans resejournaler
Trolldomskommissionen
Göta hovrätt
Bergmästaren i Nora
Älvsborgs lösen
Jönköpings rådhusrätt magistrat

Training Procedure

Preprocessing

The text line polygons were masked out and placed against a white background, with dimensions decided by the polygon's bounding box.

Training Hyperparameters

See config.json. - training regime: bf16 - learning rate: 5e-5
- weight decay: 0.01

Evaluation

In-Domain Evaluation Data (Sorted by CER)

These are the character and word error rates on evaluation data taken from the same archives that was included in the training set. The evaluation samples are not part of the training data. The number of samples included in the training set give an indication of how the model improves by fine-tuning it on some specific material within the model's range.

Dataset WER CER Train Lines Eval Lines
krigshovrattens_dombocker_lines 0.0330 0.0075 16,887 1,877
stockholms_stadsarkiv_allmana_barnhuset_1700_lines 0.0647 0.0120 565 142
stockholms_stadsarkiv_blandat_2_1700_lines 0.0807 0.0170 25,024 2,781
goteborgs_poliskammare_fore_1900_lines 0.0800 0.0187 339,297 17,858
stockholms_stadsarkiv_stockholms_domkapitel_1700_lines 0.0948 0.0187 96,409 5,075
stockholms_stadsarkiv_politikollegiet_1700_lines 0.1108 0.0225 120,238 6,329
bergskollegium_relationer_och_skrivelser_lines 0.1056 0.0253 62,201 6,912
stockholms_stadsarkiv_stadens_kamnarsratt_1700_lines 0.1252 0.0278 38,330 4,259
svea_hovratt_lines 0.1484 0.0313 36,884 4,099
stockholms_stadsarkiv_stockholms_domkapitel_1800_lines 0.1400 0.0324 2,070 230
stockholms_stadsarkiv_handelskollegiet_1600_1700_lines 0.1785 0.0350 9,201 1,023
frihetstidens_utskottshandlingar_lines 0.1481 0.0362 13,490 1,499
stockholms_stadsarkiv_kungliga_hovkonsistoriet_1700_lines 0.1541 0.0364 5,753 640
national_archives_finland_court_records_lines 0.1607 0.0368 147,456 7,761
stockholms_stadsarkiv_blandat_1600_1700_lines 0.1505 0.0379 16,137 1,794
stockholms_stadsarkiv_blandat_3_1600_lines 0.1633 0.0400 43,142 4,794
stockholms_stadsarkiv_norra_forstadens_kamnarsratt_1600_1700_lines 0.1755 0.0463 18,474 2,053
carl_fredrik_pahlmans_resejournaler_lines 0.1768 0.0482 7,081 787
stockholms_stadsarkiv_sollentuna_haradsratt_1700_1800_lines 0.1921 0.0505 19,096 2,122
stockholms_stadsarkiv_byggningskollegium_1600_lines 0.2262 0.0514 3,104 345
ra_enstaka_sidor_lines 0.1991 0.0538 5,078 565
trolldomskommissionen_lines 0.2321 0.0600 33,498 3,722
stockholms_stadsarkiv_stockholms_domkapitel_1600_lines 0.2170 0.0607 11,619 1,292
stockholms_stadsarkiv_botkyrka_kyrkoarkiv_1600_1800_lines 0.2548 0.0627 3,617 402
gota_hovratt_lines 0.2450 0.0630 2,421 269
bergmastaren_i_nora_htr_lines 0.2558 0.0709 7,916 880
bergskollegium_advokatfiskalkontoret_lines 0.2906 0.0722 2,411 268
jl_fornsallskap_jamtlands_domsaga_lines 0.2585 0.0732 60,544 6,728
alvsborgs_losen_lines 0.1896 0.0806 5,632 626
jonkopings_radhusratt_och_magistrat_lines 0.2864 0.0853 1,179 131
national_archives_finland_letters_recipes_lines 0.3857 0.1360 651 163

Testing Data

Out-of-Domain Test Data (Sorted by CER)

These are the model's CER and WER on the eval_htr_out_of_domain_lines evaluation set, which contains lines from archives that were not at all included in the training data. So these are the results one would expect if one uses this model out-of-the-box on just any running text document within the model's time span.

Dataset WER CER Eval Lines
1792_R0002231_eval_lines 0.1190 0.0250 501
1794-1795_A0068546_eval_lines 0.1503 0.0303 510
1775-1786_A0068551_eval_lines 0.2203 0.0543 525
1841_Z0000017_eval_lines 0.2247 0.0555 470
1690_A0066756_eval_lines 0.2571 0.0611 249
1716_A0017151_eval_lines 0.2517 0.0650 558
1824_H0000743_eval_lines 0.2684 0.0674 260
1699-1700_C0113233_eval_lines 0.2713 0.0691 394
1845-1857_B0000011_eval_lines 0.2546 0.0706 153
1812_A0069332_eval_lines 0.2868 0.0793 69
1659-1674_R0000568_eval_lines 0.3278 0.0886 304
1755-1756_C0112394_eval_lines 0.3440 0.0918 248
1723_H0000374_eval_lines 0.3105 0.1140 378
1887-1892_A0002409_eval_lines 0.3670 0.1297 784
1679_R0002397_eval_lines 0.4768 0.1422 88
1800_C0101725_eval_lines 0.4459 0.1767 37
1871_K0017448_eval_lines 0.4504 0.1945 331
1654_R0001308_eval_lines 0.5200 0.2179 199
Metrics

Character Error Rate (CER)

Character Error Rate (CER) is a metric used to evaluate the performance of a Handwritten Text Recognition (HTR) system by comparing the recognized text to the reference (ground truth) text at the character level.

The CER is calculated using the following formula:

$$ \text{CER} = \frac{S + D + I}{N} $$

Where: - S is the number of substitutions (incorrect characters) - D is the number of deletions (missing characters) - I is the number of insertions (extra characters) - N is the total number of characters in the reference text

A lower CER indicates better recognition accuracy.

Word Error Rate (WER)

Word Error Rate (WER) is a metric used to assess the accuracy of an HTR system at the word level by comparing the recognized text to the reference text.

The WER is calculated using the following formula:

$$ \text{WER} = \frac{S + D + I}{N} $$

Where: - S is the number of substitutions (incorrect words) - D is the number of deletions (missing words) - I is the number of insertions (extra words) - N is the total number of words in the reference text

Similar to CER, a lower WER indicates better word-level accuracy.

Technical Specifications

Model Architecture

See config.json.

More details can be found in the original TrOCR paper.

Configuration

Architecture
VisionEncoderDecoderModel
Vocabulary size
50,265
Stored precision
float32
Model type
vision-encoder-decoder

Identity and Version

Repository
Riksarkivet/trocr-base-handwritten-hist-swe-2
Publisher
Swedish National Archives, AI-lab and Data Services
Task
Image to text
Modality
Image and text
Library
htrflow
Parameters
385M parameters
Languages
sv
Revision
aa79fcb1850bf3155ebc442570d6c6bfc0ac8100
First published
2024-08-15
Last updated
2026-06-04

Files and Weights

33 files, 1.5 GB in total. The weights are 1 file totalling 1.5 GB in safetensors.

Weights1 file · 1.5 GB
Configuration5 files · 8.1 KB
Tokenizer4 files · 3.4 MB
Documentation1 file · 13.4 KB
Other21 files · 4.1 MB
Repository1 file · 1.5 KB
Every file
FileTypeSizeSHA-256
model.safetensorsWeights1.5 GB 786c378f820e
config.jsonConfiguration4.8 KB
generation_config.jsonConfiguration274 B
handler.pyConfiguration1.7 KB
preprocessor_config.jsonConfiguration364 B
special_tokens_map.jsonConfiguration957 B
README.mdDocumentation13.4 KB
tensorboard/events.out.tfevents.1722593667.amlpai05.1105181.0Other3.9 MB e81f5466e797
tensorboard/events.out.tfevents.1723193022.amlpai05.965322.0Other9.3 KB da74c58ec00e
tensorboard/events.out.tfevents.1723193194.amlpai05.973492.0Other9.3 KB 6f99a604119a
tensorboard/events.out.tfevents.1723193342.amlpai05.981268.0Other9.3 KB a586b1a3f265
tensorboard/events.out.tfevents.1723193372.amlpai05.983438.0Other9.3 KB fd93fbe7d0e8
tensorboard/events.out.tfevents.1723193535.amlpai05.991824.0Other9.3 KB cc62b59f3f8c
tensorboard/events.out.tfevents.1723194050.amlpai05.1009717.0Other9.3 KB de37725d9546
tensorboard/events.out.tfevents.1723194523.amlpai05.1023845.0Other9.3 KB e734c7ada0fc
tensorboard/events.out.tfevents.1723195508.amlpai05.1058286.0Other9.3 KB bfbcada98187
tensorboard/events.out.tfevents.1723195753.amlpai05.1067357.0Other9.3 KB aef606f1453e
tensorboard/events.out.tfevents.1723196150.amlpai05.1081045.0Other9.3 KB 847ba958ca06
tensorboard/events.out.tfevents.1723196403.amlpai05.1089190.0Other9.3 KB 751f004889ba
tensorboard/events.out.tfevents.1723198169.amlpai05.1144588.0Other9.3 KB c4edf1a1d6b5
tensorboard/events.out.tfevents.1723198290.amlpai05.1149345.0Other9.3 KB 5fae89f13545
tensorboard/events.out.tfevents.1723198390.amlpai05.1153837.0Other9.3 KB 6482f55a9c61
tensorboard/events.out.tfevents.1723198574.amlpai05.1160632.0Other9.3 KB c76729f530da
tensorboard/events.out.tfevents.1723198651.amlpai05.1165918.0Other9.3 KB b14f2323fe6d
tensorboard/events.out.tfevents.1723198808.amlpai05.1174133.0Other9.3 KB d054323f5586
tensorboard/events.out.tfevents.1723198845.amlpai05.1176198.0Other9.3 KB 3a19baa0b765
tensorboard/events.out.tfevents.1723198913.amlpai05.1179428.0Other9.3 KB 737c1974ec08
tensorboard/events.out.tfevents.1723198936.amlpai05.1181588.0Other9.3 KB d269e3a8f8bc
.gitattributesRepository1.5 KB
merges.txtTokenizer456.3 KB
tokenizer.jsonTokenizer2.1 MB
tokenizer_config.jsonTokenizer1.3 KB
vocab.jsonTokenizer798.3 KB

License and Download

License
apache-2.0
Access
Open weights, no gate
Download size
1.5 GB
Download from Swedish National Archives, AI-lab and Data Services

Released by Swedish National Archives, AI-lab and Data Services through its official repository on Hugging Face. Read the license.

Built From

  • Derived from microsoft/trocr-base-handwritten
  • Described by arXiv:2109.10282
  • Trained on (disclosed) Riksarkivet/alvsborgs_losen_lines
  • Trained on (disclosed) Riksarkivet/bergmastaren_i_nora_htr_lines
  • Trained on (disclosed) Riksarkivet/bergskollegium_relationer_och_skrivelser_lines
  • Trained on (disclosed) Riksarkivet/carl_fredrik_pahlmans_resejournaler_lines
  • Trained on (disclosed) Riksarkivet/frihetstidens_utskottshandlingar_lines
  • Trained on (disclosed) Riksarkivet/gota_hovratt_lines
  • Trained on (disclosed) Riksarkivet/goteborgs_poliskammare_fore_1900_lines
  • Trained on (disclosed) Riksarkivet/jonkopings_radhusratt_och_magistrat_lines
  • Trained on (disclosed) Riksarkivet/krigshovrattens_dombocker_lines
  • Trained on (disclosed) Riksarkivet/svea_hovratt_lines
  • Trained on (disclosed) Riksarkivet/trolldomskommissionen_lines

Memory Requirements

PrecisionWeights in memory
As published1.5 GB
16-bit0.8 GB
8-bit0.4 GB
4-bit0.2 GB

Weights only, from the published parameter count; the key-value cache and runtime add to this.

Questions About trocr-base-handwritten-hist-swe-2

How much GPU memory does trocr-base-handwritten-hist-swe-2 need?

About 0.9 GB at 16-bit and 0.2 GB at 4-bit: the weights (385M parameters) plus a working margin. A long context needs more.

What is the cheapest GPU to run trocr-base-handwritten-hist-swe-2 on?

At 16-bit, 1x MI300X from $1.85 an hour; at 4-bit, 1x MI300X from $1.85 an hour, at the lowest on-demand prices the SAVRN Index lists.

Can I use trocr-base-handwritten-hist-swe-2 commercially?

Yes. trocr-base-handwritten-hist-swe-2 is released under Apache License 2.0. The Apache License 2.0 is a permissive open-source license. It permits commercial use, modification and redistribution. It requires keeping the license and copyright notices and any NOTICE file, stating significant changes, and it includes an express patent grant from contributors.

Similar Models

Model · Image to text

nougat-base

AI at Meta

Nougat model trained on PDF-to-markdown. It was introduced in the paper Nougat: Neural Optical Understanding for Academic Documents by Blecher et al. and first released in this repository. Disclaimer: The team releasing Nougat did not write a model card for this model so this model card has been written by the Hugging Face team. Note: this model corresponds to the "0.1.0-base" version of the original repository. Nougat is a Donut model trained to transcribe scientific PDFs into an easy-to-use markdown format. The model consists of a Swin Transformer as vision encoder, and an mBART model as text decoder. The model is trained to autoregressively predict the markdown given only the pixels of…

Open weights cc-by-nc-4.0 349M parameters transformers

Model · Image to text

trocr-base-printed

Microsoft

TrOCR model fine-tuned on the SROIE dataset. It was introduced in the paper TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models by Li et al. and first released in this repository. Disclaimer: The team releasing TrOCR did not write a model card for this model so this model card has been written by the Hugging Face team. The TrOCR model is an encoder-decoder model, consisting of an image Transformer as encoder, and a text Transformer as decoder. The image encoder was initialized from the weights of BEiT, while the text decoder was initialized from the weights of RoBERTa. Images are presented to the model as a sequence of fixed-size patches (resolution 16x16), which…

Open weights 333M parameters transformers

Model · Image to text

trocr-base-handwritten

Microsoft

TrOCR model fine-tuned on the IAM dataset. It was introduced in the paper TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models by Li et al. and first released in this repository. Disclaimer: The team releasing TrOCR did not write a model card for this model so this model card has been written by the Hugging Face team. The TrOCR model is an encoder-decoder model, consisting of an image Transformer as encoder, and a text Transformer as decoder. The image encoder was initialized from the weights of BEiT, while the text decoder was initialized from the weights of RoBERTa. Images are presented to the model as a sequence of fixed-size patches (resolution 16x16), which…

Open weights mit 333M parameters transformers

captioning pretrained on COCO dataset - base architecture (with ViT large backbone). Authors from the paper write in the abstract: Vision-Language Pre-training (VLP) has advanced the performance for many vision-language tasks. However, most existing pre-trained models only excel in either understanding-based tasks or generation-based tasks. Furthermore, performance improvement has been largely achieved by scaling up the dataset with noisy image-text pairs collected from the web, which is a suboptimal source of supervision. In this paper, we propose BLIP, a new VLP framework which transfers flexibly to both vision-language understanding and generation tasks. BLIP effectively utilizes the…

Open weights bsd-3-clause 470M parameters 512 tokens transformers

Model · Image to text

pix2struct-base

Google

This model is the pretrained version of Pix2Struct, use this model for fine-tuning purposes only. Pix2Struct is an image encoder - text decoder model that is trained on image-text pairs for various tasks, including image captionning and visual question answering. The full list of available models can be found on the Table 1 of the paper: The abstract of the model states that: forms. Perhaps due to this diversity, previous work has typically relied on domainspecific recipes with limited sharing of the underlying data, model architectures, and objectives. We present Pix2Struct, a pretrained image-to-text model for purely visual language understanding, which can be finetuned on tasks…

Open weights apache-2.0 282M parameters transformers

Model · Image to text

git-base

Microsoft

GIT (short for GenerativeImage2Text) model, base-sized version. It was introduced in the paper GIT: A Generative Image-to-text Transformer for Vision and Language by Wang et al. and first released in this repository. Disclaimer: The team releasing GIT did not write a model card for this model so this model card has been written by the Hugging Face team. GIT is a Transformer decoder conditioned on both CLIP image tokens and text tokens. The model is trained using "teacher forcing" on a lot of (image, text) pairs. The goal for the model is simply to predict the next text token, giving the image tokens and previous text tokens. The model has full access to (i.e. a bidirectional attention mask…

Open weights mit 177M parameters 1,024 tokens transformers