class_docstr: Utility class for opening embeddings text files. Handles various compression formats,
  as well as context management.
  
  Parameters
  ----------
  file_uri: str
      It can be:
  
      * a file system path or a URL of an eventually compressed text file or a zip/tar archive
        containing a single file.
      * URI of the type ``(archive_path_or_url)#file_path_inside_archive`` if the text file
        is contained in a multi-file archive.
  
  encoding: str
  cache_dir: str
class_docstr_tok: ["Utility","class","for","opening","embeddings","text","files",".","Handles","various","compression","formats",",","as","well","as","context","management",".","Parameters","--","--","--","--","--","file_uri",":","str","It","can","be",":","*","a","file","system","path","or","a","URL","of","an","eventually","compressed","text","file","or","a","zip\/tar","archive","containing","a","single","file",".","*","URI","of","the","type","``","(","archive_path_or_url",")","#","file_path_inside_archive","``","if","the","text","file","is","contained","in","a","multi-file","archive",".","encoding",":","str","cache_dir",":","str"]
code: def __init__(
      self, file_uri, encoding=DEFAULT_ENCODING, cache_dir=None
  ):
      self.uri = file_uri
      self._encoding = encoding
      self._cache_dir = cache_dir
      self._archive_handle = (
          None  # only if the file is inside an archive
      )
  
      main_file_uri, path_inside_archive = parse_embeddings_file_uri(
          file_uri
      )
      main_file_local_path = cached_path(
          main_file_uri, cache_dir=cache_dir
      )
  
      if zipfile.is_zipfile(main_file_local_path):  # ZIP archive
          self._open_inside_zip(main_file_uri, path_inside_archive)
  
      elif tarfile.is_tarfile(main_file_local_path):  # TAR archive
          self._open_inside_tar(main_file_uri, path_inside_archive)
  
      else:  # all the other supported formats, including uncompressed files
          if path_inside_archive:
              raise ValueError(
                  "Unsupported archive format: %s" + main_file_uri
              )
  
          # All the python packages for compressed files share the same interface of io.open
          extension = get_file_extension(main_file_uri)
          package = {
              ".txt": io,
              ".vec": io,
              ".gz": gzip,
              ".bz2": bz2,
          }.get(extension, None)
  
          if package is None:
              logger.warning(
                  'The embeddings file has an unknown file extension "%s". '
                  "We will assume the file is an (uncompressed) text file",
                  extension,
              )
              package = io
  
          self._handle = package.open(main_file_local_path, "rt", encoding=encoding)  # type: ignore
  
      # To use this with tqdm we'd like to know the number of tokens. It's possible that the
      # first line of the embeddings file contains this: if it does, we want to start iteration
      # from the 2nd line, otherwise we want to start from the 1st.
      # Unfortunately, once we read the first line, we cannot move back the file iterator
      # because the underlying file may be "not seekable"; we use itertools.chain instead.
      first_line = next(self._handle)  # this moves the iterator forward
      self.num_tokens = (
          EmbeddingsTextFile._get_num_tokens_from_first_line(first_line)
      )
      if self.num_tokens:
          # the first line is a header line: start iterating from the 2nd line
          self._iterator = self._handle
      else:
          # the first line is not a header line: start iterating from the 1st line
          self._iterator = itertools.chain([first_line], self._handle)
  
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 1 to create a new EmbeddingsTextFile object  with example: obj = EmbeddingsTextFile(file_uri, encoding, cache_dir)