Confused about priority between stem and pos tagger

So, I analyzed the text body, and I used a stammer for all expressed words. But I also have to find all the nouns in the corpus, so I again did nltk.pos_tag(stemmed_sentence) But my question is: am I doing this right?

 A.] tokenize->stem->pos_tagging 

OR

 B.] tokenize->stem #stemming and pos_tagging done seperately tokeinze->pos_tagging 

Ive followed method A, but Im confused as to its correct path to achieving pos_tagging.

+5
source share
2 answers

Why don't you give it a try?

Here is an example:

 >>> from nltk.stem import PorterStemmer >>> from nltk import word_tokenize, pos_tag >>> sent = "This is a messed up sentence from the president Orama and it going to be sooo good, you're gonna laugh." 

This is the result of tokenization.

 >>> [word for word in word_tokenize(sent)] ['This', 'is', 'a', 'messed', 'up', 'sentence', 'from', 'the', 'president', "'s", 'Orama', 'and', 'it', "'s", 'going', 'to', 'be', 'sooo', 'good', ',', 'you', "'re", 'gon', 'na', 'laugh', '.'] 

This is the result of tokenize -> stem

 >>> porter = PorterStemmer() >>> [porter.stem(word) for word in word_tokenize(sent)] [u'Thi', u'is', u'a', u'mess', u'up', u'sentenc', u'from', u'the', u'presid', u"'s", u'Orama', u'and', u'it', u"'s", u'go', u'to', u'be', u'sooo', u'good', u',', u'you', u"'re", u'gon', u'na', u'laugh', u'.'] 

This is the result of tokenize -> stem -> POS tag

 >>> pos_tag([porter.stem(word) for word in word_tokenize(sent)]) [(u'Thi', 'NNP'), (u'is', 'VBZ'), (u'a', 'DT'), (u'mess', 'NN'), (u'up', 'RP'), (u'sentenc', 'NN'), (u'from', 'IN'), (u'the', 'DT'), (u'presid', 'JJ'), (u"'s", 'POS'), (u'Orama', 'NNP'), (u'and', 'CC'), (u'it', 'PRP'), (u"'s", 'VBZ'), (u'go', 'RB'), (u'to', 'TO'), (u'be', 'VB'), (u'sooo', 'RB'), (u'good', 'JJ'), (u',', ','), (u'you', 'PRP'), (u"'re", 'VBP'), (u'gon', 'JJ'), (u'na', 'NN'), (u'laugh', 'IN'), (u'.', '.')] 

This is the result of tokenize -> POS tag

 >>> pos_tag([word for word in word_tokenize(sent)]) [('This', 'DT'), ('is', 'VBZ'), ('a', 'DT'), ('messed', 'VBN'), ('up', 'RP'), ('sentence', 'NN'), ('from', 'IN'), ('the', 'DT'), ('president', 'NN'), ("'s", 'POS'), ('Orama', 'NNP'), ('and', 'CC'), ('it', 'PRP'), ("'s", 'VBZ'), ('going', 'VBG'), ('to', 'TO'), ('be', 'VB'), ('sooo', 'RB'), ('good', 'JJ'), (',', ','), ('you', 'PRP'), ("'re", 'VBP'), ('gon', 'JJ'), ('na', 'NN'), ('laugh', 'IN'), ('.', '.')] 

So what is the right way?

+7
source

I think you do not want to stop in front of POS tags

See this example here :

How to use POS tagging in NLTK

After importing NLTK in the python interpreter, you should use word_tokenize before marking pos, which is called the pos_tag method:

 >>> import nltk >>> text = nltk.word_tokenize("Dive into NLTK: Part-of-speech tagging and POS Tagger") >>> text ['Dive', 'into', 'NLTK', ':', 'Part-of-speech', 'tagging', 'and', 'POS', 'Tagger'] >>> nltk.pos_tag(text) [('Dive', 'JJ'), ('into', 'IN'), ('NLTK', 'NNP'), (':', ':'), ('Part-of-speech', 'JJ'), ('tagging', 'NN'), ('and', 'CC'), ('POS', 'NNP'), ('Tagger', 'NNP')] 
+2
source

Source: https://habr.com/ru/post/1208025/


All Articles