Skip to main content

thai-orthographic-segmenter (Python)

PyPI Python versions PyPI downloads CI License

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.1

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.1
File Size Uploaded Provenance Actions
thai_orthographic_segmenter-0.1.1.tar.gz 7.5 MB Without provenance Details for thai_orthographic_segmenter-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for thai-orthographic-segmenter 0.1.1
File Interpreter ABI Platform Actions
thai_orthographic_segmenter-0.1.1-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.1-cp313-cp313-manylinux_2_34_x86_64.whl

Total release size: 16.2 MB

Release files / thai_orthographic_segmenter-0.1.1.tar.gz

Download URL thai_orthographic_segmenter-0.1.1.tar.gz
Size 7.5 MB
Tags Source
SHA-256 checksum
How to use checksums
649e009ab2bdde7184bb30ff27b97769683c39753ce7354c3a3dce0ec10522dd
BLAKE2b-256 checksum
How to use checksums
d1e084960f7af28b8fb45941d833c5dbe7878bbf27300047216a4d28057fedd0
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.1-cp313-cp313-manylinux_2_34_x86_64.whl

Download URL thai_orthographic_segmenter-0.1.1-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
e53df4047e7ea8b29fac30f053bcc10a8a7e397751c9fd315479d6a9223781e7
BLAKE2b-256 checksum
How to use checksums
6e2d22061e75e4bf8d3a1772092b2a3f6fcd08c485ca982e199fb0cbd27fc1db
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.1

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.1 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