def attention_bias_ignore_padding(source_len, max_length):
  """Create a bias tensor to be added to attention logits.

  Out-of-range elements will have an effective negative-infinity value.

  Args:
    source_len: <int>[batch_size]
    max_length: Integer specifying maxmimum sequence length in batch.

  Returns:
    <float>[batch_size, 1, 1, max_length]
  """
  memory_padding = tf.to_float(
      tf.logical_not(tf.sequence_mask(source_len, maxlen=max_length)))
  ret = memory_padding * -1e9
  # Expand so tensor can be broadcast across heads and query length.
  return tf.expand_dims(tf.expand_dims(ret, axis=1), axis=1)
Create a bias tensor to be added to attention logits.

  Out-of-range elements will have an effective negative-infinity value.

  Args:
    source_len: <int>[batch_size]
    max_length: Integer specifying maxmimum sequence length in batch.

  Returns:
    <float>[batch_size, 1, 1, max_length]
  
language/xsp/model/common_layers.py