问题
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.
What is it that I'm doing wrong? Is there any specific function that I have to use for tagging d Hindi data.
Thank you for your help.
回答1:
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')]
来源:https://stackoverflow.com/questions/28859234/not-able-to-tag-hindi-sentence-properly