Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pythainlp/tag/pos_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@ def pos_tag_sents(


def pos_tag_transformers(
words: str, engine: str = "bert-base-th-cased-blackboard"
words: str, engine: str = "phayathai"
):
"""
"wangchanberta-ud-thai-pud-upos",
"mdeberta-v3-ud-thai-pud-upos",
"bert-base-th-cased-blackboard",
"wangchanberta",
"mdeberta",
"bert_cased",
"phayathai",

"""

Expand All @@ -199,17 +200,21 @@ def pos_tag_transformers(
if not words:
return []

if engine == "wangchanberta-ud-thai-pud-upos":
if engine == "wangchanberta":
model = AutoModelForTokenClassification.from_pretrained(
"Pavarissy/wangchanberta-ud-thai-pud-upos")
tokenizer = AutoTokenizer.from_pretrained("Pavarissy/wangchanberta-ud-thai-pud-upos")
elif engine == "mdeberta-v3-ud-thai-pud-upos":
elif engine == "mdeberta":
model = AutoModelForTokenClassification.from_pretrained(
"Pavarissy/mdeberta-v3-ud-thai-pud-upos")
tokenizer = AutoTokenizer.from_pretrained("Pavarissy/mdeberta-v3-ud-thai-pud-upos")
elif engine == "bert-base-th-cased-blackboard":
elif engine == "bert_cased":
model = AutoModelForTokenClassification.from_pretrained("lunarlist/pos_thai")
tokenizer = AutoTokenizer.from_pretrained("lunarlist/pos_thai")
elif engine == "phayathai":
model = AutoModelForTokenClassification.from_pretrained(
"lunarlist/pos_thai_phayathai")
tokenizer = AutoTokenizer.from_pretrained("lunarlist/pos_thai_phayathai")
else:
raise ValueError(
"pos_tag_transformers not support {0} engine.".format(
Expand Down
8 changes: 5 additions & 3 deletions tests/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,12 @@ def test_NNER_class(self):

def test_pos_tag_transformers(self):
self.assertIsNotNone(pos_tag_transformers(
words="แมวทำอะไรตอนห้าโมงเช้า", engine="bert-base-th-cased-blackboard"))
words="แมวทำอะไรตอนห้าโมงเช้า", engine="bert_cased"))
self.assertIsNotNone(pos_tag_transformers(
words="แมวทำอะไรตอนห้าโมงเช้า", engine="mdeberta-v3-ud-thai-pud-upos"))
words="แมวทำอะไรตอนห้าโมงเช้า", engine="mdeberta"))
self.assertIsNotNone(pos_tag_transformers(
words="แมวทำอะไรตอนห้าโมงเช้า", engine="wangchanberta-ud-thai-pud-upos"))
words="แมวทำอะไรตอนห้าโมงเช้า", engine="wangchanberta"))
self.assertIsNotNone(pos_tag_transformers(
words="แมวทำอะไรตอนห้าโมงเช้า", engine="phayathai"))
with self.assertRaises(ValueError):
pos_tag_transformers(words="แมวทำอะไรตอนห้าโมงเช้า", engine="non-existing-engine")