微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spacy token.lemma_ 不识别名词和代词

如何解决Spacy token.lemma_ 不识别名词和代词

我一直在学习关于词形还原的教程 -> https://www.machinelearningplus.com/nlp/lemmatization-examples-python/

如 spacy lemmatization 部分所述,我加载了 'en-core-web-sm' 模型,解析并提取了给定句子中每个单词的词条。

我的代码如下

nlp = spacy.load('en_core_web_sm',disable=['parser','ner'])

sentence = "The striped bats are hanging on their feet for best"

doc = nlp(sentence)

lemmatized_spacy_output = " ".join([token.lemma_ for token in doc])
print(lemmatized_spacy_output)

用于输入

"The striped bats are hanging on their feet for best"

它给出的输出

the stripe bat be hang on their foot for good

而预期的输出

the strip bat be hang on -PRON- foot for good'

可以看出,stripes 单词应该被识别为动词,但由于某种原因它被归类为名词(因为输出是条带,而不是条带)。 此外,它不识别人称代词,而是按原样提供标记

我已经尝试了很多 github 和 stackoverflow 问题,但没有一个针对我的查询

解决方法

就像 aab 在他的评论中所说的那样。您使用的是哪个版本?我使用 spacy 的第 3 版并调用

nlp = spacy.load('en_core_web_sm',disable=['parser','ner'])
sentence = "The striped bats are hanging on their feet for best"
doc = nlp(sentence)

for token in doc:
    print(token.text," -- ",token.pos_,token.lemma_)

返回

The  --  DET  --  the
striped  --  VERB  --  stripe
bats  --  NOUN  --  bat
are  --  VERB  --  be
hanging  --  VERB  --  hang
on  --  ADP  --  on
their  --  PRON  --  their
feet  --  NOUN  --  foot
for  --  ADP  --  for
best  --  ADJ  --  good

这意味着 striped 被标识为动词

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。