Skip to main content

thai-orthographic-segmenter (Python)

Python bindings for the Thai orthographic segmenter crates, as plain tokenizer functions (word_tokenize, syllable_tokenize, ...). The models are bundled in the wheel, so there is nothing to download, and every call releases the interpreter lock.

pip install thai-orthographic-segmenter

Python 3.10 or later is required.

from thai_orthographic_segmenter import syllable_tokenize, word_tokenize

word_tokenize("ในปฐมกาลพระวาทะทรงดำรงอยู่")
# ['ในปฐมกาล', 'พระวาทะ', 'ทรงดำรง', 'อยู่']
syllable_tokenize("พระวาทะ")
# ['พระ', 'วา', 'ทะ']

Functions

Function Backed by Returns
syllable_tokenize(text) thai-syllable-segmenter written syllables, a list[str]
word_tokenize(text, keep_whitespace=True) thai-word-segmenter words (lexical clusters), a list[str]
word_tokenize_many(texts, jobs=None) thai-word-segmenter the words of each text, scored together on up to jobs threads
syllable_spans(text), word_spans(text) the same (start, end) code point offsets, so text[start:end] is the token
mark_line_breaks(text) thai-line-segmenter text with zero-width spaces at break opportunities and joiners inside words
orthographic_parts(text) thai-syllable-rules OrthographicPart(kind, text, start, end) from spelling rules alone, with ambiguity left as "undecided"

Syllables and words are slices of the input, so "".join(tokens) == text. The functions use shared default models built on first use (about 5 ms for syllables, 40 ms for words and line breaks). For anything else, build a tokenizer once and pass it in:

from thai_orthographic_segmenter import WordTokenizer, word_tokenize

tokenizer = WordTokenizer.with_dictionary(["ปฐมกาลพระวาทะ"])  # replaces the bundled dictionary
word_tokenize("ในปฐมกาลพระวาทะทรงดำรงอยู่", tokenizer=tokenizer)
WordTokenizer.load("path/to/artifact")  # config.json, dictionary.txt, model.safetensors

SyllableTokenizer, WordTokenizer and LineBreaker(icu_dictionary=None) take the same text and return the same results as the functions through tokenize, spans and mark.

Behaviour

  • Granularity: the word model is trained to under-segment, keeping compounds and collocations together, so it returns fewer, longer words than annotation-style word segmenters. See the word segmenter readme for the benchmark scores.
  • One model per level: there is no choice of engine. A custom dictionary replaces the bundled one rather than extending it.
  • Failures: they raise SegmenterError, a ValueError. A Thai run over 4,096 scalars is rejected by the syllable segmenter.

Build and test

uvx maturin develop --manifest-path thai-segmenter-python/Cargo.toml --uv
uv run --with pytest pytest thai-segmenter-python/tests

maturin build --release produces a wheel. The wheel needs nothing beyond the Python interpreter that imports it.

Metadata

Release files for thai-orthographic-segmenter 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 thai-orthographic-segmenter 0.1.0
File Size Uploaded Provenance Actions
thai_orthographic_segmenter-0.1.0.tar.gz 7.5 MB Without provenance Details for thai_orthographic_segmenter-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for thai-orthographic-segmenter 0.1.0
File Interpreter ABI Platform Actions
thai_orthographic_segmenter-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64 Details for thai_orthographic_segmenter-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl

Total release size: 16.2 MB

Release files / thai_orthographic_segmenter-0.1.0.tar.gz

Download URL thai_orthographic_segmenter-0.1.0.tar.gz
Size 7.5 MB
Tags Source
SHA-256 checksum
How to use checksums
b89f1f2899a7a1bee0e5d9a1eae1c35ebef3857812d3f178c0be588d04b03fe4
BLAKE2b-256 checksum
How to use checksums
bdb770474aabecf99b5e9ba728f13ebcaac6ab5b8e6e908c5af1005367e09e8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.11","id":"zokor","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / thai_orthographic_segmenter-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl

Download URL thai_orthographic_segmenter-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl
Size 8.7 MB
Tags CPython 3.13 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
9c3964993271ec9bc31ca345ae468aecc58285e89443bd2a60d472dff4f63253
BLAKE2b-256 checksum
How to use checksums
f5fae260a429a21d550365a89e5e76b34f8bb4e679cecb76663a680293363f8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.11","id":"zokor","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for thai-orthographic-segmenter 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.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No 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