Text similarity is the process of determining the two closest texts. Text similarity is very helpful in finding similar documents, questions, and queries. For example, a search engine such as Google uses similarity to find document relevance, and Q&A systems such as StackOverflow or a consumer service system use similar questions. There are two common metrics used for text similarity, namely Jaccard and cosine similarity.
We can also use the similarity method available in spaCy. The nlp object's similarity method returns a score between two sentences. Let's look at the following example:
# Import spacy
import spacy
# Load English model for tokenizer, tagger, parser, and NER
nlp = spacy.load('en')
# Create documents
doc1 = nlp(u'I love pets.')
doc2 = nlp(u'I hate pets')
# Find similarity
print(doc1.similarity(doc2))
This results in the following output:
0.724494176985974
<ipython-input-32-f157deaa344d>:12: UserWarning: [W007] The...