Skip to main content

OpenThai2.0-NLP-Core-Lite

All core Thai NLP tasks in one lightweight network, from the OpenThai 2.0 model family. From raw text, it splits sentences and clauses, segments words, tags parts of speech, builds dependency and constituency trees, and finds named entities, on one CPU thread.

  • One network instead of a chain of tools: sentences, clauses, words in three units, POS tags (UD, and 37 tags based on the ORCHID tag set), dependency trees (UD), constituency trees (Penn Treebank style) and named entities (the 16 types of ThaiNER). All tasks share one network and read the same words.
  • Text without spaces: it finds sentence ends in running Thai text and in speech transcripts, where spaces are missing.
  • Lightweight, CPU only: 25.5M parameters in 30 MB of int8 model files. It needs only ONNX Runtime and NumPy, no GPU.
  • Fast on a CPU: on one thread, one line per call, about 25,000 characters per second for sentences, 20,000 for POS tags, 18,000 for named entities and 8,900 for dependency trees. That is 14 to 69 times as fast as the best other tool of each task.
  • Commercial use: trained only on data whose licences allow commercial use. Model: CC BY-SA 4.0.

Tasks

Four examples, as the model gives them:

Task Output
Words, long เจ้าหน้าที่ | การศึกษา | เปิดเผย | ว่า
Words, short (default) เจ้า | หน้าที่ | การ | ศึกษา | เปิด | เผย | ว่า
Words, minimal เจ้า | หน้า | ที่ | การ | ศึกษา | เปิด | เผย | ว่า
Sentences ร้านนี้อาหารอร่อยแต่ราคาค่อนข้างแพง ‖ ครั้งหน้าจะลองสั่งเมนูอื่นดู
Clauses ร้านนี้อาหารอร่อย ‖ แต่ราคาค่อนข้างแพง ‖ ครั้งหน้าจะลองสั่งเมนูอื่นดู
POS, UD นักเรียน NOUN · อ่าน VERB · หนังสือ NOUN · ใน ADP · ห้องสมุด NOUN
POS, ORCHID-based นักเรียน NCMN · อ่าน VTRA · หนังสือ NCMN · ใน RPRE · ห้องสมุด NCMN
Dependencies อ่าน is the root, over นักเรียน (nsubj), หนังสือ (obj) and ห้องสมุด (obl); ใน hangs on ห้องสมุด (case)
Constituency (S (NP (NCMN นักเรียน)) (VP (VTRA อ่าน) (NP (NCMN หนังสือ)) (PP (RPRE ใน) (NP (NCMN ห้องสมุด)))))
Named entities กรมอุตุนิยมวิทยา ORGANIZATION · จังหวัดเชียงใหม่ LOCATION · 3 ธันวาคม 2569 DATE, in กรมอุตุนิยมวิทยาประกาศเตือนฝนตกหนักในจังหวัดเชียงใหม่ตั้งแต่วันที่ 3 ธันวาคม 2569

Quick start

pip install "iapp-ai[nlp]"

One call runs every task and returns one document:

from iapp_ai.nlp import core

doc = core.analyze("นักเรียนอ่านหนังสือในห้องสมุด")
for w in doc.sentences[0].words:
    print(w.id, w.text, w.upos, w.head, w.deprel)
# 1 นักเรียน NOUN 2 nsubj
# 2 อ่าน VERB 0 root
# 3 หนังสือ NOUN 2 obj
# 4 ใน ADP 5 case
# 5 ห้องสมุด NOUN 2 obl
doc.sentences[0].tree   # (S (NP (NCMN นักเรียน)) (VP (VTRA อ่าน) (NP (NCMN หนังสือ)) (PP (RPRE ใน) (NP (NCMN ห้องสมุด)))))
core.analyze("กรมอุตุนิยมวิทยาประกาศเตือนฝนตกหนักในจังหวัดเชียงใหม่", tasks=["ner"]).entities
# [Entity(text='กรมอุตุนิยมวิทยา', label='ORGANIZATION', start=0, end=16),
#  Entity(text='จังหวัดเชียงใหม่', label='LOCATION', start=37, end=53)]

Or one function per task:

from iapp_ai.nlp import core

