gpt4 book ai didi

python - 如何使用 spacy lemmatizer 将单词转换为基本形式

转载 作者:IT老高 更新时间:2023-10-28 21:14:57 25 4
gpt4 key购买 nike

我是 spacy 的新手,我想使用它的 lemmatizer 功能,但我不知道如何使用它,就像我进入单词字符串一样,它将以单词的基本形式返回字符串。

例子:

  • '单词'=>'单词'
  • '做过' =>'做'

谢谢。

最佳答案

上一个答案很复杂,无法编辑,所以这里是一个更传统的答案。

# make sure your downloaded the english model with "python -m spacy download en"

import spacy
nlp = spacy.load('en')

doc = nlp(u"Apples and oranges are similar. Boots and hippos aren't.")

for token in doc:
print(token, token.lemma, token.lemma_)

输出:

Apples 6617 apples
and 512 and
oranges 7024 orange
are 536 be
similar 1447 similar
. 453 .
Boots 4622 boot
and 512 and
hippos 98365 hippo
are 536 be
n't 538 not
. 453 .

来自 official Lighting tour

关于python - 如何使用 spacy lemmatizer 将单词转换为基本形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38763007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com