无法正确标记印地文句子 [英] Not able to tag hindi sentence properly
本文介绍了无法正确标记印地文句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近启动了一个关于印地语数据处理的项目.我尝试执行某些下面的代码,但没有得到预期的输出.
I have recently started a project on Hindi data processing. I have tried executing certain below code but have not got the expected output.
e = u"पूर्ण प्रतिबंध हटाओ : इराक"
tokens=nltk.word_tokenize(e)
from nltk import pos_tag
print tokens
tag = nltk.pos_tag(tokens)
print tag
我获得的输出如下所示:
The output I have obtained is shown below:
[u'\u092a\u0942\u0930\u094d\u0923', u'\u092a\u094d\u0930\u0924\u093f\u092c\u0902\u0927', u'\u0939\u091f\u093e\u0913', u':', u'\u0907\u0930\u093e\u0915']
[(u'\u092a\u0942\u0930\u094d\u0923', 'NN'), (u'\u092a\u094d\u0930\u0924\u093f\u092c\u0902\u0927', '``'), (u'\u0939\u091f\u093e\u0913', ':'), (u':', ':'), (u'\u0907\u0930\u093e\u0915', ':')]
我的查询将输入的第一个单词标记为名词,其余的标记不正确.相同的查询会为英语数据提供正确的输出.
My query is tagging the first word of my input as noun and rest are tagged incorrectly. The same query gives a correct output for English data.
我做错了什么?我必须使用什么特定功能来标记d北印度语数据.
What is it that I'm doing wrong? Is there any specific function that I have to use for tagging d Hindi data.
谢谢您的帮助.
推荐答案
您可以使用tnt
标记器进行训练,然后使用自己的数据进行测试.
You can use tnt
tagger for training and then testing with you own data.
word_to_be_tagged = u"पूर्ण प्रतिबंध हटाओ : इराक"
word_to_be_tagged_next = u"मैं बहुत हैरान हूँ"
from nltk.corpus import indian
train_data = indian.tagged_sents('hindi.pos')[:300] //used for training
test_data = indian.tagged_sents('hindi.pos')[301:] //used for testing
print train_data
[[(u'\u092a\u0942\u0930\u094d\u0923', u'JJ'), (u'\u092a\u094d\u0930\u0924\u093f\u092c\u0902\u0927', u'NN'), (u'\u0939\u091f\u093e\u0913', u'VFM'), (u':', u'SYM'), (u'\u0907\u0930\u093e\u0915', u'NNP')], [(u'\u0938\u0902\u092f\u0941\u0915\u094d\u0924', u'NNC'), (u'\u0930\u093e\u0937\u094d\u091f\u094d\u0930', u'NN'), (u'\u0964', u'SYM')], ...]
print hindi_sents[0][0][0]
पूर्ण
print hindi_sents[0][0][1]
JJ
from nltk.tag import tnt
tnt_pos_tagger = tnt.TnT()
tnt_pos_tagger.train(train_data)
tnt_pos_tagger.evaluate(test_data)
0.6599664991624791
tnt_pos_tagger.tag(nltk.word_tokenize(word_to_be_tagged))
[(u'\u092a\u0942\u0930\u094d\u0923', u'JJ'),
(u'\u092a\u094d\u0930\u0924\u093f\u092c\u0902\u0927', u'NN'),
(u'\u0939\u091f\u093e\u0913', u'VFM'),
(u':', u'SYM'),
(u'\u0907\u0930\u093e\u0915', u'NNP')]
tnt_pos_tagger.tag(nltk.word_tokenize(word_to_be_tagged_next))
[(u'\u092e\u0948\u0902', u'PRP'),
(u'\u092c\u0939\u0941\u0924', u'INTF'),
(u'\u0939\u0948\u0930\u093e\u0928', 'Unk'),
(u'\u0939\u0942\u0901', 'Unk')]
这篇关于无法正确标记印地文句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文