def corpus_chrf(list_of_references, hypotheses, min_len=1, max_len=6, beta=3.0):
 assert (len(list_of_references) == len(hypotheses)), 'The number of hypotheses and their references should be the same'
 for (reference, hypothesis) in zip(list_of_references, hypotheses):
  if (type(reference) and (type(hypothesis) != str)):
   (reference, hypothesis) = (' '.join(reference), ' '.join(hypothesis))
  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)
 factor = (beta ** 2)
 score = (((1 + factor) * (precision * recall)) / ((factor * precision) + recall))
 return score

def corpus_chrf ( list_of_references , hypotheses , min_len = 1 , max_len = 6 , beta = 3.0 ) : assert ( len ( list_of_references ) == len ( hypotheses ) ) , 'The number of hypotheses and their references should be the same' for ( reference , hypothesis ) in zip ( list_of_references , hypotheses ) : if ( type ( reference ) and ( type ( hypothesis ) != str ) ) : ( reference , hypothesis ) = ( ' ' . join ( reference ) , ' ' . join ( hypothesis ) ) 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 ) factor = ( beta ** 2 ) score = ( ( ( 1 + factor ) * ( precision * recall ) ) / ( ( factor * precision ) + recall ) ) return score
calculates the corpus level chrf .