使用 NLTK 的命名实体识别:提取审计员姓名、地址和组织

Named Entity Recognition using NLTK: Extract Auditor name, address and organisation

我正在尝试使用 nltk 从句子中识别人物、组织和地点。

我的用例基本上是从年度财务报告中提取审计员姓名、组织和地点

在 python 中使用 nltk 结果似乎并不令人满意

import nltk
from nltk.tokenize import word_tokenize
from nltk.tag import pos_tag

ex='Alastair John Richard Nuttall (Senior statutory auditor) for and on behalf of Ernst & Young LLP (Statutory auditor) Leeds'

ne_tree = ne_chunk(pos_tag(word_tokenize(ex)))

print(ne_tree)

Tree('S', [Tree('PERSON', [('Alastair', 'NNP')]), Tree('PERSON', [('John', 'NNP'), ('Richard', 'NNP'), ('Nuttall', 'NNP')]), ('(', '('), Tree('ORGANIZATION', [('Senior', 'NNP')]), ('statutory', 'NNP'), ('auditor', 'NN'), (')', ')'), ('for', 'IN'), ('and', 'CC'), ('on', 'IN'), ('behalf', 'NN'), ('of', 'IN'), Tree('GPE', [('Ernst', 'NNP')]), ('&', 'CC'), Tree('PERSON', [('Young', 'NNP'), ('LLP', 'NNP')]), ('(', '('), ('Statutory', 'NNP'), ('auditor', 'NN'), (')', ')'), ('Leeds', 'NNS')])

如上所示,'Leeds' 未被识别为地点,Ernst & Young LLP 也未被识别为组织

在 Python 中是否有更好的方法来实现这一目标?

尝试用 spacy 代替 NLTK:

https://spacy.io/usage/linguistic-features#named-entities

我认为 spacy 的预训练模型可能会表现更好。你的句子的结果(spacy 2.1,en_core_web_lg)是:

Alastair John Richard Nuttall PERSON
Ernst & Young LLP ORG
Leeds GPE