当前位置:网站首页>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
边栏推荐
- A slow SQL drags the whole system down
- 子组件传递给父组件
- Algorithm --- bit count (kotlin)
- How can gyms improve their competitiveness?
- 工具类:对象转map 驼峰转下划线 下划线转驼峰
- 一条慢SQL拖死整个系统
- Several index utilization of joint index ABC
- 【mysqld】Can't create/write to file
- Sqlserver multithreaded query problem
- SolidWorks GB Library (steel profile library, including aluminum profile, aluminum tube and other structures) installation and use tutorial (generating aluminum profile as an example)
猜你喜欢
随机推荐
【JDBC以及内部类的讲解】
sqlserver多线程查询问题
Paranoid unqualified company
Bus消息总线
数据资产管理与数据安全国内外最新趋势
Graduation design game mall
AddressSanitizer 技术初体验
Get the city according to IP
Answer to the first stage of the assignment of "information security management and evaluation" of the higher vocational group of the 2018 Jiangsu Vocational College skills competition
.net 5 FluentFTP连接FTP失败问题:This operation is only allowed using a successfully authenticated context
MySQL SQL的完整处理流程
How to model and simulate the target robot [mathematical / control significance]
2018 Jiangsu Vocational College skills competition vocational group "information security management and evaluation" competition assignment
【NOI模拟赛】区域划分(结论,构造)
Learning records on July 4, 2022
The latest trends of data asset management and data security at home and abroad
Under what circumstances should we consider sub database and sub table
剑指offer-高质量的代码
详解机器翻译任务中的BLEU
AVL树的实现









