Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

computing doc.length with mallet #47

Open
gpcoursera opened this issue Oct 13, 2015 · 2 comments
Open

computing doc.length with mallet #47

gpcoursera opened this issue Oct 13, 2015 · 2 comments

Comments

@gpcoursera
Copy link

Hi,
I used to have a previous version of LDAvis (2014) installed with devtools.
In the version I had of LDAvis I would call createJSON as:
json <- createJSON(K, phi, term.frequency, vocab, topic.proportions)

Today I updated my R packages and have a newer vesion of LDAvis (from CRAN) which uses createJSON as:
json <- createJSON(phi, theta, doc.length, vocab, term.frequency)

I'm using MALLET for the LDA. I can easily access to the phi and theta matrices as well as the vocab and term.frequency but not so much to doc.length.
According to the doc of LDAvis it's a vector containing the number of tokens in each document of the corpus.

Question: how can I construct such vector from a MALLET instance (mallet.import)?

Thanks!
G.

@LalaNguyen
Copy link

just figured out that you can compute it yourself. Here is my take

doc.tokens <- data.frame(id=c(1:nrow(doc.topics)), tokens=0)
for(i in vocab){
  # Find word if word in text
  matched <- grepl(i,docs$text)
  doc.tokens[matched,2] =doc.tokens[matched,2] +  1
}

@aronlindberg
Copy link

@gpcoursera: how do you get phi, theta, vocab, and term.frequency from a topic model defined by mallet in R?

Also, did the code by @LalaNguyen work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants