Search code examples
pythongensimldamalletmodulenotfounderror

ModuleNotFoundError: No module named 'gensim.models.wrappers'


I am trying to use LDA MAllet model. but I am facing with "No module named 'gensim.models.wrappers'" error.

  • I have gensim installed and ' gensim.models.LdaMulticore' works properly.

  • Java developer’s kit is installed

  • I have already downloaded mallet-2.0.8.zip and unzipped it on c:\ drive.

  • This is the code I am trying to use:

    import os
    from gensim.models.wrappers import LdaMallet
    os.environ.update({'MALLET_HOME':r'C:/mallet-2.0.8/'}) 
    mallet_path = r'C:/mallet-2.0.8/bin/mallet' 
    
    

Does anyone know what is wrong here? Many thanks!


Solution

  • If you've installed the latest Gensim, 4.0.0 (as of late March, 2021), the LdaMallet model has been removed, along with a number of other tools which simply wrapped external tools/APIs.

    You can see the note in the Gensim migration guide at:

    https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4#15-removed-third-party-wrappers

    If the use of that tool is essential to your project, you may be able to:

    • install an older version of Gensim, such as 3.8.3 - though of course you'd then be missing the latest fixes & optimizations on any other Gensim models you're using

    • extract the ldamallet.py source code from that older version & update/move it to your own code for private use - dealing with whatever issues arise