NLTK西班牙语词性标注结果很差?
我正在尝试为西班牙语创建一个标记器性能比较。我的当前脚本是对这个脚本的修改版本,虽然我也尝试了另一个版本,结果非常相似。
我使用的是cess_esp语料库,并且为这个语料库创建了单字(Unigram)、双字(Bigram)、三字(Trigram)和Brill标记器,都是用带标签的句子来训练每个标记器。
我对双字和三字标记器的表现感到担忧……从结果来看,它们似乎根本没有起作用。
例如,以下是我脚本的一些输出:
*************** START TAGGING FOR LINE 6 ****************************************************************************************************************************************
Current line contents before tagging-> mejor ve a la sucursal de Juan Pablo II es la que menos gente tiene y no te tardas nada
Unigram tagger-> [('@yadimota', None), ('@ContactoBanamex', None), ('mejor', 'aq0cs0'), ('ve', 'vmip3s0'), ('a', 'sps00'), ('la', 'da0fs0'), ('sucursal', 'ncfs000'), ('de', 'sps00'), ('Juan', 'np0000p'), ('Pablo', None), ('II', None), ('es', 'vsip3s0'), ('la', 'da0fs0'), ('que', 'pr0cn000'), ('menos', 'rg'), ('gente', 'ncfs000'), ('tiene', 'vmip3s0'), ('y', 'cc'), ('no', 'rn'), ('te', 'pp2cs000'), ('tardas', None), ('nada', 'pi0cs000')]
Bigram tagger-> [('@yadimota', None), ('@ContactoBanamex', None), ('mejor', None), ('ve', None), ('a', None), ('la', None), ('sucursal', None), ('de', None), ('Juan', None), ('Pablo', None), ('II', None), ('es', None), ('la', None), ('que', None), ('menos', None), ('gente', None), ('tiene', None), ('y', None), ('no', None), ('te', None), ('tardas', None), ('nada', None)]
Trigram tagger-> [('@yadimota', None), ('@ContactoBanamex', None), ('mejor', None), ('ve', None), ('a', None), ('la', None), ('sucursal', None), ('de', None), ('Juan', None), ('Pablo', None), ('II', None), ('es', None), ('la', None), ('que', None), ('menos', None), ('gente', None), ('tiene', None), ('y', None), ('no', None), ('te', None), ('tardas', None), ('nada', None)]
****************************************************************************************************************************************
*************** START TAGGING FOR LINE 7 ****************************************************************************************************************************************
Current line contents before tagging-> He levantado ya varios reporte pero no resuelven nada
Unigram tagger-> [('He', 'vaip1s0'), ('levantado', 'vmp00sm'), ('ya', 'rg'), ('varios', 'di0mp0'), ('reporte', 'vmsp1s0'), ('pero', 'cc'), ('no', 'rn'), ('resuelven', None), ('nada', 'pi0cs000')]
Bigram tagger-> [('He', None), ('levantado', None), ('ya', None), ('varios', None), ('reporte', None), ('pero', None), ('no', None), ('resuelven', None), ('nada', None)]
Trigram tagger-> [('He', None), ('levantado', None), ('ya', None), ('varios', None), ('reporte', None), ('pero', None), ('no', None), ('resuelven', None), ('nada', None)]
*************** START TAGGING FOR LINE 8 ****************************************************************************************************************************************
Current line contents before tagging-> Es lamentable el servicio que brindan
Unigram tagger-> [('@ContactoBanamex', None), ('Es', 'vsip3s0'), ('lamentable', 'aq0cs0'), ('el', 'da0ms0'), ('servicio', 'ncms000'), ('que', 'pr0cn000'), ('brindan', None)]
Bigram tagger-> [('@ContactoBanamex', None), ('Es', None), ('lamentable', None), ('el', None), ('servicio', None), ('que', None), ('brindan', None)]
Trigram tagger-> [('@ContactoBanamex', None), ('Es', None), ('lamentable', None), ('el', None), ('servicio', None), ('que', None), ('brindan', None)]
现在双字和三字标记器正在按照指定的链接进行训练,顺便说一下,这也是《NLTK书》中描述的最直接的方法:
from nltk.corpus import cess_esp as cess
from nltk import BigramTagger as bt
from nltk import TrigramTagger as tt
cess_sents = cess.tagged_sents()
# Training BigramTagger.
bi_tag = bt(cess_sents)
#Training TrigramTagger
tri_tag = tt(cess_sents)
你觉得我是不是漏掉了什么?双字和三字标记器不应该比单字标记器表现更好吗?我是否应该总是为双字和三字标记器使用回退标记器?
谢谢!
亚历杭德罗
2 个回答
在我看来,Jacob Perkins 的关于使用 NLTK 进行词性标注的教程博客文章可能是网上比较好的资源之一。他首先教你如何构建一个简单的回退 ngram 标注器,然后再介绍如何添加正则表达式和基于词缀的标注,接着是 Brill 标注,最后是基于分类器的完整标注。这些文章内容清晰易懂,跟起来也很顺,里面还有一些有用的性能比较。
可以从这里开始,继续阅读到第四部分:http://streamhacker.com/2008/11/03/part-of-speech-tagging-with-nltk-part-1/
spaghetti-tagger(https://code.google.com/p/spaghetti-tagger/)是为了简单的教学目的而创建的,目的是教大家如何使用NLTK库中的语料库和标记模块轻松地创建可扩展的标记器。
这个工具并不是最先进的系统,正如网站所说的那样。建议使用一些更先进的标记器,比如http://nlp.lsi.upc.edu/freeling/。如果你需要,我很乐意为Freeling写一个合适的Python封装类。
回到你的问题,正如Francis提到的(https://groups.google.com/forum/#!topic/nltk-users/FtqksaZLLvY),首先去看看这个教程http://nltk.googlecode.com/svn/trunk/doc/howto/tag.html,然后你会发现backoff
这个参数可能会解决你的问题
免责声明:我写了spaghetti.py https://spaghetti-tagger.googlecode.com/svn/spaghetti.py