sacrebleu-mojo
A drop-in faster replacement for sacrebleu's
corpus BLEU and chrF metrics, powered by a clean-room Mojo kernel — with a
vendored pure-Python fallback for platforms without a native build (including Windows — tested there in CI: windows-fallback).
import sacrebleu_mojo # same call shapes as sacrebleu
bleu = sacrebleu_mojo.corpus_bleu(hypotheses, [reference_stream])
bleu.score # matches sacrebleu.corpus_bleu(...).score
bleu.counts, bleu.totals, bleu.precisions, bleu.bp, bleu.sys_len, bleu.ref_len
chrf = sacrebleu_mojo.corpus_chrf(hypotheses, [reference_stream])
chrf.score # matches sacrebleu.corpus_chrf(...).score
- Same results:
.scorematches the publishedsacrebleupackage (tested against 2.5.1) within 1e-9 on both the native and fallback backends. BLEU is bit-exact in practice — counts, totals, precisions and the brevity penalty are asserted exactly equal by the differential suite; chrF is bit-exact in the large majority of cases and otherwise within a couple of ulps. - Same defaults: BLEU with the mteval-v13a (
'13a') tokenizer and'exp'smoothing (plus'floor'/'none'anduse_effective_order); chrF withchar_order=6,word_order=0(0-4 supported),beta=2,remove_whitespace=True, and multi-reference best-per-sentence selection. - Much faster: integer-exact n-gram statistics from a compiled Mojo
kernel instead of nested Python
Counterloops — see the benchmark table below (measured on this machine; full method inbenchmarks/bench_sacrebleu.py). - No toolchain needed: per-platform wheels ship the compiled kernel. Everywhere else the package transparently uses its pure-Python fallback.
- Force the fallback with
SACREBLEU_MOJO_DISABLE_NATIVE=1; inspect the active backend withsacrebleu_mojo.backend_info().
Benchmarks
Measured on this machine (Apple M4 Max, macOS 26.6.2 arm64, Python 3.12.5,
numpy 2.5.3, Mojo 1.1.0, oracle sacrebleu 2.5.1) on 2026-09-19, with
synthetic hypothesis/reference corpora (10-40 token sentences from a
Zipf-ish 12k-term vocabulary; correctness to the oracle asserted within
1e-9 before timing — measured agreement was 0.0). "Cold" is the first call
after import; "warm" is the median of 5 repeated calls. Reproduce with
PYTHONPATH=python/sacrebleu_mojo python benchmarks/bench_sacrebleu.py.
BLEU (corpus_bleu, 13a tokenizer):
| pairs | sacrebleu cold (s) | sacrebleu_mojo cold (s) | sacrebleu warm (s) | sacrebleu_mojo warm (s) | cold speedup | warm speedup |
|---|---|---|---|---|---|---|
| 2,000 | 0.3258 | 0.1410 | 0.3825 | 0.1294 | 2.31x | 2.95x |
| 10,000 | 1.5659 | 0.5584 | 1.7333 | 0.5575 | 2.80x | 3.11x |
| 30,000 | 4.6475 | 1.7285 | 4.5162 | 1.5534 | 2.69x | 2.91x |
chrF (corpus_chrf):
| pairs | sacrebleu cold (s) | sacrebleu_mojo cold (s) | sacrebleu warm (s) | sacrebleu_mojo warm (s) | cold speedup | warm speedup |
|---|---|---|---|---|---|---|
| 2,000 | 0.9505 | 0.0738 | 1.0730 | 0.0713 | 12.88x | 15.04x |
| 10,000 | 5.2638 | 0.4947 | 4.2024 | 0.2980 | 10.64x | 14.10x |
| 30,000 | 14.2391 | 1.8352 | 20.4381 | 1.3486 | 7.76x | 15.15x |
BLEU's end-to-end speedup is bounded by the mteval-v13a tokenization, which runs in Python on both sides (identical text in, identical tokens out); the Mojo kernel computes the corpus n-gram statistics ~20x faster than the reference loops. chrF's character n-gram matching is almost entirely inside the kernel, hence the larger speedup. The pure-Python fallback is correctness-first (for platforms without a native build), not tuned for speed.
Scope and limitations
- Supported:
corpus_bleu/corpus_chrfwith default tokenizers ('13a'for BLEU, none for chrF), BLEU smoothing methods'exp'(default) and'floor'anduse_effective_order, chrFchar_order1-6,word_order0-4, any numericbeta,remove_whitespaceboth values. - Not supported (raises a clear error instead of guessing): BLEU tokenizers
other than
'13a'/'none', chrFchar_orderoutside [1, 6] orword_orderoutside [0, 4], andeps_smoothing=True(its exact reference behavior could not be pinned empirically; the defaultFalseis fully supported). Ragged inputs follow the oracle's zip-with-longest-stream truncation semantics. - chrF sentence-level selection over multiple references is exact (ties keep the earliest reference, like the oracle).
Source, benchmarks, and development: https://github.com/thyn-ai/mojo-kernels
License: Apache-2.0, © 2026 Algenta
Metadata
Release files for sacrebleu-mojo 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sacrebleu_mojo-0.2.5-py3-none-manylinux_2_35_x86_64.whl | Python 3 | none | Linux glibc 2.35+ x86-64 | Details for sacrebleu_mojo-0.2.5-py3-none-manylinux_2_35_x86_64.whl |
| sacrebleu_mojo-0.2.5-py3-none-macosx_14_0_arm64.whl | Python 3 | none | macOS 14.0+ ARM64 | Details for sacrebleu_mojo-0.2.5-py3-none-macosx_14_0_arm64.whl |
| sacrebleu_mojo-0.2.5-py3-none-any.whl | Python 3 | none | any | Details for sacrebleu_mojo-0.2.5-py3-none-any.whl |
Total release size: 2.0 MB
Release files / sacrebleu_mojo-0.2.5-py3-none-manylinux_2_35_x86_64.whl
| Download URL | sacrebleu_mojo-0.2.5-py3-none-manylinux_2_35_x86_64.whl |
|---|---|
| Size | 842.8 kB |
| Tags | Linux glibc 2.35+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
2db47e0ee5d2e69bfb33acaf1c89cded7362b678b6a2e06900bb180073451d16
|
|
BLAKE2b-256 checksum How to use checksums |
8c108c0e60325f10147c5c83691c56f717149428c408d955f313fc4a892f311e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / sacrebleu_mojo-0.2.5-py3-none-macosx_14_0_arm64.whl
| Download URL | sacrebleu_mojo-0.2.5-py3-none-macosx_14_0_arm64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Python 3 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
eb779706c476df4fe3206e9521fa62e5251c9814bae00e075f6ad1c0335462b8
|
|
BLAKE2b-256 checksum How to use checksums |
72124ea669069619979568419e169c959d23b5739578c726ab14a1d17d86cd82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / sacrebleu_mojo-0.2.5-py3-none-any.whl
| Download URL | sacrebleu_mojo-0.2.5-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
77a79b60c263b7b42855f40bf567ae1368d884bd4a6a0cf0346c8684a913bb15
|
|
BLAKE2b-256 checksum How to use checksums |
fd3a858d62ed54a5249d63c29ca8e177c2e59b8c456d1dfc0a37704a3e375bb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for sacrebleu-mojo 0.2.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.