Skip to main content

semcer

Equal CER, Unequal Damage: Severity-Weighted Character Error Rate for OCR
Nguyen Nguyen, Yongyi Zang

Paper (coming soon) Model Dataset Docs Open in Colab

Six one-character OCR errors, each charged 1 by CER and a different severity by semcer

CER counts every character error as 1. semcer uses the same alignment and gives each error a severity from 0 (harmless) to 1 (meaning lost), predicted by a 0.8B model that runs locally. The figure shows six one-character errors from the paper, with the mean rating of human readers on the same scale.

A line's score is the sum of its severities divided by the reference length, so semcer is at most CER.

Install

pip install semcer

Usage

import semcer

result = semcer.score(reference="The total is 15 dollars.", hypothesis="The total is 75 dollars.")
print(result.explain())
# semcer=0.0414  CER=0.0417  (1 edit(s) over 24 reference graphemes; lower is better)
#   SUB ref[13:14] '1' -> '7'  severity 0.99 (meaning lost)

For many lines, load the scorer once. The model downloads on first use.

scorer = semcer.SemCER()
results = scorer.score_batch(references=refs, hypotheses=hyps)

Or from the shell, with two text files that hold one line each per row:

semcer score --references refs.txt --hypotheses hyps.txt --output scores.jsonl

Speed

Device Precision Edits/s Lines/s
CPU (12-vCPU Xeon, 2.2 GHz) fp32 5.2 0.63
NVIDIA T4 16 GB (free Colab) fp32 46 5.5
NVIDIA A100 40 GB fp32 174 20.9
NVIDIA A100 40 GB bf16 (dtype="bf16") 286 34.5

Measured on 201 lines containing 1,667 edits; a larger corpus runs faster per line. A GPU is used when available. bf16 moves a severity by up to 0.006.

Citation

To be added with the paper.

License

Apache-2.0 for the code and the model weights.

The scan crops in the figure come from OmniDocBench and VieBookRead. They are shown for illustration, remain under those datasets' terms, and are not covered by this repository's license.

Metadata

Release files for semcer 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for semcer 0.1.4
File Size Uploaded Provenance Actions
semcer-0.1.4.tar.gz 68.4 kB Without provenance Details for semcer-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for semcer 0.1.4
File Interpreter ABI Platform Actions
semcer-0.1.4-py3-none-any.whl Python 3 none any Details for semcer-0.1.4-py3-none-any.whl

Total release size: 122.5 kB

Release files / semcer-0.1.4.tar.gz

Download URL semcer-0.1.4.tar.gz
Size 68.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bfc1db52523736a28b4ff7befdb2f7f378cfb41cb1a6bcff3eb1b9e5ed2c5740
BLAKE2b-256 checksum
How to use checksums
78cf83641a6c00297c92f140caa0cc81f106b91ed55a888f4afc79c232db68b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / semcer-0.1.4-py3-none-any.whl

Download URL semcer-0.1.4-py3-none-any.whl
Size 54.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aeb5671fa6656fb8b7d7c93b4021064c137a153308474c78d934f2b91441036f
BLAKE2b-256 checksum
How to use checksums
36f2447f2bc377f36376127c7355e8e5c5c6cdb03599129e850afb3fe12662c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for semcer 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page