def _ignore_pad(embeddings_table, ids, use_one_hot_embeddings=False):
  """Use mean of symbol embeddings as overall embedding but ignore PAD."""
  source_embeddings = common_layers.embedding_lookup(embeddings_table, ids,
                                                     use_one_hot_embeddings)
  # Set weights to ignore padding.
  embedded_weights = tf.to_float(tf.not_equal(ids, constants.PAD_SYMBOL_ID))
  embedded_weights = tf.expand_dims(embedded_weights, -1)
  return source_embeddings * embedded_weights
Use mean of symbol embeddings as overall embedding but ignore PAD.
language/xsp/model/embeddings.py