(ids_BxI, dtype=tf.float32, padding_id=0)
return bias_Bx1xI
Convert ids to attention bias for attention.
Convert ids to attention bias for attention.
Convert ids to attention bias for attention .
def ids_to_bias(ids_BxI, dtype=tf.float32, padding_id=0):
  """Convert ids to attention bias for attention."""
  pad_BxI = tf.cast(tf.equal(ids_BxI, padding_id), dtype)
  bias_Bx1xI = tf.expand_dims(pad_BxI * dtype.min, axis=1)
  return bias_Bx1xI
def ids_to_bias ( ids_BxI , dtype = tf . float32 , padding_id = 0 ) : pad_BxI = tf . cast ( tf . equal ( ids_BxI , padding_id ) , dtype ) bias_Bx1xI = tf . expand_dims ( pad_BxI * dtype . min , axis = 1 ) return bias_Bx1xI