class_docstr: Token Classification Model with BERT, applicable for tasks such as Named Entity Recognition
class_docstr_tok: ["Token","Classification","Model","with","BERT",",","applicable","for","tasks","such","as","Named","Entity","Recognition"]
docstr: Setup dataloader from config
  Args:
      cfg: config for the dataloader
  Return:
      Pytorch Dataloader
docstr_tok: ["Setup","dataloader","from","config","Args",":","cfg",":","config","for","the","dataloader","Return",":","Pytorch","Dataloader"]
code: def _setup_dataloader_from_config(
      self, cfg: DictConfig
  ) -> DataLoader:
      """
      Setup dataloader from config
      Args:
          cfg: config for the dataloader
      Return:
          Pytorch Dataloader
      """
      dataset_cfg = self._cfg.dataset
      data_dir = dataset_cfg.data_dir
  
      if not os.path.exists(data_dir):
          raise FileNotFoundError(
              f"Data directory is not found at: {data_dir}."
          )
  
      text_file = os.path.join(data_dir, cfg.text_file)
      labels_file = os.path.join(data_dir, cfg.labels_file)
  
      if not (
          os.path.exists(text_file) and os.path.exists(labels_file)
      ):
          raise FileNotFoundError(
              f"{text_file} or {labels_file} not found. The data should be split into 2 files: text.txt and \
                  labels.txt. Each line of the text.txt file contains text sequences, where words are separated with \
                  spaces. The labels.txt file contains corresponding labels for each word in text.txt, the labels are \
                  separated with spaces. Each line of the files should follow the format:  \
                     [WORD] [SPACE] [WORD] [SPACE] [WORD] (for text.txt) and \
                     [LABEL] [SPACE] [LABEL] [SPACE] [LABEL] (for labels.txt)."
          )
      dataset = BertTokenClassificationDataset(
          text_file=text_file,
          label_file=labels_file,
          max_seq_length=dataset_cfg.max_seq_length,
          tokenizer=self.tokenizer,
          num_samples=cfg.num_samples,
          pad_label=dataset_cfg.pad_label,
          label_ids=self._cfg.label_ids,
          ignore_extra_tokens=dataset_cfg.ignore_extra_tokens,
          ignore_start_end=dataset_cfg.ignore_start_end,
          use_cache=dataset_cfg.use_cache,
      )
      return DataLoader(
          dataset=dataset,
          collate_fn=dataset.collate_fn,
          batch_size=cfg.batch_size,
          shuffle=cfg.shuffle,
          num_workers=dataset_cfg.num_workers,
          pin_memory=dataset_cfg.pin_memory,
          drop_last=dataset_cfg.drop_last,
      )
  
imports: import os
  from typing import List, Optional, Union
  import torch
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from torch.utils.data import DataLoader
  from nemo.collections.common.losses import CrossEntropyLoss
  from nemo.collections.nlp.data.data_utils.data_preprocessing import get_labels_to_labels_id_mapping
  from nemo.collections.nlp.data.token_classification.token_classification_dataset import BertTokenClassificationDataset, BertTokenClassificationInferDataset
  from nemo.collections.nlp.data.token_classification.token_classification_utils import get_label_ids
  from nemo.collections.nlp.metrics.classification_report import ClassificationReport
  from nemo.collections.nlp.models.nlp_model import NLPModel
  from nemo.collections.nlp.modules.common import TokenClassifier
  from nemo.collections.nlp.parts.utils_funcs import get_classification_report, plot_confusion_matrix, tensor2list
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.utils import logging
label_desc: Use image node_id 13 for calling the TokenClassificationModel obj's underlying member method code with example usage: obj._setup_dataloader_from_config(cfg) and returns: DataLoader