所以我有一个数据集,我想删除使用的停止词
stopwords.words('english')
Run Code Online (Sandbox Code Playgroud)
我正在努力如何在我的代码中使用它只是简单地取出这些单词.我已经有了这个数据集中的单词列表,我正在努力的部分是与此列表进行比较并删除停用词.任何帮助表示赞赏.
我试图从一串文本中删除停用词:
from nltk.corpus import stopwords
text = 'hello bye the the hi'
text = ' '.join([word for word in text.split() if word not in (stopwords.words('english'))])
Run Code Online (Sandbox Code Playgroud)
我正在处理6密耳的这种弦,所以速度很重要.分析我的代码,最慢的部分是上面的行,有没有更好的方法来做到这一点?我正在考虑使用像正则表达式这样的东西,re.sub但我不知道如何为一组单词编写模式.有人可以帮助我,我也很高兴听到其他可能更快的方法.
注意:我试过有人建议包装stopwords.words('english'),set()但没有区别.
谢谢.
我正在为一些英语文本生成一些统计数据,我想跳过一些不感兴趣的词,比如"a"和"the".
更新:这些显然被称为"停止词"而不是"跳过词".
我有下面的代码,我试图将停用词列表应用于单词列表.然而,结果仍然显示"a"和"the"这样的词,我认为这个词会被这个过程删除.任何出错的想法都会很棒.
import nltk
from nltk.corpus import stopwords
word_list = open("xxx.y.txt", "r")
filtered_words = [w for w in word_list if not w in stopwords.words('english')]
print filtered_words
Run Code Online (Sandbox Code Playgroud) 术语频率(TF)和反向文档频率(IDF)如何受到停用词删除和词干的影响?
谢谢!
我有一个用例,我想使用 spacy 或 nltk 或任何 NLP 库提取句子的主要有意义的部分。
例句1: “我如何提高反对骚扰的声音” 意图是: “提高反对骚扰的声音”
例句2: “唐老鸭是由哪个漫画家/哪个男人/谁创作的?” 意图是: “唐老鸭是由”创造的
例句3: “如何使用spacy或nltk检索句子的主要意图”? 意图: “使用 spacy nltk 检索句子的主要意图”
我是依赖解析的新手,并不完全知道如何做到这一点。请帮我。
所以,我是使用Python和NLTK的新手.我有一个名为reviews.csv的文件,其中包含从亚马逊中提取的注释.我已将此csv文件的内容标记化并将其写入名为csvfile.csv的文件中.这是代码:
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.stem import PorterStemmer
import csv #CommaSpaceVariable
from nltk.corpus import stopwords
ps = PorterStemmer()
stop_words = set(stopwords.words("english"))
with open ('reviews.csv') as csvfile:
readCSV = csv.reader(csvfile,delimiter='.')
for lines in readCSV:
word1 = word_tokenize(str(lines))
print(word1)
with open('csvfile.csv','a') as file:
for word in word1:
file.write(word)
file.write('\n')
with open ('csvfile.csv') as csvfile:
readCSV1 = csv.reader(csvfile)
for w in readCSV1:
if w not in stopwords:
print(w)
Run Code Online (Sandbox Code Playgroud)
我试图在csvfile.csv上执行词干.但我得到这个错误:
Traceback (most recent call last):<br>
File "/home/aarushi/test.py", line …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的简单句子。我想把介词和词如A和IT从列表中删除。我查看了自然语言工具包 (NLTK) 文档,但找不到任何内容。有人可以告诉我怎么做吗?这是我的代码:
import nltk
from nltk.tokenize import RegexpTokenizer
test = "Hello, this is my sentence. It is a very basic sentence with not much information in it"
test = test.upper()
tokenizer = RegexpTokenizer(r'\w+')
tokens = tokenizer.tokenize(test)
fdist = nltk.FreqDist(tokens)
common = fdist.most_common(100)
Run Code Online (Sandbox Code Playgroud) nltk ×5
python ×5
stop-words ×5
nlp ×2
stemming ×2
csv ×1
data-mining ×1
filtering ×1
indexing ×1
list ×1
pos-tagger ×1
regex ×1
spacy ×1
tf-idf ×1