{"id":21759,"library":"pyldavis","title":"pyLDAvis","description":"Interactive topic model visualization, port of the R package. Current version 3.4.1. Supports LDA models from gensim, scikit-learn, and other sources. Release cadence: irregular, last update in 2023.","status":"active","version":"3.4.1","language":"python","source_language":"en","source_url":"https://github.com/bmabey/pyLDAvis","tags":["topic-modeling","visualization","lda","nlp","gensim","scikit-learn"],"install":[{"cmd":"pip install pyldavis","lang":"bash","label":"PyPI install"}],"dependencies":[{"reason":"Required for data manipulation, version ≥? (compatible with pandas 2.x)","package":"pandas","optional":false},{"reason":"For input from gensim LDA models","package":"gensim","optional":true},{"reason":"For input from sklearn LDA models; note the module renamed in 3.4.0","package":"scikit-learn","optional":true}],"imports":[{"note":"","wrong":"","symbol":"pyLDAvis","correct":"import pyLDAvis"},{"note":"In 3.3.0, the gensim module was renamed to gensim_models to avoid conflicts. Old import path no longer works.","wrong":"import pyLDAvis.gensim as gensimvis","symbol":"gensimvis","correct":"from pyLDAvis import gensim_models as gensimvis"},{"note":"In 3.4.0, the sklearn module was renamed to sklearn_models. Old path raises import error.","wrong":"import pyLDAvis.sklearn as sklearnvis","symbol":"sklearnvis","correct":"from pyLDAvis import sklearn_models as sklearnvis"},{"note":"Do not use 'from pyLDAvis import sklearn' because 'sklearn' is the package itself.","wrong":"","symbol":"sklearn_models","correct":"from pyLDAvis import sklearn_models"}],"quickstart":{"code":"import pyLDAvis\nimport pyLDAvis.gensim_models as gensimvis\n\n# Prepare data (example: using gensim LDA model)\n# If using real API key, set it via os.environ\nimport os\napi_key = os.environ.get('OPENAI_API_KEY', 'sk-...')  # not used in this example\n\n# Example with dummy data\nfrom gensim.corpora import Dictionary\nfrom gensim.models import LdaModel\n\n# Create a simple corpus\ndocs = [['apple', 'orange', 'banana'], ['car', 'truck', 'bus']]\ndictionary = Dictionary(docs)\ncorpus = [dictionary.doc2bow(doc) for doc in docs]\nlda_model = LdaModel(corpus, num_topics=2, id2word=dictionary, passes=5)\n\n# Prepare visualization\nvis_data = gensimvis.prepare(lda_model, corpus, dictionary)\n# Save to HTML file\npyLDAvis.save_html(vis_data, 'vis.html')\nprint('Visualization saved as vis.html')","lang":"python","description":"Load a gensim LDA model, prepare interactive visualization, and save as HTML."},"warnings":[{"fix":"Change import from 'pyLDAvis.sklearn' to 'pyLDAvis.sklearn_models'.","message":"Module renamed in v3.4.0: 'pyLDAvis.sklearn' no longer exists. Use 'pyLDAvis.sklearn_models'.","severity":"breaking","affected_versions":">=3.4.0"},{"fix":"Change import from 'pyLDAvis.gensim' to 'pyLDAvis.gensim_models'.","message":"Module renamed in v3.3.0: 'pyLDAvis.gensim' no longer exists. Use 'pyLDAvis.gensim_models'.","severity":"breaking","affected_versions":">=3.3.0"},{"fix":"Upgrade pyLDAvis to 3.4.1 or later, or downgrade pandas to 1.x.","message":"Pandas 2.x changed .drop behavior; pyLDAvis 3.4.1 fixed this by adding axis=1 argument. If using older pyLDAvis with pandas 2.x, you'll get a ValueError.","severity":"gotcha","affected_versions":"<=3.4.0, pandas>=2.0"},{"fix":"Upgrade pyLDAvis to 3.4.0+ or use older scikit-learn.","message":"sklearn's get_feature_names is removed in scikit-learn 1.0; pyLDAvis 3.4.0+ handles this. Older versions may raise AttributeError.","severity":"deprecated","affected_versions":"<=3.3.1, sklearn>=1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use 'from pyLDAvis import sklearn_models' instead.","cause":"In pyLDAvis 3.4.0, the sklearn module was renamed to sklearn_models.","error":"ModuleNotFoundError: No module named 'pyLDAvis.sklearn'"},{"fix":"Use 'from pyLDAvis import gensim_models' instead.","cause":"In pyLDAvis 3.3.0, the gensim module was renamed to gensim_models.","error":"ModuleNotFoundError: No module named 'pyLDAvis.gensim'"},{"fix":"When preparing sklearn LDA data, set init='random' or adjust metric parameter in the prepare call.","cause":"When using pyLDAvis with sklearn LDA models, the default init='pca' is incompatible with some distance metrics.","error":"ValueError: The parameter init='pca' cannot be used with metric='precomputed'."},{"fix":"Upgrade pyLDAvis to latest version (>=3.3.0) which uses updated gensim API.","cause":"In older pyLDAvis versions, the API expects a method that doesn't exist in newer gensim.","error":"AttributeError: 'LdaModel' object has no attribute 'get_topics'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}