class_docstr: The :class:`Word2vecEmbedding` class is a fully connected layer.
  For Word Embedding, words are input as integer index.
  The output is the embedded word vector.
  
  The layer integrates NCE loss by default (activate_nce_loss=True).
  If the NCE loss is activated, in a dynamic model,
  the computation of nce loss can be turned off in customised forward feeding
  by setting use_nce_loss=False when the layer is called.
  The NCE loss can be deactivated by setting activate_nce_loss=False.
  
  Parameters
  ----------
  vocabulary_size : int
      The size of vocabulary, number of words
  embedding_size : int
      The number of embedding dimensions
  num_sampled : int
      The number of negative examples for NCE loss
  activate_nce_loss : boolean
      Whether activate nce loss or not. By default, True
      If True, the layer will return both outputs of embedding and nce_cost in forward feeding.
      If False, the layer will only return outputs of embedding.
      In a dynamic model, the computation of nce loss can be turned off in forward feeding
      by setting use_nce_loss=False when the layer is called.
      In a static model, once the model is constructed, the computation of nce loss
      cannot be changed (always computed or not computed).
  nce_loss_args : dictionary
      The arguments for tf.nn.nce_loss()
  E_init : initializer
      The initializer for initializing the embedding matrix
  nce_W_init : initializer
      The initializer for initializing the nce decoder weight matrix
  nce_b_init : initializer
      The initializer for initializing of the nce decoder bias vector
  name : str
      A unique layer name
  
  Attributes
  ----------
  outputs : Tensor
      The embedding layer outputs.
  normalized_embeddings : Tensor
      Normalized embedding matrix.
  nce_weights : Tensor
      The NCE weights only when activate_nce_loss is True.
  nce_biases: Tensor
      The NCE biases only when activate_nce_loss is True.
  
  Examples
  --------
  Word2Vec With TensorLayer (Example in `examples/text_word_embedding/tutorial_word2vec_basic.py`)
  
  >>> import tensorflow as tf
  >>> import tensorlayer as tl
  >>> batch_size = 8
  >>> embedding_size = 50
  >>> inputs = tl.layers.Input([batch_size], dtype=tf.int32)
  >>> labels = tl.layers.Input([batch_size, 1], dtype=tf.int32)
  >>> emb_net = tl.layers.Word2vecEmbedding(
  >>>     vocabulary_size=10000,
  >>>     embedding_size=embedding_size,
  >>>     num_sampled=100,
  >>>     activate_nce_loss=True, # the nce loss is activated
  >>>     nce_loss_args={},
  >>>     E_init=tl.initializers.random_uniform(minval=-1.0, maxval=1.0),
  >>>     nce_W_init=tl.initializers.truncated_normal(stddev=float(1.0 / np.sqrt(embedding_size))),
  >>>     nce_b_init=tl.initializers.constant(value=0.0),
  >>>     name='word2vec_layer',
  >>> )
  >>> print(emb_net)
  Word2vecEmbedding(vocabulary_size=10000, embedding_size=50, num_sampled=100, activate_nce_loss=True, nce_loss_args={})
  >>> embed_tensor = emb_net(inputs, use_nce_loss=False) # the nce loss is turned off and no need to provide labels
  >>> embed_tensor = emb_net([inputs, labels], use_nce_loss=False) # the nce loss is turned off and the labels will be ignored
  >>> embed_tensor, embed_nce_loss = emb_net([inputs, labels]) # the nce loss is calculated
  >>> outputs = tl.layers.Dense(n_units=10, name="dense")(embed_tensor)
  >>> model = tl.models.Model(inputs=[inputs, labels], outputs=[outputs, embed_nce_loss], name="word2vec_model") # a static model
  >>> out = model([data_x, data_y], is_train=True) # where data_x is inputs and data_y is labels
  
  References
  ----------
  `https://www.tensorflow.org/tutorials/representation/word2vec`
