lemmatize()缺少1个必需的位置参数:'word'

问题描述 投票:0回答:1

当我尝试将其传递给这样的词机时:

def lemmatization(token_txt):
    text = [wn.lemmatize(word) for word in token_txt]
   # text = [[wn.lemmatize(word) for word in l] for l in token_text]
    return text

data['Tweet_lem'] = data['Tweet_sw'].apply(lambda x:lemmatization(x))
data.head()

我收到以下错误

TypeError: lemmatize() missing 1 required positional argument: 'word'

当我让它像这样运行时:

def lemmatization(token_txt):
      # text = [wn.lemmatize(word) for word in token_txt]
        text = [[wn.lemmatize(word) for word in l] for l in token_text]
        return text


data['Tweet_lem'] = data['Tweet_sw'].apply(lambda x:lemmatization(x))
data.head()

我收到此错误

NameError:未定义名称'token_text'

我该怎么办?

我正在尝试将该功能应用于标点符号,并将停用词删除的句子。不会应用词干和标记化的步骤。

DataSet

DataSet new

Full example first part

Full example second part

python nlp nltk stemming lemmatization
1个回答
0
投票

经过几番评论,我终于明白了这个问题。这是导入WordNetLemmatizer的方式,请按照以下方式导入它: import nltk wn = nltk.WordNetLemmatizer() 那么您可以按已使用的方式使用它,即:wn.lemmatize("hello")

© www.soinside.com 2019 - 2024. All rights reserved.