移除停用詞
你正在進行一個專案,目標是將使用者回饋分類為不同類別,例如「產品問題」、「服務問題」與「建議」。通常,停用詞在區分類別時不太有意義。你的任務是移除這些停用詞,專注在能幫助後續機器將回饋正確歸類的重要字詞。
nltk.tokenize 中的 word_tokenize 與 nltk.corpus 中的 stopwords.words 已為你匯入。此外,NLTK 的 punkt_tab 與 stopwords 資源也已經下載完成。
本練習屬於課程
Python 的 Natural Language Processing(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)