code: def transformers_collate_fn(
      batch,
      multi_label=None,
      num_classes=None,
      use_sample_weights=False,
  ):
      with torch.no_grad():
          text = torch.cat(
              [
                  entry[TransformersDataset.INDEX_TEXT]
                  for entry in batch
              ],
              dim=0,
          )
          masks = torch.cat(
              [
                  entry[TransformersDataset.INDEX_MASK]
                  for entry in batch
              ],
              dim=0,
          )
          if multi_label:
              multi_hot = [
                  [
                      0
                      if i
                      not in set(entry[TransformersDataset.INDEX_LABEL])
                      else 1
                      for i in range(num_classes)
                  ]
                  for entry in batch
              ]
              label = torch.tensor(multi_hot, dtype=float)
          else:
              label = torch.tensor(
                  [
                      entry[TransformersDataset.INDEX_LABEL]
                      for entry in batch
                  ]
              )
  
      if use_sample_weights:
          weights = torch.tensor([entry[-1] for entry in batch])
      else:
          weights = torch.ones(text.size(0), device=text.device)
  
      return text, masks, label, weights
  
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 a global function with example usage: transformers_collate_fn(batch, multi_label, num_classes, use_sample_weights) and returns: text,  masks,  label,  weights