This release is a pre-release and may not be stable for production use.
cleave-sbd: Sentence Boundary Disambiguation
cleave-sbd is a high-performance, strictly-typed sentence boundary disambiguation (SBD) engine. It isolates sentence boundaries across abbreviations, honorifics, numbers, lists, ellipses, and quotations without machine learning dependencies.
Features
- Zero Heavy Dependencies: Pure Python logic without neural models, PyTorch, or GPU requirements.
- Length-Preserving Coordinate Mapping: PUA sentinel substitutions and offset delta tracking ensure 1:1 character offset invariance for precise span extraction.
- Strict Typing: Fully typed and verified in strict mode with Basedpyright/Pyright (PEP 561 compliant with
py.typed). - Multilingual Support: Out-of-the-box rule sets for 22 languages.
- High Performance: Pre-compiled regular expressions and immutable lookup tables.
Installation
pip install cleave-sbd
Or with uv:
uv add cleave-sbd
Quickstart
import csbd
text = "My name is Jonas E. Smith. Please turn to p. 55."
seg = csbd.Segmenter(language="en", clean=False)
sentences = seg.segment(text)
print(sentences)
# Output:
# ('My name is Jonas E. Smith.', 'Please turn to p. 55.')
Character Span Mode
Extract start and end character offsets alongside segmented sentences:
import csbd
text = "Hello world! This is a test."
seg = csbd.Segmenter(language="en", char_span=True)
spans = seg.segment(text)
for span in spans:
print(f"{span.sent!r} -> [{span.start}:{span.end}]")
# Output:
# 'Hello world!' -> [0:12]
# 'This is a test.' -> [13:28]
Streaming Mode
Lazily process large texts or documents paragraph-by-paragraph with bounded memory:
import csbd
seg = csbd.Segmenter(language="en")
for sentence in seg.stream(large_text, chunk_paragraphs=1000):
print(sentence)
Parallel Processing (Multi-Worker Safe) (Coming Soon)
Native multi-core batch processing leveraging pure immutable state machines across worker processes.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
language |
str |
"en" |
Two-letter ISO 639-1 language code (e.g., "en", "de", "fr", "es", "ja"). |
clean |
bool |
False |
When True, normalizes noisy formatting (e.g., consecutive whitespace, unusual line breaks) before splitting. |
doc_type |
str |
"" |
Set to "pdf" for OCR/PDF extracted line break handling (requires clean=True). |
char_span |
bool |
False |
When True, returns character offset spans (TextSpan) with exact coordinates projected back to the raw source document. |
Supported Languages
| Code | Language | Code | Language | Code | Language |
|---|---|---|---|---|---|
am |
Amharic | el |
Greek | mr |
Marathi |
ar |
Arabic | en |
English | nl |
Dutch |
bg |
Bulgarian | es |
Spanish | pl |
Polish |
da |
Danish | fa |
Persian | ru |
Russian |
de |
German | fr |
French | sk |
Slovak |
hy |
Armenian | hi |
Hindi | ur |
Urdu |
it |
Italian | ja |
Japanese | zh |
Chinese |
kk |
Kazakh |
Why cleave-sbd?
| Feature | cleave-sbd |
pySBD |
spaCy (sm) |
NLTK (Punkt) |
|---|---|---|---|---|
| Dependencies | 0 (Stdlib) | 0 | Heavy (ML/C) | 1+ (Data downloads) |
| Typing | Strict (PEP 561) | Partial | Strict | Loose / Dynamic |
| Memory Footprint | Constant $O(\text{chunk})$ | Variable | Large (~50MB+) | Medium |
| 1:1 Span Projection | Yes (OffsetMap) |
Basic | Token-based | Manual slice |
| Python Target | 3.11+ Native | Legacy 3.x | 3.9+ | Legacy 3.x |
Documentation & Deep Dives
For complete documentation, architectural specifications, and recipes, see the cleave-sbd Wiki:
- 1. Design Philosophy: The 10 design rules behind our zero-dependency build, strict typing, and memory model.
- 2. Span Tracking: The mechanics behind our PUA masks and $O(\log K)$ delta tracking for exact character offsets.
- 3. Use Cases: Code recipes for sentence segmentation, span extraction, bounded streaming, and data cleaning.
- 4. Languages: How we handle abbreviations, legal numbering, non-Latin scripts, and unspaced text across 22 languages.
- 5. Benchmarks: Benchmark comparisons, latency tables, and failure analysis against Stanza, spaCy, NLTK, BlingFire, Syntok, and pySBD.
- 6. Contributing: Developer guide for running automated quality gates (
validate.sh) and adding language configurations.
Acknowledgments & Attribution
cleave-sbd is an independent, complete rewrite designed from the ground up as a modern, declarative, strictly-typed sentence boundary disambiguation engine.
Sincere attribution and gratitude are given to the projects whose compiled linguistic heuristics and rule sets inspired this library:
- Pragmatic Segmenter by Kevin S. Dias (Ruby)
- pySBD by Nipun Sadvilkar (Python)
License
MIT License. See LICENSE for details.
Metadata
Release files for cleave-sbd 0.3.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cleave_sbd-0.3.0b1.tar.gz | 150.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cleave_sbd-0.3.0b1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 209.1 kB
Release files / cleave_sbd-0.3.0b1.tar.gz
| Download URL | cleave_sbd-0.3.0b1.tar.gz |
|---|---|
| Size | 150.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
828a62baddef0c329363c04f589f5152b40f019fcd0bf069fcfea9932cf04d18
|
|
BLAKE2b-256 checksum How to use checksums |
205ac4f4b85ac5d754c727aaa3b5cc8babcf07b3b818c2fc653a0e1efc5ede1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 24, 2026.
Transparency logRelease files / cleave_sbd-0.3.0b1-py3-none-any.whl
| Download URL | cleave_sbd-0.3.0b1-py3-none-any.whl |
|---|---|
| Size | 58.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8591d732d137b324aa35c4a5f44ce942d5f8393aa10faccd647c774eb980fee9
|
|
BLAKE2b-256 checksum How to use checksums |
c17c1bb2bb5c8ff668d97e7af73e510b70789a8224dd9801c5562585771acad3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 24, 2026.
Transparency log