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
shivani said…
A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
Oracle Fusion Financials Online Training
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training
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.
It was a great write up about Digital Marketing. Thank You for providing with such information. Connect to the best Flipkart Listing Services – ITDigiTech Solutions to avail the . Amazon SEO Services
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
Training said…
Great post happy to see this. I thought this was a pretty interesting read when it comes to this topic Information. Thanks..
Artificial Intelligence Course
Nice Post thank you very much for sharing such a useful information and will definitely saved and revisit your site and i have bookmarked to check out new things frm your post.
Data Science Course
EDU said…
Thanks Your post is so cool and this is an extraordinary moving article and If it's not too much trouble share more like that.
Digital Marketing Course in Hyderabad
Akshay said…
Actually I read it yesterday but I had some ideas about it and today I wanted to read it again because it is so well written.
Data Science Course in India
You have done a great job and will definitely dig it and personally recommend to my friends. Thank You.
Data Science Online Training
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
Anand said…
I got to this amazing site not long ago. I actually captured with the piece of resources you have got here. Thanks for making such wonderful blog page.
Data Science Course in Ahmedabad
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
Very great post which I really enjoy reading this and it is not everyday that I have the possibility to see something like this. Thank You.
Best Online Data Science Courses
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

Popular posts from this blog

Showing results from Cox Proportional Hazard Models in R with simPH

Update 2 February 2014: A new version of simPH (Version 1.0) will soon be available for download from CRAN. It allows you to plot using points, ribbons, and (new) lines. See the updated package description paper for examples. Note that the ribbons argument will no longer work as in the examples below. Please use type = 'ribbons' (or 'points' or 'lines' ). Effectively showing estimates and uncertainty from Cox Proportional Hazard (PH) models , especially for interactive and non-linear effects, can be challenging with currently available software. So, researchers often just simply display a results table. These are pretty useless for Cox PH models. It is difficult to decipher a simple linear variable’s estimated effect and basically impossible to understand time interactions, interactions between variables, and nonlinear effects without the reader further calculating quantities of interest for a variety of fitted values. So, I’ve been putting together th

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

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