code: def _create_embeddings(
      self,
      tensors,
      batch,
      embedding_method="avg",
      hidden_layer_index=-1,
  ):
      text, masks, *_ = batch
      text = text.to(self.device, non_blocking=True)
      masks = masks.to(self.device, non_blocking=True)
  
      outputs = self.model(
          text,
          token_type_ids=None,
          attention_mask=masks,
          output_hidden_states=True,
      )
  
      # only use states of hidden layers, excluding the token embeddings
      hidden_states = outputs.hidden_states[1:]
  
      if embedding_method == self.EMBEDDING_METHOD_CLS_TOKEN:
          representation = hidden_states[hidden_layer_index][:, 0]
      elif embedding_method == self.EMBEDDING_METHOD_AVG:
          representation = torch.mean(
              hidden_states[hidden_layer_index][:, 1:], dim=1
          )
      else:
          raise ValueError(
              f"Invalid embedding_method: {embedding_method}"
          )
  
      tensors.extend(
          representation.detach().to("cpu", non_blocking=True).numpy()
      )
  
      return text.size(0), outputs.logits
  
imports: import datetime
  import logging
  import tempfile
  import warnings
  import numpy
  from functools import partial
  from small_text.classifiers.classification import EmbeddingMixin
  from small_text.integrations.pytorch.exceptions import PytorchNotFoundError
  from small_text.utils.classification import get_splits
  from small_text.utils.context import build_pbar_context
  from small_text.utils.data import check_training_data, list_length
  from small_text.utils.datetime import format_timedelta
  from small_text.utils.annotations import early_stopping_deprecation_warning, model_selection_deprecation_warning
  from small_text.utils.labels import get_num_labels
  from small_text.utils.logging import verbosity_logger, VERBOSITY_MORE_VERBOSE
  from small_text.utils.system import get_tmp_dir_base
label_desc: Use image node_id 2 for calling the TransformerBasedEmbeddingMixin obj's underlying member method code with example usage: obj._create_embeddings(tensors, batch, embedding_method, hidden_layer_index) and returns: text,  outputs