def sparse_to_dense_1d(sparse_values: tf.Tensor, seq_length: int):
  """Convert sparse tensor ([0, 1, 4]) to dense tensor ([1, 1, 0, 0, 1])."""
  updates = tf.fill(tf.shape(sparse_values), value=1)
  updates = tf.cast(updates, sparse_values.dtype)
  return tf.scatter_nd(tf.expand_dims(sparse_values, 1), updates, [seq_length])
Convert sparse tensor ([0, 1, 4]) to dense tensor ([1, 1, 0, 0, 1]).
language/mentionmemory/utils/mention_preprocess_utils.py