class_docstr: Run a pre-trained bidirectional language model, outputing the activations at each
  layer for weighting together into an ELMo representation (with
  ``allennlp.modules.seq2seq_encoders.Elmo``).  This is a lower level class, useful
  for advanced uses, but most users should use ``allennlp.modules.seq2seq_encoders.Elmo``
  directly.
  
  Parameters
  ----------
  options_file : ``str``
      ELMo JSON options file
  weight_file : ``str``
      ELMo hdf5 weight file
  requires_grad: ``bool``, optional
      If True, compute gradient of ELMo parameters for fine tuning.
  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, _ElmoBiLm 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.
class_docstr_tok: ["Run","a","pre-trained","bidirectional","language","model",",","outputing","the","activations","at","each","layer","for","weighting","together","into","an","ELMo","representation","(","with","``","allennlp.modules.seq2seq_encoders.Elmo","``",")",".","This","is","a","lower","level","class",",","useful","for","advanced","uses",",","but","most","users","should","use","``","allennlp.modules.seq2seq_encoders.Elmo","``","directly",".","Parameters","--","--","--","--","--","options_file",":","``","str","``","ELMo","JSON","options","file","weight_file",":","``","str","``","ELMo","hdf5","weight","file","requires_grad",":","``","bool","``",",","optional","If","True",",","compute","gradient","of","ELMo","parameters","for","fine","tuning",".","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",",","_ElmoBiLm","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","."]
docstr: Given a list of tokens, this method precomputes word representations
  by running just the character convolutions and highway layers of elmo,
  essentially creating uncontextual word vectors. On subsequent forward passes,
  the word ids are looked up from an embedding, rather than being computed on
  the fly via the CNN encoder.
  
  This function sets 3 attributes:
  
  _word_embedding : ``torch.Tensor``
      The word embedding for each word in the tokens passed to this method.
  _bos_embedding : ``torch.Tensor``
      The embedding for the BOS token.
  _eos_embedding : ``torch.Tensor``
      The embedding for the EOS token.
  
  Parameters
  ----------
  tokens : ``List[str]``, required.
      A list of tokens to precompute character convolutions for.
code: def create_cached_cnn_embeddings(self, tokens):
      """
      Given a list of tokens, this method precomputes word representations
      by running just the character convolutions and highway layers of elmo,
      essentially creating uncontextual word vectors. On subsequent forward passes,
      the word ids are looked up from an embedding, rather than being computed on
      the fly via the CNN encoder.
  
      This function sets 3 attributes:
  
      _word_embedding : ``torch.Tensor``
          The word embedding for each word in the tokens passed to this method.
      _bos_embedding : ``torch.Tensor``
          The embedding for the BOS token.
      _eos_embedding : ``torch.Tensor``
          The embedding for the EOS token.
  
      Parameters
      ----------
      tokens : ``List[str]``, required.
          A list of tokens to precompute character convolutions for.
      """
      tokens = [
          ELMoCharacterMapper.bos_token,
          ELMoCharacterMapper.eos_token,
      ] + tokens
      timesteps = 32
      batch_size = 32
      chunked_tokens = lazy_groups_of(iter(tokens), timesteps)
  
      all_embeddings = []
      device = get_device_of(next(self.parameters()))
      for batch in lazy_groups_of(chunked_tokens, batch_size):
          # Shape (batch_size, timesteps, 50)
          batched_tensor = batch_to_ids(batch)
          # NOTE: This device check is for when a user calls this method having
          # already placed the model on a device. If this is called in the
          # constructor, it will probably happen on the CPU. This isn't too bad,
          # because it's only a few convolutions and will likely be very fast.
          if device >= 0:
              batched_tensor = batched_tensor.cuda(device)
          output = self._token_embedder(batched_tensor)
          token_embedding = output["token_embedding"]
          mask = output["mask"]
          token_embedding, _ = remove_sentence_boundaries(
              token_embedding, mask
          )
          all_embeddings.append(
              token_embedding.view(-1, token_embedding.size(-1))
          )
      full_embedding = torch.cat(all_embeddings, 0)
  
      # We might have some trailing embeddings from padding in the batch, so
      # we clip the embedding and lookup to the right size.
      full_embedding = full_embedding[: len(tokens), :]
      embedding = full_embedding[2 : len(tokens), :]
      vocab_size, embedding_dim = list(embedding.size())
  
      from allennlp.modules.token_embedders import Embedding  # type: ignore
  
      self._bos_embedding = full_embedding[0, :]
      self._eos_embedding = full_embedding[1, :]
      self._word_embedding = Embedding(
          vocab_size,  # type: ignore
          embedding_dim,
          weight=embedding.data,
          trainable=self._requires_grad,
          padding_index=0,
      )
  
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 _ElmoBiLm obj's underlying member method code with example usage: obj.create_cached_cnn_embeddings(tokens) without return types