0

Given a document term matrix dtm, text2vec provides a nice integration with the LDAvis package. However, I want to embed this visualisation into a markdown document. The LDAvis package has methods such as createJSON, which would allow me to do this, but these are all hidden inside a private method in textvec.

n_topics = 6
lda = LDA$new(n_topics = 6L, doc_topic_prior = 50 / n_topics, topic_word_prior = 1 / n_topics)
doc_topic_distr = lda$fit_transform(dtm, n_iter = 1000, convergence_tol = 1e-3, n_check_convergence = 10, progressbar = interactive())

Is there anyway to get back to the json of the visualisation, or otherwise access the private methods in text2vec::LDA$new?

TMrtSmith
  • 461
  • 3
  • 16

1 Answers1

1

Yes, this is possible - provide corrsponding LDAvis arguments to plot call. See example from official documentation https://github.com/dselivanov/text2vec/blob/master/docs/topic_modeling.Rmd#visualization

Dmitriy Selivanov
  • 4,545
  • 1
  • 22
  • 38
  • This is kind of the answer... the text2vec.org documentation doesn't have this, which is why I missed it. ```lda$plot(out.dir = "ldavis", open.browser = FALSE``` gives us a directory with ```lda.json``` and other files. I was hoping that I could use ```LDAvis::servis``` to embed this in my Rmarkdown, but it doesn't seem to play nice. What did work is to copy the raw html from ```index.html``` (another output of ```lda$plot(...)``` into the markdown document, but this doesn't seem to work for all browsers, and requires the document to be in the same place as the raw json/js files... – TMrtSmith Jun 26 '18 at 10:12
  • So +1 for the pointer to the correct docs, and the usual speedy (and super-succint!) response @Dmitriy-Selivanov. I'm going to leave the question open for a bit to see if anyone has a fuller answer. I found [this](https://github.com/cpsievert/LDAvis/issues/48) helpful. – TMrtSmith Jun 26 '18 at 10:14
  • 1
    You might also read the json file via `jsonlite::fromJSON("filepath/lda.json")`. This will not provide you with the dynamic functionality but you might access selected data and process it. Not sure if this really helps you... – Manuel Bickel Jul 25 '18 at 20:44