pyLDAvis Documentation
Release 2.1.2Ben Mabey

Feb 06, 2018

Contents1pyLDAvis
1.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Video demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4 More documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

33
4
4
4

2

Contributing
2.1 Types of Contributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Get Started! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Pull Request Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

556
73Credits
3.1 Development Lead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9994History

11

52.1.2 (2018-02-06)

13

62.1.1 (2017-02-13)

15

72.1.0 (2016-06-30)

1782.0.0 (2016-06-30)

19

91.5.1 (2016-04-15)

21

10 1.5.0 (2016-02-20)

23

11 1.4.1 (2016-01-31)

25

12 1.4.0 (2016-01-31)

27

13 1.3.4 (2015-11-16)

29

14 1.3.3 (2015-11-13)

31

15 1.3.2 (2015-11-09)33

i

16 1.3.1 (2015-11-02)

35

17 1.3.0 (2015-08-20)

37

18 1.2.0 (2015-06-13)

39

19 1.1.0 (2015-06-02)

41

20 1.0.0 (2015-05-29)

43

21 Indices and tables

45ii

pyLDAvis Documentation, Release 2.1.2

Contents:Contents1pyLDAvis Documentation, Release 2.1.2

2

Contents

CHAPTER

1pyLDAvis

Python library for interactive topic model visualization. This is a port of the fabulous R package by Carson Sievert
and Kenny Shirley.

pyLDAvis is designed to help users interpret the topics in a topic model that has been fit to a corpus of text data. Thepackage extracts information from a fitted LDA topic model to inform an interactive web-based visualization.
The visualization is intended to be used within an IPython notebook but can also be saved to a stand-alone HTML filefor easy sharing.

1.1 Installation• Stable version using pip:
pip install pyldavis• Development version on GitHub
Clone the repository and run python setup.py3

pyLDAvis Documentation, Release 2.1.2

1.2 Usage
The best way to learn how to use pyLDAvis is to see it in action. Check out this notebook for an overview. Refer tothe documentation for details.
For a concise explanation of the visualization see this vignette from the LDAvis R package.

1.3 Video demos
Ben Mabey walked through the visualization in this short talk using a Hacker News corpus:• Visualizing Topic Models• Notebook and visualization used in the demo
• Slide deck
Carson Sievert <https://cpsievert.me/> created a video demoing the R package. The visualization is the same and so
it applies equally to pyLDAvis:• Visualizing & Exploring the Twenty Newsgroup Data

1.4 More documentation
To read about the methodology behind pyLDAvis, see the original paper, which was presented at the 2014 ACL
Workshop on Interactive Language Learning, Visualization, and Interfaces in Baltimore on June 27, 2014.

4

Chapter 1. pyLDAvis

CHAPTER

2ContributingContributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:

2.1 Types of Contributions
2.1.1 Report Bugs
Report bugs at https://github.com/bmabey/pyLDAvis/issues.
If you are reporting a bug, please include:• Your operating system name and version.
• Any details about your local setup that might be helpful in troubleshooting.
• Detailed steps to reproduce the bug.

2.1.2 Fix Bugs
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.

2.1.3 Implement Features
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implementit.

5pyLDAvis Documentation, Release 2.1.2

2.1.4 Write Documentation
pyLDAvis could always use more documentation, whether as part of the official pyLDAvis docs, in docstrings, or evenon the web in blog posts, articles, and such.

2.1.5 Submit Feedback
The best way to send feedback is to file an issue at https://github.com/bmabey/pyLDAvis/issues.
If you are proposing a feature:• Explain in detail how it would work.
• Keep the scope as narrow as possible, to make it easier to implement.
• Remember that this is a volunteer-driven project, and that contributions are welcome :)2.2 Get Started!
Ready to contribute? Here’s how to set up pyLDAvis for local development.
1. Fork the pyLDAvis repo on GitHub.
2. Clone your fork locally:$ git clone git@github.com:your_name_here/pyLDAvis.git

3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up
your fork for local development:$ mkvirtualenv pyLDAvis$ cd pyLDAvis/$ python setup.py develop

4. Create a branch for local development:$ git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.
5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing otherPython versions with tox:$ flake8 pyLDAvis tests$ python setup.py test
$ tox

To get flake8 and tox, just pip install them into your virtualenv.
6. Commit your changes and push your branch to GitHub:$ git add .
$ git commit -m "Your detailed description of your changes."$ git push origin name-of-your-bugfix-or-feature

7. Submit a pull request through the GitHub website.

6

Chapter 2. Contributing

pyLDAvis Documentation, Release 2.1.2

2.3 Pull Request Guidelines
Before you submit a pull request, check that it meets these guidelines:
1. The pull request should include tests.
2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function
with a docstring, and add the feature to the list in README.rst.
3. The pull request should work for Python 2.6, 2.7, 3.3, and 3.4, and for PyPy. Check https://travis-ci.org/bmabey/pyLDAvis/pull_requests and make sure that the tests pass for all supported Python versions.

2.3. Pull Request Guidelines

7

pyLDAvis Documentation, Release 2.1.2

8Chapter 2. Contributing

CHAPTER3Credits3.1 Development Lead
• Ben Mabey <ben@benmabey.com>

3.2 Contributors• Paul English <paul@onfrst.com> - JS and CSS fixes and improvements.

9pyLDAvis Documentation, Release 2.1.2

10Chapter 3. Credits

CHAPTER

4History

11

