使用 spacy 添加/删除自定义停用词 [英] Add/remove custom stop words with spacy
本文介绍了使用 spacy 添加/删除自定义停用词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 spacy 添加/删除停用词的最佳方法是什么?我正在使用 token.is_stop
函数,并希望进行一些自定义对集合的更改.我正在查看文档,但找不到有关停用词的任何信息.谢谢!
解决方案
您可以在像这样处理文本之前编辑它们(请参阅 这篇文章):
<预><代码>>>>进口空间>>>nlp = spacy.load("en")>>>nlp.vocab["the"].is_stop = False>>>nlp.vocab["绝对notastopword"].is_stop = True>>>sentence = nlp("这个词绝对是notastopword")>>>句子[0].is_stop错误的>>>句子[3].is_stop真的注意:这似乎有效 <=v1.8.对于较新的版本,请参阅其他答案.
What is the best way to add/remove stop words with spacy? I am using token.is_stop
function and would like to make some custom changes to the set. I was looking at the documentation but could not find anything regarding of stop words. Thanks!
解决方案
You can edit them before processing your text like this (see this post):
>>> import spacy
>>> nlp = spacy.load("en")
>>> nlp.vocab["the"].is_stop = False
>>> nlp.vocab["definitelynotastopword"].is_stop = True
>>> sentence = nlp("the word is definitelynotastopword")
>>> sentence[0].is_stop
False
>>> sentence[3].is_stop
True
Note: This seems to work <=v1.8. For newer versions, see other answers.
这篇关于使用 spacy 添加/删除自定义停用词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文