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 (Apple M1 Pro laptop) fp32 11.5 1.39
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.5

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.5
File Size Uploaded Provenance Actions
semcer-0.1.5.tar.gz 68.4 kB Without provenance Details for semcer-0.1.5.tar.gz

Built distribution (wheel)

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

Total release size: 122.5 kB

Release files / semcer-0.1.5.tar.gz

Download URL semcer-0.1.5.tar.gz
Size 68.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a264b6c55701f2932f0346e39f20f75a82580c4a8a429272031050b80236bc6d
BLAKE2b-256 checksum
How to use checksums
91893c51f69fa443344110638764f393bd3376f7dbfa41f1a311422e2365d2b2
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.5-py3-none-any.whl

Download URL semcer-0.1.5-py3-none-any.whl
Size 54.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0924578732dbb9ac812310ddc1dde6230a136a325704c88ea0f19501444e438
BLAKE2b-256 checksum
How to use checksums
1acc59f68c8e13eb23beb518824f6eaabab6bc617b4132ec967068cd4f5d9d85
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.5

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