Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add per_word_topics parameter to apply call #923

Closed
wants to merge 2 commits into from

Conversation

SND96
Copy link

@SND96 SND96 commented Oct 6, 2016

Solving the issue
per_word_topics for a corpus #908

@tmylk
Copy link
Contributor

tmylk commented Oct 7, 2016

Thanks for the pr. Please add a line in changelog and a test

@SND96
Copy link
Author

SND96 commented Oct 7, 2016

Can you please advise me on how to proceed to modify the tests.

@tmylk
Copy link
Contributor

tmylk commented Oct 12, 2016

First please pass all the params through the apply call, not just per_word_topics

@tmylk
Copy link
Contributor

tmylk commented Oct 12, 2016

The tests should be the same as for a single word, just modified to be for a corpus.

@tmylk tmylk mentioned this pull request Oct 13, 2016
@SND96
Copy link
Author

SND96 commented Oct 13, 2016

I passed all the params in the apply call.
return self._apply(corpus, minimum_probability = self.minimum_probability, minimum_phi_value = self.minimum_phi_value, per_word_topics = self.per_word_topics)

But when I ran this line
lda.per_word_topics(corpus, per_word_topics = True)

I got this error
AttributeError: 'LdaModel' object has no attribute 'per_word_topics'

@tmylk
Copy link
Contributor

tmylk commented Oct 14, 2016

lda.per_word_topics calls a non-existing method per_word_topics

@SND96
Copy link
Author

SND96 commented Oct 14, 2016

Sorry I ran this,
lda.get_document_topics(corpus, per_word_topics = True)

And this was the error I got

'LdaModel' object has no attribute 'minimum_phi_value'

@tmylk
Copy link
Contributor

tmylk commented Oct 14, 2016

which line is it? please report the full error stack

@SND96
Copy link
Author

SND96 commented Oct 14, 2016

I added the attributes minimum_phi_value and per_word_topics to the attributes of LdaModel class but then this was the error I got

In [1]: import logging
   ...: import unittest
   ...: import os
   ...: import os.path
   ...: import tempfile
   ...: import numbers
   ...: 
   ...: import six
   ...: import bumpy
   ...: import scipy.linalg
   ...: 
   ...: from gensim.corpora import mmcorpus, Dictionary
   ...: from gensim.models import ldamodel, ldamulticore
   ...: from gensim import matutils
   ...: 
/Users/sahithdambekodi/Desktop/RaRe/gensim/gensim/utils.py:1014: UserWarning: Pattern library is not installed, lemmatization won't be available.
  warnings.warn("Pattern library is not installed, lemmatization won't be available.")
Slow version of gensim.models.word2vec is being used
Slow version of gensim.models.doc2vec is being used

In [2]: texts = [['human', 'interface', 'computer'],
   ...:  ['survey', 'user', 'computer', 'system', 'response', 'time'],
   ...:  ['eps', 'user', 'interface', 'system'],
   ...:  ['system', 'human', 'system', 'eps'],
   ...:  ['user', 'response', 'time'],
   ...:  ['trees'],
   ...:  ['graph', 'trees'],
   ...:  ['graph', 'minors', 'trees'],
   ...:  ['graph', 'minors', 'survey']]
   ...: dictionary = Dictionary(texts)
   ...: corpus = [dictionary.doc2bow(text) for text in texts]
   ...: 

In [3]: from gensim import models

In [4]: lda = models.LdaModel(corpus)

In [5]: lda.get_document_topic(corpus)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-e2a60ca3cb20> in <module>()
----> 1 lda.get_document_topic(corpus)

AttributeError: 'LdaModel' object has no attribute 'get_document_topic'

In [6]: lda.get_document_topics(corpus)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-74e9bbe4f911> in <module>()
----> 1 lda.get_document_topics(corpus)

/Users/sahithdambekodi/Desktop/RaRe/gensim/gensim/models/ldamodel.py in get_document_topics(self, bow, minimum_probability, minimum_phi_value, per_word_topics)
    923         is_corpus, corpus = utils.is_corpus(bow)
    924         if is_corpus:
--> 925             return self._apply(corpus, minimum_probability = self.minimum_probability, minimum_phi_value= self.minimum_phi_value, per_word_topics = self.per_word_topics)
    926 
    927         gamma, phis = self.inference([bow], collect_sstats=True)

TypeError: _apply() got an unexpected keyword argument 'minimum_probability'

@tmylk
Copy link
Contributor

tmylk commented Nov 8, 2016

Almost done in #978

@tmylk tmylk closed this Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants