class_docstr: Words embeddings for encoder/decoder.
  
  Additionally includes ability to add sparse input features
  based on "Linguistic Input Features Improve Neural Machine Translation"
  :cite:`sennrich2016linguistic`.
  
  
  .. mermaid::
  
     graph LR
        A[Input]
        C[Feature 1 Lookup]
        A-->B[Word Lookup]
        A-->C
        A-->D[Feature N Lookup]
        B-->E[MLP/Concat]
        C-->E
        D-->E
        E-->F[Output]
  
  Args:
      word_vec_size (int): size of the dictionary of embeddings.
      word_vocab_size (int): size of dictionary of embeddings for words.
      word_padding_idx (int): padding index for words in the embeddings.
      position_encoding (bool): see :class:`~onmt.modules.PositionalEncoding`
      feat_merge (string): merge action for the features embeddings:
          concat, sum or mlp.
      feat_vec_exponent (float): when using `-feat_merge concat`, feature
          embedding size is N^feat_dim_exponent, where N is the
          number of values the feature takes.
      feat_vec_size (int): embedding dimension for features when using
          `-feat_merge mlp`
      feat_padding_idx (List[int]): padding index for a list of features
                                 in the embeddings.
      feat_vocab_sizes (List[int], optional): list of size of dictionary
          of embeddings for each feature.
      dropout (float): dropout probability.
      sparse (bool): sparse embbedings default False
      freeze_word_vecs (bool): freeze weights of word vectors.
class_docstr_tok: ["Words","embeddings","for","encoder\/decoder",".","Additionally","includes","ability","to","add","sparse","input","features","based","on","``","Linguistic","Input","Features","Improve","Neural","Machine","Translation","''",":","cite",":","`","sennrich2016linguistic","`",".","..","mermaid",":",":","graph","LR","A","[","Input","]","C","[","Feature","1","Lookup","]","A","--",">","B","[","Word","Lookup","]","A","--",">","C","A","--",">","D","[","Feature","N","Lookup","]","B","--",">","E","[","MLP\/Concat","]","C","--",">","E","D","--",">","E","E","--",">","F","[","Output","]","Args",":","word_vec_size","(","int",")",":","size","of","the","dictionary","of","embeddings",".","word_vocab_size","(","int",")",":","size","of","dictionary","of","embeddings","for","words",".","word_padding_idx","(","int",")",":","padding","index","for","words","in","the","embeddings",".","position_encoding","(","bool",")",":","see",":","class",":","`","~onmt.modules.PositionalEncoding","`","feat_merge","(","string",")",":","merge","action","for","the","features","embeddings",":","concat",",","sum","or","mlp",".","feat_vec_exponent","(","float",")",":","when","using","`","-feat_merge","concat","`",",","feature","embedding","size","is","N^feat_dim_exponent",",","where","N","is","the","number","of","values","the","feature","takes",".","feat_vec_size","(","int",")",":","embedding","dimension","for","features","when","using","`","-feat_merge","mlp","`","feat_padding_idx","(","List","[","int","]",")",":","padding","index","for","a","list","of","features","in","the","embeddings",".","feat_vocab_sizes","(","List","[","int","]",",","optional",")",":","list","of","size","of","dictionary","of","embeddings","for","each","feature",".","dropout","(","float",")",":","dropout","probability",".","sparse","(","bool",")",":","sparse","embbedings","default","False","freeze_word_vecs","(","bool",")",":","freeze","weights","of","word","vectors","."]
code: def __init__(
      self,
      word_vec_size,
      word_vocab_size,
      word_padding_idx,
      position_encoding=False,
      position_encoding_type="SinusoidalInterleaved",
      feat_merge="concat",
      feat_vec_exponent=0.7,
      feat_vec_size=-1,
      feat_padding_idx=[],
      feat_vocab_sizes=[],
      dropout=0,
      sparse=False,
      freeze_word_vecs=False,
  ):
      self._validate_args(
          feat_merge,
          feat_vocab_sizes,
          feat_vec_exponent,
          feat_vec_size,
          feat_padding_idx,
      )
  
      if feat_padding_idx is None:
          feat_padding_idx = []
      self.word_padding_idx = word_padding_idx
  
      self.word_vec_size = word_vec_size
  
      # Dimensions and padding for constructing the word embedding matrix
      vocab_sizes = [word_vocab_size]
      emb_dims = [word_vec_size]
      pad_indices = [word_padding_idx]
  
      # Dimensions and padding for feature embedding matrices
      # (these have no effect if feat_vocab_sizes is empty)
      if feat_merge == "sum":
          feat_dims = [word_vec_size] * len(feat_vocab_sizes)
      elif feat_vec_size > 0:
          feat_dims = [feat_vec_size] * len(feat_vocab_sizes)
      else:
          feat_dims = [
              int(vocab**feat_vec_exponent)
              for vocab in feat_vocab_sizes
          ]
      vocab_sizes.extend(feat_vocab_sizes)
      emb_dims.extend(feat_dims)
      pad_indices.extend(feat_padding_idx)
  
      # The embedding matrix look-up tables. The first look-up table
      # is for words. Subsequent ones are for features, if any exist.
      emb_params = zip(vocab_sizes, emb_dims, pad_indices)
      embeddings = [
          skip_init(
              nn.Embedding,
              num_embeddings=vocab,
              embedding_dim=dim,
              padding_idx=pad,
              sparse=sparse,
          )
          for vocab, dim, pad in emb_params
      ]
      emb_luts = Elementwise(feat_merge, embeddings)
  
      # The final output size of word + feature vectors. This can vary
      # from the word vector size if and only if features are defined.
      # This is the attribute you should access if you need to know
      # how big your embeddings are going to be.
      self.embedding_size = (
          sum(emb_dims) if feat_merge == "concat" else word_vec_size
      )
  
      # The sequence of operations that converts the input sequence
      # into a sequence of embeddings. At minimum this consists of
      # looking up the embeddings for each word and feature in the
      # input. Model parameters may require the sequence to contain
      # additional operations as well.
      super(Embeddings, self).__init__()
      self.make_embedding = nn.Sequential()
      self.make_embedding.add_module("emb_luts", emb_luts)
  
      if feat_merge == "mlp" and len(feat_vocab_sizes) > 0:
          in_dim = sum(emb_dims)
          mlp = nn.Sequential(
              nn.Linear(in_dim, word_vec_size), nn.ReLU()
          )
          self.make_embedding.add_module("mlp", mlp)
  
      self.position_encoding = position_encoding
      self.dropout = nn.Dropout(p=dropout)
      self.dropout_p = dropout
  
      if self.position_encoding:
          pe = PositionalEncoding(
              self.embedding_size, position_encoding_type
          )
          self.make_embedding.add_module("pe", pe)
  
      if freeze_word_vecs:
          self.word_lut.weight.requires_grad = False
  
imports: import math
  import warnings
  import torch
  import torch.nn
  from torch.nn.utils import skip_init
  from onmt.modules.util_class import Elementwise
  from onmt.utils.logging import logger
label_desc: Use image node_id 1 to create a new Embeddings object from inherited base classes: nn with example: obj = Embeddings(word_vec_size, word_vocab_size, word_padding_idx, position_encoding, position_encoding_type, feat_merge, feat_vec_exponent, feat_vec_size, feat_padding_idx, feat_vocab_sizes, dropout, sparse, freeze_word_vecs)