【问题标题】:Why the num of languages in `nltk.corpus` stop words is different depending on the OS?为什么 `nltk.corpus` 停用词中的语言数量因操作系统而异?
【发布时间】:2018-02-06 10:45:29
【问题描述】:

我在两台不同的机器(Mac 和 Linux)上运行相同的代码,尽管两台机器都运行相同版本的 nltk,但它们提供了不同数量语言的停用词列表(Mac 为 14 个,Linux 为 17 个) .

import nltk
nltk.__version__
from nltk.corpus import stopwords
stopwords.ensure_loaded
stopwords_dict = {lang:stopwords.words(lang) for lang in stopwords.__dict__.get('_fileids')}
stopwords_dict.keys()
len(stopwords_dict.keys())

两台机器上的nltk 版本相同'3.2.5',但语言数量不同:

苹果机

dict_keys(['danish', 'dutch', 'english', 'finnish', 'french', 'german', 'hungarian', 'italian', 'norwegian', 'portuguese', 'russian', 'spanish', 'swedish', 'turkish'])

14

Linux

dict_keys(['kazakh', 'swedish', 'spanish', 'danish', 'english', 'italian', 'portuguese', 'dutch', 'turkish', 'arabic', 'romanian', 'russian', 'french', 'hungarian', 'german', 'finnish', 'norwegian'])
17

我试图在nltk 文档中找到答案,但没有成功。

【问题讨论】:

  • 在 Mac 上更新您的nltk_data
  • 哎哟!漂亮,你完全正确nltk.download("stopwords") 在我的情况下解决了它。我忘了 nltk 数据是分开处理的。 @alvas,您能否将其作为答案进行回复,以免我们将其作为未回答的问题?我知道解决方案是微不足道的,但它可能对其他人有帮助,这样我们就可以保持 SO questions-answers 的主要思想。
  • 尝试回答并为下一个用户提供信息=)

标签: python-3.x nlp nltk


【解决方案1】:

我完全忘记了nltk 和“它为数十个语料库和训练模型提供的内置支持”是两个不同的东西。这就解释了为什么即使 nltk 版本相同,语料库也可能不同。

正如@alvas 在 cmets 中指出的那样,解决方案只是更新nltk_data

 nltk.download("stopwords")

nltk_data 提供的资源的完整列表可以在here 找到。

【讨论】:

    猜你喜欢
    • 2021-10-01
    • 2010-11-08
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多