python - 使用 word2vec / wordnet 的两个列表之间的余弦相似度
问题描述
可以使用 word2vec 预训练模型 (GoogleNews-vectors-negative300) 或 wordnet 获得两个单词列表之间的相似度平均值:
dic_email=['email','e-mail','address'] # dictionary of email contain word similar to email
dic_identity=['name','first','last','identity','forename']
lista = ['fullname','user'] # fullname is similar to name
listb = ['phone','number']
resa=lista.compare(dic_email,dic_identity) #just an example of my function compare
restb=listb.compare(dic_email,dic_identity)
print('the percent of similarity is :'+resa)
print('the percent of similarity is :'+resb)
结果应该是:
the percent of similarity is : [('dic_identity',0.8),('dic_email',0.0)] # i just gives a rondom percent to explain lista is similar to dic_identity beacause fullname is similar to the item in dic_identity
the percent of similarity is : [('dic_identity',0.0),('dic_email',0.0)]
解决方案
推荐阅读
- angularjs - 如何从angularjs的ui-grid中的单元格模板多次调用函数?
- scala - 如何使用折叠在 Scala 中创建不可变的 Map?
- openssl - openssl 结构在 openssl-1.1.1 中变得不透明
- puppet - puppet apply vs puppet agent -t
- mysql - 在 MYSQL Sp 中传递 JSON 列表作为输入
- jsf - 尝试有条件地渲染面板时更新属性未按预期工作
- java - 数组中的Java匹配模式
- java - 在 LIBGDX 中隐藏敌人
- symfony - 在管道中编辑 env 文件
- java - 如何在运行时使用条件在 log4j 配置文件之间切换