code: def dataloader(data, batch_size, collate_fn, train=True):
      """
      Convenience method to obtain a `DataLoader`.
  
      Parameters
      ----------
      data : list of tuples
          The data to be loaded.
      batch_size : int
          Batch size.
      collate_fn : func
          The `collate-fn` required by `DataLoader`.
      train : bool
          Indicates if the dataloader is used for training or testing. For training random sampling
          is used, otherwise sequential sampling.
  
      Returns
      -------
      iter : DataLoader
          A DataLoader for the given `data_set`.
      """
      data_source = np.empty(len(data), dtype=object)
      data_source[:] = data
  
      if train:
          base_sampler = RandomSampler(data_source)
      else:
          base_sampler = SequentialSampler(data_source)
  
      sampler = BatchSampler(
          base_sampler, batch_size=batch_size, drop_last=False
      )
  
      return DataLoader(
          data_source,
          batch_size=None,
          collate_fn=collate_fn,
          sampler=sampler,
      )
  
imports: import numpy
  from small_text.data.sampling import _get_class_histogram
  from small_text.integrations.pytorch.exceptions import PytorchNotFoundError
label_desc: Use image node_id 1 for calling a global function with example usage: dataloader(data, batch_size, collate_fn, train) and returns: DataLoader