Build masks for this batch.

  Args:
    source: (batch, source_len) array of integer-coded symbols for inputs
    target_in: (batch, batch_len) array of integer-coded symbols for targets
    pad: int: the padding symbol used to pad the above

  Returns:
    Prepared batch of tuple of arrays: source, input-target, shifted-target,
    source mask, target mask, source-target "memory" mask, minibatch token count

def PreparePairedSequenceBatch(source, target_in, pad=0):
  """Build masks for this batch.

  Args:
    source: (batch, source_len) array of integer-coded symbols for inputs
    target_in: (batch, batch_len) array of integer-coded symbols for targets
    pad: int: the padding symbol used to pad the above

  Returns:
    Prepared batch of tuple of arrays: source, input-target, shifted-target,
    source mask, target mask, source-target "memory" mask, minibatch token count
  """
  target = target_in[:, :-1]
  target_y = target_in[:, 1:]
  source_mask = np.reshape(source != pad,
                           (source.shape[0], 1, 1, source.shape[-1]))
  target_mask = MakeTargetMask(target, pad)
  memory_mask = (
      np.reshape(np.arange(target.shape[-1]) < source.shape[-1], [-1, 1]))
  ntokens = np.sum(target_y != pad)
  return (source, target, target_y,
          source_mask, target_mask, memory_mask, ntokens)