Search code examples
pythonnlpnltklemmatization

Why are there different Lemmatizers in NLTK library?


>> from nltk.stem import WordNetLemmatizer as lm1
>> from nltk import WordNetLemmatizer as lm2
>> from nltk.stem.wordnet import WordNetLemmatizer as lm3

For me all of the three works the same way, but just to confirm, do they provide anything different?


Solution

  • No they're not different they're all the same.

    from nltk.stem import WordNetLemmatizer as lm1
    from nltk import WordNetLemmatizer as lm2
    from nltk.stem.wordnet import WordNetLemmatizer as lm3
    
    lm1 == lm2 
    >>> True
    
    
    lm2 == lm3 
    >>> True
    
    
    lm1 == lm3 
    >>> True
    

    As corrected by erip why this is happening is because :

    That Class(WordNetLemmatizer) is origanlly written in nltk.stem.wordnet so you can do from nltk.stem.wordnet import WordNetLemmatizer as lm3

    Which is also import in nltk __init__.py file so you can do from nltk import WordNetLemmatizer as lm2

    And is also imported in __init__.py nltk.stem module so you can do from nltk.stem import WordNetLemmatizer as lm1