title: Index Error when running LDA in gensim
body: <p>I read the docs I have</p>
  
  <pre><code>corpusObj.readDocsSample(sampleFile)
  </code></pre>
  
  <p>Next,</p>
  
  <pre><code>dictionary = corpusObj.buildDictionary()
  </code></pre>
  
  <p>Then I build a corpus:</p>
  
  <pre><code>corpus = corpusObj.buildCorpus()
  </code></pre>
  
  <p>Definition of buildDictionary and buildCorpus:</p>
  
  <pre><code>def buildDictionary(self):
  
           texts = [[word for word in self.docs[i]] for i in self.docs]
           self.dictionary = corpora.Dictionary(texts)
           return self.dictionary
  
  
  def buildCorpus(self):
           return [self.dictionary.doc2bow(words) for words in self.docs.itervalues()]
  </code></pre>
  
  <p>Then I do stop words stuff:</p>
  
  <pre><code>stop = corpus.readStopWords()
  stopids = [dictionary.token2id[stopword] for stopword in stop
           if stopword in dictionary.token2id]
  dictionary.filter_tokens(stopids)
  dictionary.compactify()
  </code></pre>
  
  <p>Then I call:</p>
  
  <pre><code> lda = gensim.models.ldamodel.LdaModel(corpus=corp, id2word=dictionary, num_topics=100, update_every=1, chunksize=1000, passes=1)
  </code></pre>
  
  <p>Here is the error:</p>
  
  <pre><code> Traceback (most recent call last):
  File "/Users/jsuit/PycharmProjects/MyGensimPlaything/GensimPlayToy.py", line 33, in &lt;module&gt;
  lda = gensim.models.ldamodel.LdaModel(corpus=corp, id2word=dictionary, num_topics=100,     update_every=1, chunksize=1000, passes=1)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gensim/models/ldamodel.py", line 313, in __init__
  self.update(corpus)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gensim/models/ldamodel.py", line 553, in update
  self.log_perplexity(chunk, total_docs=lencorpus)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gensim/models/ldamodel.py", line 464, in log_perplexity
  perwordbound = self.bound(chunk, subsample_ratio=subsample_ratio) / (subsample_ratio * corpus_words)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gensim/models/ldamodel.py", line 639, in bound
  gammad, _ = self.inference([doc])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gensim/models/ldamodel.py", line 376, in inference
  expElogbetad = self.expElogbeta[:, ids]
  IndexError: index 46979 is out of bounds for axis 1 with size 46979
  </code></pre>
  
  <p>The logging information below shows that it gets started but then crashes.</p>
  
  <pre><code>2014-11-07 19:31:56,096 : INFO : adding document #0 to Dictionary(0 unique tokens: [])
  2014-11-07 19:32:00,458 : INFO : built Dictionary(47445 unique tokens: [u'Szczecin', u'pro-Soviet', u'Negroponte', u'1,800', u'woods']...) from 2250 documents (total 1050902 corpus positions)
  2014-11-07 19:32:08,192 : DEBUG : rebuilding dictionary, shrinking gaps
  2014-11-07 19:32:08,237 : INFO : using symmetric alpha at 0.01
  2014-11-07 19:32:08,237 : INFO : using serial LDA version on this node
  2014-11-07 19:32:08,856 : INFO : running online LDA training, 100 topics, 1 passes over   
  the supplied corpus of 2250 documents, updating model once every 1000 documents,           
  evaluating perplexity every 2250 documents, iterating 50x with a convergence threshold of 
  0.001000
  2014-11-07 19:32:08,856 : WARNING : too few updates, training might not converge; 
  consider increasing the number of passes or iterations to improve accuracy
  2014-11-07 19:32:08,931 : INFO : PROGRESS: pass 0, at document #1000/2250
  2014-11-07 19:32:08,931 : DEBUG : performing inference on a chunk of 1000 documents
  2014-11-07 19:32:15,414 : DEBUG : 22/1000 documents converged within 50 iterations
  2014-11-07 19:32:15,432 : DEBUG : updating topics
  2014-11-07 19:32:15,476 : INFO : merging changes from 1000 documents into a model of 2250  
  documents
  2014-11-07 19:32:16,222 : INFO : topic #60 (0.010): 0.057*Neeman + 0.042*woods + 0.039*needed + 0.024*timeout + 0.020*reggae + 0.020*Shocked + 0.019*Dexter + 0.015*nonsensical + 0.014*3-to-1 + 0.011*Mauritius
  2014-11-07 19:32:16,237 : INFO : topic #45 (0.010): 0.049*needed + 0.047*Neeman + 0.042*woods + 0.024*reggae + 0.023*timeout + 0.022*Dexter + 0.022*Shocked + 0.019*nonsensical + 0.012*3-to-1 + 0.011*mid-week
  2014-11-07 19:32:16,251 : INFO : topic #86 (0.010): 0.049*needed + 0.048*Neeman + 0.047*woods + 0.029*Shocked + 0.023*timeout + 0.017*nonsensical + 0.016*reggae + 0.016*3-to-1 + 0.014*Dexter + 0.014*Mauritius
  2014-11-07 19:32:16,265 : INFO : topic #92 (0.010): 0.017*Neeman + 0.016*needed + 0.014*woods + 0.011*Dexter + 0.010*timeout + 0.009*reggae + 0.006*Shocked + 0.006*nonsensical + 0.005*22-month-old + 0.004*3-to-1
  2014-11-07 19:32:16,279 : INFO : topic #95 (0.010): 0.045*needed + 0.041*woods + 0.032*Shocked + 0.028*Neeman + 0.022*timeout + 0.020*nonsensical + 0.018*reggae + 0.017*Dexter + 0.013*Mauritius + 0.010*3-to-1
  2014-11-07 19:32:16,294 : INFO : topic #30 (0.010): 0.054*needed + 0.052*Neeman + 0.033*woods + 0.024*timeout + 0.022*nonsensical + 0.021*Dexter + 0.021*Shocked + 0.016*reggae + 0.013*Mauritius + 0.012*3-to-1
  2014-11-07 19:32:16,307 : INFO : topic #51 (0.010): 0.000*expands + 0.000*Promotion + 0.000*Arnold + 0.000*1,320.75 + 0.000*credits + 0.000*tuition + 0.000*_Or + 0.000*Hunt + 0.000*Futrell + 0.000*stagecoaches
  2014-11-07 19:32:16,321 : INFO : topic #41 (0.010): 0.045*Neeman + 0.032*needed + 0.031*woods + 0.016*Dexter + 0.013*nonsensical + 0.013*Shocked + 0.013*timeout + 0.011*reggae + 0.009*peux + 0.009*Mauritius
  2014-11-07 19:32:16,336 : INFO : topic #28 (0.010): 0.052*Neeman + 0.046*needed + 0.040*woods + 0.030*timeout + 0.026*Shocked + 0.019*nonsensical + 0.018*Dexter + 0.014*reggae + 0.011*3-to-1 + 0.010*crouch
  2014-11-07 19:32:16,351 : INFO : topic #11 (0.010): 0.046*Neeman + 0.044*woods + 0.037*needed + 0.031*Shocked + 0.021*Dexter + 0.021*reggae + 0.017*nonsensical + 0.017*timeout + 0.012*3-to-1 + 0.010*Mauritius
  2014-11-07 19:32:16,365 : INFO : topic #20 (0.010): 0.067*Neeman + 0.036*woods + 0.035*needed + 0.028*timeout + 0.020*reggae + 0.018*Dexter + 0.016*Mauritius + 0.015*Shocked + 0.015*nonsensical + 0.014*mid-week
  2014-11-07 19:32:16,379 : INFO : topic #31 (0.010): 0.001*Neeman + 0.001*woods + 0.001*timeout + 0.001*reggae + 0.000*needed + 0.000*Dexter + 0.000*3-to-1 + 0.000*Shocked + 0.000*romped + 0.000*1,800
  2014-11-07 19:32:16,393 : INFO : topic #80 (0.010): 0.043*woods + 0.042*Neeman + 0.037*needed + 0.029*timeout + 0.024*Shocked + 0.017*nonsensical + 0.015*reggae + 0.014*Dexter + 0.011*1,800 + 0.011*3-to-1
  2014-11-07 19:32:16,407 : INFO : topic #58 (0.010): 0.029*Neeman + 0.027*needed + 0.019*woods + 0.019*timeout + 0.013*Dexter + 0.010*Shocked + 0.008*nonsensical + 0.008*mid-week + 0.007*reggae + 0.007*3-to-1
   2014-11-07 19:32:16,421 : INFO : topic #79 (0.010): 0.002*woods + 0.002*needed + 0.002*sustaining + 0.001*Neeman + 0.001*timeout + 0.001*Godchaux + 0.001*Dexter + 0.001*dozen + 0.001*rumor + 0.001*Miami-based
   2014-11-07 19:32:16,437 : INFO : topic diff=78.067282, rho=1.000000  
   2014-11-07 19:32:16,523 : INFO : PROGRESS: pass 0, at document #2000/2250
   2014-11-07 19:32:16,523 : DEBUG : performing inference on a chunk of 1000 documents
   2014-11-07 19:32:22,841 : DEBUG : 38/1000 documents converged within 50 iterations
   2014-11-07 19:32:22,862 : DEBUG : updating topics
   2014-11-07 19:32:22,919 : INFO : merging changes from 1000 documents into a model of     
   2250 documents
   2014-11-07 19:32:23,640 : INFO : topic #63 (0.010): 0.017*Neeman + 0.016*needed + 0.014*autobiography + 0.013*teacher + 0.012*woods + 0.011*Mauritius + 0.010*Shocked + 0.009*timeout + 0.007*mid-week + 0.007*CFC
   2014-11-07 19:32:23,654 : INFO : topic #8 (0.010): 0.028*Neeman + 0.027*woods + 0.024*Shocked + 0.023*needed + 0.016*timeout + 0.013*Dexter + 0.010*reggae + 0.010*nonsensical + 0.007*Mauritius + 0.007*65-plus
   2014-11-07 19:32:23,669 : INFO : topic #85 (0.010): 0.054*needed + 0.041*woods + 0.036*Neeman + 0.036*Shocked + 0.031*timeout + 0.023*nonsensical + 0.016*reggae + 0.014*Dexter + 0.011*3-to-1 + 0.011*crouch
   2014-11-07 19:32:23,683 : INFO : topic #18 (0.010): 0.017*needed + 0.013*woods + 0.011*Neeman + 0.010*timeout + 0.009*Shocked + 0.008*reggae + 0.008*Guttierez + 0.006*livid + 0.006*Vermont + 0.006*Dexter
    2014-11-07 19:32:23,697 : INFO : topic #49 (0.010): 0.028*needed + 0.028*Neeman + 0.026*woods + 0.024*timeout + 0.019*Dexter + 0.017*nonsensical + 0.012*reggae + 0.009*Shocked + 0.007*3-to-1 + 0.007*crouch
   2014-11-07 19:32:23,712 : INFO : topic #53 (0.010): 0.035*mid-week + 0.034*Mauritius + 0.028*Neeman + 0.028*needed + 0.027*woods + 0.024*Tourism + 0.023*macho + 0.014*Shocked + 0.013*nonsensical + 0.012*timeout
   2014-11-07 19:32:23,726 : INFO : topic #32 (0.010): 0.071*Neeman + 0.031*woods + 0.022*needed + 0.015*timeout + 0.013*Shocked + 0.012*Dexter + 0.012*Mauritius + 0.009*nonsensical + 0.009*mid-week + 0.007*reggae
   2014-11-07 19:32:23,740 : INFO : topic #78 (0.010): 0.040*needed + 0.039*Neeman + 0.039*woods + 0.019*timeout + 0.019*Shocked + 0.017*Dexter + 0.017*reggae + 0.016*nonsensical + 0.015*3-to-1 + 0.011*mid-week
   2014-11-07 19:32:23,754 : INFO : topic #94 (0.010): 0.002*needed + 0.002*Neeman + 0.001*woods + 0.001*timeout + 0.001*Dexter + 0.001*nonsensical + 0.001*Shocked + 0.001*3-to-1 + 0.001*reggae + 0.000*dozen
   2014-11-07 19:32:23,768 : INFO : topic #17 (0.010): 0.023*needed + 0.022*woods + 0.018*Neeman + 0.018*timeout + 0.012*1,800 + 0.011*reggae + 0.011*Shocked + 0.010*Dexter + 0.008*Anderson + 0.007*Bovek
   2014-11-07 19:32:23,781 : INFO : topic #73 (0.010): 0.001*woods + 0.001*timeout + 0.001*Neeman + 0.001*Shocked + 0.001*reggae + 0.001*Falcon + 0.001*Dexter + 0.001*needed + 0.001*dozes + 0.001*dozen
   2014-11-07 19:32:23,796 : INFO : topic #96 (0.010): 0.049*Neeman + 0.048*needed + 0.043*woods + 0.025*timeout + 0.019*nonsensical + 0.018*Shocked + 0.015*Dexter + 0.013*3-to-1 + 0.011*reggae + 0.010*crouch
   2014-11-07 19:32:23,810 : INFO : topic #46 (0.010): 0.042*needed + 0.035*Neeman + 0.033*woods + 0.025*Shocked + 0.019*3-to-1 + 0.016*reggae + 0.016*timeout + 0.013*Dexter + 0.012*nonsensical + 0.011*Mauritius
   2014-11-07 19:32:23,824 : INFO : topic #39 (0.010): 0.002*needed + 0.002*Neeman + 0.001*woods + 0.001*Shocked + 0.001*Dexter + 0.001*mid-week + 0.001*timeout + 0.001*18th + 0.001*nonsensical + 0.001*Mauritius
   2014-11-07 19:32:23,838 : INFO : topic #66 (0.010): 0.036*Neeman + 0.032*woods + 0.021*needed + 0.020*timeout + 0.019*Shocked + 0.019*Blank + 0.014*cares + 0.013*Dexter + 0.011*reggae + 0.010*nonsensical
   2014-11-07 19:32:23,855 : INFO : topic diff=5.923197, rho=0.707107
   2014-11-07 19:32:24,260 : DEBUG : bound: at document #0
  </code></pre>
  
  <p>And then we get the error message I posted above.</p>