class_docstr: This will be superseded by a framework-agnostic approach soon.
code: def __init__(
      self,
      tokenizer: PreTrainedTokenizer,
      file_path: str,
      block_size: int,
      overwrite_cache=False,
      short_seq_probability=0.1,
      nsp_probability=0.5,
  ):
      warnings.warn(
          DEPRECATION_WARNING.format(
              "https://github.com/huggingface/transformers/blob/main/examples/pytorch/language-modeling/run_mlm.py"
          ),
          FutureWarning,
      )
      if not os.path.isfile(file_path):
          raise ValueError(f"Input file path {file_path} not found")
  
      self.short_seq_probability = short_seq_probability
      self.nsp_probability = nsp_probability
  
      directory, filename = os.path.split(file_path)
      cached_features_file = os.path.join(
          directory,
          f"cached_nsp_{tokenizer.__class__.__name__}_{block_size}_{filename}",
      )
  
      self.tokenizer = tokenizer
  
      # Make sure only the first process in distributed training processes the dataset,
      # and the others will use the cache.
      lock_path = cached_features_file + ".lock"
  
      # Input file format:
      # (1) One sentence per line. These should ideally be actual sentences, not
      # entire paragraphs or arbitrary spans of text. (Because we use the
      # sentence boundaries for the "next sentence prediction" task).
      # (2) Blank lines between documents. Document boundaries are needed so
      # that the "next sentence prediction" task doesn't span between documents.
      #
      # Example:
      # I am very happy.
      # Here is the second sentence.
      #
      # A new document.
  
      with FileLock(lock_path):
          if (
              os.path.exists(cached_features_file)
              and not overwrite_cache
          ):
              start = time.time()
              with open(cached_features_file, "rb") as handle:
                  self.examples = pickle.load(handle)
              logger.info(
                  f"Loading features from cached file {cached_features_file} [took %.3f s]",
                  time.time() - start,
              )
          else:
              logger.info(
                  f"Creating features from dataset file at {directory}"
              )
  
              self.documents = [[]]
              with open(file_path, encoding="utf-8") as f:
                  while True:
                      line = f.readline()
                      if not line:
                          break
                      line = line.strip()
  
                      # Empty lines are used as document delimiters
                      if not line and len(self.documents[-1]) != 0:
                          self.documents.append([])
                      tokens = tokenizer.tokenize(line)
                      tokens = tokenizer.convert_tokens_to_ids(tokens)
                      if tokens:
                          self.documents[-1].append(tokens)
  
              logger.info(
                  f"Creating examples from {len(self.documents)} documents."
              )
              self.examples = []
              for doc_index, document in enumerate(self.documents):
                  self.create_examples_from_document(
                      document, doc_index, block_size
                  )
  
              start = time.time()
              with open(cached_features_file, "wb") as handle:
                  pickle.dump(
                      self.examples,
                      handle,
                      protocol=pickle.HIGHEST_PROTOCOL,
                  )
              logger.info(
                  f"Saving features into cached file {cached_features_file} [took {time.time() - start:.3f} s]"
              )
  
imports: import json
  import os
  import pickle
  import random
  import time
  import warnings
  from typing import Dict, List, Optional
  import torch
  from torch.utils.data import Dataset
  from filelock import FileLock
  from ...tokenization_utils import PreTrainedTokenizer
  from ...utils import logging
label_desc: Use image node_id 1 to create a new TextDatasetForNextSentencePrediction object from inherited base classes: Dataset with example: obj = TextDatasetForNextSentencePrediction(tokenizer, file_path, block_size, overwrite_cache, short_seq_probability, nsp_probability)