Cannot import name 'lemmatize' from 'gensim.utils' although I have installed Pattern

Viewed 1972

I try to use lemmatize() function from gensim. They said I have to install pattern also to use this function. I have already install both gensim and pattern but every time I try to import lemmatize from gensim, it keeps showing this error

I use pip install gensim and pip install pattern to install the libraries. My gensim version is 4.0.1 and pattern is 3.6

Traceback (most recent call last):
  File "c:\Users\huynh\Desktop\machine_learning\test.py", line 1, in <module>
    from gensim.utils import lemmatize
ImportError: cannot import name 'lemmatize' from 'gensim.utils' (C:\Users\huynh\AppData\Local\Programs\Python\Python39\lib\site-packages\gensim\utils.py)

I tried to look up documentation about this but all I could find is that I have to install pattern to be able to use it. Does anyone have an idea why I still don't have lemmatize()? Thank you

2 Answers

Gensim only ever previously wrapped the lemmatization routines of another library (Pattern) – which was not a particularly modern or well-maintained option, so it was removed from Gensim-4.0.

Users can choose & apply their own lemmatization operations, if they think that's necessary, as a preprocessing step before applying Gensim's algorithms.

Some Python libraries offering lemmatization include:

For now, the best bet would be to use a gensim 3.x.x version as in the API documentation for version 4.0.0, gensim.utils.lemmatize() is not listed, while it is listed for the 3.8.3 version here.

Edit:

During further reading of the documentation, I found a tutorial which uses the nltk package for lemmatize() function. You might want to look at this. Seems like they have dropped the utils.lemmatize()

Related