Ejemplo n.º 1
0
        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]:
    """"Returns the eval score (e.g. BLEU) of the hyp sents using reference trg sents
Ejemplo n.º 2
0
 def setUp(self):
     self.evaluator = metrics.GLEUEvaluator()