当前位置:网站首页>Détailler le bleu dans les tâches de traduction automatique
Détailler le bleu dans les tâches de traduction automatique
2022-07-07 07:08:00 【Aelum】
Table des matières
Un.、 n n n Métagrammaire(N-Gram)
n n n Métagrammaire(n-gram)Dans le texteContinuIl est apparu n n n - Oui.Word Yuan.Quand n n n Respectivement: 1 , 2 , 3 1,2,3 1,2,3 Heure,n-gram Aussi appelé unigram(Syntaxe unidimensionnelle)、bigram(Syntaxe binaire)Et trigram(Syntaxe ternaire).
n n n Le modèle métagrammatical est basé sur n − 1 n-1 n−1 Un modèle de langage probabiliste pour les chaînes de Markov d'ordre(C'est - à - dire qu'avant seulement n − 1 n-1 n−1 Quand les mots apparaissent,La probabilité que ce dernier mot apparaisse):
unigram: P ( w 1 , w 2 , ⋯ , w T ) = ∏ i = 1 T P ( w i ) bigram: P ( w 1 , w 2 , ⋯ , w T ) = P ( x 1 ) ∏ i = 1 T − 1 P ( w i + 1 ∣ w i ) trigram: P ( w 1 , w 2 , ⋯ , w T ) = P ( x 1 ) P ( x 2 ∣ x 1 ) ∏ i = 1 T − 2 P ( w i + 2 ∣ w i , w i + 1 ) \begin{aligned} \text{unigram:}\quad&P(w_1,w_2,\cdots,w_T)=\prod_{i=1}^T P(w_i) \\ \text{bigram:}\quad&P(w_1,w_2,\cdots,w_T)=P(x_1)\prod_{i=1}^{T-1} P(w_{i+1}|w_i) \\ \text{trigram:}\quad&P(w_1,w_2,\cdots,w_T)=P(x_1)P(x_2|x_1)\prod_{i=1}^{T-2} P(w_{i+2}|w_{i},w_{i+1}) \\ \end{aligned} unigram:bigram:trigram:P(w1,w2,⋯,wT)=i=1∏TP(wi)P(w1,w2,⋯,wT)=P(x1)i=1∏T−1P(wi+1∣wi)P(w1,w2,⋯,wT)=P(x1)P(x2∣x1)i=1∏T−2P(wi+2∣wi,wi+1)
2.、BLEU(Bilingual Evaluation Understudy)
2.1 BLEU Définition
BLEU( Prononciation et mots blue Même chose.) Les premiers résultats ont été utilisés pour évaluer la traduction automatique , Mais il est maintenant largement utilisé pour évaluer la qualité des séquences de sortie dans de nombreuses applications . Pour les séries de prévisions pred Tout n n n Métagrammaire, BLEU C'est l'évaluation de n n n La métasyntaxe apparaît - elle dans la séquence des étiquettes label Moyenne.
BLEU Les définitions sont les suivantes::
BLEU = exp ( min ( 0 , 1 − len(label) len(pred) ) ) ∏ n = 1 k p n 1 / 2 n \text{BLEU}=\exp\left(\min\left(0,1-\frac{\text{len(label)}}{\text{len(pred)}}\right)\right)\prod_{n=1}^kp_n^{1/2^n} BLEU=exp(min(0,1−len(pred)len(label)))n=1∏kpn1/2n
Parmi eux len(*) \text{len(*)} len(*) Séquence représentative ∗ * ∗ Nombre d'éléments de mot dans , k k k Pour correspondre au plus long n n n Métagrammaire(Accès fréquent 4 4 4), p n p_n pn Représentation n n n Précision de la métagrammaire .
En particulier:,Compte tenu de label: A , B , C , D , E , F A,B,C,D,E,F A,B,C,D,E,F Et pred: A , B , B , C , D A,B,B,C,D A,B,B,C,D,Prends - le. k = 3 k=3 k=3.
Regardez d'abord. p 1 p_1 p1 Comment calculer.Nous allons d'abord pred Chaque unigram Tout est compté.: ( A ) , ( B ) , ( B ) , ( C ) , ( D ) (A),(B),(B),(C),(D) (A),(B),(B),(C),(D),Encore. label Chaque unigram Tout est compté.: ( A ) , ( B ) , ( C ) , ( D ) , ( E ) , ( F ) (A),(B),(C),(D),(E),(F) (A),(B),(C),(D),(E),(F), Et voir combien ils correspondent ( On ne peut pas répéter la correspondance , C'est - à - dire qu'une relation individuelle doit être maintenue ). On peut voir qu'il y a 4 4 4 Correspondance,Et pred Au total. 5 5 5 - Oui. unigram,Et donc, p 1 = 4 / 5 p_1=4/5 p1=4/5.
Regarde encore. p 2 p_2 p2 Comment calculer.Nous allons d'abord pred Chaque bigram Tout est compté.: ( A , B ) , ( B , B ) , ( B , C ) , ( C , D ) (A,B),(B,B),(B,C),(C,D) (A,B),(B,B),(B,C),(C,D),Encore. label Chaque bigram Tout est compté.: ( A , B ) , ( B , C ) , ( C , D ) , ( D , E ) , ( E , F ) (A,B),(B,C),(C,D),(D,E),(E,F) (A,B),(B,C),(C,D),(D,E),(E,F), Et voir combien ils correspondent . On peut voir qu'il y a 3 3 3 Correspondance,Et pred Au total. 4 4 4 - Oui. bigram,Et donc, p 2 = 3 / 4 p_2=3/4 p2=3/4.
Enfin... p 3 p_3 p3 Comment calculer.Nous allons d'abord pred Chaque trigram Tout est compté.: ( A , B , B ) , ( B , B , C ) , ( B , C , D ) (A,B,B),(B,B,C),(B,C,D) (A,B,B),(B,B,C),(B,C,D),Encore. label Chaque trigram Tout est compté.: ( A , B , C ) , ( B , C , D ) , ( C , D , E ) , ( D , E , F ) (A,B,C),(B,C,D),(C,D,E),(D,E,F) (A,B,C),(B,C,D),(C,D,E),(D,E,F), Et voir combien ils correspondent .On peut voir que seulement 1 1 1 Correspondance,Et pred Au total. 3 3 3 - Oui. trigram,Et donc, p 3 = 1 / 3 p_3=1/3 p3=1/3.
Donc, dans cet exemple BLEU Le score est
BLEU = exp ( min ( 0 , 1 − 6 / 5 ) ) ⋅ p 1 1 / 2 ⋅ p 2 1 / 4 ⋅ p 3 1 / 8 = e − 0.2 ⋅ ( 4 5 ) 1 / 2 ⋅ ( 3 4 ) 1 / 4 ⋅ ( 1 3 ) 1 / 8 ≈ 0.5940 \begin{aligned} \text{BLEU}&=\exp(\min(0,1-6/5))\cdot p_1^{1/2}\cdot p_2^{1/4}\cdot p_3^{1/8} \\ &=e^{-0.2}\cdot \left(\frac45\right)^{1/2}\cdot \left(\frac34\right)^{1/4}\cdot\left(\frac13\right)^{1/8} \\ &\approx0.5940 \end{aligned} BLEU=exp(min(0,1−6/5))⋅p11/2⋅p21/4⋅p31/8=e−0.2⋅(54)1/2⋅(43)1/4⋅(31)1/8≈0.5940
2.2 BLEU Discussion sur
Selon BLEU Définitions, .Lorsque la séquence prévue est identique à la séquence de l'étiquette ,BLEU La valeur de 1 1 1.D'un autre côté,Parce que e x > 0 e^x>0 ex>0 Et p n ≥ 0 p_n\geq0 pn≥0,Il y a donc
BLEU ∈ [ 0 , 1 ] \text{BLEU}\in[0,1] BLEU∈[0,1]
BLEU Plus la valeur est proche de 1 1 1, Cela signifie que l'effet de prédiction est meilleur ;BLEU Plus la valeur est proche de 0 0 0, Cela signifie que plus la prévision est mauvaise .
En outre,Parce que n n n Plus la métagrammaire est longue, plus il est difficile de faire correspondre , Alors... BLEU Pour plus long n n n La précision de la métagrammaire attribue plus de poids (Fixe a ∈ ( 0 , 1 ) a\in(0,1) a∈(0,1),Et a 1 / 2 n a^{1/2^n} a1/2n Va suivre n n n Une augmentation de).Et, Parce que plus la séquence de prédiction est courte p n p_n pn Plus la valeur est élevée,Donc le coefficient exp ( ⋅ ) \exp(\cdot) exp(⋅) Ce terme est utilisé pour punir les séquences de prédiction plus courtes .
2.3 BLEU Mise en œuvre simple de
import math
from collections import Counter
def bleu(label, pred, k=4):
# Nous supposons que l'entrée labelEtpred Tout a été segmenté
score = math.exp(min(0, 1 - len(label) / len(pred)))
for n in range(1, k + 1):
# Utilisez une table de hachage pour stocker labelTous lesn-gram
hashtable = Counter([' '.join(label[i:i + n]) for i in range(len(label) - n + 1)])
# Nombre de correspondances réussies
num_matches = 0
for i in range(len(pred) - n + 1):
ngram = ' '.join(pred[i:i + n])
if ngram in hashtable and hashtable[ngram] > 0:
num_matches += 1
hashtable[ngram] -= 1
score *= math.pow(num_matches / (len(pred) - n + 1), math.pow(0.5, n))
return score
Par exemple:
label = 'A B C D E F'
pred = 'A B B C D'
for i in range(4):
print(bleu(label.split(), pred.split(), k=i + 1))
# 0.7322950476607851
# 0.6814773296495302
# 0.5940339360503315
# 0.0
References
边栏推荐
- From zero to one, I will teach you to build the "clip search by text" search service (2): 5 minutes to realize the prototype
- Please ask a question, flick Oracle CDC, read a table without update operation, and repeatedly read the full amount of data every ten seconds
- freeswitch拨打分机号源代码跟踪
- Bus message bus
- jdbc数据库连接池使用问题
- Take you to brush (niuke.com) C language hundred questions (the first day)
- Bus消息总线
- Complete process of MySQL SQL
- Master-slave replication principle of MySQL
- sqlserver多线程查询问题
猜你喜欢

