七类分类器在StanfordNLP python中没有给出期望的结果

2024-09-29 18:53:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用斯坦福的命名实体识别器。我想使用7类分类器,因为我甚至想检测句子中的时间(或日期)和其他东西。输入句子时:

"He was born on October 15, 1931 at Dhanushkothi in the temple town Rameshwaram in Tamil Nadu."

在Stanford NLP站点(http://nlp.stanford.edu:8080/ner/process)的在线演示中,它的分类正确,如下图所示(上面一行的斯坦福网站上的演示):

The demo in the stanford site for the above line

但是,当我尝试使用NLTL和stanfordtager在我的系统上运行代码时,我得到了错误的结果。我得到的输出是:

^{pr2}$

它把这里的日期错误地标识为“其他”,甚至泰米尔纳德邦也被误认为是一个组织而不是一个地点。我使用的代码如下:

from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.tag import StanfordNERTagger

st = StanfordNERTagger('english.muc.7class.distsim.crf.ser.gz','stanford-ner.jar')

i= "He was born on October 15, 1931 at Dhanushkothi in the temple town Rameshwaram in Tamil Nadu."

words = nltk.word_tokenize(i)
namedEnt = st.tag(words)

print namedEnt 

有谁能告诉我的错误(如果有的话)或任何其他的方式,以确定地点和时间在一句话?我是NLP的初学者,任何关于这方面的帮助将不胜感激。在


Tags: theinon错误时间at句子he
1条回答
网友
1楼 · 发布于 2024-09-29 18:53:32

我尝试运行您的代码,发现word_tokenize有一些问题。在

请尝试以下代码:

from nltk import sent_tokenize, word_tokenize
from nltk.tag import StanfordNERTagger

st = StanfordNERTagger('english.muc.7class.distsim.crf.ser.gz','stanford-ner.jar')

i= "He was born on October 15, 1931 at Dhanushkothi in the temple town Rameshwaram in Tamil Nadu."

words = word_tokenize(i)
namedEnt = st.tag(words)

print namedEnt

以下是我的输出:

^{pr2}$

相关问题 更多 >

    热门问题