python生成相似句子_python-2个句子的语义相似性度量

s1 = "she is good a dog "

s2 = "she is nice a heel"

我需要证明“好”类似于“好”.对于名词和动词,按路径进行相似性度量的工作方式类似于此伪代码:

def get max :

for loop

(wn.synset ('dog ')).path_similarity(wn.synset ('animal'))

结果:.33,这是一个很高的值,那么这些词是相关的,我可以说这是相似的.但是对于副词(“ nice”和“ good”),. 09值很低!

有任何想法吗?

解决方法:

您可以找到所有好的同义词集的path_similarity然后选择最大值:

>>> from nltk.corpus import wordnet as wn

>>> n=wn.synsets('nice')

>>> g=wn.synsets('good')

>>> [i.path_similarity(n[0]) for i in g]

[0.0625, 0.06666666666666667, 0.07142857142857142, 0.09090909090909091, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]

>>> max(i.path_similarity(n[0]) for i in g)

0.09090909090909091

请注意,单词的同义词集包含单词的许多形式,例如动词,none,adj等,因此您需要选择适当的单词!

另外,您还可以使用wup_similarity:

>>> round(max(i.wup_similarity(n[0]) for i in g), 1)

0.4

Wu-Palmer Similarity: Return a score denoting how similar two word senses are, based on the depth of the two senses in the taxonomy and that of their Least Common Subsumer (most specific ancestor node).

标签:wordnet,nlp,semantics,python

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值