How can gyms improve their competitiveness?

. Net 5 fluentftp connection FTP failure problem: this operation is only allowed using a successfully authenticated context

IP address

剑指offer-高质量的代码

关于数据库数据转移的问题,求各位解答下

How to do sports training in venues?

2018年江苏省职业院校技能大赛高职组“信息安全管理与评估”赛项任务书第一阶段答案

Config分布式配置中心

. Net core accesses uncommon static file types (MIME types)

Academic report series (VI) - autonomous driving on the journey to full autonomy
随机推荐
MYSQL binlog相关命令
毕业设计游戏商城
Several index utilization of joint index ABC
MySQL binlog related commands
服装门店如何盈利?
Under what circumstances should we consider sub database and sub table
After the promotion, sales volume and flow are both. Is it really easy to relax?
How can clothing stores make profits?
多学科融合
MATLAB小技巧(30)非线性拟合 lsqcurefit
使用net core优势/为什么使用
Academic report series (VI) - autonomous driving on the journey to full autonomy
MySQL的主从复制原理
DHCP路由器工作原理
readonly 只读
Matlab tips (29) polynomial fitting plotfit
什么情况下考虑分库分表
leetcode 509. Fibonacci number
算法---比特位计数(Kotlin)
从零到一,教你搭建「CLIP 以文搜图」搜索服务(二):5 分钟实现原型