gpt4 book ai didi

python-3.x - 如何手动安装 nltk 停用词包

转载 作者:行者123 更新时间:2023-12-01 01:56:40 30 4
gpt4 key购买 nike

这是我的代码:

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)

但是在运行代码时,我得到了这个错误:

Resource stopwords not found.
Please use the NLTK Downloader to obtain the resource

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

[nltk_data] Error loading popular: <urlopen error [WinError 10054] An
[nltk_data] existing connection was forcibly closed by the remote
[nltk_data] host>

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

最佳答案

这行得通吗?

import nltk
nltk.download('stopwords')

关于python-3.x - 如何手动安装 nltk 停用词包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52076153/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com