Skip to main content

Grammar-based Text Segmentation

The mmdt-tokenizer is designed with a grammar-oriented approach to Myanmar text segmentation. It models tokenization through the grammatical structure of the language, particularly the use of postpositions, particles, and predicate constructions.

Core Principles

Pattern Protection

Before segmentation, special patterns such as URLs, numbers, emails, and date formats are temporarily protected to prevent accidental splitting during tokenization.

Grammar-driven lexicons

Lexicons are built around grammatical categories such as postpositions, conjunctions, sentence-final particles, auxiliary verbs, and negation markers. Each entry is syllable-based, allowing flexible matching and better handling of morphological variations.

Pipeline-based rule segmentation

The tokenization process passes through a defined sequence of grammatical matchers (e.g., POSTP, AUX, SFP, NEG), which reflect the syntactic order of Myanmar sentences.

Structural merging

Rules like merge_predicate() combine related chunks (e.g., verb + auxiliary + negation + particle) into coherent grammatical units, producing more linguistically meaningful tokens.

Extensible design

The system is designed to grow with additional grammatical patterns and lexicon types without retraining, making it adaptable for both general text and domain-specific applications.

Summary

This approach enables mmdt-tokenizer to segment Myanmar text based on grammar and structure — resulting in context-aware tokenization that aligns with natural language syntax.


Features

  • Normalize Myanmar text (remove unwanted spaces, support space removal modes) (Developed by NW)
  • Tokenize into syllables (Developed by NW)
  • Protection (Developed by NW)
  • Tokenize into words using grammar-rules (Developed by Myo)
  • Optionally save tokenization results to CSV (Developed by NW)

Credit & Inspiration

This library draws inspiration from the oppaWord: Myanmar Word Segmenter by Ye Kyaw Thu. The license of oppaWord is MIT.


Folder Structure

src/
└── mmdt_tokenizer/
    ├── __init__.py
    ├── core.py
    │
    ├── data/
    │
    ├── preprocessing/
    │   ├── __init__.py
    │   ├── cleaner.py
    │   ├── normalizer.py
    │   ├── preprocess.py
    │   └── protector.py
    │
    ├── rule_segmenter/
    │   ├── __init__.py
    |   ├── cleaner.py
    │   ├── collapse.py
    │   ├── engine.py
    │   ├── lexicon.py
    │   ├── merge_ops.py
    │   ├── scanner.py
    │   └── types.py
    │
    ├── tokenizer/
    │   ├── __init__.py
    │   ├── syllable_tokenizer.py
    │   └── word_tokenizer.py
    │
    ├── utils/
    │   ├── __init__.py
    │   ├── config.py
    │   ├── csv_utils.py
    │   ├── data_utils.py
    │   └── patterns.py
    │
    ├── scripts/
    │   ├── build_lexicons.py
    │   └── build_lexicons.ipynb
    │
    └── tests/
└─ pyproject.toml
└─ LICENSE    
└─ README.md


Folder Purpose
data/ Holds raw and formatted datasets, lexicon CSVs, and output files.
preprocessing/ Handles text cleaning, normalization, and input preparation.
rule_segmenter/ Core rule-based segmentation logic, including lexicon operations and chunk merging.
tokenizer/ Contains syllable-level and word-level tokenizers.
utils/ Utility functions — CSV and data handling, text patterns, configs, and helpers.
scripts/ Developer utilities and notebooks (e.g., lexicon builder).
tests/ Unit and integration test cases for validation.
core.py Main entry module coordinating tokenization and pipeline components.

Installation

pip install mmdt-tokenizer

Usage Example

from mmdt_tokenizer import MyanmarTokenizer

tokenizer = MyanmarTokenizer()

text = "သူသွားမယ်သို့မဟုတ်သူလာမယ်။"
tokens = tokenizer.word_tokenize(text)

print(tokens)
# Expected Output: ["သူ", "သွားမယ်", "သို့မဟုတ်", "သူ", "လာမယ်။"]

License

Distributed under the MIT License. See LICENSE for more information.


Changelog / Versioning

v0.1.0 — initial release with core tokenization features

Release files for mmdt-tokenizer 0.1.3

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

Source distribution (sdist)

Source distribution for mmdt-tokenizer 0.1.3
File Size Uploaded
mmdt_tokenizer-0.1.3.tar.gz 28.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mmdt-tokenizer 0.1.3
File Interpreter ABI Platform
mmdt_tokenizer-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 63.1 kB

Release files / mmdt_tokenizer-0.1.3.tar.gz

Download URL mmdt_tokenizer-0.1.3.tar.gz
Size 28.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ccaacac74be67451a450c8fceaa1f436890c1fbf59c4c533b3013d742aaa8900
BLAKE2b-256 checksum
How to use checksums
02b096dd41f72d2dec4d44bc14606cd8ab955d9fbde855901e27c272964bdbe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / mmdt_tokenizer-0.1.3-py3-none-any.whl

Download URL mmdt_tokenizer-0.1.3-py3-none-any.whl
Size 34.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b6682c2a513f6d4d97c399c6663b2ee47d32f49c6fadf41632126060248d6db
BLAKE2b-256 checksum
How to use checksums
f936c64bcbcac04c8d4f77464b9ec6814c4a6c4860088d26212606190660cc15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

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