class_docstr: Contextual word embeddings using word-level LM, as proposed in Peters et al., 2018.
  ELMo word vectors can be constructed by combining layers in different ways.
  Default is to concatene the top 3 layers in the LM.
code: def __init__(
      self,
      model: str = "original",
      options_file: Optional[str] = None,
      weight_file: Optional[str] = None,
      embedding_mode: str = "all",
  ) -> None:
      super().__init__()
  
      self.instance_parameters = self.get_instance_parameters(
          locals=locals()
      )
  
      try:
          import allennlp.commands.elmo
      except ModuleNotFoundError:
          log.warning("-" * 100)
          log.warning(
              'ATTENTION! The library "allennlp" is not installed!'
          )
          log.warning(
              'To use ELMoEmbeddings, please first install with "pip install allennlp==0.9.0"'
          )
          log.warning("-" * 100)
  
      assert embedding_mode in ["all", "top", "average"]
  
      self.name = f"elmo-{model}-{embedding_mode}"
      self.static_embeddings = True
  
      if not options_file or not weight_file:
          # the default model for ELMo is the 'original' model, which is very large
          options_file = allennlp.commands.elmo.DEFAULT_OPTIONS_FILE
          weight_file = allennlp.commands.elmo.DEFAULT_WEIGHT_FILE
          # alternatively, a small, medium or portuguese model can be selected by passing the appropriate mode name
          if model == "small":
              options_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x1024_128_2048cnn_1xhighway/elmo_2x1024_128_2048cnn_1xhighway_options.json"
              weight_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x1024_128_2048cnn_1xhighway/elmo_2x1024_128_2048cnn_1xhighway_weights.hdf5"
          if model == "medium":
              options_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x2048_256_2048cnn_1xhighway/elmo_2x2048_256_2048cnn_1xhighway_options.json"
              weight_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x2048_256_2048cnn_1xhighway/elmo_2x2048_256_2048cnn_1xhighway_weights.hdf5"
          if model in ["large", "5.5B"]:
              options_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x4096_512_2048cnn_2xhighway_5.5B/elmo_2x4096_512_2048cnn_2xhighway_5.5B_options.json"
              weight_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x4096_512_2048cnn_2xhighway_5.5B/elmo_2x4096_512_2048cnn_2xhighway_5.5B_weights.hdf5"
          if model == "pt" or model == "portuguese":
              options_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/contributed/pt/elmo_pt_options.json"
              weight_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/contributed/pt/elmo_pt_weights.hdf5"
          if model == "pubmed":
              options_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/contributed/pubmed/elmo_2x4096_512_2048cnn_2xhighway_options.json"
              weight_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/contributed/pubmed/elmo_2x4096_512_2048cnn_2xhighway_weights_PubMed_only.hdf5"
  
      if embedding_mode == "all":
          self.embedding_mode_fn = self.use_layers_all
      elif embedding_mode == "top":
          self.embedding_mode_fn = self.use_layers_top
      elif embedding_mode == "average":
          self.embedding_mode_fn = self.use_layers_average
  
      # put on Cuda if available
      from flair import device
  
      if device.type == "cuda":
          cuda_device = device.index
      elif device.type == "cpu":
          cuda_device = -1
      else:
          cuda_device = 0
  
      self.ee = allennlp.commands.elmo.ElmoEmbedder(
          options_file=options_file,
          weight_file=weight_file,
          cuda_device=cuda_device,
      )
  
      # embed a dummy sentence to determine embedding_length
      dummy_sentence: Sentence = Sentence([Token("hello")])
      embedded_dummy = self.embed(dummy_sentence)
      self.__embedding_length: int = len(
          embedded_dummy[0][0].get_embedding()
      )
  
imports: import logging
  import re
  from pathlib import Path
  from typing import List, Optional, Union
  import torch
  from deprecated.sphinx import deprecated
  import flair
  from flair.data import Sentence, Token
  from flair.embeddings.document import DocumentEmbeddings
  from flair.embeddings.token import StackedEmbeddings, TokenEmbeddings
  from flair.file_utils import cached_path
  from flair.nn import LockedDropout, WordDropout
label_desc: Use image node_id 1 to create a new ELMoEmbeddings object from inherited base classes: TokenEmbeddings with example: obj = ELMoEmbeddings(model, options_file, weight_file, embedding_mode)