docstr: Parameters
  ----------
  transformer_model : TransformerModelArguments
      Settings for transformer model, tokenizer and config.
  num_classes : int
      Number of classes.
  multi_label : bool, default=False
      If `False`, the classes are mutually exclusive, i.e. the prediction step results in
      exactly one predicted label per instance.
  num_epochs : int, default=10
      Epochs to train.
  lr : float, default=2e-5
      Learning rate.
  mini_batch_size : int, default=12
      Size of mini batches during training.
  validation_set_size : float, default=0.1
      The size of the validation set as a fraction of the training set.
  validations_per_epoch : int, default=1
      Defines how of the validation set is evaluated during the training of a single epoch.
  early_stopping_no_improvement : int, default=5
      Number of epochs with no improvement in validation loss until early stopping
      is triggered.
  
      .. deprecated:: 1.1.0
         Use the `early_stopping` kwarg in `fit()` instead.
  early_stopping_acc : float, default=-1
      Accuracy threshold in the interval (0, 1] which triggers early stopping.
  
      .. deprecated:: 1.1.0
         Use the `early_stopping` kwarg in `fit()` instead.
  model_selection : bool, default=True
      If True, model selects first saves the model after each epoch. At the end of the
      training step the model with the lowest validation error is selected.
  fine_tuning_arguments : FineTuningArguments or None, default=None
      Fine tuning arguments.
  device : str or torch.device, default=None
      Torch device on which the computation will be performed.
  memory_fix : int, default=1
      If this value is greater than zero, every `memory_fix`-many epochs the cuda cache will
      be emptied to force unused GPU memory being released.
  class_weight : 'balanced' or None, default=None
      If 'balanced', then the loss function is weighted inversely proportional to the
      label distribution to the current train set.
