首页 > 解决方案 > 来自 gensim 的意外 lemmatize 结果

问题描述

我使用以下代码对已经排除停用词并保持单词长度超过 3 的文本进行词形还原。但是,在使用以下代码后,它将现有单词(例如 'wheres' 拆分为 ['where', 's']; '你'到['-PRON-','be']。我没想到's','-PRON-','be'这些结果在我的文本中,是什么导致了这种行为以及我能做什么?

def lemmatization(texts, allowed_postags=['NOUN', 'ADJ', 'VERB', 'ADV']):
"""https://spacy.io/api/annotation"""

texts_out = []
for sent in texts:
    doc = nlp(" ".join(sent)) 
    texts_out.append([token.lemma_ for token in doc]) # though rare, if only keep the tokens with given posttags, add 'if token.pos_ in allowed_postags'
return texts_out

# Initialize spacy 'en' model, keeping only tagger component (for efficiency)
nlp = spacy.load('en', disable=['parser', 'ner'])

data_lemmatized = lemmatization(data_words_trigrams, allowed_postags=['NOUN', 'ADJ', 'VERB', 'ADV'])

标签: nlpnltkgensimlemmatization

解决方案


推荐阅读