class_docstr_tok: ["The",":","class",":","`","Word2vecEmbedding","`","class","is","a","fully","connected","layer",".","For","Word","Embedding",",","words","are","input","as","integer","index",".","The","output","is","the","embedded","word","vector",".","The","layer","integrates","NCE","loss","by","default","(","activate_nce_loss=True",")",".","If","the","NCE","loss","is","activated",",","in","a","dynamic","model",",","the","computation","of","nce","loss","can","be","turned","off","in","customised","forward","feeding","by","setting","use_nce_loss=False","when","the","layer","is","called",".","The","NCE","loss","can","be","deactivated","by","setting","activate_nce_loss=False",".","Parameters","--","--","--","--","--","vocabulary_size",":","int","The","size","of","vocabulary",",","number","of","words","embedding_size",":","int","The","number","of","embedding","dimensions","num_sampled",":","int","The","number","of","negative","examples","for","NCE","loss","activate_nce_loss",":","boolean","Whether","activate","nce","loss","or","not",".","By","default",",","True","If","True",",","the","layer","will","return","both","outputs","of","embedding","and","nce_cost","in","forward","feeding",".","If","False",",","the","layer","will","only","return","outputs","of","embedding",".","In","a","dynamic","model",",","the","computation","of","nce","loss","can","be","turned","off","in","forward","feeding","by","setting","use_nce_loss=False","when","the","layer","is","called",".","In","a","static","model",",","once","the","model","is","constructed",",","the","computation","of","nce","loss","can","not","be","changed","(","always","computed","or","not","computed",")",".","nce_loss_args",":","dictionary","The","arguments","for","tf.nn.nce_loss","(",")","E_init",":","initializer","The","initializer","for","initializing","the","embedding","matrix","nce_W_init",":","initializer","The","initializer","for","initializing","the","nce","decoder","weight","matrix","nce_b_init",":","initializer","The","initializer","for","initializing","of","the","nce","decoder","bias","vector","name",":","str","A","unique","layer","name","Attributes","--","--","--","--","--","outputs",":","Tensor","The","embedding","layer","outputs",".","normalized_embeddings",":","Tensor","Normalized","embedding","matrix",".","nce_weights",":","Tensor","The","NCE","weights","only","when","activate_nce_loss","is","True",".","nce_biases",":","Tensor","The","NCE","biases","only","when","activate_nce_loss","is","True",".","Examples","--","--","--","--","Word2Vec","With","TensorLayer","(","Example","in","`","examples\/text_word_embedding\/tutorial_word2vec_basic.py","`",")",">",">",">","import","tensorflow","as","tf",">",">",">","import","tensorlayer","as","tl",">",">",">","batch_size","=","8",">",">",">","embedding_size","=","50",">",">",">","inputs","=","tl.layers.Input","(","[","batch_size","]",",","dtype=tf.int32",")",">",">",">","labels","=","tl.layers.Input","(","[","batch_size",",","1","]",",","dtype=tf.int32",")",">",">",">","emb_net","=","tl.layers.Word2vecEmbedding","(",">",">",">","vocabulary_size=10000",",",">",">",">","embedding_size=embedding_size",",",">",">",">","num_sampled=100",",",">",">",">","activate_nce_loss=True",",","#","the","nce","loss","is","activated",">",">",">","nce_loss_args=","{","}",",",">",">",">","E_init=tl.initializers.random_uniform","(","minval=-1.0",",","maxval=1.0",")",",",">",">",">","nce_W_init=tl.initializers.truncated_normal","(","stddev=float","(","1.0","\/","np.sqrt","(","embedding_size",")",")",")",",",">",">",">","nce_b_init=tl.initializers.constant","(","value=0.0",")",",",">",">",">","name='word2vec_layer","'",",",">",">",">",")",">",">",">","print","(","emb_net",")","Word2vecEmbedding","(","vocabulary_size=10000",",","embedding_size=50",",","num_sampled=100",",","activate_nce_loss=True",",","nce_loss_args=","{","}",")",">",">",">","embed_tensor","=","emb_net","(","inputs",",","use_nce_loss=False",")","#","the","nce","loss","is","turned","off","and","no","need","to","provide","labels",">",">",">","embed_tensor","=","emb_net","(","[","inputs",",","labels","]",",","use_nce_loss=False",")","#","the","nce","loss","is","turned","off","and","the","labels","will","be","ignored",">",">",">","embed_tensor",",","embed_nce_loss","=","emb_net","(","[","inputs",",","labels","]",")","#","the","nce","loss","is","calculated",">",">",">","outputs","=","tl.layers.Dense","(","n_units=10",",","name=","''","dense","''",")","(","embed_tensor",")",">",">",">","model","=","tl.models.Model","(","inputs=","[","inputs",",","labels","]",",","outputs=","[","outputs",",","embed_nce_loss","]",",","name=","''","word2vec_model","''",")","#","a","static","model",">",">",">","out","=","model","(","[","data_x",",","data_y","]",",","is_train=True",")","#","where","data_x","is","inputs","and","data_y","is","labels","References","--","--","--","--","--","`","https",":","\/\/www.tensorflow.org\/tutorials\/representation\/word2vec","`"]
docstr: Parameters
  ----------
  inputs_shape : tuple
      the shape of inputs tensor
docstr_tok: ["Parameters","--","--","--","--","--","inputs_shape",":","tuple","the","shape","of","inputs","tensor"]
code: def build(self, inputs_shape):
      """
      Parameters
      ----------
      inputs_shape : tuple
          the shape of inputs tensor
      """
      # Look up embeddings for inputs.
      # Note: a row of 'embeddings' is the vector representation of a word.
      # for the sake of speed, it is better to slice the embedding matrix
      # instead of transferring a word id to one-hot-format vector and then
      # multiply by the embedding matrix.
      # embed is the outputs of the hidden layer (embedding layer), it is a
      # row vector with 'embedding_size' values.
  
      self.embeddings = self._get_weights(
          "embeddings",
          shape=(self.vocabulary_size, self.embedding_size),
          init=self.E_init,
      )
  
      self.normalized_embeddings = tf.nn.l2_normalize(
          self.embeddings, 1
      )
  
      if self.activate_nce_loss:
          # Construct the variables for the NCE loss (i.e. negative sampling)
          self.nce_weights = self._get_weights(
              "nce_weights",
              shape=(self.vocabulary_size, self.embedding_size),
              init=self.nce_W_init,
          )
  
          self.nce_biases = self._get_weights(
              "nce_biases",
              shape=(self.vocabulary_size,),
              init=self.nce_b_init,
          )
  
imports: import numpy
  import tensorflow
  import tensorlayer
  from tensorlayer import logging
  from tensorlayer.layers.core import Layer
label_desc: Use image node_id 3 for calling the Word2vecEmbedding obj's underlying member method code with example usage: obj.build(inputs_shape) without return types