class_docstr: A more featureful embedding module than the default in Pytorch.  Adds the ability to:
  
      1. embed higher-order inputs
      2. pre-specify the weight matrix
      3. use a non-trainable embedding
      4. project the resultant embeddings to some other dimension (which only makes sense with
         non-trainable embeddings).
      5. build all of this easily ``from_params``
  
  Note that if you are using our data API and are trying to embed a
  :class:`~allennlp.data.fields.TextField`, you should use a
  :class:`~allennlp.modules.TextFieldEmbedder` instead of using this directly.
  
  Parameters
  ----------
  num_embeddings : int:
      Size of the dictionary of embeddings (vocabulary size).
  embedding_dim : int
      The size of each embedding vector.
  projection_dim : int, (optional, default=None)
      If given, we add a projection layer after the embedding layer.  This really only makes
      sense if ``trainable`` is ``False``.
  weight : torch.FloatTensor, (optional, default=None)
      A pre-initialised weight matrix for the embedding lookup, allowing the use of
      pretrained vectors.
  padding_index : int, (optional, default=None)
      If given, pads the output with zeros whenever it encounters the index.
  trainable : bool, (optional, default=True)
      Whether or not to optimize the embedding parameters.
  max_norm : float, (optional, default=None)
      If given, will renormalize the embeddings to always have a norm lesser than this
  norm_type : float, (optional, default=2):
      The p of the p-norm to compute for the max_norm option
  scale_grad_by_freq : boolean, (optional, default=False):
      If given, this will scale gradients by the frequency of the words in the mini-batch.
  sparse : bool, (optional, default=False):
      Whether or not the Pytorch backend should use a sparse representation of the embedding weight.
  
  Returns
  -------
  An Embedding module.
class_docstr_tok: ["A","more","featureful","embedding","module","than","the","default","in","Pytorch",".","Adds","the","ability","to",":","1.","embed","higher-order","inputs","2.","pre-specify","the","weight","matrix","3.","use","a","non-trainable","embedding","4.","project","the","resultant","embeddings","to","some","other","dimension","(","which","only","makes","sense","with","non-trainable","embeddings",")",".","5.","build","all","of","this","easily","``","from_params","``","Note","that","if","you","are","using","our","data","API","and","are","trying","to","embed","a",":","class",":","`","~allennlp.data.fields.TextField","`",",","you","should","use","a",":","class",":","`","~allennlp.modules.TextFieldEmbedder","`","instead","of","using","this","directly",".","Parameters","--","--","--","--","--","num_embeddings",":","int",":","Size","of","the","dictionary","of","embeddings","(","vocabulary","size",")",".","embedding_dim",":","int","The","size","of","each","embedding","vector",".","projection_dim",":","int",",","(","optional",",","default=None",")","If","given",",","we","add","a","projection","layer","after","the","embedding","layer",".","This","really","only","makes","sense","if","``","trainable","``","is","``","False","``",".","weight",":","torch.FloatTensor",",","(","optional",",","default=None",")","A","pre-initialised","weight","matrix","for","the","embedding","lookup",",","allowing","the","use","of","pretrained","vectors",".","padding_index",":","int",",","(","optional",",","default=None",")","If","given",",","pads","the","output","with","zeros","whenever","it","encounters","the","index",".","trainable",":","bool",",","(","optional",",","default=True",")","Whether","or","not","to","optimize","the","embedding","parameters",".","max_norm",":","float",",","(","optional",",","default=None",")","If","given",",","will","renormalize","the","embeddings","to","always","have","a","norm","lesser","than","this","norm_type",":","float",",","(","optional",",","default=2",")",":","The","p","of","the","p-norm","to","compute","for","the","max_norm","option","scale_grad_by_freq",":","boolean",",","(","optional",",","default=False",")",":","If","given",",","this","will","scale","gradients","by","the","frequency","of","the","words","in","the","mini-batch",".","sparse",":","bool",",","(","optional",",","default=False",")",":","Whether","or","not","the","Pytorch","backend","should","use","a","sparse","representation","of","the","embedding","weight",".","Returns","--","--","--","-","An","Embedding","module","."]
docstr: We need the vocabulary here to know how many items we need to embed, and we look for a
  ``vocab_namespace`` key in the parameter dictionary to know which vocabulary to use.  If
  you know beforehand exactly how many embeddings you need, or aren't using a vocabulary
  mapping for the things getting embedded here, then you can pass in the ``num_embeddings``
  key directly, and the vocabulary will be ignored.
  
  In the configuration file, a file containing pretrained embeddings can be specified
  using the parameter ``"pretrained_file"``.
  It can be the path to a local file or an URL of a (cached) remote file.
  Two formats are supported:
  
      * hdf5 file - containing an embedding matrix in the form of a torch.Tensor;
  
      * text file - an utf-8 encoded text file with space separated fields::
  
              [word] [dim 1] [dim 2] ...
  
        The text file can eventually be compressed with gzip, bz2, lzma or zip.
        You can even select a single file inside an archive containing multiple files
        using the URI::
  
              "(archive_uri)#file_path_inside_the_archive"
  
        where ``archive_uri`` can be a file system path or a URL. For example::
  
              "(http://nlp.stanford.edu/data/glove.twitter.27B.zip)#glove.twitter.27B.200d.txt"
