如何解释fairseq生成的P数?

2024-06-14 20:06:12 发布

您现在位置:Python中文网/ 问答频道 /正文

使用fairseq-generate.py和transformer体系结构,每次转换都会生成如下部分:

Why is it rare to discover new marine mammal species?
S-0     Why is it rare to discover new marine mam@@ mal species ?
H-0     -0.0643349438905716     Pourquoi est-il rare de découvrir de nouvelles espèces de mammifères marins?
P-0     -0.0763 -0.1849 -0.0956 -0.0946 -0.0735 -0.1150 -0.1301 -0.0042 -0.0321 -0.0171 -0.0052 -0.0062 -0.0015

this explanation一起:

H is the hypothesis along with an average log-likelihood; and P is the positional score per token position, including the end-of-sentence marker

我想知道,如果说p行中的一个低(绝对)数字意味着对这个特定单词的信心更高,这是否合理?例如,“Pourquoi”的-0.07是否意味着它比“est il”的-0.1849更快乐?最后的低-0.0015意味着它确信判决应该在这里结束

背景:我想弄清楚的是,我是否可以使用H数,或者以某种方式使用单个的p数,来获得其翻译的置信度。我一直在根据H数分析一些翻译,并没有注意到它和我对翻译质量的主观看法之间有多少对应关系。但我有一对夫妇,我认为它特别差-它错过了一些关键信息-最终的P数是一个相对较高的-0.6099-0.3091(最终的P数是-0.11左右,大多数都是如此。)


Tags: thetonewisdeitilest
1条回答
网友
1楼 · 发布于 2024-06-14 20:06:12

Q: I'm wondering if it is reasonable to say a low (absolute) number in the P row means higher confidence in that particular word?

  • 对。正如文档所说,“P是每个标记位置的位置分数”。分数实际上是对数概率,因此越高(即绝对数越低)越“自信”。源代码可能不那么容易理解,但是分数是由^{}生成的,在那里您可以看到分数是标准化的(如果您使用single modelensemble,它包括一个log)。此外,在打印分数时,他们convert them from base e to 2

    print('P-{}\t{}'.format(
        sample_id,
        ' '.join(map(
            lambda x: '{:.4f}'.format(x),
            # convert from base e to base 2
            hypo['positional_scores'].div_(math.log(2)).tolist(),
    ))
    

Q: What I'm trying to work out is if I can use either the H number, or somehow to use the individual P numbers, to get a confidence measure in its translation.

  • 结果表明,H值只是p值的平均值,如您所见here

    score_i = avg_probs_i.sum() / tgt_len
    

    还有converted to base 2。您可以在示例中检查:

    import numpy as np
    print(np.mean([-0.0763,-0.1849 ,-0.0956 ,-0.0946 ,-0.0735 ,-0.1150 ,-0.1301 ,-0.0042 ,-0.0321 ,-0.0171 ,-0.0052 ,-0.0062 ,-0.0015]))
    # >>> -0.06433076923076922
    

    另一个常用于评估语言模型性能的度量是Perplexity。一件好事是,可以根据P值轻松计算复杂度,如fairseq存储库的Language Model example所示:

    # Compute perplexity for a sequence
    en_lm.score('Barack Obama is coming to Sydney and New Zealand')['positional_scores'].mean().neg().exp()
    # tensor(15.1474)
    

    我不是NLP方面的专家,所以我真的不能告诉你在你的案例中应该使用哪一个

相关问题 更多 >