code: def _compute_rouge_score(
      preds: Union[str, Sequence[str]],
      target: Union[str, Sequence[Union[str, Sequence[str]]]],
      use_stemmer: bool,
      rouge_level: str,
      metric: str,
      accumulate: Literal["avg", "best", None],
  ) -> Tensor:
      """Evaluate rouge scores from rouge-score package for baseline evaluation."""
      if isinstance(target, list) and all(
          isinstance(tgt, str) for tgt in target
      ):
          target = (
              [target]
              if isinstance(preds, str)
              else [[tgt] for tgt in target]
          )
  
      if isinstance(preds, str) and accumulate:
          preds = [preds]
  
      if isinstance(target, str) and accumulate:
          target = [[target]]
  
      scorer = RougeScorer(ROUGE_KEYS, use_stemmer=use_stemmer)
      if not accumulate:
          rs_scores = scorer.score(target, preds)
          rs_result = getattr(rs_scores[rouge_level], metric)
          return torch.tensor(rs_result, dtype=torch.float)
  
      aggregator = BootstrapAggregator()
  
      for target_raw, pred_raw in zip(target, preds):
          list_results = [
              scorer.score(tgt, pred_raw) for tgt in target_raw
          ]
          aggregator_avg = BootstrapAggregator()
  
          if accumulate == "best":
              key_curr = next(iter(list_results[0].keys()))
              all_fmeasure = torch.tensor(
                  [v[key_curr].fmeasure for v in list_results]
              )
              highest_idx = torch.argmax(all_fmeasure).item()
              aggregator.add_scores(list_results[highest_idx])
          elif accumulate == "avg":
              for _score in list_results:
                  aggregator_avg.add_scores(_score)
              _score = {
                  rouge_key: scores.mid
                  for rouge_key, scores in aggregator_avg.aggregate().items()
              }
              aggregator.add_scores(_score)
          else:
              raise ValueError(
                  f"Got unknown accumulate value {accumulate}. Expected to be one of ['best', 'avg']"
              )
  
      rs_scores = aggregator.aggregate()
      rs_result = getattr(rs_scores[rouge_level].mid, metric)
      return torch.tensor(rs_result, dtype=torch.float)
  
imports: import re
  from functools import partial
  from typing import Callable, Sequence, Union
  import pytest
  import torch
  from torch import Tensor
  from torchmetrics.functional.text.rouge import rouge_score
  from torchmetrics.text.rouge import ROUGEScore
  from torchmetrics.utilities.imports import _NLTK_AVAILABLE, _ROUGE_SCORE_AVAILABLE
  from typing_extensions import Literal
  from unittests.text.helpers import TextTester, skip_on_connection_issues
  from unittests.text.inputs import _Input, _inputs_multiple_references, _inputs_single_sentence_single_reference
label_desc: Use image node_id 1 for calling a global function with example usage: _compute_rouge_score(preds, target, use_stemmer, rouge_level, metric, accumulate) and returns: torch, torch