// For each order of ngram, calculate the no. of ngram matches and
// keep track of no. of ngram in references.
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()) // True positives.
tpfp = sum(hyp_ngrams.values()) // True positives + False positives.
tpfn = sum(ref_ngrams.values()) // True positives + False negatives.
// While defined as the minimum of precision and recall, we can
// reduce the number of division operations by one by instead finding
// the maximum of the denominators for the precision and recall
// formulae, since the numerators are the same:
// precision = tp / tpfp
// recall = tp / tpfn
// min(precision, recall) == tp / max(tpfp, tpfn)
return tp / max(tpfp, tpfn)
def corpus_gleu(references, hypotheses, min_len=1, max_len=4):