-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
SparseTermSimilarityMatrix - TypeError: 'numpy.float32' object is not iterable #2496
Comments
@Witiko can you please have a look? |
Hi there, I came across the same issue a few days ago. The issue lies in line 248 of gensim/termsim.py The fix is simply to replace the "<=" test with a "<". Hope this helps you guys! |
@piskvorky I will take a closer look when I am on a PC, but this seems to be the same issue as the one reported by @tvrbanec earlier (#2105 (comment), #2356, #2461). @mkoa Thank you for the report, but this seems unrelated. Moreover, the limit should not be broken, because |
@Witiko Thank you very much for the heads up! I can confirm I got the same error as @magiob but with a word2vec model on my side. My fix aims at directly preventing a call to |
@mkoa That is a useful suggestion. Changing 232,235c232,238
< most_similar = [
< (dictionary.token2id[term], similarity)
< for term, similarity in index.most_similar(t1, num_rows)
< if term in dictionary.token2id]
---
> if num_rows > 0:
> most_similar = [
> (dictionary.token2id[term], similarity)
> for term, similarity in index.most_similar(t1, topn=num_rows)
> if term in dictionary.token2id]
> else:
> most_similar = [] Even though this does not address the root cause, it is still good defensive programming. |
Suggested fixes:
|
I found the root cause: @piskvorky I hope I will not be the root cause of a 3.7.4 bugfix release. 😅 |
Yes, I can confirm that code used to work on gensim==3.7.2 now on gensim=3.7.3 throw the error: |
I use Gensim 3.7.3. When I executed:
I received: And I fixed it completely by #2356 (comment) |
I am having same problem with my own word2vec model while following tutorial here: Is there any time table to publish the fix? Or any workaround other then downgrade to 3.7.2? |
@mehmetilker: The fix is published, see #2496 (comment). Hopefully, #2497 will be merged soon; what do you think, @mpenkov? |
I am using gensim 3.7.3 and python3.6.
I am following the exact example of SoftCosineSimilarity at https://radimrehurek.com/gensim/similarities/docsim.html
but with my own dataset and embeddings trained on Fasttext.
Dictionary and WordEmbeddingSimilarityIndex are executed properly but then I get an error when trying SparseTermSimilarityMatrix. I found a similar issue, that was solved in the pull below, but I still seem to get this error. However, I tried the exact same code with Word2Vec and the gensim imported common_texts and it worked. Why it doesnt work in my case, is it related to FastText?
#2356
My code:
The text was updated successfully, but these errors were encountered: