class_docstr: Simple word embedder that maps indexes into embeddings. The indexes
  can be soft (e.g., distributions over vocabulary).
  
  Either :attr:`init_value` or :attr:`vocab_size` is required. If both are
  given, there must be ``init_value.shape[0]==vocab_size``.
  
  Args:
      init_value (optional): A Tensor or numpy array that contains the
          initial value of embeddings. It is typically of shape
          ``[vocab_size] + embedding-dim``. Embedding can have dimensionality
          > 1.
  
          If `None`, embedding is initialized as specified in
          ``hparams["initializer"]``. Otherwise, the
          ``"initializer"`` and ``"dim"`` hyperparameters in
          :attr:`hparams` are ignored.
      vocab_size (int, optional): The vocabulary size. Required if
          :attr:`init_value` is not given.
      hparams (dict, optional): Embedder hyperparameters. Missing
          hyperparamerter will be set to default values. See
          :meth:`default_hparams` for the hyperparameter structure and
          default values.
  
  See :meth:`_build` for the inputs and outputs of the embedder.
  
  Example:
  
      .. code-block:: python
  
          ids = tf.random_uniform(shape=[32, 10], maxval=10, dtype=tf.int64)
          soft_ids = tf.random_uniform(shape=[32, 10, 100])
  
          embedder = WordEmbedder(vocab_size=100, hparams={'dim': 256})
          ids_emb = embedder(ids=ids) # shape: [32, 10, 256]
          soft_ids_emb = embedder(soft_ids=soft_ids) # shape: [32, 10, 256]
  
      .. code-block:: python
  
          # Use with Texar data module
          hparams={
              'dataset': {
                  'embedding_init': {'file': 'word2vec.txt'}
                  ...
              },
          }
          data = MonoTextData(data_params)
          iterator = DataIterator(data)
          batch = iterator.get_next()
  
          # Use data vocab size
          embedder_1 = WordEmbedder(vocab_size=data.vocab.size)
          emb_1 = embedder_1(batch['text_ids'])
  
          # Use pre-trained embedding
          embedder_2 = WordEmbedder(init_value=data.embedding_init_value)
          emb_2 = embedder_2(batch['text_ids'])
  
  
  .. document private functions
  .. automethod:: _build
