Downloads · 30 days
67
6% of all-time downloads
nlp-chula/phayathaibert-thai-pos-tagger
phayathaibert-thai-pos-tagger is a token classification model from nlp-chula. Use it when you need labels on individual words, such as names. The card lists the license as mit.
Fine-tuned PhayaThaiBERT for UPOS Part-of-Speech tagging on Thai sentences. Trained on the UDThai-TUD treebank following Universal Dependencies conventions.
Downloads · 30 days
67
6% of all-time downloads
All-time downloads
1.2K
Public
Parameters
277M
1.1 GB on disk
Likes
2
Public
Click a slice to open those files.
.safetensors1.1 GB · 98%
From the Hugging Face model README
Fine-tuned PhayaThaiBERT for UPOS Part-of-Speech tagging on Thai sentences.
Trained on the UD_Thai-TUD treebank following Universal Dependencies conventions.
ADJ, ADP, ADV, AUX, CCONJ, DET, NOUN, NUM, PART, PRON, PROPN, PUNCT, SCONJ, SYM, VERBThis model predicts word-level POS tags for Thai text. For best performance, use pre-segmented Thai words.
from transformers import AutoTokenizer, AutoModelForTokenClassification
import torch
tokenizer = AutoTokenizer.from_pretrained("nlp-chula/phayathaibert-thai-pos-tagger")
model = AutoModelForTokenClassification.from_pretrained("nlp-chula/phayathaibert-thai-pos-tagger")
model.eval()
from pythainlp.tokenize import word_tokenize
def predict_pos(text: str):
"""POS tag Thai text (raw string)."""
# 1. Word segmentation
words = word_tokenize(text)
# 2. Tokenize with alignment
encoded = tokenizer(
words,
is_split_into_words=True,
return_tensors="pt"
)
word_ids = encoded.word_ids()
with torch.no_grad():
outputs = model(**encoded)
preds = outputs.logits.argmax(dim=-1)[0]
# 3. Align subwords → words
results = []
prev = None
for idx, w_id in enumerate(word_ids):
if w_id is None:
continue
if w_id != prev:
label = model.config.id2label[preds[idx].item()]
results.append((words[w_id], label))
prev = w_id
return results
# Example
text = "ฉันกินข้าวที่ร้านอาหาร"
for w, p in predict_pos(text):
print(f"{w:15s} {p}")
def predict_pos_from_words(words):
"""POS tag a list of pre-segmented Thai words."""
encoded = tokenizer(
words,
is_split_into_words=True,
return_tensors="pt"
)
word_ids = encoded.word_ids()
with torch.no_grad():
outputs = model(**encoded)
preds = outputs.logits.argmax(dim=-1)[0]
results = []
prev = None
for idx, w_id in enumerate(word_ids):
if w_id is None:
continue
if w_id != prev:
label = model.config.id2label[preds[idx].item()]
results.append((words[w_id], label))
prev = w_id
return results
# Example
words = ["ฉัน", "กิน", "ข้าว", "ที่", "ร้านอาหาร"]
for w, p in predict_pos_from_words(words):
print(f"{w:15s} {p}")
Input: "ฉันกินข้าวที่ร้านอาหาร"
ฉัน: PRON
กิน: VERB
ข้าว: NOUN
ที่: ADP
ร้านอาหาร: NOUN
If you use this model, please cite the base model PhayaThaiBERT:
@article{Sriwirote_2025,
title={PhayaThaiBERT: Enhancing a Pretrained Thai Language Model with Unassimilated Loanwords},
volume={24},
ISSN={2375-4702},
url={http://dx.doi.org/10.1145/3765962},
DOI={10.1145/3765962},
number={11},
journal={ACM Transactions on Asian and Low-Resource Language Information Processing},
publisher={Association for Computing Machinery (ACM)},
author={Sriwirote, Panyut and Rutherford, Attapol T. and Thapiang, Jalinee and Timtong, Vasan},
year={2025},
month=Oct, pages={1–17} }
MIT License