Skip to content

deprecation warnings in LDA example code #125

Description

@cartazio

hey @bob-carpenter , @lizzyagibson and I have been looking at the lda example code (its nice how it closely maps to the generative description in the LDA journal paper), and theres a few deprecation warnings related to <- along with the target update increment_log_sum_exp expression. you may wanna update them :)

thanks for the lovely examples!

Activity

  1. cartazio commented on Nov 12, 2017

    @cartazio
    Author

    relatedly, whats the correct / recommend way to rewrite the sum over the gammas?

    as written, its increment_log_prob = log_sum_exp(gamma)

    should it be

    a) target+= gamma
    b) target+= something something gamma
    c) something else?

  2. bob-carpenter commented on Nov 12, 2017

    @bob-carpenter
    Member

    The code is way out of date. It's in

    https://github.com/stan-dev/example-models/blob/ec6d329bb5a88fa53e44c28fa01287701660933c/misc/cluster/lda/lda.stan

    The current marginalization over the topic (k) for a given word (n) where is this:

      for (n in 1:N) {
        real gamma[K];
        for (k in 1:K) 
          gamma[k] <- log(theta[doc[n],k]) + log(phi[k,w[n]]);
        increment_log_prob(log_sum_exp(gamma));  // likelihood
      }
    

    That can be reduced to

      for (n in 1:N)
        target += log_sum_exp(log(theta[doc[n]]) + to_vector(log(phi[ , w[n]])));
    

    It'd be even better to define log_phi in vector form and reuse for each n. It would also be worth doing this for log_theta if the number of words per document is greater than the total number of topics.

  3. bob-carpenter commented on Nov 12, 2017

    @bob-carpenter
    Member

    @cartazio: Feel free to submit a pull request.

    And a warning---you can't really do Bayesian inference for LDA because of the multimodality. You'll see that you won't satisfy convergence diagnostics running in multiple chains, and not just because of label switching.

  4. cartazio commented on Nov 12, 2017

    @cartazio
    Author

    @bob-carpenter thanks! Thats super helpful.

    by multi-mode you mean: there are different local optima when viewed as an optimization problem / things are nonconvex? (ie vary the priors and there will be different local optima in the posterior?). I had to google around to figure out what you meant, https://scholar.harvard.edu/files/dtingley/files/multimod.pdf seemed the most clearly expositional despite the double spaced formatting :)

    is there any good reading/references on how the "variational" formulations such as Mallet/VowpalWabbit etc deal with that issue? or is it just one of those things that tends to stay hidden in folklore common knowledge?

  5. bob-carpenter commented on Nov 12, 2017

    @bob-carpenter
    Member
  6. cartazio commented on Nov 13, 2017

    @cartazio
    Author
  7. bob-carpenter commented on Nov 13, 2017

    @bob-carpenter
    Member
  8. cartazio commented on Nov 13, 2017

    @cartazio
    Author
  9. bob-carpenter commented on Nov 13, 2017

    @bob-carpenter
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions