【问题标题】:SpaCy custom stopwords not working properlySpaCy 自定义停用词无法正常工作
【发布时间】:2019-01-11 23:48:48
【问题描述】:

有一个词未被识别为停用词,尽管在列表中。 我正在使用 spacy 2.0.11、python 3.7、conda env、Debian 9.5

import spacy
from spacy.lang.es.stop_words import STOP_WORDS
nlp = spacy.load('es', disable=['tagger', 'parser', 'ner'])
STOP_WORDS.add('y')

做一些测试:

>>> word = 'y'
>>> word in STOP_WORDS
True
>>> nlp(word)[0].is_stop
False
>>> len(STOP_WORDS)
305
>>> [word for word in STOP_WORDS if not nlp(word)[0].is_stop]
['y']

因此,从 STOP_WORDS 中列出的 305 中,没有一个被标记为这样。我不知道我做错了什么......也许这是一个错误?

【问题讨论】:

    标签: python nlp spacy stop-words


    【解决方案1】:

    根据this answer,事实证明我没有正确添加单词

    word = 'y'
    spacy.lang.es.stop_words.STOP_WORDS.add(word)
    nlp.vocab[word].is_stop = True
    

    问题解决了


    老答案,没解决问题

    我找到了原因。

    我在导入 spacy 时收到警告:

    RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility.
    

    显然这表明版本不匹配。 More info

    每当您导入针对旧 numpy 编译的 scipy(或其他包)时,这些警告都是可见的。

    spaCy GitHub 中建议使用 numpy 版本。这最终解决了问题:

    conda install numpy=1.14.5
    

    【讨论】:

      猜你喜欢
      • 2020-07-03
      • 2019-03-13
      • 2018-09-14
      • 2016-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多