小编VJA*_*SLN的帖子

如何告诉 Spacy 不要使用 retokenizer 用撇号分割任何单词?

我在这里遇到了一个问题。我将使用 spacy 的单词分词器。但是我有一些限制,例如我的标记器不会拆分包含撇号 (') 的单词。

例子:

输入字符串:“我不能这样做”
当前输出:["I","ca","n't","do","this"]
预期输出:["I","can't","do","this"]

我的尝试:

doc = nlp(sent)
position = [token.i for token in doc if token.i!=0 and "'" in token.text]
with doc.retokenize() as retokenizer:
    for pos in position:
       retokenizer.merge(doc[pos-1:pos+1])
for token in doc:
    print(token.text)
Run Code Online (Sandbox Code Playgroud)

通过这种方式,我得到了预期的输出。但是不知道这个方法对不对?或者有没有更好的方法来进行重新标记化?

tokenize python-3.x spacy

0
推荐指数
1
解决办法
1799
查看次数

标签 统计

python-3.x ×1

spacy ×1

tokenize ×1