(one_hot, embedding_size=None)
return tf.nn.embedding_lookup(embedding, label_id, name='token_to_embedding')
Gets a dense embedding vector from a one-hot encoding.
Gets a dense embedding vector from a one-hot encoding.
Gets a dense embedding vector from a one - hot encoding .
def one_hot_to_embedding(one_hot, embedding_size=None):
  """Gets a dense embedding vector from a one-hot encoding."""
  num_tokens = int(one_hot.shape[1])
  label_id = tf.argmax(one_hot, axis=1)
  if embedding_size is None:
    embedding_size = get_default_embedding_size(num_tokens)
  embedding = tf.get_variable(
      'one_hot_embedding', [num_tokens, embedding_size], dtype=tf.float32)
  return tf.nn.embedding_lookup(embedding, label_id, name='token_to_embedding')
def one_hot_to_embedding ( one_hot , embedding_size = None ) : num_tokens = int ( one_hot . shape [ 1 ] ) label_id = tf . argmax ( one_hot , axis = 1 ) if embedding_size is None : embedding_size = get_default_embedding_size ( num_tokens ) embedding = tf . get_variable ( 'one_hot_embedding' , [ num_tokens , embedding_size ] , dtype = tf . float32 ) return tf . nn . embedding_lookup ( embedding , label_id , name = 'token_to_embedding' )