docstr_tok: ["Parameters","--","--","--","--","--","transformer_model",":","TransformerModelArguments","Settings","for","transformer","model",",","tokenizer","and","config",".","num_classes",":","int","Number","of","classes",".","multi_label",":","bool",",","default=False","If","`","False","`",",","the","classes","are","mutually","exclusive",",","i.e",".","the","prediction","step","results","in","exactly","one","predicted","label","per","instance",".","num_epochs",":","int",",","default=10","Epochs","to","train",".","lr",":","float",",","default=2e-5","Learning","rate",".","mini_batch_size",":","int",",","default=12","Size","of","mini","batches","during","training",".","validation_set_size",":","float",",","default=0.1","The","size","of","the","validation","set","as","a","fraction","of","the","training","set",".","validations_per_epoch",":","int",",","default=1","Defines","how","of","the","validation","set","is","evaluated","during","the","training","of","a","single","epoch",".","early_stopping_no_improvement",":","int",",","default=5","Number","of","epochs","with","no","improvement","in","validation","loss","until","early","stopping","is","triggered",".","..","deprecated",":",":","1.1.0","Use","the","`","early_stopping","`","kwarg","in","`","fit","(",")","`","instead",".","early_stopping_acc",":","float",",","default=-1","Accuracy","threshold","in","the","interval","(","0",",","1","]","which","triggers","early","stopping",".","..","deprecated",":",":","1.1.0","Use","the","`","early_stopping","`","kwarg","in","`","fit","(",")","`","instead",".","model_selection",":","bool",",","default=True","If","True",",","model","selects","first","saves","the","model","after","each","epoch",".","At","the","end","of","the","training","step","the","model","with","the","lowest","validation","error","is","selected",".","fine_tuning_arguments",":","FineTuningArguments","or","None",",","default=None","Fine","tuning","arguments",".","device",":","str","or","torch.device",",","default=None","Torch","device","on","which","the","computation","will","be","performed",".","memory_fix",":","int",",","default=1","If","this","value","is","greater","than","zero",",","every","`","memory_fix","`","-many","epochs","the","cuda","cache","will","be","emptied","to","force","unused","GPU","memory","being","released",".","class_weight",":","'balanced","'","or","None",",","default=None","If","'balanced","'",",","then","the","loss","function","is","weighted","inversely","proportional","to","the","label","distribution","to","the","current","train","set","."]
code: def __init__(
      self,
      transformer_model: TransformerModelArguments,
      num_classes: int,
      multi_label: bool = False,
      num_epochs: int = 10,
      lr: float = 2e-5,
      mini_batch_size: int = 12,
      validation_set_size: float = 0.1,
      validations_per_epoch: int = 1,
      early_stopping_no_improvement: int = 5,
      early_stopping_acc: float = -1,
      model_selection: bool = True,
      fine_tuning_arguments=None,
      device=None,
      memory_fix=1,
      class_weight=None,
      verbosity=VERBOSITY_MORE_VERBOSE,
      cache_dir=".active_learning_lib_cache/",
  ):
      """
      Parameters
      ----------
      transformer_model : TransformerModelArguments
          Settings for transformer model, tokenizer and config.
      num_classes : int
          Number of classes.
      multi_label : bool, default=False
          If `False`, the classes are mutually exclusive, i.e. the prediction step results in
          exactly one predicted label per instance.
      num_epochs : int, default=10
          Epochs to train.
      lr : float, default=2e-5
          Learning rate.
      mini_batch_size : int, default=12
          Size of mini batches during training.
      validation_set_size : float, default=0.1
          The size of the validation set as a fraction of the training set.
      validations_per_epoch : int, default=1
          Defines how of the validation set is evaluated during the training of a single epoch.
      early_stopping_no_improvement : int, default=5
          Number of epochs with no improvement in validation loss until early stopping
          is triggered.
  
          .. deprecated:: 1.1.0
             Use the `early_stopping` kwarg in `fit()` instead.
      early_stopping_acc : float, default=-1
          Accuracy threshold in the interval (0, 1] which triggers early stopping.
  
          .. deprecated:: 1.1.0
             Use the `early_stopping` kwarg in `fit()` instead.
      model_selection : bool, default=True
          If True, model selects first saves the model after each epoch. At the end of the
          training step the model with the lowest validation error is selected.
      fine_tuning_arguments : FineTuningArguments or None, default=None
          Fine tuning arguments.
      device : str or torch.device, default=None
          Torch device on which the computation will be performed.
      memory_fix : int, default=1
          If this value is greater than zero, every `memory_fix`-many epochs the cuda cache will
          be emptied to force unused GPU memory being released.
      class_weight : 'balanced' or None, default=None
          If 'balanced', then the loss function is weighted inversely proportional to the
          label distribution to the current train set.
      """
      super().__init__(
          multi_label=multi_label,
          device=device,
          mini_batch_size=mini_batch_size,
      )
      early_stopping_deprecation_warning(
          early_stopping_no_improvement, early_stopping_acc
      )
      model_selection_deprecation_warning(model_selection)
  
      with verbosity_logger():
          self.logger = logging.getLogger(__name__)
          self.logger.verbosity = verbosity
  
      # Training parameters
      self.num_classes = num_classes
      self.num_epochs = num_epochs
      self.lr = lr
  
      self.criterion = None
      self.optimizer = None
      self.scheduler = None
  
      self.validation_set_size = validation_set_size
      self.validations_per_epoch = validations_per_epoch
  
      self.transformer_model = transformer_model
  
      # Other
      self.early_stopping_no_improvement = early_stopping_no_improvement
      self.early_stopping_acc = early_stopping_acc
      self.class_weight = class_weight
  
      self.model_selection = model_selection
      self.fine_tuning_arguments = fine_tuning_arguments
  
      self.memory_fix = memory_fix
      self.verbosity = verbosity
      self.cache_dir = cache_dir
  
      self.model = None
      self.model_selection_manager = None
  
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 to create a new TransformerBasedClassification object from inherited base classes: TransformerBasedEmbeddingMixin, PytorchClassifier with example: obj = TransformerBasedClassification(transformer_model, num_classes, multi_label, num_epochs, lr, mini_batch_size, validation_set_size, validations_per_epoch, early_stopping_no_improvement, early_stopping_acc, model_selection, fine_tuning_arguments, device, memory_fix, class_weight, verbosity, cache_dir)