-
-
Save vanatteveldt/6269f1336ac54e752fa22c85bf2354fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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