code: def edit_distance_filter(
      source_target_input, max_equal_to_diff_ratio=0
  ):
      """Filter out examples that exceed max_edit_ratio between source and target.
  
      Args:
        source_target_input:     a list of [source, target] pairs
        max_equal_to_diff_ratio: cutoff for ratio of equal chars / diff chars
          between source and target
  
      Returns:
        source_target_output:    filtered subset of [source, target] input pairs
        thrown_out_count:        number of examples filtered out
      """
      thrown_out_count = 0
      source_target_output = []
  
      if not max_equal_to_diff_ratio:
          return source_target_input, thrown_out_count
  
      for src_tgt in source_target_input:
          opcodes = fast_match_sequences(*src_tgt)
          diff_char_count = 0
          equal_char_count = 0
          for tag, i1, i2, j1, j2 in opcodes:
              if tag == "diff":
                  # max() prevents double-counting substitutions.
                  diff_char_count += max(i2 - i1, j2 - j1)
              else:
                  equal_char_count += i2 - i1
          if (
              diff_char_count
              <= max_equal_to_diff_ratio * equal_char_count
          ):
              source_target_output.append(src_tgt)
          else:
              thrown_out_count += 1
      return source_target_output, thrown_out_count
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import os
  import random
  import re
  import subprocess
  from tensor2tensor.data_generators import generator_utils
  from tensor2tensor.data_generators import text_encoder
  import tensorflow.compat.v1
label_desc: Use image node_id 24 for calling a global function with example usage: edit_distance_filter(source_target_input, max_equal_to_diff_ratio) and returns: source_target_output,  thrown_out_count, source_target_input,  thrown_out_count