def sentence_gleu(reference, hypothesis, min_len=1, max_len=4):
 ref_ngrams = Counter(everygrams(reference, min_len, max_len))
 hyp_ngrams = Counter(everygrams(hypothesis, min_len, max_len))
 overlap_ngrams = (ref_ngrams & hyp_ngrams)
 tp = sum(overlap_ngrams.values())
 tpfp = sum(hyp_ngrams.values())
 tffn = sum(ref_ngrams.values())
 precision = (tp / tpfp)
 recall = (tp / tffn)
 return min(precision, recall)

def sentence_gleu ( reference , hypothesis , min_len = 1 , max_len = 4 ) : ref_ngrams = Counter ( everygrams ( reference , min_len , max_len ) ) hyp_ngrams = Counter ( everygrams ( hypothesis , min_len , max_len ) ) overlap_ngrams = ( ref_ngrams & hyp_ngrams ) tp = sum ( overlap_ngrams . values ( ) ) tpfp = sum ( hyp_ngrams . values ( ) ) tffn = sum ( ref_ngrams . values ( ) ) precision = ( tp / tpfp ) recall = ( tp / tffn ) return min ( precision , recall )
calculates the sentence level gleu score described in yonghui wu .