使用 SpaCy 的英语 Lang 人名检测。寻找答案

问题描述 投票:0回答:2

我正在使用 Spacy 并尝试检测文本中的名称。例如,text = 'Keras 是一个很好的包。亚当斯密使用黑色汽车。我希望卡特里娜飓风在她的工作中表现出色。'

答案应该是这样的:亚当·斯密和卡特里娜飓风。

谁能推荐一下

python nlp nltk spacy named-entity-recognition
2个回答
6
投票

这是一个典型的命名实体识别问题。 Spacy 有一个预训练的模型来实现这一点,它应该能够准确地检测人名。

看看这个代码示例。

根据Spacy的注释方案,名称被标记为

PERSON
.


6
投票

spacy 有一个名为 person 的标签。模型有多种选择:小型、中型或大型。 large 使用更多资源来运行

def find_persons(text):
    # Create Doc object
    doc2 = nlp(text)

    # Identify the persons
    persons = [ent.text for ent in doc2.ents if ent.label_ == 'PERSON']

    # Return persons
    return persons

尝试 nltk 查找名词,然后对有效名称的名词进行模式匹配:

tokenized_sent = nltk.word_tokenize(sentence)
tagged_sent = nltk.pos_tag(tokenized_sent)
nouns
pronouns
adjectives
verbs

NNP - proper noun singular
PRP - proper noun
VB - verb
DT - determinant

NNP - proper noun singular
PRP - proper noun
VB - verb
DT - determinant
© www.soinside.com 2019 - 2024. All rights reserved.