Skip to main content

sacremoses-rs

Rust-accelerated drop-in classes for sacremoses (the Python port of the Moses tokenizer, detokenizer and punctuation normalizer). Same API, same output, byte for byte, much faster.

from sacremoses_rs import MosesTokenizer, MosesDetokenizer, MosesPunctNormalizer

tok = MosesTokenizer("en")
tok.tokenize("Hello, world... it's 5,300 dollars.", return_str=True)

# batch API (extra): one call, all CPU cores, GIL released, order preserved
tok.tokenize_many(list_of_sentences)
MosesPunctNormalizer("en").normalize_many(list_of_sentences)
MosesDetokenizer("en").detokenize_many(list_of_token_lists)

# or speed up everything that already uses sacremoses (CLI, truecaser, ...)
import sacremoses_rs; sacremoses_rs.patch()

The classes subclass the originals, so every option and attribute keeps working. Requires sacremoses>=0.2.0.

Speed

20,000 lines / 1.7 MB of English prose, Python 3.13, three runs, one core unless noted (the batch rows use both cores of the 2-thread test machine; more cores scale further):

step speedup vs. python
tokenize (return_str=True) 28-30x
tokenize (token list) 18-19x
tokenize (aggressive dashes) 27-30x
tokenize (batch API) 50-55x
punctuation normalize 4-6x
punctuation normalize (batch) 6-7x
detokenize 4-5x
detokenize (batch) 5-6x

Reproduce: python -I bench/bench.py <sacremoses checkout> <corpus.txt> 20000

How it was verified

  • tests/diff_test.py: differential test, original vs. Rust, outputs must be identical. About 1.2 million cases per run: a real corpus plus adversarial fuzz (unicode whitespace, control characters, exotic scripts, the library's own marker strings, ...) across 19 languages, all option combinations of the normalizer, the detokenizer, and the batch APIs. Result: 0 mismatches against both sacremoses 0.2.0 (PyPI) and the current git HEAD.
  • tests/test_basic.py: 54 self-contained pytest tests (golden outputs, fallbacks, batch order, thread safety, patch()).
  • sacremoses' own test suite with patch() applied gives the same results as without it (the truecaser tests that need network downloads fail identically either way).
  • cargo fmt and cargo clippy -D warnings are clean.

sacremoses 0.1.x is not supported: its handling of inputs that literally contain the text DOTMULTI differs from 0.2.0 (a quirk upstream fixed).

What is NOT accelerated (falls back to the original Python, same results)

  • tokenize(..., protected_patterns=...) and penn_tokenize
  • strings containing lone surrogates, non-str input
  • Czech detokenization of x - li / e-mail style tokens (the original raises a TypeError there; the fallback keeps that behaviour)

Known limits

  • Changing NONBREAKING_PREFIXES / NUMERIC_ONLY_PREFIXES of an existing tokenizer is noticed when the list object or its length changes, not when an item is edited in place.
  • The normalizer uses the Rust regex crate for \d and \p{C}; for code points newly assigned in a recent Unicode version, Python and Rust may disagree.
  • Everything above was measured on Linux x86-64 with Python 3.13. The GitHub Actions workflows (.github/workflows) that test and build Linux, macOS and Windows wheels are written but have not been run yet.

Build

pip install maturin "sacremoses>=0.2.0"
maturin build --release -o dist && pip install dist/*.whl
pytest tests/test_basic.py

License / attribution

MIT. The algorithms are ported from sacremoses (MIT, (c) 2020 alvations), which in turn ports the Moses scripts. Keep both copyright lines.

Metadata

Release files for sacremoses-rs 0.1.0

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

Source distribution (sdist)

Source distribution for sacremoses-rs 0.1.0
File Size Uploaded Provenance Actions
sacremoses_rs-0.1.0.tar.gz 19.9 kB With provenance Details for sacremoses_rs-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for sacremoses-rs 0.1.0
File Actions
sacremoses_rs-0.1.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for sacremoses_rs-0.1.0-cp39-abi3-win_amd64.whl
sacremoses_rs-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for sacremoses_rs-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sacremoses_rs-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for sacremoses_rs-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
sacremoses_rs-0.1.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for sacremoses_rs-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
sacremoses_rs-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for sacremoses_rs-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 4.3 MB

Release files / sacremoses_rs-0.1.0.tar.gz

Download URL sacremoses_rs-0.1.0.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
60b603552e2107c112f9853f518b4d765ef16f1f6f2403904cf906497b5c71e1
BLAKE2b-256 checksum
How to use checksums
2279fde9156cb2bccabbbaee9017dbbce3a2c32a40dc65830625a183f0115023
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / sacremoses_rs-0.1.0-cp39-abi3-win_amd64.whl

Download URL sacremoses_rs-0.1.0-cp39-abi3-win_amd64.whl
Size 787.6 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fdf8788eb22f1308b38c654ce6f45e24acd9e3bc455b08c47a507983d4fe0409
BLAKE2b-256 checksum
How to use checksums
39e620ef28032c657f8fae62adfd2e1af61fe80707ad6c978cd81fa313ed185b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / sacremoses_rs-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sacremoses_rs-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 925.7 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
937f4d4f0f566046f2338b0e5a7c9331283e852a84826fc9a73e21ea8eb0c6aa
BLAKE2b-256 checksum
How to use checksums
e40fd2afa8cc306bfa63266a551edca811a3969608f857f9d0e7c069e091d7e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / sacremoses_rs-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL sacremoses_rs-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 890.8 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8e4e390d64bf115260e6e113eaa1d680a17e3954708ef2685069bf502aab3f4f
BLAKE2b-256 checksum
How to use checksums
c9c8667ed4c6ee5a6c8c043842c847be88e71e0637c323c1ac3585bdfbc13734
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / sacremoses_rs-0.1.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL sacremoses_rs-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Size 810.3 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
364db35a481337f7802614ffdab2b59960bd30beb7827cee33bd1179ecdbed52
BLAKE2b-256 checksum
How to use checksums
26e6907179d592faa5ad4237ae21978e2d07345a83fdacb76d2de39989e6cb39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / sacremoses_rs-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL sacremoses_rs-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 859.8 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
767ed6a4c5cae1af9273d8a0245cd3cd7580b642db9ffabf86a192fc12db3638
BLAKE2b-256 checksum
How to use checksums
f54e273f1edd7350c2d9dc54c77db318342f6e3e57e8b5a8261e6dc9ddfadc69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for sacremoses-rs 0.1.0

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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for sacremoses_rs-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

6 release files Full provenance

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