如何解决 'str' object has no attribute 'lemma_' using Spacy?
How to solve 'str' object has no attribute 'lemma_' using Spacy?
我尝试使用 python 中的 Spacy
对我的 DataFrame 进行词形还原。我使用的代码如下所示:
# 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' object has no attribute 'lemma_'
我该如何解决这个问题?
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']
我尝试使用 python 中的 Spacy
对我的 DataFrame 进行词形还原。我使用的代码如下所示:
# 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' object has no attribute 'lemma_'
我该如何解决这个问题?
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']