title: Using Latent Dirichlet Allocation with Gensim
body: <p>I am working on a project and I would like to use Latent Dirichlet Allocation in order to extract topics from a large amount of articles.</p>
  
  <p>My code is this:</p>
  
  <pre><code>import gensim
  import csv
  import json
  import glob
  from gensim import corpora, models
  from nltk.corpus import stopwords
  from nltk.tokenize import RegexpTokenizer
  from time import gmtime, strftime
  
  tokenizer = RegexpTokenizer(r'\w+')
  cachedStopWords = set(stopwords.words("english"))
  body = []
  processed = []
  
  with open('/…/file.json') as j:
      data = json.load(j)
  
  for i in range(0,len(data)):
      body.append(data[i]['text'].lower())
  
  for entry in body:
      row = tokenizer.tokenize(entry)
      processed.append([word for word in row if word not in cachedStopWords])
  
  dictionary = corpora.Dictionary(processed)
  corpus = [dictionary.doc2bow(text) for text in processed]
  lda = gensim.models.ldamodel.LdaModel(corpus, id2word=dictionary, num_topics=50, update_every=1, passes=1)
  topics = lda.show_topics(num_topics=50, num_words=8)
  
  other_doc = "After being jailed for life in 1964, Nelson Mandela became a worldwide symbol of resistance to apartheid. But his opposition to racism began many years before."
  print lda[other_doc]
  
  Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-  packages/gensim/models/ldamodel.py", line 714, in __getitem__
  gamma, _ = self.inference([bow])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site
  packages/gensim/models/ldamodel.py", line 361, in inference ids = [id for id, _ in doc]
  ValueError: need more than 1 value to unpack
  </code></pre>
  
  <p>I also tried to use LdaMulticore in 3 different ways :</p>
  
  <pre><code>lda = gensim.models.LdaMulticore(corpus, id2word=dictionary, num_topics=100, workers=3)
  lda = gensim.models.ldamodel.LdaMulticore(corpus, id2word=dictionary, num_topics=100, workers=3)
  lda = models.LdaMulticore(corpus, id2word=dictionary, num_topics=100, workers=3)
  </code></pre>
  
  <p>And every time I got this error :</p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  AttributeError: 'module' object has no attribute ‘LdaMulticore'
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thank you in advance.</p>