class_docstr_tok: ["Simple","word","embedder","that","maps","indexes","into","embeddings",".","The","indexes","can","be","soft","(","e.g.",",","distributions","over","vocabulary",")",".","Either",":","attr",":","`","init_value","`","or",":","attr",":","`","vocab_size","`","is","required",".","If","both","are","given",",","there","must","be","``","init_value.shape","[","0","]","==vocab_size","``",".","Args",":","init_value","(","optional",")",":","A","Tensor","or","numpy","array","that","contains","the","initial","value","of","embeddings",".","It","is","typically","of","shape","``","[","vocab_size","]","+","embedding-dim","``",".","Embedding","can","have","dimensionality",">","1",".","If","`","None","`",",","embedding","is","initialized","as","specified","in","``","hparams","[","``","initializer","''","]","``",".","Otherwise",",","the","``","``","initializer","''","``","and","``","``","dim","''","``","hyperparameters","in",":","attr",":","`","hparams","`","are","ignored",".","vocab_size","(","int",",","optional",")",":","The","vocabulary","size",".","Required","if",":","attr",":","`","init_value","`","is","not","given",".","hparams","(","dict",",","optional",")",":","Embedder","hyperparameters",".","Missing","hyperparamerter","will","be","set","to","default","values",".","See",":","meth",":","`","default_hparams","`","for","the","hyperparameter","structure","and","default","values",".","See",":","meth",":","`","_build","`","for","the","inputs","and","outputs","of","the","embedder",".","Example",":","..","code-block",":",":","python","ids","=","tf.random_uniform","(","shape=","[","32",",","10","]",",","maxval=10",",","dtype=tf.int64",")","soft_ids","=","tf.random_uniform","(","shape=","[","32",",","10",",","100","]",")","embedder","=","WordEmbedder","(","vocab_size=100",",","hparams=","{","'dim","'",":","256","}",")","ids_emb","=","embedder","(","ids=ids",")","#","shape",":","[","32",",","10",",","256","]","soft_ids_emb","=","embedder","(","soft_ids=soft_ids",")","#","shape",":","[","32",",","10",",","256","]","..","code-block",":",":","python","#","Use","with","Texar","data","module","hparams=","{","'dataset","'",":","{","'embedding_init","'",":","{","'file","'",":","'word2vec.txt","'","}","...","}",",","}","data","=","MonoTextData","(","data_params",")","iterator","=","DataIterator","(","data",")","batch","=","iterator.get_next","(",")","#","Use","data","vocab","size","embedder_1","=","WordEmbedder","(","vocab_size=data.vocab.size",")","emb_1","=","embedder_1","(","batch","[","'text_ids","'","]",")","#","Use","pre-trained","embedding","embedder_2","=","WordEmbedder","(","init_value=data.embedding_init_value",")","emb_2","=","embedder_2","(","batch","[","'text_ids","'","]",")","..","document","private","functions","..","automethod",":",":","_build"]
docstr: Returns a dictionary of hyperparameters with default values.
  
  .. code-block:: python
  
      {
          "dim": 100,
          "dropout_rate": 0,
          "dropout_strategy": 'element',
          "trainable": True,
          "initializer": {
              "type": "random_uniform_initializer",
              "kwargs": {
                  "minval": -0.1,
                  "maxval": 0.1,
                  "seed": None
              }
          },
          "regularizer": {
              "type": "L1L2",
              "kwargs": {
                  "l1": 0.,
                  "l2": 0.
              }
          },
          "name": "word_embedder",
      }
  
  Here:
  
  `"dim"`: int or list
      Embedding dimension. Can be a list of integers to yield embeddings
      with dimensionality > 1.
  
      Ignored if :attr:`init_value` is given to the embedder constructor.
  
  `"dropout_rate"`: float
      The dropout rate between 0 and 1. E.g., ``dropout_rate=0.1`` would
      drop out 10% of the embedding. Set to 0 to disable dropout.
  
  `"dropout_strategy"`: str
      The dropout strategy. Can be one of the following
  
      - ``"element"``: The regular strategy that drops individual
        elements of embedding vectors.
      - ``"item"``: Drops individual items (e.g., words) entirely. E.g.,
        for the word sequence "the simpler the better", the strategy can
        yield "_ simpler the better", where the first "the" is dropped.
      - :attr:`"item_type"`: Drops item types (e.g., word types). E.g.,
        for the above sequence, the strategy can yield
        "_ simpler _ better", where the word type "the" is dropped.
        The dropout will never yield "_ simpler the better" as in the
        ``"item"`` strategy.
  
  `"trainable"`: bool
      Whether the embedding is trainable.
  
  `"initializer"`: dict or None
      Hyperparameters of the initializer for embedding values. See
      :func:`~texar.tf.core.get_initializer` for the details. Ignored if
      :attr:`init_value` is given to the embedder constructor.
  
  `"regularizer"`: dict
      Hyperparameters of the regularizer for embedding values. See
      :func:`~texar.tf.core.get_regularizer` for the details.
  
  `"name"`: str
      Name of the embedding variable.
