# Path: t5/evaluation/qa_utils.py
# def _normalize_answer(text, punc_chars, punc_repl):
#   def remove_articles(s):
#   def replace_punctuation(s):
#   def white_space_fix(s):
# def normalize_trivia_qa(answer):
# def normalize_squad(answer):
# def _metric_max_over_ground_truths(metric_fn, ground_truths, prediction):
# def _exact_match_score(target, prediction):
# def _f1_score(target, prediction):
# def qa_metrics(targets, predictions):


import collections
import itertools
import re
import string
import editdistance
import numpy as np
import sacrebleu
import scipy.stats
import sklearn.metrics
from typing import Dict, Mapping, Optional, Sequence, Tuple, Union
from absl import logging
from t5.evaluation import qa_utils
from rouge_score import rouge_scorer
from rouge_score import scoring
    try:
      start_index = int(answer_tokens[1])
      end_index = int(answer_tokens[3])
    except ValueError:
      return ""

    return " ".join(context[start_index:end_index+1])

  contexts = [space_tok(t["context"]) for t in targets]
  answers = [t["answers"] for t in targets]

  predictions = [space_tok(p) for p in predictions]
  final_predictions = [
      get_answer_text_from_context(c, p) for c, p in zip(contexts, predictions)
  ]

  return squad(answers, final_predictions)


def squad(targets, predictions):
  """Computes SQuAD metrics, maximizing over answers per question.

  Args:
    targets: list of lists of strings
    predictions: list of strings

  Returns:
    dict with score_key: squad score across all targets and predictions
  """
  targets = [[qa_utils.normalize_squad(t) for t in u] for u in targets]

# Path: t5/evaluation/qa_utils.py
# def _normalize_answer(text, punc_chars, punc_repl):
#   def remove_articles(s):
#   def replace_punctuation(s):
#   def white_space_fix(s):
# def normalize_trivia_qa(answer):
# def normalize_squad(answer):
# def _metric_max_over_ground_truths(metric_fn, ground_truths, prediction):
# def _exact_match_score(target, prediction):
# def _f1_score(target, prediction):
# def qa_metrics(targets, predictions):


# Path: t5/evaluation/metrics.py
import collections
import itertools
import re
import string
import editdistance
import numpy as np
import sacrebleu
import scipy.stats
import sklearn.metrics
from typing import Dict, Mapping, Optional, Sequence, Tuple, Union
from absl import logging
from t5.evaluation import qa_utils
from rouge_score import rouge_scorer
from rouge_score import scoring

    try:
      start_index = int(answer_tokens[1])
      end_index = int(answer_tokens[3])
    except ValueError:
      return ""

    return " ".join(context[start_index:end_index+1])

  contexts = [space_tok(t["context"]) for t in targets]
  answers = [t["answers"] for t in targets]

  predictions = [space_tok(p) for p in predictions]
  final_predictions = [
      get_answer_text_from_context(c, p) for c, p in zip(contexts, predictions)
  ]

  return squad(answers, final_predictions)


def squad(targets, predictions):
  """Computes SQuAD metrics, maximizing over answers per question.

  Args:
    targets: list of lists of strings
    predictions: list of strings

  Returns:
    dict with score_key: squad score across all targets and predictions
  """
  targets = [[qa_utils.normalize_squad(t) for t in u] for u in targets]

  predictions = [qa_utils.normalize_squad(p) for p in predictions]