Skip to content

Commit dfed5ff

Browse files
committed
Update pythainlp.wsd api
1 parent 797432f commit dfed5ff

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

notebooks/test_wsd.ipynb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 9,
17+
"execution_count": 2,
1818
"id": "2ef43b65-5df9-42e3-a712-0e60ca64ea16",
1919
"metadata": {
2020
"tags": []
@@ -24,7 +24,8 @@
2424
"name": "stdout",
2525
"output_type": "stream",
2626
"text": [
27-
"[('โปรแกรมคอมพิวเตอร์ใช้ในทางอินเทอร์เน็ตสำหรับเก็บข้อมูลของผู้ใช้งาน', 0.0974416732788086), ('ชื่อขนมชนิดหนึ่งจำพวกขนมเค้ก แต่ทำเป็นชิ้นเล็ก ๆ แบน ๆ แล้วอบให้กรอบ', 0.09319090843200684)]\n"
27+
"Setting ds_accelerator to cuda (auto detect)\n",
28+
"[('ชื่อขนมชนิดหนึ่งจำพวกขนมเค้ก แต่ทำเป็นชิ้นเล็ก ๆ แบน ๆ แล้วอบให้กรอบ', 0.09319090843200684), ('โปรแกรมคอมพิวเตอร์ใช้ในทางอินเทอร์เน็ตสำหรับเก็บข้อมูลของผู้ใช้งาน', 0.0974416732788086)]\n"
2829
]
2930
}
3031
],
@@ -34,7 +35,7 @@
3435
},
3536
{
3637
"cell_type": "code",
37-
"execution_count": 10,
38+
"execution_count": 3,
3839
"id": "6aafefdf-4658-4e35-b69f-7d2b54e34d33",
3940
"metadata": {
4041
"tags": []
@@ -44,7 +45,7 @@
4445
"name": "stdout",
4546
"output_type": "stream",
4647
"text": [
47-
"[('โปรแกรมคอมพิวเตอร์ใช้ในทางอินเทอร์เน็ตสำหรับเก็บข้อมูลของผู้ใช้งาน', 0.1005704402923584), ('ชื่อขนมชนิดหนึ่งจำพวกขนมเค้ก แต่ทำเป็นชิ้นเล็ก ๆ แบน ๆ แล้วอบให้กรอบ', 0.12473666667938232)]\n"
48+
"[('ชื่อขนมชนิดหนึ่งจำพวกขนมเค้ก แต่ทำเป็นชิ้นเล็ก ๆ แบน ๆ แล้วอบให้กรอบ', 0.12473666667938232), ('โปรแกรมคอมพิวเตอร์ใช้ในทางอินเทอร์เน็ตสำหรับเก็บข้อมูลของผู้ใช้งาน', 0.1005704402923584)]\n"
4849
]
4950
}
5051
],
@@ -128,7 +129,7 @@
128129
{
129130
"data": {
130131
"text/plain": [
131-
"('เดิน', ['ยกเท้าก้าวไป', 'เคลื่อนไปด้วยกำลังต่าง ๆ'])"
132+
"('เดิน', ['เคลื่อนไปด้วยกำลังต่าง ๆ', 'ยกเท้าก้าวไป'])"
132133
]
133134
},
134135
"execution_count": 8,

pythainlp/wsd/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_sense(
5252
sentence: str,
5353
word: str,
5454
device:str="cpu",
55-
custom_dict: dict=_mean_all,
55+
custom_dict: Union[dict,None]=None,
5656
custom_tokenizer: Tokenizer=_word_cut,
5757
) -> Union[List[Tuple[str, float]], None]:
5858
"""
@@ -96,6 +96,8 @@ def get_sense(
9696
# 0.12473666667938232)]
9797
"""
9898
global _MODEL
99+
if custom_dict == None:
100+
custom_dict = _mean_all
99101
_w = custom_tokenizer.word_tokenize(sentence)
100102
if word not in set(custom_dict.keys()) or word not in sentence:
101103
return None

0 commit comments

Comments
 (0)