Skip to main content

A Link Between topicmodels LDA and LDAvis

Carson Sievert and Kenny Shirley have put together the really nice LDAvis R package. It provides a Shiny-based interactive interface for exploring the output from Latent Dirichlet Allocation topic models. If you've never used it, I highly recommend checking out their XKCD example (this paper also has some nice background).

LDAvis doesn't fit topic models, it just visualises the output. As such it is agnostic about what package you use to fit your LDA topic model. They have a useful example of how to use output from the lda package.

I wanted to use LDAvis with output from the topicmodels package. It works really nicely with texts preprocessed using the tm package. The trick is extracting the information LDAvis requires from the model and placing it into a specifically structured JSON formatted object.

To make the conversion from topicmodels output to LDAvis JSON input easier, I created a linking function called topicmodels_json_ldavis. The full function is below. To use it follow these steps:

  1. Create a VCorpus object using the tm package's Corpus function.

  2. Convert this to a document term matrix using DocumentTermMatrix, also from tm.

  3. Run your model using topicmodel's LDA function.

  4. Convert the output into JSON format using topicmodels_json_ldavis. The function requires the output from steps 1-3.

  5. Visualise with LDAvis' serVis.

Comments

titaniumtroop said…
At line 32, the method 'inspect' should instead by 'as.matrix', because inspect just provides a sample.
rmouniak said…
It was really a nice post and I was really impressed by reading this AWS Online Training
Taylor said…
This post was very helpful, but is there an easy way to assign the reordered topics that the LDAVis produces to the original LDA (i.e. 'fitted')?
Thankful to you for this amazing information sharing with us. Get website designing and development services by Ogen Infosystem.
SEO Service in Delhi
basha said…
Excellent blog I visit this blog it's really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative.
Magnificent blog I visit this blog it's extremely wonderful. Interestingly, in this blog content composed plainly and reasonable. The substance of data is useful.
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training
Oracle Fusion Financials Online Training
Big Data and Hadoop Training In Hyderabad
oracle fusion financials classroom training
Oracle Fusion HCM Classroom Training
oracle cpq online training / Oracle CPQ Class Room Training
Oracle Taleo Online Training
jeewangarg said…
Wow!!! It was really an Informational Article which provide me with much Insightful Information. I would like to first thank the author for such an Insightful Content. If someone here is looking for a Website Designing Company in India, then look no further than Jeewangarg.com as we are the Best website designing in Delhi working in the arena for the last 8 years.
Best website designing company in Delhi NCR
website designing company in India
Chanson Water said…

Great website, continue the good work! Also visit my site – alkaline water machine
Imperial Garden said…
Imperial Garden is the best wedding garden in Faridabad. The garden is capable of easily accommodating 2000 to 3000 people with easy connectivity and a free parking zone. Call now : 9990977115
I would first like to thank the author for coming up with the insightful information every time. People if you are also looking for the best shimla tour packages | Best Rajasthan Tour Packages then reach out to Indian Travel Store as we are the best Travel Partners of yours.
phautecouture said…

Thank You Author!!! You are sharing the very informative and great post. If anyone is looking to lehenga indian wedding dresses | manish malhotra designer sarees then visit Panache Haute Couture, a leading Indian Designer House for Indian Dresses.
Big Data 360 said…
Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.

Data Science Course in Trichy
lionelmessi said…
Fantastic Site with relevant information and content Shared was knowledgeable thank you.

AWS Training in Hyderabad
Ramesh Sampangi said…
Really awesome article. Nice information. Informative and knowledgeable. Thanks for sharing this article with us. Keep sharing more.
Data Science Training in Hyderabad
Anonymous said…
Are you searching for a software development company in Delhi? Get the detailed information of the software that you are looking for! Techdost.com helps you to deliver the best deals on software development with AMC services. Know more here.
software development company in delhi
Gsm Gateway said…
Best IP PBX System Vendor in India with Cost - effective Price so If you have a small business, you need a reliable IP PBX phone system to keep things running smoothly. check Our Website : https://www.gsmgateway.in/ip-pbx-system
Diego Feres said…
Hello
My name is Cory
Please let me know if you accept Guest or Sponsored Posts on your website
I would like to post an article with dofollow link
Send me please all the guidelines

Best Regards
Cory Klingshirn
rachelehamler9@gmail.com
John Albert said…
We realize all connecting with the convincing strategy you make supportive ideas through your blog and consequently draw in commitment from guests on this region while my princess is finding a ton of things. Edgerunner David jacket
Johan battler said…
Here is the detail of India’s Set to Play the World Cup 2023 Semi-Final at Wankhede Stadium. This is because the team India is now at the top and has qualified for the semi-final matches of the Cricket World Cup 2023.

Popular posts from this blog

Dropbox & R Data

I'm always looking for ways to download data from the internet into R. Though I prefer to host and access plain-text data sets (CSV is my personal favourite) from GitHub (see my short paper on the topic) sometimes it's convenient to get data stored on Dropbox . There has been a change in the way Dropbox URLs work and I just added some functionality to the repmis R package. So I though that I'ld write a quick post on how to directly download data from Dropbox into R. The download method is different depending on whether or not your plain-text data is in a Dropbox Public folder or not. Dropbox Public Folder Dropbox is trying to do away with its public folders. New users need to actively create a Public folder. Regardless, sometimes you may want to download data from one. It used to be that files in Public folders were accessible through non-secure (http) URLs. It's easy to download these into R, just use the read.table command, where the URL is the file name

Slide: one function for lag/lead variables in data frames, including time-series cross-sectional data

I often want to quickly create a lag or lead variable in an R data frame. Sometimes I also want to create the lag or lead variable for different groups in a data frame, for example, if I want to lag GDP for each country in a data frame. I've found the various R methods for doing this hard to remember and usually need to look at old blog posts . Any time we find ourselves using the same series of codes over and over, it's probably time to put them into a function. So, I added a new command– slide –to the DataCombine R package (v0.1.5). Building on the shift function TszKin Julian posted on his blog , slide allows you to slide a variable up by any time unit to create a lead or down to create a lag. It returns the lag/lead variable to a new column in your data frame. It works with both data that has one observed unit and with time-series cross-sectional data. Note: your data needs to be in ascending time order with equally spaced time increments. For example 1995, 1996