def embedding_to_non_padding(emb, dtype=tf.float32):
  """Calculates the padding mask based on which embeddings are not zero."""
  emb_sum = tf.reduce_sum(tf.abs(emb), axis=-1)
  return tf.cast(tf.not_equal(emb_sum, 0.0), dtype=dtype)
Calculates the padding mask based on which embeddings are not zero.
tensor2tensor/models/research/transformer_vae_flow_prior_ops.py