Skip to content

Instantly share code, notes, and snippets.

Created November 5, 2017 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/60b412de7c4e863c22228c5914af679c to your computer and use it in GitHub Desktop.
Save anonymous/60b412de7c4e863c22228c5914af679c to your computer and use it in GitHub Desktop.
ldavis_json <- function(m, dtm){
dtm = dtm[slam::row_sums(dtm) > 0, ]
# Find required quantities
phi <- posterior(m)$terms %>% as.matrix
theta <- posterior(m)$topics %>% as.matrix
vocab <- colnames(phi)
doc.length = slam::row_sums(dtm)
term.freq = slam::col_sums(dtm)[match(vocab, colnames(dtm))]
createJSON(phi = phi, theta = theta,
vocab = vocab,
doc.length = doc.length,
term.frequency = term.freq)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment