Answers for "doc2vec similarity"

0

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
Posted by: Guest on December-07-2020

Python Answers by Framework

Browse Popular Code Answers by Language