docstr_tok: ["Returns","a","dictionary","of","hyperparameters","with","default","values",".","..","code-block",":",":","python","{","``","dim","''",":","100",",","``","dropout_rate","''",":","0",",","``","dropout_strategy","''",":","'element","'",",","``","trainable","''",":","True",",","``","initializer","''",":","{","``","type","''",":","``","random_uniform_initializer","''",",","``","kwargs","''",":","{","``","minval","''",":","-0.1",",","``","maxval","''",":","0.1",",","``","seed","''",":","None","}","}",",","``","regularizer","''",":","{","``","type","''",":","``","L1L2","''",",","``","kwargs","''",":","{","``","l1","''",":","0.",",","``","l2","''",":","0.","}","}",",","``","name","''",":","``","word_embedder","''",",","}","Here",":","`","``","dim","''","`",":","int","or","list","Embedding","dimension",".","Can","be","a","list","of","integers","to","yield","embeddings","with","dimensionality",">","1",".","Ignored","if",":","attr",":","`","init_value","`","is","given","to","the","embedder","constructor",".","`","``","dropout_rate","''","`",":","float","The","dropout","rate","between","0","and","1",".","E.g.",",","``","dropout_rate=0.1","``","would","drop","out","10","%","of","the","embedding",".","Set","to","0","to","disable","dropout",".","`","``","dropout_strategy","''","`",":","str","The","dropout","strategy",".","Can","be","one","of","the","following","-","``","``","element","''","``",":","The","regular","strategy","that","drops","individual","elements","of","embedding","vectors",".","-","``","``","item","''","``",":","Drops","individual","items","(","e.g.",",","words",")","entirely",".","E.g.",",","for","the","word","sequence","``","the","simpler","the","better","''",",","the","strategy","can","yield","``","_","simpler","the","better","''",",","where","the","first","``","the","''","is","dropped",".","-",":","attr",":","`","``","item_type","''","`",":","Drops","item","types","(","e.g.",",","word","types",")",".","E.g.",",","for","the","above","sequence",",","the","strategy","can","yield","``","_","simpler","_","better","''",",","where","the","word","type","``","the","''","is","dropped",".","The","dropout","will","never","yield","``","_","simpler","the","better","''","as","in","the","``","``","item","''","``","strategy",".","`","``","trainable","''","`",":","bool","Whether","the","embedding","is","trainable",".","`","``","initializer","''","`",":","dict","or","None","Hyperparameters","of","the","initializer","for","embedding","values",".","See",":","func",":","`","~texar.tf.core.get_initializer","`","for","the","details",".","Ignored","if",":","attr",":","`","init_value","`","is","given","to","the","embedder","constructor",".","`","``","regularizer","''","`",":","dict","Hyperparameters","of","the","regularizer","for","embedding","values",".","See",":","func",":","`","~texar.tf.core.get_regularizer","`","for","the","details",".","`","``","name","''","`",":","str","Name","of","the","embedding","variable","."]
code: def default_hparams():
      r"""Returns a dictionary of hyperparameters with default values.
  
      .. code-block:: python
  
          {
              "dim": 100,
              "dropout_rate": 0,
              "dropout_strategy": 'element',
              "trainable": True,
              "initializer": {
                  "type": "random_uniform_initializer",
                  "kwargs": {
                      "minval": -0.1,
                      "maxval": 0.1,
                      "seed": None
                  }
              },
              "regularizer": {
                  "type": "L1L2",
                  "kwargs": {
                      "l1": 0.,
                      "l2": 0.
                  }
              },
              "name": "word_embedder",
          }
  
      Here:
  
      `"dim"`: int or list
          Embedding dimension. Can be a list of integers to yield embeddings
          with dimensionality > 1.
  
          Ignored if :attr:`init_value` is given to the embedder constructor.
  
      `"dropout_rate"`: float
          The dropout rate between 0 and 1. E.g., ``dropout_rate=0.1`` would
          drop out 10% of the embedding. Set to 0 to disable dropout.
  
      `"dropout_strategy"`: str
          The dropout strategy. Can be one of the following
  
          - ``"element"``: The regular strategy that drops individual
            elements of embedding vectors.
          - ``"item"``: Drops individual items (e.g., words) entirely. E.g.,
            for the word sequence "the simpler the better", the strategy can
            yield "_ simpler the better", where the first "the" is dropped.
          - :attr:`"item_type"`: Drops item types (e.g., word types). E.g.,
            for the above sequence, the strategy can yield
            "_ simpler _ better", where the word type "the" is dropped.
            The dropout will never yield "_ simpler the better" as in the
            ``"item"`` strategy.
  
      `"trainable"`: bool
          Whether the embedding is trainable.
  
      `"initializer"`: dict or None
          Hyperparameters of the initializer for embedding values. See
          :func:`~texar.tf.core.get_initializer` for the details. Ignored if
          :attr:`init_value` is given to the embedder constructor.
  
      `"regularizer"`: dict
          Hyperparameters of the regularizer for embedding values. See
          :func:`~texar.tf.core.get_regularizer` for the details.
  
      `"name"`: str
          Name of the embedding variable.
      """
      hparams = embedder_utils.default_embedding_hparams()
      hparams["name"] = "word_embedder"
      return hparams
  
file_path: texar/texar/tf/modules/embedders/embedders.py
imports: import tensorflow
  from texar.tf.modules.embedders.embedder_base import EmbedderBase
  from texar.tf.modules.embedders import embedder_utils
  from texar.tf.utils.mode import is_train_mode
  from texar.tf.utils.shapes import get_rank
label_desc: Use image node_id 2 for calling the WordEmbedder obj's underlying member method code with example usage: obj.default_hparams() and returns: hparams