Character error rate in Python: 6 libraries, one test
6 of 6
libraries gave 11.25% CER on cleaned text
CER counts fixes per true character
CER = (wrong + missing + extra) / true characters.
| True text | OCR text | CER |
|---|---|---|
Total due |
total due |
11.1% |
abc |
nothing | 100% |
ok |
ok ok ok ok |
450% |
So CER can pass 100% when the OCR adds text.
All 6 agreed on cleaned text
I read the 12 files of our sample scanned PDFs with Tesseract 5.5.4, then scored that one output with each library.
| Library | Raw text | Cleaned |
|---|---|---|
| jiwer 4.0.0 | 12.88% | 11.25% |
| torchmetrics 1.9.0 | 12.89% | 11.25% |
| Hugging Face evaluate 0.4.6 | 12.88% | 11.25% |
| evaluate, with jiwer 3.1.0 | 12.36% | 11.25% |
| rapidfuzz 3.14.6, distance / length | 12.89% | 11.25% |
| editdistance 0.8.1 | 12.89% | 11.25% |
| fastwer 0.2.0 | 12.89% | 11.25% |
Cleaned means NFKC and one space between words. On raw text, jiwer and evaluate drop spaces and line breaks at the ends. With jiwer 3, evaluate also makes each run of 2 or more of them one space.
cer.py: one file, same 11.25%
pip install rapidfuzz
python cer.py truth/ ocr/
Put the true text as .txt files in truth/, and the OCR text under the same names in ocr/. It prints the CER of each file, then the total:
CER 11.25% (1198 edits, 10645 characters)
It skips an empty truth file. Without rapidfuzz it runs in plain Python, with the same result: 3 to 4 seconds here, not under 0.1.
The same number with jiwer
import unicodedata
import jiwer # pip install jiwer
def clean(text):
return " ".join(unicodedata.normalize("NFKC", text).split())
print(jiwer.cer([clean(t) for t in truths], [clean(o) for o in outputs]))
truths and outputs are lists of strings, in the same order. jiwer takes the truth first.
Averaging moved CER more than the library
- Summed over files
- 11.25%
- Mean of 12 file scores
- 12.56%
Same output, same cleaning. On raw text, the biggest gap between two libraries was 0.53 points. Sum the edits and the characters first, as cer.py does. With a list, jiwer, torchmetrics, evaluate and fastwer sum too.
6 traps that change the number
| Trap | What happened |
|---|---|
| Truth file ends in a line break | jiwer and evaluate: 0%. The other 4: 10%. |
| Empty truth | OCR text abc: 3 (jiwer counts the inserts), inf, 1.0, ZeroDivisionError or ValueError. |
| Arguments swapped |
ok vs ok ok ok ok: 82%, not 450%.
torchmetrics and fastwer take the OCR text first.
|
rapidfuzz normalized_distance |
It divides by the longer text, so it never passes 100%. |
| Lists of different lengths | torchmetrics drops the extra pair, with no error. |
| Markdown output | Our Actor: 7.5% with the marks, 3.9% without. |
Which library to pick
| Library | Pick it when |
|---|---|
| rapidfuzz | You want speed: 1.1 ms on the 12 files. |
| jiwer | You also want WER. Pin the version. |
| torchmetrics | You score inside PyTorch. It took 4.7 seconds. |
| evaluate | You use the Hugging Face Hub. Install and pin jiwer. |
| editdistance, fastwer | You use Python 3.12 or older: neither has a wheel for 3.14. fastwer needs char_level=True and returns a percent. |
Our Actor: about a third of the errors
PDF OCR to Markdown, our Apify Actor, reads a scanned PDF by URL and returns Markdown. With the Markdown marks removed, its text had 417 character errors on the same 12 files. Plain Tesseract had 1,198.
- That is build 0.1.102, from November 21. Newer builds were not scored here.
- Remove the marks (#, |, **, and the |---| rows) before you score. They count as errors.
- A scanned page costs $0.006, plus $0.00005 to start each run. The call is on PDF OCR API.
What I did not test
- WER. Measure OCR accuracy has it.
- OCR of handwriting, or of languages other than English.
- Speed on a GPU. All times are from one Mac, at low priority.
Hindi and emoji: code points, not letters
All 6 libraries count Unicode code points. One lost vowel sign in क्षेत्र is 1 of 7 code points, 14%. Split as a reader sees it, in 2 grapheme clusters, it is 50%. A thumbs up that lost its skin tone is 50%, or 100% as a reader sees it.
How I tested it
- 12 PDFs, 14 pages, made by code: a letter, an invoice, a fax, a receipt, a form and more.
-
pdftoppm -r 300, thentesseractwith its defaults. Pages of one file joined with a line break. - Python 3.12 on macOS. Times are the best of 3 runs on the raw text.
- Our Actor's text is from its code, run on our Mac.
- Scripts and results stay in our private repo, in research/bench/character-error-rate-2026-11-25/.
Sources
- jiwer
- torchmetrics
- Hugging Face evaluate, cer
- rapidfuzz
- editdistance
- fastwer
- We make cer.py and the Apify Actor, and none of the libraries.
Questions people ask
What is a good character error rate?
It depends on the page. Plain Tesseract scored 0% on our clean letter and 47% on our scanned invoice, mostly because it read the table in another order. Over 60 book pages it scored 5.3%. Compare tools on your own pages.
Is character error rate case sensitive?
Yes, in all 6 libraries we tested. None of them lowercases the text or applies Unicode normalization by default. Lowercase both texts first if case does not matter to you.
What is the difference between CER and WER?
CER counts character fixes, and WER counts whole word fixes. One wrong letter costs a whole word. On our 60 book pages, WER was about 3 times CER.