【发布时间】:2018-09-14 08:11:46
【问题描述】:
我在使用 spaCy 停用词时遇到了问题。任何帮助,将不胜感激。我正在将 TED 谈话记录加载到 pandas 数据框中
df['parsed_transcript'] = df['transcript'].apply(nlp)
#making a list of stop words to add
my_stop_words = ["thing", "people", "way", "year", " year " "time", "lot", "day"]
#adding the list to the stop words
for stopword in my_stop_words:
lexeme = nlp.vocab[stopword]
lexeme.is_stop = True
#filtering out stop words and all non noun words
def preprocess_texts(texts_as_csv_column):
#Takes a column from a pandas datafram and converts it into a list of nouns.
lemmas = []
for doc in texts_as_csv_column:
# Append the lemmas of all nouns that are not stop words
lemma = ([token.lemma_ for token in doc if token.pos_ == 'NOUN' and not token.is_stop])
lemmas.append(lemma)
return lemmas
现在,如果我计算一下“年”这个词,它会减少大约 4,000 次,但仍会显示超过 8,000 次。
count = 0
for row in df['list_of_words']:
for word in row:
if word == "year":
count +=1
print(count)
有些令牌被完全删除,有些被部分删除,有些根本没有。我尝试添加尾随和前导空格,但这无济于事。关于我可能做错了什么的任何想法?谢谢
【问题讨论】:
标签: spacy stop-words