code: def __init__(
      self,
      data_dir,
      label_dir,
      tokenizer,
      train_file="train.csv",
      val_file="val.csv",
      test_data=None,
      label_file="labels.csv",
      text_col="text",
      label_col="label",
      batch_size_per_gpu=16,
      max_seq_length=512,
      multi_gpu=True,
      multi_label=False,
      backend="nccl",
      model_type="bert",
      logger=None,
      clear_cache=False,
      no_cache=False,
      custom_sampler=None,
      pos_weight=None,
      weight=None,
  ):
      # just in case someone passes string instead of Path
      if isinstance(data_dir, str):
          data_dir = Path(data_dir)
  
      if isinstance(label_dir, str):
          label_dir = Path(label_dir)
  
      if isinstance(tokenizer, str):
          # instantiate the new tokeniser object using the tokeniser name
          tokenizer = AutoTokenizer.from_pretrained(
              tokenizer, use_fast=True
          )
  
      self.tokenizer = tokenizer
      self.data_dir = data_dir
      self.train_file = train_file
      self.val_file = val_file
      self.test_data = test_data
      self.cache_dir = data_dir / "cache"
      self.max_seq_length = max_seq_length
      self.batch_size_per_gpu = batch_size_per_gpu
      self.train_dl = None
      self.val_dl = None
      self.test_dl = None
      self.multi_label = multi_label
      self.n_gpu = 1
      self.no_cache = no_cache
      self.model_type = model_type
      self.output_mode = "classification"
      self.custom_sampler = custom_sampler
      self.pos_weight = pos_weight
      self.weight = weight
      if logger is None:
          logger = logging.getLogger()
      self.logger = logger
      if multi_gpu:
          self.n_gpu = torch.cuda.device_count()
  
      if clear_cache:
          shutil.rmtree(self.cache_dir, ignore_errors=True)
  
      if multi_label:
          processor = MultiLabelTextProcessor(data_dir, label_dir)
      else:
          processor = TextProcessor(data_dir, label_dir)
  
      self.labels = processor.get_labels(label_file)
  
      if train_file:
          # Train DataLoader
          train_examples = None
          cached_features_file = os.path.join(
              self.cache_dir,
              "cached_{}_{}_{}_{}_{}".format(
                  self.model_type.replace("/", "-"),
                  "train",
                  "multi_label" if self.multi_label else "multi_class",
                  str(self.max_seq_length),
                  os.path.basename(train_file),
              ),
          )
  
          if (
              os.path.exists(cached_features_file) is False
              or self.no_cache is True
          ):
              train_examples = processor.get_train_examples(
                  train_file, text_col=text_col, label_col=label_col
              )
  
          train_dataset = self.get_dataset_from_examples(
              train_examples, "train", no_cache=self.no_cache
          )
  
          self.train_batch_size = self.batch_size_per_gpu * max(
              1, self.n_gpu
          )
  
          if self.custom_sampler is not None:
              train_sampler = self.custom_sampler
          else:
              train_sampler = RandomSampler(train_dataset)
  
          self.train_dl = DataLoader(
              train_dataset,
              sampler=train_sampler,
              batch_size=self.train_batch_size,
          )
  
      if val_file:
          # Validation DataLoader
          val_examples = None
          cached_features_file = os.path.join(
              self.cache_dir,
              "cached_{}_{}_{}_{}_{}".format(
                  self.model_type.replace("/", "-"),
                  "dev",
                  "multi_label" if self.multi_label else "multi_class",
                  str(self.max_seq_length),
                  os.path.basename(val_file),
              ),
          )
  
          if os.path.exists(cached_features_file) is False:
              val_examples = processor.get_dev_examples(
                  val_file, text_col=text_col, label_col=label_col
              )
  
          val_dataset = self.get_dataset_from_examples(
              val_examples, "dev", no_cache=self.no_cache
          )
  
          # no grads necessary, hence double val batch size
          self.val_batch_size = (
              self.batch_size_per_gpu * 2 * max(1, self.n_gpu)
          )
          val_sampler = SequentialSampler(val_dataset)
          self.val_dl = DataLoader(
              val_dataset,
              sampler=val_sampler,
              batch_size=self.val_batch_size,
          )
  
      if test_data:
          # Test set loader for predictions
          test_examples = []
          input_data = []
  
          for index, text in enumerate(test_data):
              test_examples.append(InputExample(index, text))
              input_data.append({"id": index, "text": text})
  
          test_dataset = self.get_dataset_from_examples(
              test_examples,
              "test",
              is_test=True,
              no_cache=self.no_cache,
          )
  
          self.test_batch_size = self.batch_size_per_gpu * max(
              1, self.n_gpu
          )
          test_sampler = SequentialSampler(test_dataset)
          self.test_dl = DataLoader(
              test_dataset,
              sampler=test_sampler,
              batch_size=self.test_batch_size,
          )
  
imports: import pandas
  import os
  import torch
  from pathlib import Path
  import pickle
  import logging
  import shutil
  from torch.utils.data import Dataset, TensorDataset, DataLoader, RandomSampler, SequentialSampler
  from torch.utils.data.distributed import DistributedSampler
  from transformers import AutoTokenizer
label_desc: Use image node_id 1 to create a new BertDataBunch object from inherited base classes: object with example: obj = BertDataBunch(data_dir, label_dir, tokenizer, train_file, val_file, test_data, label_file, text_col, label_col, batch_size_per_gpu, max_seq_length, multi_gpu, multi_label, backend, model_type, logger, clear_cache, no_cache, custom_sampler, pos_weight, weight)