Beispiel #1
0
def BLEU(hyp, ref):
    # print 'BLEU'
    metric = 0.0
    hyp_list = split_by_words_and_punctuation(hyp.lower())
    ref_list = split_by_words_and_punctuation(ref.lower())
    hyp_len = len(hyp_list)
    ref_len = len(ref_list)
    h_list = split_into_ngramm(hyp, 5)
    r_list = split_into_ngramm(ref, 5)

    if ref_len < hyp_len:
        Bp = 1
    else:
        Bp = exp(1 - (float(hyp_len) / ref_len))
    sum = 0.0
    N = 4
    for i in range(1, N + 1):
        try:
            p = log(Pn(h_list, r_list, i), 2)
        except:
            p = -99999
        sum += (p / float(N))

    metric = Bp * exp(sum)
    print 'BLEU =', metric
    return metric
Beispiel #2
0
def BLEU(hyp, ref):
    # print 'BLEU'
    metric = 0.0
    hyp_list = split_by_words_and_punctuation(hyp.lower())
    ref_list = split_by_words_and_punctuation(ref.lower())   
    hyp_len = len(hyp_list)
    ref_len = len(ref_list)
    h_list = split_into_ngramm(hyp, 5)
    r_list = split_into_ngramm(ref, 5)
    
    if ref_len < hyp_len:
        Bp = 1
    else:
        Bp = exp(1-(float(hyp_len)/ref_len))    
    sum = 0.0
    N = 4
    for i in range(1, N+1):
        try:
            p = log(Pn(h_list, r_list, i), 2)        
        except:
            p = -99999
        sum += (p/float(N))

    metric = Bp*exp(sum)
    print 'BLEU =', metric
    return metric
Beispiel #3
0
def bitext(orig, trans):
    for (o, t) in zip(orig, trans):
        yield (split_into_ngramm(o, 5), split_into_ngramm(t, 5))
Beispiel #4
0
def bitext(orig, trans):
    for (o, t) in zip(orig, trans):        
        yield (split_into_ngramm(o, 5), split_into_ngramm(t, 5))