I was confused by how LDA (by the original variational inference) can be implemented in a way such that the number of operations for each document $j$ is $\mathcal{O}(N_j~K)$, where $N_j$ is the unique number of words in $j$ and $K$ is the number of topics. In the original paper by Blei, their inference is done by scanning through each individual word (not unique) for the variational parameter $\gamma_{jik}$ where $i$ is the $i$th word in document $j$.
In an email from the topic modeling mailing list, the authors (Prof. Blei) also said that
the complexity of mean-field variational inference is actually
O(NKV). the reason is that, in a document, we need not compute
posterior multinomials for each instance of each term but only once
for each unique term in that document. in the LDA paper, we did not
write things down that way to make the math simpler. (though, we
should have mentioned this speed-up.)if you'll look at the LDA-C code, which is on my web-site, you'll see
that we only need to iterate through the unique terms of each document
for each iteration of variational inference.
For me, it will take up too much time to look at the C code. Can anyone provide an intuitive way on how to implement VB LDA by iterating thru each document's unique word?