NLTK WordNet Lemmatizer: Shouldn't it lemmatize all inflections of a word?

匿名 (未验证) 提交于 2019-12-03 02:05:01

问题:

I'm using the NLTK WordNet Lemmatizer for a Part-of-Speech tagging project by first modifying each word in the training corpus to its stem (in place modification), and then training only on the new corpus. However, I found that the lemmatizer is not functioning as I expected it to.

For example, the word loves is lemmatized to love which is correct, but the word loving remains loving even after lemmatization. Here loving is as in the sentence "I'm loving it".

Isn't love the stem of the inflected word loving? Similarly, many other 'ing' forms remain as they are after lemmatization. Is this the correct behavior?

What are some other lemmatizers that are accurate? (need not be in NLTK) Are there morphology analyzers or lemmatizers that also take into account a word's Part Of Speech tag, in deciding the word stem? For example, the word killing should have kill as the stem if killing is used as a verb, but it should have killing as the stem if it is used as a noun (as in the killing was done by xyz).

回答1:

The WordNet lemmatizer does take the POS tag into account, but it doesn't magically determine it:

>>> nltk.stem.WordNetLemmatizer().lemmatize('loving') 'loving' >>> nltk.stem.WordNetLemmatizer().lemmatize('loving', 'v') u'love' 

Without a POS tag, it assumes everything you feed it is a noun. So here it thinks you're passing it the noun "loving" (as in "sweet loving").



回答2:

The best way to troubleshoot this is to actually look in Wordnet. Take a look here: Loving in wordnet. As you can see, there is actually an adjective "loving" present in Wordnet. As a matter of fact, there is even the adverb "lovingly": lovingly in Wordnet. Because wordnet doesn't actually know what part of speech you actually want, it defaults to noun ('n' in Wordnet). If you are using Penn Treebank tag set, here's some handy function for transforming Penn to WN tags:

from nltk.corpus import wordnet as wn  def is_noun(tag):     return tag in ['NN', 'NNS', 'NNP', 'NNPS']   def is_verb(tag):     return tag in ['VB', 'VBD', 'VBG', 'VBN', 'VBP', 'VBZ']   def is_adverb(tag):     return tag in ['RB', 'RBR', 'RBS']   def is_adjective(tag):     return tag in ['JJ', 'JJR', 'JJS']   def penn_to_wn(tag):     if is_adjective(tag):         return wn.ADJ     elif is_noun(tag):         return wn.NOUN     elif is_adverb(tag):         return wn.ADV     elif is_verb(tag):         return wn.VERB     return None 

Hope this helps.



回答3:

it's clearer and more effective than enumeration:

from nltk.corpus import wordnet  def get_wordnet_pos(self, treebank_tag):     if treebank_tag.startswith('J'):         return wordnet.ADJ     elif treebank_tag.startswith('V'):         return wordnet.VERB     elif treebank_tag.startswith('N'):         return wordnet.NOUN     elif treebank_tag.startswith('R'):         return wordnet.ADV     else:         return ''  def penn_to_wn(tag):     return get_wordnet_pos(tag) 


回答4:

Similar woth @bogs

I use a dict:

from textblob.wordnet import NOUN, VERB, ADJ, ADV  pos_to_wornet_dict = {      'JJ': ADJ,     'JJR': ADJ,     'JJS': ADJ,     'RB': ADV,     'RBR': ADV,     'RBS': ADV,     'NN': NOUN,     'NNP': NOUN,     'NNS': NOUN,     'NNPS': NOUN,     'VB': VERB,     'VBG': VERB,     'VBD': VERB,     'VBN': VERB,     'VBP': VERB,     'VBZ': VERB,  } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!