Skip to content
Advertisement

Doc2Vec find the similar sentence

I am trying find similar sentence using doc2vec. What I am not able to find is actual sentence that is matching from the trained sentences.

Below is the code from this article:

JavaScript

But the above code only gives me vectors or numbers. But how can I get the actual sentence matched from training data. For Eg – In this case I am expecting the result as “I love building chatbots”.

Advertisement

Answer

The output of similar_doc is: [('2', 0.991769552230835), ('0', 0.989276111125946), ('3', 0.9854298830032349)]

This shows the similarity score of each document in the data with the requested document and it is sorted in descending order.

Based in this, '2' index in the data is the closest to the requested data i.e. test_data.

JavaScript

Note: this code is giving different results every time, maybe you need a better model or more training data.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement