code: def test_embedding_vocab_extension_works_with_pretrained_embedding_file(
      self,
  ):
      vocab = Vocabulary()
      vocab.add_token_to_namespace("word1")
      vocab.add_token_to_namespace("word2")
  
      embeddings_filename = str(self.TEST_DIR / "embeddings2.gz")
      with gzip.open(embeddings_filename, "wb") as embeddings_file:
          embeddings_file.write("word3 0.5 0.3 -6.0\n".encode("utf-8"))
          embeddings_file.write("word4 1.0 2.3 -1.0\n".encode("utf-8"))
          embeddings_file.write("word2 0.1 0.4 -4.0\n".encode("utf-8"))
          embeddings_file.write("word1 1.0 2.3 -1.0\n".encode("utf-8"))
  
      embedding_params = Params(
          {
              "vocab_namespace": "tokens",
              "embedding_dim": 3,
              "pretrained_file": embeddings_filename,
          }
      )
      embedder = Embedding.from_params(embedding_params, vocab=vocab)
  
      # Change weight to simulate embedding training
      embedder.weight.data += 1
      assert torch.all(
          embedder.weight[2:, :]
          == torch.Tensor([[2.0, 3.3, 0.0], [1.1, 1.4, -3.0]])
      )
      original_weight = embedder.weight
  
      assert tuple(original_weight.size()) == (
          4,
          3,
      )  # 4 because of padding and OOV
  
      vocab.add_token_to_namespace("word3")
      embedder.extend_vocab(
          vocab, extension_pretrained_file=embeddings_filename
      )  # default namespace
      extended_weight = embedder.weight
  
      # Make sure extenstion happened for extra token in extended vocab
      assert tuple(extended_weight.size()) == (5, 3)
  
      # Make sure extension doesn't change original trained weights.
      assert torch.all(original_weight[:4, :] == extended_weight[:4, :])
  
      # Make sure extended weight is taken from the embedding file.
      assert torch.all(
          extended_weight[4, :] == torch.Tensor([0.5, 0.3, -6.0])
      )
  
imports: import gzip
  import warnings
  import numpy
  import pytest
  import torch
  from allennlp.common import Params
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.data import Vocabulary
  from allennlp.modules.token_embedders.embedding import _read_pretrained_embeddings_file, Embedding, EmbeddingsTextFile, format_embeddings_file_uri, parse_embeddings_file_uri
label_desc: Use image node_id 14 for calling the TestEmbedding obj's underlying member method code with example usage: obj.test_embedding_vocab_extension_works_with_pretrained_embedding_file() without return types