Skip to main content
 首页 » 编程设计

python之NLTK 中的斯坦福 NER 标注器

2025年05月04日10cloudgamer

我正在尝试在 Python 中导入 Stanford 命名实体识别器。这已经内置在 NLTK 包中。但是,我的以下代码不起作用:

 from nltk.tag.stanford import NERTagger 
 Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
 ImportError: cannot import name NERTagger 

可能是什么原因?在我阅读的所有文章中,它都默认工作。谢谢。

请您参考如下方法:

那个类(class)已经renamed to StanfordNERTagger in version 3.0.3 (提交 190673c7 )。

因此,对于 nltk >= 3.0.3,您需要改用此导入:

from nltk.tag import StanfordNERTagger 

(您也可以执行 from nltk.tag.stanford import StanfordNERTagger,但由于它们现在还在 nltk.tag 模块中提供了方便的导入,这可能是他们想要使用的,导入位置应该不太容易发生类似这样的 future 更改。)