首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Spacy解决“str”对象没有属性“lemma_”的问题?

如何使用Spacy解决“str”对象没有属性“lemma_”的问题?
EN

Stack Overflow用户
提问于 2022-04-22 00:20:40
回答 1查看 776关注 0票数 0

我试图在python中使用DataFrame对我的Spacy进行柠檬化。我使用的代码如下所示:

代码语言:javascript
复制
# 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_’

我怎么解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-23 03:40:48

代码语言:javascript
复制
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']
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71962152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档