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

TypeError: object of type 'map' has no len() #4

Closed
wilkens opened this issue Jun 13, 2015 · 5 comments
Closed

TypeError: object of type 'map' has no len() #4

wilkens opened this issue Jun 13, 2015 · 5 comments

Comments

@wilkens
Copy link

wilkens commented Jun 13, 2015

I can't seem to get pyLDAvis to work on even a toy collection. I build a model with gensim as described in the gensim docs. Then, when I try to run

vis_data = gensimvis.prepare(lda, corpus, dictionary)

I get TypeError: object of type 'map' has no len(). I've tried this with other document collections, getting the same problem.

Minimal code to duplicate is below. I'm using Python 3.4.3 on a Mac (via Anaconda), gensim 0.10.3, and pyLDAvis 1.1.0. Hope I'm just doing something obviously dumb. Thanks for any help you can provide.

import gensim
from gensim import corpora, models, similarities
import pyLDAvis.gensim as gensimvis
import pyLDAvis
import sys

print(sys.version)
print(pyLDAvis.__version__)
print(gensim.__version__)

documents = ["Human machine interface for lab abc computer applications",
             "A survey of user opinion of computer system response time",
             "The EPS user interface management system",
             "System and human system engineering testing of EPS",
             "Relation of user perceived response time to error measurement",
             "The generation of random binary unordered trees",
             "The intersection graph of paths in trees",
             "Graph minors IV Widths of trees and well quasi ordering",
             "Graph minors A survey"]

stoplist = set('for a of the and to in'.split())
texts = [[word for word in document.lower().split() if word not in stoplist]
         for document in documents]

from collections import defaultdict
frequency = defaultdict(int)
for text in texts:
    for token in text:
        frequency[token] += 1
texts = [[token for token in text if frequency[token] > 1]
         for text in texts]

dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]
lda = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, num_topics=2, passes=10)

vis_data = gensimvis.prepare(lda, corpus, dictionary)
bmabey added a commit that referenced this issue Jun 13, 2015
While not related to the issue reported in #4 this edge case appeared
after the gensim portion of the code worked.
@bmabey
Copy link
Owner

bmabey commented Jun 13, 2015

Thank you for reporting this. I reproduced your error which means the gensim 1.1.0 code isn't compatible with 3.x. I didn't test the gensim portion in 3.x so this got by. On master I have a different version of the gensim code (that I hadn't released yet) that doesn't blow up on this. I'll push a new version of the library and let you know when it is available.

@bmabey
Copy link
Owner

bmabey commented Jun 14, 2015

@wilkens I just pushed v1.2.0. Will you please verify that it works for you?

@wilkens
Copy link
Author

wilkens commented Jun 14, 2015

Thanks - yes, it works fine now. I appreciate the quick turnaround!

@bmabey
Copy link
Owner

bmabey commented Jun 14, 2015

Great, thanks again for the report and feedback.

BTW, I checked out your wright-topics repo- cool stuff! I think it would be helpful to incorporate document information into ldavis at somepoint. It would probably be an optional extension for people who want to provide and host additional document data in the right format.

@bmabey bmabey closed this as completed Jun 14, 2015
@wilkens
Copy link
Author

wilkens commented Jun 14, 2015

Thanks, Ben! I wish I could take more credit for the visualization work in the wright-topics repo, but it's really just a light adaptation from Andrew Goldstone's code. If you're interested, the most robust public version of his stuff is at [http://signsat40.signsjournal.org/topic-model/].

On Jun 14, 2015, at 12:41 AM, Ben Mabey [email protected] wrote:

Great, thanks again for the report and feedback.

BTW, I checked out your wright-topics repo- cool stuff! I think it would be helpful to incorporate document information into ldavis at somepoint. It would probably be an optional extension for people who want to provide and host additional document data in the right format.


Reply to this email directly or view it on GitHub.

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

No branches or pull requests

2 participants