1. 安装相关包
(1)spacy
github地址:https://github.com/explosion/spaCy
pip install spacy
python -m spacy download en_core_web_sm # 安装模型包
python -m spacy download en_core_web_md # 安装模型包
(2)wmd
github地址:https://github.com/src-d/wmd-relax
pip install wmd
2. Python Demo
(1) 使用spacy加载模型
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("This is a sentence.")
(2)使用wmd计算两个句子的wmd匹配程度
import numpy
import spacy
from wmd import WMD
nlp = spacy.load('en_core_web_md')
doc1 = nlp("Politician speaks to the media in Illinois.")
doc2 = nlp("The president greets the press in Chicago.")
print(doc1.similarity(doc2))