Ejemplo n.º 1
0
        loc_: str,
        post_process: Optional[Callable[[str], str]] = None) -> List[str]:
    """Reads the lines in the file specified in loc_ and return the list after inserting the tokens
  """
    data = list()
    with open(loc_, encoding='utf-8') as fp:
        for line in fp:
            t = line.strip()
            if post_process is not None:
                t = post_process(t)
            data.append(t)
    return data


eval_shortcuts = {
    "bleu": lambda: metrics.BLEUEvaluator(),
    "gleu": lambda: metrics.GLEUEvaluator(),
    "wer": lambda: metrics.WEREvaluator(),
    "cer": lambda: metrics.CEREvaluator(),
    "recall": lambda: metrics.RecallEvaluator(),
    "accuracy": lambda: metrics.SequenceAccuracyEvaluator(),
    "fmeasure": lambda: metrics.FMeasureEvaluator(),
    "seg_fmeasure": lambda: metrics.SegmentationFMeasureEvaluator(),
    "rnng_parse_fmeasure": lambda: metrics.RNNGParseFMeasureEvaluator(),
}


def xnmt_evaluate(ref_file: Union[str, Sequence[str]],
                  hyp_file: Union[str, Sequence[str]],
                  evaluators: Sequence[metrics.Evaluator],
                  desc: Any = None) -> Sequence[metrics.EvalScore]:
Ejemplo n.º 2
0
 def test_bleu_1gram(self):
     bleu = metrics.BLEUEvaluator(ngram=1)
     exp_bleu = 3.0 / 5.0
     act_bleu = bleu.evaluate(self.ref, self.hyp).value()
     self.assertEqual(act_bleu, exp_bleu)