code: def _train_loop_process_batches(
      self,
      num_epoch,
      sub_train_,
      sub_valid_,
      weights,
      early_stopping,
      model_selection,
      optimizer,
      scheduler,
      tmp_dir,
      validate_every=None,
  ):
      train_loss = 0.0
      train_acc = 0.0
      valid_losses = []
      valid_accs = []
  
      data = sub_train_.data
      if weights is not None:
          data = [d + (weights[i],) for i, d in enumerate(data)]
  
      train_iter = dataloader(
          data,
          self.mini_batch_size,
          self._create_collate_fn(
              use_sample_weights=weights is not None
          ),
      )
  
      stop = False
  
      for i, (x, masks, cls, weight, *_) in enumerate(train_iter):
          if not stop:
              loss, acc = self._train_single_batch(
                  x, masks, cls, weight, optimizer
              )
              scheduler.step()
  
              train_loss += loss
              train_acc += acc
  
              if validate_every and i % validate_every == 0:
                  valid_loss, valid_acc = self.validate(sub_valid_)
                  self.model.train()
                  valid_losses.append(valid_loss)
                  valid_accs.append(valid_acc)
  
                  measured_values = {
                      "val_loss": valid_loss,
                      "val_acc": valid_acc,
                  }
                  stop = stop or early_stopping.check_early_stop(
                      num_epoch + 1, measured_values
                  )
                  self._save_model(
                      optimizer,
                      model_selection,
                      f"{num_epoch}-b{i+1}",
                      train_acc,
                      train_loss,
                      valid_acc,
                      valid_loss,
                      stop,
                      tmp_dir,
                  )
  
      if validate_every:
          valid_loss, valid_acc = np.mean(valid_losses), np.mean(
              valid_accs
          )
  
      else:
          valid_loss, valid_acc = None, None
          if validate_every is None and sub_valid_ is not None:
              valid_loss, valid_acc = self.validate(sub_valid_)
      train_loss = train_loss / len(sub_train_)
      train_acc = train_acc / len(sub_train_)
  
      measured_values = {
          "train_loss": train_loss,
          "train_acc": train_acc,
          "val_loss": valid_loss,
          "val_acc": valid_acc,
      }
      stop = early_stopping.check_early_stop(
          num_epoch + 1, measured_values
      )
      self._save_model(
          optimizer,
          model_selection,
          f"{num_epoch}-b0",
          train_acc,
          train_loss,
          valid_acc,
          valid_loss,
          stop,
          tmp_dir,
      )
      return train_loss, train_acc, valid_loss, valid_acc, stop
  
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 8 for calling the TransformerBasedClassification obj's underlying member method code with example usage: obj._train_loop_process_batches(num_epoch, sub_train_, sub_valid_, weights, early_stopping, model_selection, optimizer, scheduler, tmp_dir, validate_every) and returns: train_loss,  train_acc,  valid_loss,  valid_acc,  stop