1

I am trying to visualize topics using PyLDAVis but the following code is giving error. Not sure what the issue is.

import pyLDAvis.gensim_models

pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim_models.prepare(lda_model, corpus, id2word)
pyLDAvis.show(vis)

File ~/PycharmProjects/KeyWordExtractor/venv/lib/python3.9/site-packages/pyLDAvis/_prepare.py:228, in _topic_info(topic_term_dists, topic_proportion, term_frequency, term_topic_freq, vocab, lambda_step, R, n_jobs)
    225 saliency = term_proportion * distinctiveness
    227 # Order the terms for the "default" view by decreasing saliency:
--> 228 default_term_info  = pd.DataFrame({'saliency': saliency, 'Term': vocab, \
    229                                    'Freq': term_frequency, 'Total': term_frequency, \
    230                                    'Category': 'Default'}). \
    231    sort_values(by='saliency', ascending=False). \
    232    head(R).drop('saliency', 1)
    233 # Rounding Freq and Total to integer values to match LDAvis code:
    234 default_term_info['Freq'] = np.floor(default_term_info['Freq'])

TypeError: drop() takes from 1 to 2 positional arguments but 3 were given
Prince Modi
  • 425
  • 1
  • 4
  • 16

3 Answers3

0

I think this can be fixed by changing line 243 of the pyLDAvis._prepare module to read

    default_term_info = default_term_info.sort_values(
        by='saliency', ascending=False).head(R).drop('saliency', axis=1)

Note the axis is no longer a position argument. I'm new to pyLDAvis but this worked for me.

BillyC
  • 1
0

I can reproduce the error with pyLDAvis 3.4.0, pandas 2.0.0, python 3.11.3.

Fix with .drop('saliency', axis=1)

import pyLDAvis.gensim_models

pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim_models.prepare(lda, corpus, dictionary)
pyLDAvis.show(vis, local=False)

Please update your pyLDAvis to vs 3.4.1 https://github.com/bmabey/pyLDAvis/issues/247#issuecomment-1517214945

Susol
  • 1
  • 2
0

I'm getting this error too with pyLDAvis 3.4.0, pandas 2.0.0, python 3.11.3. I only started getting this error when I updated to python 3.11.

Bruce Sherin
  • 179
  • 1
  • 8