core.tokenize("เจ้าหน้าที่การศึกษาเปิดเผยว่า")                # ['เจ้า', 'หน้าที่', 'การ', 'ศึกษา', 'เปิด', 'เผย', 'ว่า']
core.tokenize("เจ้าหน้าที่การศึกษาเปิดเผยว่า", unit="long")   # ['เจ้าหน้าที่', 'การศึกษา', 'เปิดเผย', 'ว่า']
core.sent_tokenize("ร้านนี้อาหารอร่อยแต่ราคาค่อนข้างแพงครั้งหน้าจะลองสั่งเมนูอื่นดู")
# ['ร้านนี้อาหารอร่อยแต่ราคาค่อนข้างแพง', 'ครั้งหน้าจะลองสั่งเมนูอื่นดู']
core.pos_tag("นักเรียนอ่านหนังสือในห้องสมุด")
# [('นักเรียน', 'NOUN'), ('อ่าน', 'VERB'), ('หนังสือ', 'NOUN'), ('ใน', 'ADP'), ('ห้องสมุด', 'NOUN')]

pip install "iapp-ai[nlp]" installs NLP Core with iApp's Python package, as iapp_ai.nlp.core. The model package alone is pip install openthai2.0-nlp-core-lite, with the same functions in openthai_nlp_core_lite. It holds the model and runs offline on the CPU, with NumPy and ONNX Runtime (Python 3.10 or later).

Functions

To get Call
every task at once analyze(text): one document with its sentences, clauses, words (POS tags, heads, relations), trees and named entities; tasks=["pos", "ner"] for some of them
words tokenize(text), or word_tokenize(text) without the whitespace tokens
words of many lines, other readings tokenize_batch(texts), tokenize_nbest(text, n=3)
sentences sent_tokenize(text), or sent_spans(text) with their offsets
clauses clause_tokenize(text), or clause_spans(text)
POS tags pos_tag(text, tagset="ud"), with "ud" (17 tags) or "orchid" (37 tags based on ORCHID); also on a list of words
dependency trees dependency_parse(text), one tree per sentence
constituency trees constituency_parse(text), one Penn tree per sentence
named entities ner(text): an Entity (text, label, start, end) for each entity, or ner_batch(texts)

Every task reads the same words. tokenize, tokenize_batch and tokenize_nbest take the arguments of the OpenThai 2.0 word segmenter. Only what a call needs runs: words load the word part of the model alone, and pos_tag never loads the parsers.

Options

To Use
choose the unit unit="long", "short" (the default) or "minimal"
see other readings tokenize_nbest(text, n=3): the n most probable segmentations, each with its probability
read many lines faster analyze_batch(texts), tokenize_batch(texts), ner_batch(texts), or NLPCore().pipe(lines) for a file
save the results doc.to_dict() for JSON, doc.to_conllu() for CoNLL-U
add your own words NLPCore(extra_words=[...]): names or terms the dictionary lacks (below)
use more threads NLPCore(threads=4)
use the command line openthai-nlp-core-lite --task all < input.txt (one JSON object per line), or --task ner, --format conllu

Your own words are hints that the model reads, not cuts it must make. They reach every task. In the model package alone, the argument is user_words:

from iapp_ai.nlp import NLPCore

nlp = NLPCore(extra_words=["ไอโอที", "ดิจิทัลทวิน"])
nlp.tokenize("โรงงานใช้ระบบไอโอทีกับดิจิทัลทวิน", unit="long")
# ['โรงงาน', 'ใช้', 'ระบบ', 'ไอโอที', 'กับ', 'ดิจิทัลทวิน']   (without them: ไอโอ | ที, ดิจิทัล | ทวิน)

In iApp's package

pip install "iapp-ai[nlp]" installs NLP Core with iapp-ai, iApp's Python package, next to its word segmenter. The two stay apart: iapp_ai.nlp.word_tokenize and the other functions of the segmenter give its words, and iapp_ai.nlp.core gives the outputs of NLP Core, whose tags and trees read its own words.

Results

NLP Core against the state-of-the-art (SOTA) system of each task, the best tool from other authors, on raw text:

