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",
      bs=32,
      maxlen=512,
      multi_gpu=True,
      multi_label=False,
      backend="nccl",
      model_type="bert",
      custom_sampler=None,
  ):
      if isinstance(tokenizer, str):
          _, _, tokenizer_class = MODEL_CLASSES[model_type]
          # instantiate the new tokeniser object using the tokeniser name
          tokenizer = tokenizer_class.from_pretrained(
              tokenizer, do_lower_case=("uncased" in tokenizer)
          )
  
      self.tokenizer = tokenizer
      self.data_dir = data_dir
      self.maxlen = maxlen
      self.bs = bs
      self.train_dl = None
      self.val_dl = None
      self.test_dl = None
      self.multi_label = multi_label
      self.n_gpu = 0
      self.custom_sampler = custom_sampler
      if multi_gpu:
          self.n_gpu = torch.cuda.device_count()
  
      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 = processor.get_train_examples(
              train_file, text_col=text_col, label_col=label_col
          )
          train_features = convert_examples_to_features(
              train_examples,
              label_list=self.labels,
              tokenizer=tokenizer,
              max_seq_length=maxlen,
          )
  
          all_input_ids = torch.tensor(
              [f.input_ids for f in train_features], dtype=torch.long
          )
          all_input_mask = torch.tensor(
              [f.input_mask for f in train_features], dtype=torch.long
          )
          all_segment_ids = torch.tensor(
              [f.segment_ids for f in train_features], dtype=torch.long
          )
          if multi_label:
              all_label_ids = torch.tensor(
                  [f.label_id for f in train_features],
                  dtype=torch.float,
              )
          else:
              all_label_ids = torch.tensor(
                  [f.label_id for f in train_features], dtype=torch.long
              )
  
          train_data = TensorDataset(
              all_input_ids,
              all_input_mask,
              all_segment_ids,
              all_label_ids,
          )
  
          train_batch_size = bs * max(1, self.n_gpu)
  
          if multi_gpu:
              if self.custom_sampler is not None:
                  train_sampler = self.custom_sampler
              else:
                  train_sampler = RandomSampler(train_data)
          else:
              try:
                  #                    torch.distributed.init_process_group(backend='nccl')
                  torch.distributed.init_process_group(
                      backend=backend,
                      init_method="tcp://localhost:23459",
                      rank=0,
                      world_size=1,
                  )
              except:
                  pass
              # torch.distributed.init_process_group(backend='nccl')
              train_sampler = DistributedSampler(train_data)
          self.train_dl = DataLoader(
              train_data,
              sampler=train_sampler,
              batch_size=train_batch_size,
          )
  
      if val_file:
          # Validation DataLoader
          val_examples = processor.get_dev_examples(
              val_file, text_col=text_col, label_col=label_col
          )
          val_features = convert_examples_to_features(
              val_examples,
              label_list=self.labels,
              tokenizer=tokenizer,
              max_seq_length=maxlen,
          )
  
          all_input_ids = torch.tensor(
              [f.input_ids for f in val_features], dtype=torch.long
          )
          all_input_mask = torch.tensor(
              [f.input_mask for f in val_features], dtype=torch.long
          )
          all_segment_ids = torch.tensor(
              [f.segment_ids for f in val_features], dtype=torch.long
          )
          if multi_label:
              all_label_ids = torch.tensor(
                  [f.label_id for f in val_features], dtype=torch.float
              )
          else:
              all_label_ids = torch.tensor(
                  [f.label_id for f in val_features], dtype=torch.long
              )
  
          val_data = TensorDataset(
              all_input_ids,
              all_input_mask,
              all_segment_ids,
              all_label_ids,
          )
  
          val_batch_size = bs * max(1, self.n_gpu)
          if multi_gpu:
              val_sampler = RandomSampler(val_data)
          else:
              try:
                  #                    torch.distributed.init_process_group(backend=backend)
                  torch.distributed.init_process_group(
                      backend=backend,
                      init_method="tcp://localhost:23459",
                      rank=0,
                      world_size=1,
                  )
  
              except:
                  pass
  
              val_sampler = DistributedSampler(val_data)
  
          self.val_dl = DataLoader(
              val_data, sampler=val_sampler, batch_size=val_batch_size
          )
  
      if test_data:
          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_features = convert_examples_to_features(
              test_examples,
              label_list=self.labels,
              tokenizer=tokenizer,
              max_seq_length=maxlen,
          )
          all_input_ids = torch.tensor(
              [f.input_ids for f in test_features], dtype=torch.long
          )
          all_input_mask = torch.tensor(
              [f.input_mask for f in test_features], dtype=torch.long
          )
          all_segment_ids = torch.tensor(
              [f.segment_ids for f in test_features], dtype=torch.long
          )
  
          test_data = TensorDataset(
              all_input_ids, all_input_mask, all_segment_ids
          )
  
          test_sampler = SequentialSampler(test_data)
          self.test_dl = DataLoader(
              test_data, sampler=test_sampler, batch_size=bs
          )
  
imports: import pandas
  import os
  import torch
  from pathlib import Path
  import pickle
  from torch.utils.data import TensorDataset, DataLoader, RandomSampler, SequentialSampler
  from torch.utils.data.distributed import DistributedSampler
  from transformers import WEIGHTS_NAME, BertConfig, BertForSequenceClassification, BertTokenizer, XLMConfig, XLMForSequenceClassification, XLMTokenizer, XLNetConfig, XLNetForSequenceClassification, XLNetTokenizer
label_desc: Use image node_id 4 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, bs, maxlen, multi_gpu, multi_label, backend, model_type, custom_sampler)