首页 > 解决方案 > “解压的值太多(预期为 2)”错误

问题描述

我曾多次尝试为 LDA 运行 pos_tagger 和词形还原过程,但总是得到相同的错误。这是代码:

#Pos_tagger function
from nltk import pos_tag_sents
def pos_tagger(nltk_tag):
    if nltk_tag.startswith('J'):
        return wordnet.ADJ
    elif nltk_tag.startswith('V'):
        return wordnet.VERB
    elif nltk_tag.startswith('N'):
        return wordnet.NOUN
    elif nltk_tag.startswith('R'):
        return wordnet.ADV
    else:
        return None

pos_tagged = pos_tag_sents(tokenized_word)
print(pos_tagged)

#Lemmatization
from nltk import WordNetLemmatizer
from nltk.corpus import wordnet
lem = WordNetLemmatizer()
lemma_sent = []
for word, tag in pos_tagged:
    if tag is None:
        lemma_sent.append(word)
    else:        
        lemma_sent.append(lem.lemmatize(word, tag))
lemma_sent = " ".join(lemma_sent)
print(lemma_sent)

当我尝试在词形还原步骤中运行 for 循环时,错误才浮出水面。

有谁知道如何修理它?

标签: ldatopic-modelingpos-taggerlemmatization

解决方案


推荐阅读