4

I wish to know the default number of iterations in gensim's LDA (Latent Dirichlet Allocation) algorithm. I don't think the documentation talks about this. (Number of iterations is denoted by the parameter iterations while initializing the LdaModel ). Thanks !

3 Answers 3

7

Checked the module's files in the python/Lib/site-packages directory. The constructor is something like this -

def __init__(self, corpus=None, num_topics=100, id2word=None,
                 distributed=False, chunksize=2000, passes=1, update_every=1,
                 alpha='symmetric', eta=None, decay=0.5, offset=1.0,
                 eval_every=10, iterations=50, gamma_threshold=0.001)

So, the default number of iterations stands at 50.

2
  • Difference between passes and iterations?
    – BlackSwan
    Jul 13, 2017 at 10:16
  • 1
    A little bit of googling - The passes parameter is indeed unique to gensim. It essentially allows LDA to see your corpus multiple times and is very handy for smaller corpora. The iterations parameter puts a limit on how many times LDA will execute the E-Step for each document (see repeat-until loop in algorithm 2 in cs.princeton.edu/~blei/papers/HoffmanBleiBach2010b.pdf), meaning that some documents may not converge in time. You can set this as high as you would like (or have time for). Link : thread.gmane.org/gmane.comp.ai.gensim/4732
    – Utsav T
    Jul 13, 2017 at 12:59
1

If you use:

import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', 
    level=logging.INFO)

It will tell you

running batch LDA training, 17 topics, 10 passes over the supplied corpus of 1130 documents, updating model once every 1130 documents, evaluating perplexity every 1130 documents, iterating 50x with a convergence threshold of 0.001000
0

The default number of iterations = 50

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.