code: def test_end_to_end_for_first_sub_token_embedding(
      self, sub_token_mode: str
  ):
      token_indexer = PretrainedTransformerMismatchedIndexer(
          "bert-base-uncased"
      )
  
      sentence1 = ["A", ",", "AllenNLP", "sentence", "."]
      sentence2 = ["AllenNLP", "is", "open", "source", "NLP", "library"]
  
      tokens1 = [Token(word) for word in sentence1]
      tokens2 = [Token(word) for word in sentence2]
  
      vocab = Vocabulary()
  
      params = Params(
          {
              "token_embedders": {
                  "bert": {
                      "type": "pretrained_transformer_mismatched",
                      "model_name": "bert-base-uncased",
                      "sub_token_mode": sub_token_mode,
                  }
              }
          }
      )
      token_embedder = BasicTextFieldEmbedder.from_params(
          vocab=vocab, params=params
      )
  
      instance1 = Instance(
          {"tokens": TextField(tokens1, {"bert": token_indexer})}
      )
      instance2 = Instance(
          {"tokens": TextField(tokens2, {"bert": token_indexer})}
      )
  
      batch = Batch([instance1, instance2])
      batch.index_instances(vocab)
  
      padding_lengths = batch.get_padding_lengths()
      tensor_dict = batch.as_tensor_dict(padding_lengths)
      tokens = tensor_dict["tokens"]
  
      assert tokens["bert"]["mask"].tolist() == [
          [True, True, True, True, True, False],
          [True, True, True, True, True, True],
      ]
  
      assert tokens["bert"]["offsets"].tolist() == [
          [[1, 1], [2, 2], [3, 5], [6, 6], [7, 7], [0, 0]],
          [[1, 3], [4, 4], [5, 5], [6, 6], [7, 8], [9, 9]],
      ]
  
      # Attention mask
      bert_vectors = token_embedder(tokens)
  
      assert bert_vectors.size() == (
          2,
          max(len(sentence1), len(sentence2)),
          768,
      )
      assert not torch.isnan(bert_vectors).any()
  
imports: import pytest
  import torch
  from allennlp.common import Params, cached_transformers
  from allennlp.common.checks import ConfigurationError
  from allennlp.data import Token, Vocabulary
  from allennlp.data.batch import Batch
  from allennlp.data.fields import TextField
  from allennlp.data.instance import Instance
  from allennlp.data.token_indexers import PretrainedTransformerMismatchedIndexer
  from allennlp.modules.text_field_embedders import BasicTextFieldEmbedder
  from allennlp.modules.token_embedders import PretrainedTransformerMismatchedEmbedder
  from allennlp.common.testing import AllenNlpTestCase
label_desc: Use image node_id 6 for calling the TestPretrainedTransformerMismatchedEmbedder obj's underlying member method code with example usage: obj.test_end_to_end_for_first_sub_token_embedding(sub_token_mode) without return types