【问题标题】:Seven class classifier not giving desired results in StanfordNLP python七类分类器在 StanfordNLP python 中没有给出预期的结果
【发布时间】:2017-01-06 19:42:13
【问题描述】:

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

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

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

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

[(u'He', u'O'), (u'was', u'O'), (u'born', u'O'), (u'on', u'O'), (u'1931-10-15', u'O'), 
(u'at', u'O'), (u'Dhanushkothi', u'O'), (u'in', u'O'), (u'the', u'O'), 
(u'temple', u'O'), (u'town', u'O'), (u'Rameshwaram', u'O'), (u'in', u'O'), 
(u'Tamil', u'ORGANIZATION'), (u'Nadu', u'ORGANIZATION'), (u'.', u'O')]

它在这里错误地将日期识别为“其他”,甚至将泰米尔纳德邦识别为一个组织而不是一个位置。我使用的代码如下:

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 的初学者,如有任何帮助,我们将不胜感激。

【问题讨论】:

    标签: python algorithm nlp stanford-nlp named-entity-recognition


    【解决方案1】:

    我尝试运行您的代码,发现 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
    

    这是我的输出:

    [(u'He', u'O'), (u'was', u'O'), (u'born', u'O'), (u'on', u'O'), (u'October', u'DATE'), (u'15', u'DATE'), (u',', u'DATE'), (u'1931', u'DATE'), (u'at', u'O'), (u'Dhanushkothi', u'O'), (u'in', u'O'), (u'the', u'O'), (u'temple', u'O'), (u'town', u'O'), (u'Rameshwaram', u'O'), (u'in', u'O'), (u'Tamil', u'ORGANIZATION'), (u'Nadu', u'ORGANIZATION'), (u'.', u'O')]
    

    【讨论】:

      猜你喜欢
      • 2021-04-14
      • 2021-01-06
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 2020-05-29
      • 1970-01-01
      • 2019-06-15
      相关资源
      最近更新 更多