开始使用免费开始使用

移除停用词

您正在进行一个项目,目标是将用户反馈分类为不同类别,如 "product issues"、"service issues" 和 "suggestions"。通常,停用词在区分类别时并不携带太多信息。您的任务是移除这些停用词,把注意力放在有助于后续机器将反馈归入正确主题的重要词上。

nltk.tokenize 中的 word_tokenizenltk.corpus 中的 stopwords.words 已为您导入。此外,NLTK 资源 punkt_tabstopwords 已经下载完成。

本练习是课程的一部分

Python 中的自然语言处理(NLP)

查看课程

练习说明

  • 将提供的反馈按词进行分词。
  • 获取英文停用词列表。
  • 移除英文停用词,并将结果保存到 filtered_tokens

交互式实操练习

通过完成这段示例代码来试试这个练习。

feedback = "I reached out to support and got a helpful response within minutes!!! Very #impressed"

# Tokenize the text
tokens = word_tokenize(____)

# Get the list of English stop words
stop_words = stopwords.____('____')

# Remove stop words 
filtered_tokens = [____ for word in tokens if ____.lower() not in ____]

print(filtered_tokens)
编辑并运行代码