📜  句子相似度 spacy - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:56.787000             🧑  作者: Mango

代码示例1
# 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)