docstr: Embeds each sample in the given `data_set`.
  
  The embedding is created by using hidden representation from the transformer model's
  representation in the hidden layer at the given `hidden_layer_index`.
  
  Parameters
  ----------
  return_proba : bool
      Also return the class probabilities for `data_set`.
  embedding_method : str
      Embedding method to use [avg, cls].
  hidden_layer_index : int, default=-1
      Index of the hidden layer.
  pbar : 'tqdm' or None, default='tqdm'
      Displays a progress bar if 'tqdm' is passed.
  
  Returns
  -------
  embeddings : np.ndarray
      Embeddings in the shape (N, hidden_layer_dimensionality).
  proba : np.ndarray
      Class probabilities for `data_set` (only if `return_predictions` is `True`).
docstr_tok: ["Embeds","each","sample","in","the","given","`","data_set","`",".","The","embedding","is","created","by","using","hidden","representation","from","the","transformer","model's","representation","in","the","hidden","layer","at","the","given","`","hidden_layer_index","`",".","Parameters","--","--","--","--","--","return_proba",":","bool","Also","return","the","class","probabilities","for","`","data_set","`",".","embedding_method",":","str","Embedding","method","to","use","[","avg",",","cls","]",".","hidden_layer_index",":","int",",","default=-1","Index","of","the","hidden","layer",".","pbar",":","'tqdm","'","or","None",",","default='tqdm'","Displays","a","progress","bar","if","'tqdm","'","is","passed",".","Returns","--","--","--","-","embeddings",":","np.ndarray","Embeddings","in","the","shape","(","N",",","hidden_layer_dimensionality",")",".","proba",":","np.ndarray","Class","probabilities","for","`","data_set","`","(","only","if","`","return_predictions","`","is","`","True","`",")","."]
code: def embed(
      self,
      data_set,
      return_proba=False,
      embedding_method=EMBEDDING_METHOD_AVG,
      hidden_layer_index=-1,
      pbar="tqdm",
  ):
      """Embeds each sample in the given `data_set`.
  
      The embedding is created by using hidden representation from the transformer model's
      representation in the hidden layer at the given `hidden_layer_index`.
  
      Parameters
      ----------
      return_proba : bool
          Also return the class probabilities for `data_set`.
      embedding_method : str
          Embedding method to use [avg, cls].
      hidden_layer_index : int, default=-1
          Index of the hidden layer.
      pbar : 'tqdm' or None, default='tqdm'
          Displays a progress bar if 'tqdm' is passed.
  
      Returns
      -------
      embeddings : np.ndarray
          Embeddings in the shape (N, hidden_layer_dimensionality).
      proba : np.ndarray
          Class probabilities for `data_set` (only if `return_predictions` is `True`).
      """
  
      if self.model is None:
          raise ValueError(
              "Model is not trained. Please call fit() first."
          )
  
      self.model.eval()
  
      train_iter = dataloader(
          data_set.data,
          self.mini_batch_size,
          self._create_collate_fn(),
          train=False,
      )
  
      tensors = []
      predictions = []
  
      with build_pbar_context(
          pbar, tqdm_kwargs={"total": list_length(data_set)}
      ) as pbar:
          for batch in train_iter:
              batch_len, logits = self._create_embeddings(
                  tensors,
                  batch,
                  embedding_method=embedding_method,
                  hidden_layer_index=hidden_layer_index,
              )
              pbar.update(batch_len)
              if return_proba:
                  predictions.extend(
                      F.softmax(logits, dim=1)
                      .detach()
                      .to("cpu")
                      .tolist()
                  )
  
      if return_proba:
          return np.array(tensors), np.array(predictions)
  
      return np.array(tensors)
  
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 1 for calling the TransformerBasedEmbeddingMixin obj's underlying member method code with example usage: obj.embed(data_set, return_proba, embedding_method, hidden_layer_index, pbar) and returns: np, np,  np