SacreMoses is a Python port of the widely-used Moses tokenizer, truecaser, and punctuation normalizer tools, essential for many Natural Language Processing (NLP) tasks, particularly in machine translation workflows. The current version is 0.1.1. Releases are made periodically, addressing bug fixes, performance improvements, and alignment with the original Perl implementation.
pip install sacremosesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core functionalities: punctuation normalization and the tokenization/detokenization of a sample English sentence.
Upgrade to Python 3.8+ or pin sacremoses to version 0.0.40.
Review your code for any reliance on previous behavior, especially regarding truecasing and custom protected patterns. Retest your NLP pipeline after updating.
Consider explicitly setting `perl_parity=True` in `MosesPunctNormalizer` to ensure future compatibility and consistent behavior with the latest Perl Moses. Be aware that this might subtly change normalization output.
Thoroughly test any custom span tokenization logic, especially when dealing with escaped characters or complex detokenization scenarios. Consult existing implementations if available.
pip install sacremoses
from sacremoses import MosesTokenizer tokenizer = MosesTokenizer()
Ensure an active internet connection, clear any proxy or firewall issues, and try re-initializing `MosesTruecaser` to trigger a model download. You might need to delete incomplete model files manually.
tokenizer = MosesTokenizer()
tokenized_text = tokenizer.tokenize('This is a test sentence.')No dependency data recorded yet.