code: def test_rouge_metrics(candidates, references):
      for multiref in ["average", "best"]:
          # PERL 1.5.5 reference
          apply_avg = multiref == "average"
          apply_best = multiref == "best"
          evaluator = pyrouge.Rouge(
              metrics=["rouge-n", "rouge-l"],
              max_n=4,
              apply_avg=apply_avg,
              apply_best=apply_best,
              alpha=0.5,
              stemming=False,
              ensure_compatibility=False,
          )
          scores = evaluator.get_scores(candidates, references)
  
          lower_split_references = [
              [ref.lower().split() for ref in refs_per_candidate]
              for refs_per_candidate in references
          ]
  
          lower_split_candidates = [
              candidate.lower().split() for candidate in candidates
          ]
  
          m = Rouge(
              variants=[1, 2, 4, "L"], multiref=multiref, alpha=0.5
          )
          m.update((lower_split_candidates, lower_split_references))
          results = m.compute()
  
          for key in ["1", "2", "4", "L"]:
              assert (
                  pytest.approx(results[f"Rouge-{key}-R"], abs=1e-4)
                  == scores[f"rouge-{key.lower()}"]["r"]
              )
              assert (
                  pytest.approx(results[f"Rouge-{key}-P"], abs=1e-4)
                  == scores[f"rouge-{key.lower()}"]["p"]
              )
              assert (
                  pytest.approx(results[f"Rouge-{key}-F"], abs=1e-4)
                  == scores[f"rouge-{key.lower()}"]["f"]
              )
  
imports: import os
  import nltk
  import pytest
  import rouge
  import torch
  import ignite.distributed
  from ignite.exceptions import NotComputableError
  from ignite.metrics.nlp import Rouge
  from ignite.metrics.nlp.rouge import compute_ngram_scores, RougeL, RougeN
  from .None import CorpusForTest
label_desc: Use image node_id 4 for calling a global function with example usage: test_rouge_metrics(candidates, references) without return types