Answers for "sentence similarity spacy"

0

sentence similarity spacy

# credit to spacy documentation

import spacy

# replace your_language_model with:
# en_core_web_sm(_md, _lg for different size) for english
# it_core_news_sm for italian 
# etc. see spacy docs

nlp = spacy.load('your_language_model') 

# it works with single words too
sent1 = nlp('Your first sentence')
sent2 = nlp('Your second sentence')

# similarity ranges from 0 (totally dissimilar) to 1 (identical)

sent1.similarity(sent2)
Posted by: Guest on April-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language