Task Metric Test data SOTA system SOTA NLP Core Speed
Sentences boundary F1 12 sets SaT-12l-sm 74.6 78.1† 14×
Clauses boundary F1 3 treebanks HoogBERTa 30.0* 71.4† 25×
Words word F1 7 sets SEFR CUT-best 84.5 85.7† 20×
POS tags UPOS F1 3 treebanks Stanza 1.15 accurate 73.1 74.7† 69×
Dependency trees LAS F1 3 treebanks Stanza 1.15 accurate 49.5 52.8† 59×
Constituency trees bracket F1 TUD Stanza 1.15 accurate 76.7* 79.4† 58×
Named entities entity F1 ThaiNER PyThaiNLP thainer-v2 82.8 84.1 20×
  • The higher score is bold, and † marks a lead beyond the 95% interval of a paired bootstrap. Speed is how many times as fast NLP Core runs, on one CPU core and one line per call.
  • A score over several test sets is their mean. The 12 sentence sets are four sets, each as written, without spaces and as speech transcripts. The three treebanks are UD Thai-TUD, PUD and TDT.
  • * No SOTA system exists for the task, so the closest tool is shown. HoogBERTa learnt another clause unit, and Stanza reaches constituency trees by conversion of its dependency trees.
  • From raw text, each system reads its own sentences and words. On TUD alone, NLP Core has 83.8 UPOS F1 against 83.1 and 67.2 LAS F1 against 65.2. Given the gold words of TUD, it has 92.0 UPOS accuracy against 91.4, 78.8 LAS against 76.3 and 80.2 bracket F1 against 79.6.
  • thainer-v2 is scored on the first piece of each newmm word and timed as PyThaiNLP calls it. It learnt from ThaiNER train, while NLP Core learnt from no ThaiNER text. On the 1,385 test texts that share no text with ThaiNER train, NLP Core leads by 1.5, beyond the interval.
  • Another system leads on some single sets. At gold words, Stanza 1.11 accurate tags PUD better (78.4 against 77.8), and Stanza 1.15 default tags TDT better (80.0 against 79.3). On the older TUD release of the TUD paper, the models trained on its own split lead. Systems trained on a test set are not counted.
  • Every system, test set and interval of sentences, clauses, POS, dependencies, constituency and named entities is in OpenThai2.0-NLP-Core-Benchmark, which is not public yet. The word scores come from OpenThai2.0-WordSeg-Benchmark 1.0. The named entities are scored on the test split of ThaiNER v2.2, on character spans.

Training data

Its teachers learnt from UD Thai-TUD, scb-mt-en-th-2020, Tatoeba, VISTEC-TP-TH-2021, Wisesight-1000 and the CC BY-SA rows of the khammoon data. The model also read unlabelled text from FineWeb-2, Thai Wikipedia and Wisesight. Its named entities come from our own labels on that text and on Blognone news, written by Qwen3.8-27B (Apache-2.0) and by a teacher trained on them. No ThaiNER, BEST, ORCHID, LST20 or other non-commercial data were used, and the training text was filtered against every test set above. Sources, licences and attributions: the NOTICE inside the package.

Limitations

  • Thai corpora disagree on what a word is. POS follows UD Thai-TUD, which tags many state words VERB where a dictionary has ADJ.
  • Parsing reads short words, one sentence at a time. A long paragraph without a sentence end inside parses slowly.
  • The constituency trees have phrase labels and word tags, but no function tags (-SBJ) and no empty elements. They were learnt from trees converted from TUD dependency trees.
  • The int8 results can change in the last digits with the number of threads, or with the other texts of one ner_batch call, which can flip a borderline decision.
  • Named entities follow the 16 types of ThaiNER. Rare types are weak: on ThaiNER test, FACILITY 42.8 and URL 48.4, against PERSON 92.8 and ORGANIZATION 85.1.

Files

chars.int8.onnx and tower.int8.onnx hold the shared network, and each head.*.int8.onnx one task, with head.dep.npz and head.span.npz for the two parsers. manifest.json lists the labels, the two thresholds and the SHA-256 of every file. The Python package holds the same files with the runtime, and the dictionary and character table of the OpenThai 2.0 word segmenter that the model reads. Licences: Apache-2.0 for the code, CC BY-SA 4.0 for the model files, and the Unicode licence for part of the dictionary. Their texts and the NOTICE are inside the package.

Metadata

Release files for openthai2.0-nlp-core-lite 0.2.1

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

Built distribution (wheel)

Table of built distributions (wheels) for openthai2.0-nlp-core-lite 0.2.1
File Interpreter ABI Platform Actions
openthai2_0_nlp_core_lite-0.2.1-py3-none-any.whl Python 3 none any Details for openthai2_0_nlp_core_lite-0.2.1-py3-none-any.whl

Release files / openthai2_0_nlp_core_lite-0.2.1-py3-none-any.whl

Download URL openthai2_0_nlp_core_lite-0.2.1-py3-none-any.whl
Size 23.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
9ace54e37923f3d4f792b36d770a32b1090287825246ea766a56418281e7d1a1
BLAKE2b-256 checksum
How to use checksums
f44b2c2b82744ad23bc6e909c90f6f9938a737329faa857088ba3701f4c60790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Security for openthai2.0-nlp-core-lite 0.2.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.2.1 This release

1 release file 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