Skip to main content

OpenThai 2.0 NLP Core Lite: seven Thai NLP tasks in one 31 MB model, on a CPU

· 7 min read
Kobkrit Viriyayudhakorn
CEO @ iApp Technology

OpenThai (formerly OpenThaiGPT) and iApp release OpenThai 2.0 NLP Core Lite, one model for the basic tasks of Thai language processing. From raw text it splits sentences and clauses, segments words, tags parts of speech, finds named entities, and builds dependency and constituency trees. Its accuracy is close to or above the best available tool for each task, it runs 14 to 69 times as fast on a CPU, and the whole model is 31 MB. It is free to download, and commercial use is allowed.

Model: huggingface.co/iapp/OpenThai2.0-NLP-Core-Lite · Benchmark: huggingface.co/datasets/iapp/OpenThai2.0-NLP-Core-Benchmark · Install: pip install "iapp-ai[nlp]"

OpenThai 2.0 NLP Core Lite (infographic in Thai): one Thai sentence analysed into sentences, clauses, words, parts of speech, named entities, a dependency tree and a constituency tree; 26.5M parameters (31 MB) against 957M for the best tools of the seven tasks combined, no GPU needed; scores against the best other tool of each task and speed on one CPU core, 14 to 69 times as fast

Why one model​

Thai text processing usually chains several tools: one segments words, the next tags them, a third parses them and a fourth finds names. An error at the start of the chain carries into every step after it, and each tool may cut words its own way, so their outputs have to be aligned by hand. In OpenThai 2.0 NLP Core Lite every task runs on one shared network and reads the same words, so the results of all seven tasks fit together.

Seven results from one call​

TaskWhat it givesTypical use
SentencesSentence ends in running Thai text, also without spaces or punctuationSubtitles, input for translation and summarisation
ClausesEach sentence split into clausesText-to-speech phrasing, RAG chunks
WordsThree units: long keeps compounds whole, short (the default) gives words, minimal gives morphemesSearch, keywords
Parts of speech17 UD tags, or 37 tags based on ORCHIDFiltering words, grammar
Named entitiesThe 16 types of ThaiNER, such as people, organisations, places and datesPersonal-data (PDPA) screening, organisation lists
Dependency treesWhich word modifies which (UD)Who did what, information extraction
Constituency treesNested phrases, Penn Treebank styleNoun phrases, sentence structure

Results​

Each score is out of 100 and is the main score of its task, measured on raw text. The comparison is with the best tool from other authors for each task, and every system gets the same input. Speed is measured on one CPU core with one line per call, for every system.

TaskScoreOpenThai 2.0 NLP Core LiteBest other toolIts scoreTimes as fast
Sentencesboundary F1, 12 test sets78.6†SaT-12l-sm, tuned77.514
Clausesboundary F1, 3 treebanks70.8HoogBERTa*30.025
Wordsword F1, 7 test sets85.7†SEFR CUT84.520
Parts of speechUPOS F1, 3 treebanks74.7†Stanza 1.1573.169
Dependency treesLAS F1, 3 treebanks52.8†Stanza 1.1549.859
Constituency treesbracket F1, UD Thai-TUD79.4Stanza 1.15*78.658
Named entitiesentity F1, ThaiNER84.7phayathaibert-thainer85.719
  • † marks a lead beyond the 95% interval of a paired bootstrap. A higher score without † is a tie.
  • * No tool does this task directly, so the closest one is used: HoogBERTa cuts a different unit from a clause, and Stanza's constituency trees are converted from its dependency trees. The clause and constituency labels were made by rules from the gold treebank trees and partly checked by hand.
  • Size: 26.5 million parameters. The best tools of the seven tasks hold 957 million between them, 36 times as many.
  • On one CPU thread the model reads about 25,000 characters a second for sentences, 20,000 for parts of speech, 18,000 for named entities and 8,900 for dependency trees.
  • The benchmark holds the test sets, the outputs of every system compared and the scoring script, so you can score the tool you use today on the same data. Where a source's licence does not allow its text to be shared, the benchmark gives ids and character offsets instead.

Where it is behind​

  • Named entities: phayathaibert-thainer leads by 1.0 point. It was trained on ThaiNER's training split and OpenThai 2.0 NLP Core Lite was not; on the 1,385 test texts that share no text with that split, the two are level: 84.8 for OpenThai 2.0 NLP Core Lite and 85.4 for phayathaibert-thainer, a gap inside the margin of error.
  • Rare entity types are weak: FACILITY scores 46.4 and URL 51.7, against 94.0 for PERSON and 85.6 for ORGANIZATION.
  • Parsing reads one sentence at a time, so a long paragraph with no sentence end parses slowly.
  • Words: Thai corpora disagree on what a word is. Part-of-speech tags follow UD Thai-TUD, which tags many state words VERB where a dictionary has ADJ.

Install and use​

With Python 3.10 or later:

pip install "iapp-ai[nlp]"

One call to analyze returns all seven results in one document:

from iapp_ai.nlp import core

doc = core.analyze("กรมอุตุนิยมวิทยาประกาศเตือนฝนตกหนักในจังหวัดเชียงใหม่")
print(doc.entities)
# [Entity(text='กรมอุตุนิยมวิทยา', label='ORGANIZATION', start=0, end=16),
# Entity(text='จังหวัดเชียงใหม่', label='LOCATION', start=37, end=53)]

Each task can also be called on its own:

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

Only what a call needs is loaded: tokenize loads the word part of the model alone, and pos_tag never loads the parsers. Results can be saved as JSON with doc.to_dict() or as CoNLL-U with doc.to_conllu(). The model runs offline with ONNX Runtime and NumPy, and needs no GPU. Every function and option is listed on the model page.

Licence​

  • The model is licensed CC BY-SA 4.0. You may use it in commercial products with attribution, and if you modify the model and share it, you share it under the same licence. The code is Apache-2.0.
  • Every training dataset carries a licence that its owner states allows commercial use. ThaiNER, BEST, ORCHID, LST20 and other non-commercial corpora were not used, and the training text was filtered against every test set.
  • The datasets and the licence of each: NOTICE.

Developed by iApp, launched with AIEAT. Thank you to Siam AI Corporation for the GPUs used to train this model.