Find most similar sentence in the file to the input sentence | NLP
In this article, we will find the most similar sentence in the file to the input sentence.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
File content: "This is movie." "This is romantic movie" "This is a girl." Input: "This is a boy" Similar sentence to input: "This is a girl", "This is movie".
- Create a list to store all the unique words of the file.
- Convert all the sentences of the file into the binary format by comparing each word with the content of the list, after cleaning(removing stopword, stemming, etc.)
- Convert the input sentence in the binary format.
- Find the number of similar words in the input sentence to each sentence and store the value in the list named similarity index.
- Find the maximum value of similarity index and return the sentence having maximum similar words.
Content of the file:
Code to get a similar sentence: