code: def test_elmo_bilm_can_cache_char_cnn_embeddings(self):
      sentences = [
          ["This", "is", "a", "sentence"],
          ["Here", "'s", "one"],
          ["Another", "one"],
      ]
      vocab, tensor = self.get_vocab_and_both_elmo_indexed_ids(
          sentences
      )
      words_to_cache = list(
          vocab.get_token_to_index_vocabulary("tokens").keys()
      )
      elmo_bilm = _ElmoBiLm(self.options_file, self.weight_file)
      elmo_bilm.eval()
      no_cache = elmo_bilm(
          tensor["character_ids"]["elmo_tokens"],
          tensor["character_ids"]["elmo_tokens"],
      )
  
      # ELMo is stateful, so we need to actually re-initialise it for this comparison to work.
      elmo_bilm = _ElmoBiLm(
          self.options_file,
          self.weight_file,
          vocab_to_cache=words_to_cache,
      )
      elmo_bilm.eval()
      cached = elmo_bilm(
          tensor["character_ids"]["elmo_tokens"],
          tensor["tokens"]["tokens"],
      )
  
      numpy.testing.assert_array_almost_equal(
          no_cache["mask"].data.cpu().numpy(),
          cached["mask"].data.cpu().numpy(),
      )
      for activation_cached, activation in zip(
          cached["activations"], no_cache["activations"]
      ):
          numpy.testing.assert_array_almost_equal(
              activation_cached.data.cpu().numpy(),
              activation.data.cpu().numpy(),
              decimal=6,
          )
  
imports: import json
  import os
  import warnings
  from typing import List
  import numpy
  import torch
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.data import Instance, Token, Vocabulary
  from allennlp.data.batch import Batch
  from allennlp.data.fields import TextField
  from allennlp.data.token_indexers.elmo_indexer import ELMoTokenCharactersIndexer
  from allennlp.data.token_indexers.single_id_token_indexer import SingleIdTokenIndexer
  from allennlp.data.data_loaders import SimpleDataLoader
  from allennlp.modules.elmo import _ElmoBiLm, _ElmoCharacterEncoder, Elmo
  from allennlp.modules.token_embedders import ElmoTokenEmbedder
  from allennlp.nn.util import remove_sentence_boundaries
label_desc: Use image node_id 3 for calling the TestElmoBiLm obj's underlying member method code with example usage: obj.test_elmo_bilm_can_cache_char_cnn_embeddings() without return types