日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python去停用词用nltk_使用nltk删除英文停用词

發布時間:2024/7/5 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python去停用词用nltk_使用nltk删除英文停用词 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、概念

首先我們來看一下停用詞的概念,然后來介紹使用nltk如何刪除英文的停用詞:

由于一些常用字或者詞使用的頻率相當的高,英語中比如a,the, he等,中文中比如:我、它、個等,每個頁面幾乎都包含了這些詞匯,如果搜索引擎它們當關鍵字進行索引,那么所有的網站都會被索引,而且沒有區分度,所以一般把這些詞直接去掉,不可當做關鍵詞。

二、使用nltk刪除英文停用詞

首先我import stopwords進來,代碼如下:

from nltk.corpus import stopwords

words = stopwords.words('english')

print(words)

首先看看打印停用詞的結果:

['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', 'her', 'hers', 'herself', 'it', 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can', 'will', 'just', 'don', 'should', 'now', 'd', 'll', 'm', 'o', 're', 've', 'y', 'ain', 'aren', 'couldn', 'didn', 'doesn', 'hadn', 'hasn', 'haven', 'isn', 'ma', 'mightn', 'mustn', 'needn', 'shan', 'shouldn', 'wasn', 'weren', 'won', 'wouldn']

當然在很多任務(比如對話任務中)中,停用詞還包括下面這些符合和后綴:

['!', ',' ,'.' ,'?' ,'-s' ,'-ly' ,' ', 's']

使用下面代碼,將他們加上去

for w in ['!',',','.','?','-s','-ly','','s']:

self.stopwords.add(w)

然后刪除的用法就非常容易,假如我們的語料在word_list中,我們只需要寫上下面的代碼即可!

from nltk.corpus import stopwords

for w in ['!',',','.','?','-s','-ly','','s']:

self.stopwords.add(w)

filtered_words = [word for word in word_list if word not in stopwords.words('english')]

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的python去停用词用nltk_使用nltk删除英文停用词的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。