piskvorky / gensim

Topic Modelling for Humans
https://radimrehurek.com/gensim
GNU Lesser General Public License v2.1
15.71k stars 4.38k forks source link

parameter topN=False is not working in similar_by_vector. #2431

Open mingwei-liu opened 5 years ago

mingwei-liu commented 5 years ago

Problem description

parameter topN=False is not working in similar_by_vector. I got empty list when set topN=False.

Steps/code/corpus to reproduce

       full_node2vec_model = Word2VecKeyedVectors.load(node2vec_path)
        vector=full_node2vec_model["1"]
        result=full_node2vec_model.similar_by_vector(vector=vector,topn=10)
        print(result)

        result = full_node2vec_model.similar_by_vector(vector=vector, topn=False)
        print(result)

Problem

code in similar_by_vector just call most_similar.

        return self.most_similar(positive=[vector], topn=topn, restrict_vocab=restrict_vocab)

most_similar returns [] when TopN=False

        if topn is not None and topn < 1:
            return []

Versions

Windows-10-10.0.17134-SP0
Python 3.6.7 |Anaconda, Inc.| (default, Oct 28 2018, 19:44:12) [MSC v.1915 64 bit (AMD64)]
NumPy 1.15.4
SciPy 1.1.0
gensim 3.7.1
FAST_VERSION 1
gojomo commented 5 years ago

I believe it's just the doc-comment that's wrong, and in fact you should supply None if you want the unsorted report of all similarities. Do you get the desired result if you supply None?

mingwei-liu commented 5 years ago

Yes, it work when the topN=None