docstr: Takes gold and predicted answer sets and first finds the optimal 1-1 alignment
  between them and gets maximum metric values over all the answers.
docstr_tok: ["Takes","gold","and","predicted","answer","sets","and","first","finds","the","optimal","1-1","alignment","between","them","and","gets","maximum","metric","values","over","all","the","answers","."]
code: def _align_bags(
      self, predicted: List[Set[str]], gold: List[Set[str]]
  ) -> List[float]:
      """
      Takes gold and predicted answer sets and first finds the optimal 1-1 alignment
      between them and gets maximum metric values over all the answers.
      """
      scores = np.zeros([len(gold), len(predicted)])
      for gold_index, gold_item in enumerate(gold):
          for pred_index, pred_item in enumerate(predicted):
              scores[gold_index, pred_index] = self._compute_f1(
                  pred_item, gold_item
              )
      row_ind, col_ind = linear_sum_assignment(-scores)
  
      max_scores = np.zeros([max(len(gold), len(predicted))])
      for row, column in zip(row_ind, col_ind):
          max_scores[row] = max(max_scores[row], scores[row, column])
      return max_scores
  
imports: import re
  import string
  from typing import Dict, List, Set, Tuple, Union
  import numpy
  from pytext.common.constants import Stage
  from pytext.metric_reporters.channel import Channel, ConsoleChannel, FileChannel
  from pytext.metric_reporters.metric_reporter import MetricReporter
  from pytext.metrics.squad_metrics import SquadMetrics
  from pytext.utils.data import merge_token_labels_to_slot, parse_slot_string, Slot
  from scipy.optimize import linear_sum_assignment
label_desc: Use image node_id 16 for calling the MultiSpanQAMetricReporter obj's underlying member method code with example usage: obj._align_bags(predicted, gold) and returns: max_scores