def calc_distinct_k(self, k):
d = {}
tot = 0
for sen in self.hyps:
for i in range(0, len(sen)-k):
key = tuple(sen[i:i+k])
d[key] = 1
tot += 1
if tot > 0:
dist = len(d) / tot
else:
warnings.warn('the distinct is invalid')
dist = 0.
return dist
D-1案例如下:
reference3 = '我 说 这 是 怎 么 回 事,原 来 明 天 要 放 假 了'
reference2 = '我 说 这 是 怎 么 回 事'
hypothesis2 = '我 说 这 是 啥 呢 我 说 这 是 啥 呢'
a=[reference3, reference2]
def calc_distinct_k(a, k):
d = {}
tot = 0
for sen in a:
for i in range(0, len(sen)-k):
key = tuple(sen[i:i+k])
d[key] = 1
tot += 1
if tot > 0:
dist = len(d) / tot
else:
warnings.warn('the distinct is invalid')
dist = 0.
return dist
print(calc_distinct_k(a,1))
#0.38636363636363635
理论为下
总而言之,这个东西就是比较生成的多样性,没有办法判断是不是准确。
代码参考:ACL2022-MISC
下面截图为:BLEU1-2, DISTINCT1,Perplexity(描述句子本身像不像一句人话,不跟标签比对)_愚昧之山绝望之谷开悟之坡的博客-CSDN博客_distinct指标