class_docstr: Compute ELMo representations using a pre-trained bidirectional language model.
  
  See "Deep contextualized word representations", Peters et al. for details.
  
  This module takes character id input and computes ``num_output_representations`` different layers
  of ELMo representations.  Typically ``num_output_representations`` is 1 or 2.  For example, in
  the case of the SRL model in the above paper, ``num_output_representations=1`` where ELMo was included at
  the input token representation layer.  In the case of the SQuAD model, ``num_output_representations=2``
  as ELMo was also included at the GRU output layer.
  
  In the implementation below, we learn separate scalar weights for each output layer,
  but only run the biLM once on each input sequence for efficiency.
  
  Parameters
  ----------
  options_file : ``str``, required.
      ELMo JSON options file
  weight_file : ``str``, required.
      ELMo hdf5 weight file
  num_output_representations: ``int``, required.
      The number of ELMo representation layers to output.
  requires_grad: ``bool``, optional
      If True, compute gradient of ELMo parameters for fine tuning.
  do_layer_norm : ``bool``, optional, (default=False).
      Should we apply layer normalization (passed to ``ScalarMix``)?
  dropout : ``float``, optional, (default = 0.5).
      The dropout to be applied to the ELMo representations.
  vocab_to_cache : ``List[str]``, optional, (default = 0.5).
      A list of words to pre-compute and cache character convolutions
      for. If you use this option, Elmo expects that you pass word
      indices of shape (batch_size, timesteps) to forward, instead
      of character indices. If you use this option and pass a word which
      wasn't pre-cached, this will break.
  module : ``torch.nn.Module``, optional, (default = None).
      If provided, then use this module instead of the pre-trained ELMo biLM.
      If using this option, then pass ``None`` for both ``options_file``
      and ``weight_file``.  The module must provide a public attribute
      ``num_layers`` with the number of internal layers and its ``forward``
      method must return a ``dict`` with ``activations`` and ``mask`` keys
      (see `_ElmoBilm`` for an example).  Note that ``requires_grad`` is also
      ignored with this option.
class_docstr_tok: ["Compute","ELMo","representations","using","a","pre-trained","bidirectional","language","model",".","See","``","Deep","contextualized","word","representations","''",",","Peters","et","al",".","for","details",".","This","module","takes","character","id","input","and","computes","``","num_output_representations","``","different","layers","of","ELMo","representations",".","Typically","``","num_output_representations","``","is","1","or","2",".","For","example",",","in","the","case","of","the","SRL","model","in","the","above","paper",",","``","num_output_representations=1","``","where","ELMo","was","included","at","the","input","token","representation","layer",".","In","the","case","of","the","SQuAD","model",",","``","num_output_representations=2","``","as","ELMo","was","also","included","at","the","GRU","output","layer",".","In","the","implementation","below",",","we","learn","separate","scalar","weights","for","each","output","layer",",","but","only","run","the","biLM","once","on","each","input","sequence","for","efficiency",".","Parameters","--","--","--","--","--","options_file",":","``","str","``",",","required",".","ELMo","JSON","options","file","weight_file",":","``","str","``",",","required",".","ELMo","hdf5","weight","file","num_output_representations",":","``","int","``",",","required",".","The","number","of","ELMo","representation","layers","to","output",".","requires_grad",":","``","bool","``",",","optional","If","True",",","compute","gradient","of","ELMo","parameters","for","fine","tuning",".","do_layer_norm",":","``","bool","``",",","optional",",","(","default=False",")",".","Should","we","apply","layer","normalization","(","passed","to","``","ScalarMix","``",")","?","dropout",":","``","float","``",",","optional",",","(","default","=","0.5",")",".","The","dropout","to","be","applied","to","the","ELMo","representations",".","vocab_to_cache",":","``","List","[","str","]","``",",","optional",",","(","default","=","0.5",")",".","A","list","of","words","to","pre-compute","and","cache","character","convolutions","for",".","If","you","use","this","option",",","Elmo","expects","that","you","pass","word","indices","of","shape","(","batch_size",",","timesteps",")","to","forward",",","instead","of","character","indices",".","If","you","use","this","option","and","pass","a","word","which","was","n't","pre-cached",",","this","will","break",".","module",":","``","torch.nn.Module","``",",","optional",",","(","default","=","None",")",".","If","provided",",","then","use","this","module","instead","of","the","pre-trained","ELMo","biLM",".","If","using","this","option",",","then","pass","``","None","``","for","both","``","options_file","``","and","``","weight_file","``",".","The","module","must","provide","a","public","attribute","``","num_layers","``","with","the","number","of","internal","layers","and","its","``","forward","``","method","must","return","a","``","dict","``","with","``","activations","``","and","``","mask","``","keys","(","see","`","_ElmoBilm","``","for","an","example",")",".","Note","that","``","requires_grad","``","is","also","ignored","with","this","option","."]
code: def from_params(cls, params):
      # Add files to archive
      params.add_file_to_archive("options_file")
      params.add_file_to_archive("weight_file")
  
      options_file = params.pop("options_file")
      weight_file = params.pop("weight_file")
      requires_grad = params.pop("requires_grad", False)
      num_output_representations = params.pop(
          "num_output_representations"
      )
      do_layer_norm = params.pop_bool("do_layer_norm", False)
      dropout = params.pop_float("dropout", 0.5)
      params.assert_empty(cls.__name__)
  
      return cls(
          options_file=options_file,
          weight_file=weight_file,
          num_output_representations=num_output_representations,
          requires_grad=requires_grad,
          do_layer_norm=do_layer_norm,
          dropout=dropout,
      )
  
imports: from __future__ import with_statement
  from __future__ import absolute_import
  import json
  import logging
  import warnings
  import torch
  from torch.nn.modules import Dropout
  import numpy
  from io import open
  from allennlp.common.file_utils import cached_path
  from allennlp.common.checks import ConfigurationError
  from allennlp.common import Params
  from allennlp.common.util import lazy_groups_of
  from allennlp.modules.elmo_lstm import ElmoLstm
  from allennlp.modules.highway import Highway
  from allennlp.modules.scalar_mix import ScalarMix
  from allennlp.nn.util import remove_sentence_boundaries, add_sentence_boundary_token_ids, get_device_of
  from allennlp.data.token_indexers.elmo_indexer import ELMoCharacterMapper, ELMoTokenCharactersIndexer
  from allennlp.data.dataset import Batch
  from allennlp.data import Token, Vocabulary, Instance
  from allennlp.data.fields import TextField
label_desc: Use image node_id 4 for calling the Elmo obj's underlying member method code with example usage: obj.from_params(cls, params) and returns: cls