pyLDAvis Documentation, Release 2.1.2

12Chapter 4. History

CHAPTER

5

2.1.2 (2018-02-06)• Fix pandas deprecation warnings.

13

pyLDAvis Documentation, Release 2.1.2

14

Chapter 5. 2.1.2 (2018-02-06)

CHAPTER

62.1.1 (2017-02-13)• Fix gensim module to work with a sparse corpus #82.

15

pyLDAvis Documentation, Release 2.1.2

16

Chapter 6. 2.1.1 (2017-02-13)

CHAPTER

72.1.0 (2016-06-30)• Added missing dependency on scipy.
• Fixed term sorting that was incompatible with pandas 0.19.x.

17pyLDAvis Documentation, Release 2.1.2

18

Chapter 7. 2.1.0 (2016-06-30)

CHAPTER

82.0.0 (2016-06-30)• Removed dependency on scikit-bio by adding an internal PCoA implementation.
• Added helper functions for scikit-learn LDA model! See the new notebook for details.
• Extended gensim helper functions to work with HDP models.
• Added scikit-learn’s Multi-dimensional scaling as another MDS option when scikit-learn is installed.

19

pyLDAvis Documentation, Release 2.1.2

20

Chapter 8. 2.0.0 (2016-06-30)

CHAPTER

91.5.1 (2016-04-15)• Add sort_topics option to prepare function to allow disabling of topic re-ordering.

21

pyLDAvis Documentation, Release 2.1.2

22

Chapter 9. 1.5.1 (2016-04-15)

CHAPTER

101.5.0 (2016-02-20)• Red Bar Width bug fix
In some cases, the widths of the red topic-term bars did not decrease (as they should have) from term #1
to term #R under the relevance ranking with $lambda = 1$. In other words, when $lambda = 1$, there
were topics in which a narrow red bar was displayed above a wider red bar, which should never happen.
The issue had to do with the way topic-term bar widths are computed, and is discussed in detail in #32.
In the end, we implemented a quick fix in which we compute term frequencies implicitly, rather than using those
supplied in the createJSON() function. The upside is that the red bar widths are now explicitly controlled to produce
the correct visualization. The downside is that the blue bar widths do not necessarily match the user-supplied term
frequencies exactly – in fact, the new version of LDAvis ignores the user-supplied term frequencies entirely. In a few
experiments, the differences are small, and decrease (as a proportion of the true term frequencies) as the true term
frequencies increase.

23

pyLDAvis Documentation, Release 2.1.2

24

Chapter 10. 1.5.0 (2016-02-20)

CHAPTER

111.4.1 (2016-01-31)• Included requirements.txt in MANIFEST to (hopefully) fix bad release.

25

pyLDAvis Documentation, Release 2.1.2

26

Chapter 11. 1.4.1 (2016-01-31)

CHAPTER

121.4.0 (2016-01-31)• Updated to newest version of skibio for PCoA mds.
• requirements.txt cleanup• New ‘tsne’ option for prepare, see docs and notebook for more info.
1.3.5 (2015-12-18)• Add explicit version info for scikit-bio since the API has changed.

27

pyLDAvis Documentation, Release 2.1.2

28

Chapter 12. 1.4.0 (2016-01-31)

CHAPTER

13

1.3.4 (2015-11-16)• Gensim Python typo fix in imports. :/29pyLDAvis Documentation, Release 2.1.2

30

Chapter 13. 1.3.4 (2015-11-16)

CHAPTER

14

1.3.3 (2015-11-13)• Gensim Python 2.x fix for absolute imports.

31

pyLDAvis Documentation, Release 2.1.2

32

Chapter 14. 1.3.3 (2015-11-13)

CHAPTER

15

1.3.2 (2015-11-09)• Gensim prepare 25% speed increase, thanks @mattilyra!
• Pandas deprecation warnings are now gone.
• Pandas v0.17 is now being used.

33

pyLDAvis Documentation, Release 2.1.2

34

Chapter 15. 1.3.2 (2015-11-09)

CHAPTER

16

1.3.1 (2015-11-02)• Updates gensim and other logic to be python 3 compatible.

35

pyLDAvis Documentation, Release 2.1.2

36

Chapter 16. 1.3.1 (2015-11-02)

CHAPTER

17

1.3.0 (2015-08-20)• Fixes gensim logic and makes it more robust.
• Faster graphlab processing.
• kargs for gensim and graphlab are passed down to underlying prepare function.
• Requires recent version of pandas to avoid problems with our use of the newer DataFrame.to_dict API.

37

pyLDAvis Documentation, Release 2.1.2

38

Chapter 17. 1.3.0 (2015-08-20)

CHAPTER

181.2.0 (2015-06-13)• Updates gensim logic to be clearer and work with Python 3.x.

39pyLDAvis Documentation, Release 2.1.2

40

Chapter 18. 1.2.0 (2015-06-13)

CHAPTER

19

1.1.0 (2015-06-02)• Fixes bug with GraphLab function that was producing bogus visualizations.

41

pyLDAvis Documentation, Release 2.1.2

42

Chapter 19. 1.1.0 (2015-06-02)

CHAPTER

20

1.0.0 (2015-05-29)• First release on PyPI. Faithful port of R version with IPython support and helper functions for GraphLab &gensim.

43

pyLDAvis Documentation, Release 2.1.2

44

Chapter 20. 1.0.0 (2015-05-29)

CHAPTER

21

Indices and tables• genindex• modindex• search

45