class_docstr: A training module for NER. See BaseTransformer for the core options.
docstr: Called to initialize data. Use the call to construct features
docstr_tok: ["Called","to","initialize","data",".","Use","the","call","to","construct","features"]
code: def prepare_data(self):
      "Called to initialize data. Use the call to construct features"
      args = self.hparams
      for mode in ["train", "dev", "test"]:
          cached_features_file = self._feature_file(mode)
          if (
              os.path.exists(cached_features_file)
              and not args.overwrite_cache
          ):
              logger.info(
                  "Loading features from cached file %s",
                  cached_features_file,
              )
              features = torch.load(cached_features_file)
          else:
              logger.info(
                  "Creating features from dataset file at %s",
                  args.data_dir,
              )
              examples = self.token_classification_task.read_examples_from_file(
                  args.data_dir, mode
              )
              features = self.token_classification_task.convert_examples_to_features(
                  examples,
                  self.labels,
                  args.max_seq_length,
                  self.tokenizer,
                  cls_token_at_end=bool(
                      self.config.model_type in ["xlnet"]
                  ),
                  cls_token=self.tokenizer.cls_token,
                  cls_token_segment_id=2
                  if self.config.model_type in ["xlnet"]
                  else 0,
                  sep_token=self.tokenizer.sep_token,
                  sep_token_extra=False,
                  pad_on_left=bool(self.config.model_type in ["xlnet"]),
                  pad_token=self.tokenizer.pad_token_id,
                  pad_token_segment_id=self.tokenizer.pad_token_type_id,
                  pad_token_label_id=self.pad_token_label_id,
              )
              logger.info(
                  "Saving features into cached file %s",
                  cached_features_file,
              )
              torch.save(features, cached_features_file)
  
imports: import argparse
  import glob
  import logging
  import os
  from argparse import Namespace
  from importlib import import_module
  import numpy
  import torch
  from lightning_base import BaseTransformer, add_generic_args, generic_train
  from seqeval.metrics import accuracy_score, f1_score, precision_score, recall_score
  from torch.nn import CrossEntropyLoss
  from torch.utils.data import DataLoader, TensorDataset
  from utils_ner import TokenClassificationTask
label_desc: Use image node_id 4 for calling the NERTransformer obj's underlying member method code with example usage: obj.prepare_data() without return types