예제 #1
0
파일: admin.py 프로젝트: BergerV/denotat
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
예제 #2
0
파일: admin.py 프로젝트: BergerV/denotat
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
예제 #3
0
파일: admin.py 프로젝트: BergerV/denotat
def len_text(text):
    l = 0
    for s in text:
        l += len(split_by_words_and_punctuation(s.strip()))
    return l
예제 #4
0
파일: admin.py 프로젝트: BergerV/denotat
def len_text(text):
    l = 0
    for s in text:
        l += len(split_by_words_and_punctuation(s.strip()))        
    return l