doc2vec similarity from a list of documents code example

Example: doc2vec similarity

from gensim.models import doc2vec
from scipy import spatial

d2v_model = doc2vec.Doc2Vec.load(model_file)

fisrt_text = '..'
second_text = '..'

vec1 = d2v_model.infer_vector(fisrt_text.split())
vec2 = d2v_model.infer_vector(second_text.split())

similairty = spatial.distance.cosine(vec1, vec2)
# similarity is how much two text differ from each other, higher values mean more distinct texts