def make_sequences_compatible(seq1, seq2, op_type="max_pool"):
  """Preprocesses sequences to make them compatible for computing a loss.

  Args:
    seq1: <type> [batch_size, seq_len, ...].
    seq2: <type> [batch_size, seq_len, ...].
    op_type: String for the operation type. Must be one of
      {"avg_pool", "max_pool", "truncate"}.

  Returns:
    new_seq1, new_seq2: <type> [batch_size, ...] for preprocessed sequences.

  Raises:
    ValueError: if op_type is unknown.
  """
  if op_type not in {"avg_pool", "max_pool", "truncate"}:
    raise ValueError("Unknown op_type: %s" % op_type)

  if op_type == "avg_pool":
    new_seq1 = tf.reduce_mean(seq1, axis=1)
    new_seq2 = tf.reduce_mean(seq2, axis=1)
  elif op_type == "max_pool":
    new_seq1 = tf.reduce_max(seq1, axis=1)
    new_seq2 = tf.reduce_max(seq2, axis=1)
  elif op_type == "truncate":
    max_length = tf.minimum(tf.shape(seq1)[1], tf.shape(seq2)[1])
    new_seq1 = seq1[:, :max_length, :]
    new_seq2 = seq2[:, :max_length, :]

  return  new_seq1, new_seq2
Preprocesses sequences to make them compatible for computing a loss.

  Args:
    seq1: <type> [batch_size, seq_len, ...].
    seq2: <type> [batch_size, seq_len, ...].
    op_type: String for the operation type. Must be one of
      {"avg_pool", "max_pool", "truncate"}.

  Returns:
    new_seq1, new_seq2: <type> [batch_size, ...] for preprocessed sequences.

  Raises:
    ValueError: if op_type is unknown.
  
language/labs/consistent_zero_shot_nmt/utils/model_utils.py