如何手动安装 nltk 停用词包

Man*_*h V 3 python-3.x

这是我的代码:

from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize

example_sent = "This is a sample sentence, showing off the stop words filtration."

stop_words = set(stopwords.words('english'))

word_tokens = word_tokenize(example_sent)

filtered_sentence = [w for w in word_tokens if not w in stop_words]

filtered_sentence = []

for w in word_tokens:
    if w not in stop_words:
        filtered_sentence.append(w)


print(word_tokens)
print(filtered_sentence)
Run Code Online (Sandbox Code Playgroud)

但是在运行代码时,我收到此错误:

Resource stopwords not found.
Please use the NLTK Downloader to obtain the resource
Run Code Online (Sandbox Code Playgroud)

如果我下载NLTK Downloader,我会收到以下错误:

[nltk_data] Error loading popular: <urlopen error [WinError 10054] An
[nltk_data]     existing connection was forcibly closed by the remote
[nltk_data]     host>
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何摆脱这个错误?

小智 8

这行得通吗?

import nltk
nltk.download('stopwords')
Run Code Online (Sandbox Code Playgroud)