code: def __init__(
      self,
      data_dir,
      tokenizer,
      train_file="train.txt",
      val_file="val.txt",
      test_file="test.txt",
      label_file="labels.txt",
      batch_size_per_gpu=16,
      max_seq_length=512,
      multi_gpu=True,
      backend="nccl",
      model_type="bert",
      logger=logging.getLogger(),
      clear_cache=False,
      no_cache=False,
      processor_name="ner",
      use_fast_tokenizer=True,
      custom_sampler=None,
  ):
      # just in case someone passes string instead of Path
      if isinstance(data_dir, str):
          data_dir = Path(data_dir)
  
      # instantiate auto tokenizer if not already instantiated
      if isinstance(tokenizer, str):
          # instantiate the new tokeniser object using the tokeniser name
          tokenizer = AutoTokenizer.from_pretrained(
              tokenizer, use_fast=use_fast_tokenizer
          )
  
      self.tokenizer = tokenizer
      self.data_dir = data_dir
      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.no_cache = no_cache
      self.model_type = model_type
      self.logger = logger
      self.custom_sampler = custom_sampler
      self.n_gpu = torch.cuda.device_count()
  
      if clear_cache:
          shutil.rmtree(self.cache_dir, ignore_errors=True)
  
      self.labels = get_labels(
          "{}/{}".format(str(data_dir), label_file)
      )
      self.label_map = {i: label for i, label in enumerate(self.labels)}
  
      if train_file:
          train_dataset = NerDataset(
              data_dir=data_dir,
              file_name=train_file,
              tokenizer=tokenizer,
              labels=self.labels,
              model_type=self.model_type,
              max_seq_length=max_seq_length,
              overwrite_cache=clear_cache,
              mode=Split.train,
          )
  
          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:
          val_dataset = NerDataset(
              data_dir=data_dir,
              file_name=val_file,
              tokenizer=tokenizer,
              labels=self.labels,
              model_type=self.model_type,
              max_seq_length=max_seq_length,
              overwrite_cache=clear_cache,
              mode=Split.dev,
          )
  
          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,
          )
  
      try:
          if test_file:
              test_dataset = NerDataset(
                  data_dir=data_dir,
                  file_name=test_file,
                  tokenizer=tokenizer,
                  labels=self.labels,
                  model_type=self.model_type,
                  max_seq_length=max_seq_length,
                  overwrite_cache=clear_cache,
                  mode=Split.test,
              )
  
              self.test_batch_size = (
                  self.batch_size_per_gpu * 2 * 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,
              )
      except FileNotFoundError:
          self.logger.info("Test file not found, skipping")
          self.test_dl = None
  
imports: import pandas
  import json
  import logging
  import os
  import torch
  from torch import nn
  from dataclasses import dataclass
  from enum import Enum
  from typing import List, Optional, Union
  from pathlib import Path
  import pickle
  from filelock import FileLock
  import re
  import shutil
  from sklearn.model_selection import train_test_split
  from torch.utils.data import Dataset, TensorDataset, DataLoader, RandomSampler, SequentialSampler
  from torch.utils.data.distributed import DistributedSampler
  from transformers import PreTrainedTokenizer, AutoTokenizer
label_desc: Use image node_id 2 to create a new BertNERDataBunch object from inherited base classes: object with example: obj = BertNERDataBunch(data_dir, tokenizer, train_file, val_file, test_file, label_file, batch_size_per_gpu, max_seq_length, multi_gpu, backend, model_type, logger, clear_cache, no_cache, processor_name, use_fast_tokenizer, custom_sampler)