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

most_similar_cosmul bug fix #1177

Merged
merged 3 commits into from
Mar 3, 2017
Merged

most_similar_cosmul bug fix #1177

merged 3 commits into from
Mar 3, 2017

Conversation

dkim010
Copy link
Contributor

@dkim010 dkim010 commented Mar 2, 2017

remove unhashable type: 'numpy.ndarray' error

Signed-off-by: Dongwon Kim dongwon.kim@navercorp.com

Signed-off-by: Dongwon Kim <dongwon.kim@navercorp.com>
@tmylk
Copy link
Contributor

tmylk commented Mar 3, 2017

Thank you for the quick fix!

model.most_similar_cosmul('graph', topn=10) works but model.most_similar_cosmul(positive=[graph_vector], topn=11) still produces results TypeError: unhashable type: 'numpy.ndarray'.

Please add this unit test to test_word2vec.py

def test_cosmul():
        model = word2vec.Word2Vec(sentences, size=2, min_count=1, hs=1, negative=0)
        sims = model.most_similar_cosmul('graph', topn=10)
        # self.assertTrue(sims[0][0] == 'trees', sims)  # most similar

        # test querying for "most similar" by vector
        graph_vector = model.wv.syn0norm[model.wv.vocab['graph'].index]
        sims2 = model.most_similar_cosmul(positive=[graph_vector], topn=11)
        sims2 = [(w, sim) for w, sim in sims2 if w != 'graph']  # ignore 'graph' itself
        self.assertEqual(sims, sims2)

@dkim010
Copy link
Contributor Author

dkim010 commented Mar 3, 2017

Thank you for the quick reply!

I think that most_similar_cosmul() method allows only the string (or a string list) as the positive/negative parameters.
The method is related to the most_similar() method and both methods cannot pass the vectors of the words.
Is my idea wrong?

bug fix

Signed-off-by: Dongwon Kim <dongwon.kim@navercorp.com>
@tmylk
Copy link
Contributor

tmylk commented Mar 3, 2017

most_similar works with vectors and most_similar_cosmul is expected to work too https://github.com/RaRe-Technologies/gensim/blob/develop/gensim/test/test_word2vec.py#L360

@dkim010
Copy link
Contributor Author

dkim010 commented Mar 3, 2017

Okay, I'll fix it.

* add a test case for most_similar_cosmul

Signed-off-by: Dongwon Kim <dongwon.kim@navercorp.com>
@dkim010
Copy link
Contributor Author

dkim010 commented Mar 3, 2017

I fixed it. most_similar_cosmul works with vectors!
I refered most_similar.

@tmylk tmylk merged commit 4f0e2ae into piskvorky:develop Mar 3, 2017
@tmylk
Copy link
Contributor

tmylk commented Mar 3, 2017

Thanks for the quick fix!

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.

None yet

2 participants