class_docstr: Compute the BLEU score for Machine Translation scenarios. The implementation is based on sacrebleu.
docstr: Compute the corpus-level metric based on all reqeust_states.
code: def evaluate_instances(
      self, request_states: List[RequestState]
  ) -> List[Stat]:
      """
      Compute the corpus-level metric based on all reqeust_states.
      """
  
      bleu = BLEU()
  
      refs: List[List[str]] = [[]]
      sys: List = []
      for request_state in request_states:
          # Assume there is one referece per instance. TODO: Support multiple references after adding more scenarios.
          num_references: int = len(request_state.instance.references)
          if num_references != 1:
              raise ValueError(
                  f"This instance has {num_references} references, but we currently only support one."
              )
          # Usually there is only one completion for each instance.
          assert request_state.result is not None
          if len(request_state.result.completions) != 1:
              raise ValueError(
                  "Each request result should have only exactly one completion."
              )
          sys.append(request_state.result.completions[0].text)
          refs[0].append(
              request_state.instance.references[0].output.text
          )
      bleu_score = bleu.corpus_score(sys, refs).score
      return [Stat(MetricName("bleu")).add(bleu_score)]
  
file_path: H2O/h2o_hf/helm/src/helm/benchmark/metrics/machine_translation_metrics.py
imports: from typing import List
  from sacrebleu import BLEU
  from helm.benchmark.adaptation.request_state import RequestState
  from .metric import Metric
  from .metric_name import MetricName
  from .statistic import Stat
label_desc: Use image node_id 1 for calling the MachineTranslationMetric obj's underlying member method code with example usage: obj.evaluate_instances(request_states) and returns: list