code: def paired_bootstrap_resample(
      baseline_stats: pd.DataFrame,
      new_stats: pd.DataFrame,
      num_samples: int = 1000,
      sample_size: Optional[int] = None,
  ) -> PairedBootstrapOutput:
      """
      From http://aclweb.org/anthology/W04-3250
      Statistical significance tests for machine translation evaluation (Koehn, 2004)
      """
      assert len(baseline_stats) == len(new_stats), (
          f"Length mismatch - baseline has {len(baseline_stats)} lines "
          f"while new has {len(new_stats)} lines."
      )
      num_sentences = len(baseline_stats)
      if not sample_size:
          # Defaults to sampling new corpora of the same size as the original.
          # This is not identical to the original corpus since we are sampling
          # with replacement.
          sample_size = num_sentences
      indices = np.random.randint(
          low=0, high=num_sentences, size=(num_samples, sample_size)
      )
  
      baseline_better: int = 0
      new_better: int = 0
      num_equal: int = 0
      for index in indices:
          baseline_bleu = calc_bleu_from_stats(
              baseline_stats.iloc[index]
          ).score
          new_bleu = calc_bleu_from_stats(new_stats.iloc[index]).score
          if new_bleu > baseline_bleu:
              new_better += 1
          elif baseline_bleu > new_bleu:
              baseline_better += 1
          else:
              # If the baseline corpus and new corpus are identical, this
              # degenerate case may occur.
              num_equal += 1
  
      return PairedBootstrapOutput(
          baseline_bleu=calc_bleu_from_stats(baseline_stats),
          new_bleu=calc_bleu_from_stats(new_stats),
          num_samples=num_samples,
          baseline_better=baseline_better,
          num_equal=num_equal,
          new_better=new_better,
      )
  
file_path: translate/pytorch_translate/bleu_significance.py
imports: import argparse
  from typing import List, NamedTuple, Optional
  import numpy
  import pandas
  import sacrebleu
label_desc: Use image node_id 3 for calling a global function with example usage: paired_bootstrap_resample(baseline_stats, new_stats, num_samples, sample_size) and returns: PairedBootstrapOutput