docstr_tok: ["We","need","the","vocabulary","here","to","know","how","many","items","we","need","to","embed",",","and","we","look","for","a","``","vocab_namespace","``","key","in","the","parameter","dictionary","to","know","which","vocabulary","to","use",".","If","you","know","beforehand","exactly","how","many","embeddings","you","need",",","or","are","n't","using","a","vocabulary","mapping","for","the","things","getting","embedded","here",",","then","you","can","pass","in","the","``","num_embeddings","``","key","directly",",","and","the","vocabulary","will","be","ignored",".","In","the","configuration","file",",","a","file","containing","pretrained","embeddings","can","be","specified","using","the","parameter","``","``","pretrained_file","''","``",".","It","can","be","the","path","to","a","local","file","or","an","URL","of","a","(","cached",")","remote","file",".","Two","formats","are","supported",":","*","hdf5","file","-","containing","an","embedding","matrix","in","the","form","of","a","torch.Tensor",";","*","text","file","-","an","utf-8","encoded","text","file","with","space","separated","fields",":",":","[","word","]","[","dim","1","]","[","dim","2","]","...","The","text","file","can","eventually","be","compressed","with","gzip",",","bz2",",","lzma","or","zip",".","You","can","even","select","a","single","file","inside","an","archive","containing","multiple","files","using","the","URI",":",":","``","(","archive_uri",")","#","file_path_inside_the_archive","''","where","``","archive_uri","``","can","be","a","file","system","path","or","a","URL",".","For","example",":",":","``","(","http",":","\/\/nlp.stanford.edu\/data\/glove.twitter.27B.zip",")","#","glove.twitter.27B.200d.txt","''"]
code: def from_params(cls, vocab, params):  # type: ignore
      """
      We need the vocabulary here to know how many items we need to embed, and we look for a
      ``vocab_namespace`` key in the parameter dictionary to know which vocabulary to use.  If
      you know beforehand exactly how many embeddings you need, or aren't using a vocabulary
      mapping for the things getting embedded here, then you can pass in the ``num_embeddings``
      key directly, and the vocabulary will be ignored.
  
      In the configuration file, a file containing pretrained embeddings can be specified
      using the parameter ``"pretrained_file"``.
      It can be the path to a local file or an URL of a (cached) remote file.
      Two formats are supported:
  
          * hdf5 file - containing an embedding matrix in the form of a torch.Tensor;
  
          * text file - an utf-8 encoded text file with space separated fields::
  
                  [word] [dim 1] [dim 2] ...
  
            The text file can eventually be compressed with gzip, bz2, lzma or zip.
            You can even select a single file inside an archive containing multiple files
            using the URI::
  
                  "(archive_uri)#file_path_inside_the_archive"
  
            where ``archive_uri`` can be a file system path or a URL. For example::
  
                  "(http://nlp.stanford.edu/data/glove.twitter.27B.zip)#glove.twitter.27B.200d.txt"
      """
      # pylint: disable=arguments-differ
      num_embeddings = params.pop_int("num_embeddings", None)
      vocab_namespace = params.pop("vocab_namespace", "tokens")
      if num_embeddings is None:
          num_embeddings = vocab.get_vocab_size(vocab_namespace)
      embedding_dim = params.pop_int("embedding_dim")
      pretrained_file = params.pop("pretrained_file", None)
      projection_dim = params.pop_int("projection_dim", None)
      trainable = params.pop_bool("trainable", True)
      padding_index = params.pop_int("padding_index", None)
      max_norm = params.pop_float("max_norm", None)
      norm_type = params.pop_float("norm_type", 2.0)
      scale_grad_by_freq = params.pop_bool("scale_grad_by_freq", False)
      sparse = params.pop_bool("sparse", False)
      params.assert_empty(cls.__name__)
  
      if pretrained_file:
          # If we're loading a saved model, we don't want to actually read a pre-trained
          # embedding file - the embeddings will just be in our saved weights, and we might not
          # have the original embedding file anymore, anyway.
          weight = _read_pretrained_embeddings_file(
              pretrained_file, embedding_dim, vocab, vocab_namespace
          )
      else:
          weight = None
  
      return cls(
          num_embeddings=num_embeddings,
          embedding_dim=embedding_dim,
          projection_dim=projection_dim,
          weight=weight,
          padding_index=padding_index,
          trainable=trainable,
          max_norm=max_norm,
          norm_type=norm_type,
          scale_grad_by_freq=scale_grad_by_freq,
          sparse=sparse,
      )
  
imports: from __future__ import with_statement
  from __future__ import absolute_import
  import io
  import tarfile
  import zipfile
  import bz2
  import gzip
  import re
  import logging
  import warnings
  import itertools
  import numpy
  import torch
  from torch.nn.functional import embedding
  from allennlp.common import Params, Tqdm
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.file_utils import get_file_extension, cached_path
  from allennlp.data import Vocabulary
  from allennlp.modules.token_embedders.token_embedder import TokenEmbedder
  from allennlp.modules.time_distributed import TimeDistributed
label_desc: Use image node_id 4 for calling the Embedding obj's underlying member method code with example usage: obj.from_params(cls, vocab, params) and returns: cls