【发布时间】:2018-03-20 12:54:00
【问题描述】:
我正在尝试在 Python 中使用 deepcut 对泰语文本进行标记,但遇到了 UnicodeDecodeError。
这是我尝试过的
import deepcut
thai = 'ตัดคำได้ดีมาก'
result = deepcut.tokenize(thai)
预期输出:
[\['ตัดคำ','ได้','ดี','มาก'\]][1]
试过了:
for i in result:
print(i.decode('utf-8'))
Error: UnicodeDecodeError: 'utf8' codec can't decode byte 0xe0 in position 0: unexpected end of data
print([i for i in result])
Output: ['\xe0', '\xb8', '\x95', '\xe0', '\xb8', '\xb1', '\xe0', '\xb8', '\x94', '\xe0', '\xb8', '\x84', '\xe0', '\xb8', '\xb3', '\xe0', '\xb9', '\x84', '\xe0', '\xb8', '\x94', '\xe0', '\xb9', '\x89', '\xe0', '\xb8', '\x94', '\xe0', '\xb8', '\xb5', '\xe0', '\xb8', '\xa1', '\xe0', '\xb8', '\xb2', '\xe0', '\xb8', '\x81']
如何让它显示正确的标记化结果,或者有更好的方法来标记泰语文本?
【问题讨论】:
-
在我的机器上,它会在打印结果时给出
['ตัด', 'คำ', 'ได้', 'ดี', 'มาก']。您的 for 循环给出错误AttributeError: 'str' object has no attribute 'decode'所以提供重现错误的步骤 -
你能提供
print(result)吗? -
@EmilyE。这是有错误的确切示例,除了它在 Databricks 笔记本上运行。
标签: python-3.x tokenize python-unicode thai