def embedding_lookup_with_padding(embeddings_mat,
                                  ids,
                                  padding = -1):
  """Wrapper of tf.nn.embedding_lookup with padding.

  Args:
    embeddings_mat: embedding table
    ids: ids of elements
    padding: padded value

  Returns:
    embeddings of elements
  """
  mask = tf.cast(tf.not_equal(ids, padding), dtype=tf.int32)
  # batch_size,
  embs = tf.nn.embedding_lookup(embeddings_mat, ids * mask)
  # batch_size, hidden_size
  mask = tf.cast(tf.expand_dims(mask, axis=-1), dtype=tf.float32)
  # batch_size, 1
  embs *= mask
  # batch_size, hidden_size
  return embs
Wrapper of tf.nn.embedding_lookup with padding.

  Args:
    embeddings_mat: embedding table
    ids: ids of elements
    padding: padded value

  Returns:
    embeddings of elements
  
language/emql/util.py