我试图在python中使用DataFrame对我的Spacy进行柠檬化。我使用的代码如下所示:
# import spaCy's language model
nlp = spacy.load("en_core_web_sm")
# function to lemmatize text
def lemmatization(texts):
output = []
for i in texts:
lem = [str(token).lemma_ for token in nlp(i) or str(token) in ["-PRON-"]]
output.append(' '.join(lem))
return output
train['clean_tweet'] = lemmatization(train['clean_tweet'])
test['clean_tweet'] = lemmatization(test['clean_tweet'])结果发现我犯了一个错误,说:
'str‘对象没有属性'lemma_’
我怎么解决这个问题?
发布于 2022-04-23 03:40:48
string_ = "I am will be playing football tommorrow" # dummy string
obj = nlp(string_)
lemmatize_token = [x.lemma_ for x in obj]
print(lemmatize_token)
['I', 'be', 'will', 'be', 'play', 'football', 'tommorrow']https://stackoverflow.com/questions/71962152
复制相似问题