set(stopwords.words(‘english‘))
轉載於:https://blog.csdn.net/miaoxiaowuseng/article/details/107343427
停用詞是什麼
將資料轉換為計算機可以理解的內容的過程稱為預處理。預處理的主要形式之一是過濾掉無用的資料。在自然語言處理中,無用的單詞(資料)稱為停用詞。
停用詞是指搜尋引擎已程式設計忽略的常用詞(例如“the”,“a”,“an”,“in”)。
我們不希望這些單詞佔用我們資料庫中的空間,或佔用寶貴的處理時間。為此,我們可以通過儲存要停止使用的單詞的列表輕鬆刪除它們。python中的NLTK(自然語言工具包)具有以16種不同語言儲存的停用詞列表。可以在nltk_data目錄中找到它們。home / pratima / nltk_data / corpora / stopwords是目錄地址(不要忘記更改你的主目錄名稱)
從一段文字中刪除停用詞
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]
print(word_tokens)
print(filtered_sentence)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
輸出為
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing',
'off', 'the', 'stop', 'words', 'filtration', '.']
['This', 'sample', 'sentence', ',', 'showing', 'stop',
'words', 'filtration', '.']
- 1
- 2
- 3
- 4
相關文章
- English 4
- Business talking in English
- The Future of the English [Supplementary Exercises]
- Leetcode 273 Integer to English WordsLeetCode
- English Metric Units 介紹
- NEW CONCEPT ENGLISH 51 - 60
- 【Using English】28 - Security with HTTPS and SSLHTTP
- The English names of various berries All In One
- Learn English 10 times faster with these tipsAST
- Business English 商務一點通
- Linguistics-English-Psychology-Minds: WholePurposeOfLife + Success +NGUI
- Bilinguals-English-對於“multiple objects”的“優(advantages)缺(disadvantages)點”的對比的English template(英文模板)Object
- set /?
- Set
- 練習英文寫作 Learn to write the english word
- Linguistics-English-Happy Labor Day September 2, 2024NGUIAPP
- lombok get/set 與 JavaBean get/setLombokJavaBean
- [Javascript] Perform Set Operations using JavaScript Set MethodsJavaScriptORM
- ARABIC-ENGLISH DICTIONARY: THE HANS WEHR DICTIONARY OF MODERN WRITTEN ARABIC
- Linguistics-English-Time is money + A coin has two sides.NGUIIDE
- Linguistics-English-Would, Should, and Could: How to Use Them CorrectlyNGUI
- Jet Set
- set -o
- set -e
- Vue.set與vue.$set的使用Vue
- 訓練集(train set),驗證集(validation set)和測試集(test set)AI
- alter system set event和set events的區別
- Set 和Map
- dict和set
- Set delete() 方法delete
- URLSearchParams set() 方法
- JavaScript Set物件JavaScript物件
- 2020.11.21 Set介面
- set excel formatExcelORM
- Redis之setRedis
- Set介面_network
- Python set(集合)Python
- 使用linq查詢報錯English Message : Join a needs to be the same as OrderBy it