(input_ids,
                     vocab_size,
                     embedding_size=128,
                     initializer_range=0.02,
                     word_embedding_name="word_embeddings",
                     use_one_hot_embeddings=False)
return (output, embedding_table)
Looks up words embeddings for id tensor.

  Args:
    input_ids: int32 Tensor of shape [batch_size, seq_length] containing word
      ids.
    vocab_size: int. Size of the embedding vocabulary.
    embedding_size: int. Width of the word embeddings.
    initializer_range: float. Embedding initialization range.
    word_embedding_name: string. Name of the embedding table.
    use_one_hot_embeddings: bool. If True, use one-hot method for word
      embeddings. If False, use `tf.gather()`.

  Returns:
    float Tensor of shape [batch_size, seq_length, embedding_size].
Looks up words embeddings for id tensor.
Looks up words embeddings for id tensor .
def embedding_lookup(input_ids,
                     vocab_size,
                     embedding_size=128,
                     initializer_range=0.02,
                     word_embedding_name="word_embeddings",
                     use_one_hot_embeddings=False):
  """Looks up words embeddings for id tensor.

  Args:
    input_ids: int32 Tensor of shape [batch_size, seq_length] containing word
      ids.
    vocab_size: int. Size of the embedding vocabulary.
    embedding_size: int. Width of the word embeddings.
    initializer_range: float. Embedding initialization range.
    word_embedding_name: string. Name of the embedding table.
    use_one_hot_embeddings: bool. If True, use one-hot method for word
      embeddings. If False, use `tf.gather()`.

  Returns:
    float Tensor of shape [batch_size, seq_length, embedding_size].
  """
  # This function assumes that the input is of shape [batch_size, seq_length,
  # num_inputs].
  #
  # If the input is a 2D tensor of shape [batch_size, seq_length], we
  # reshape to [batch_size, seq_length, 1].
  if input_ids.shape.ndims == 2:
    input_ids = tf.expand_dims(input_ids, axis=[-1]) # shape of input_ids is:[ batch_size, seq_length, 1]

  embedding_table = tf.get_variable( # [vocab_size, embedding_size]
      name=word_embedding_name,
      shape=[vocab_size, embedding_size],
      initializer=create_initializer(initializer_range))

  flat_input_ids = tf.reshape(input_ids, [-1]) # one rank. shape as (batch_size * sequence_length,)
  if use_one_hot_embeddings:
    one_hot_input_ids = tf.one_hot(flat_input_ids, depth=vocab_size) # one_hot_input_ids=[batch_size * sequence_length,vocab_size]
    output = tf.matmul(one_hot_input_ids, embedding_table) # output=[batch_size * sequence_length,embedding_size]
  else:
    output = tf.gather(embedding_table, flat_input_ids) # [vocab_size, embedding_size]*[batch_size * sequence_length,]--->[batch_size * sequence_length,embedding_size]

  input_shape = get_shape_list(input_ids) # input_shape=[ batch_size, seq_length, 1]

  output = tf.reshape(output,input_shape[0:-1] + [input_shape[-1] * embedding_size]) # output=[batch_size,sequence_length,embedding_size]
  return (output, embedding_table)
def embedding_lookup ( input_ids , vocab_size , embedding_size = 128 , initializer_range = 0.02 , word_embedding_name = "word_embeddings" , use_one_hot_embeddings = False ) : # This function assumes that the input is of shape [batch_size, seq_length, # num_inputs]. # # If the input is a 2D tensor of shape [batch_size, seq_length], we # reshape to [batch_size, seq_length, 1]. if input_ids . shape . ndims == 2 : input_ids = tf . expand_dims ( input_ids , axis = [ - 1 ] ) # shape of input_ids is:[ batch_size, seq_length, 1] embedding_table = tf . get_variable ( # [vocab_size, embedding_size] name = word_embedding_name , shape = [ vocab_size , embedding_size ] , initializer = create_initializer ( initializer_range ) ) flat_input_ids = tf . reshape ( input_ids , [ - 1 ] ) # one rank. shape as (batch_size * sequence_length,) if use_one_hot_embeddings : one_hot_input_ids = tf . one_hot ( flat_input_ids , depth = vocab_size ) # one_hot_input_ids=[batch_size * sequence_length,vocab_size] output = tf . matmul ( one_hot_input_ids , embedding_table ) # output=[batch_size * sequence_length,embedding_size] else : output = tf . gather ( embedding_table , flat_input_ids ) # [vocab_size, embedding_size]*[batch_size * sequence_length,]--->[batch_size * sequence_length,embedding_size] input_shape = get_shape_list ( input_ids ) # input_shape=[ batch_size, seq_length, 1] output = tf . reshape ( output , input_shape [ 0 : - 1 ] + [ input_shape [ - 1 ] * embedding_size ] ) # output=[batch_size,sequence_length,embedding_size] return ( output , embedding_table )