code: def kimcnn_collate_fn(
      batch,
      multi_label=None,
      num_classes=None,
      use_sample_weights=False,
      max_seq_len=60,
      padding_idx=0,
      filter_padding=0,
  ):
      # TODO: torch.no_grad()?
      def prepare_tensor(t):
          t_sub = t[: max_seq_len - 2 * filter_padding]
          return torch.cat(
              [
                  t_sub.new_zeros(filter_padding) + padding_idx,
                  t_sub,
                  t_sub.new_zeros(
                      max_seq_len - 2 * filter_padding - t_sub.size(0)
                  )
                  + padding_idx,
                  t_sub.new_zeros(filter_padding) + padding_idx,
              ],
              0,
          )
  
      if multi_label:
          multi_hot = [
              [
                  0
                  if i
                  not in set(
                      entry[
                          PytorchTextClassificationDataset.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[PytorchTextClassificationDataset.INDEX_LABEL]
                  for entry in batch
              ]
          )
      text = torch.stack(
          [
              prepare_tensor(
                  entry[PytorchTextClassificationDataset.INDEX_TEXT]
              )
              for entry in batch
          ],
          0,
      )
  
      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, label, weights
  
imports: import datetime
  import logging
  import tempfile
  import numpy
  from functools import partial
  from sklearn.preprocessing import MultiLabelBinarizer
  from small_text.classifiers.classification import EmbeddingMixin
  from small_text.integrations.pytorch.classifiers.base import PytorchClassifier
  from small_text.integrations.pytorch.exceptions import PytorchNotFoundError
  from small_text.integrations.pytorch.models.kimcnn import KimCNN
  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.annotations import early_stopping_deprecation_warning
  from small_text.utils.labels import csr_to_list, get_num_labels
  from small_text.utils.datetime import format_timedelta
  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: kimcnn_collate_fn(batch, multi_label, num_classes, use_sample_weights, max_seq_len, padding_idx, filter_padding) and returns: text,  label,  weights, torch