code: def __getitem__(self, idx):
      text = torch.from_numpy(self._get_text(idx))
      if self.add_extra_token:
          tokens = text[:-1].contiguous()
          labels = text[1:].contiguous()
      else:
          tokens = text
          labels = torch.roll(text, shifts=-1, dims=0)
          labels[-1] = -1
      if self.create_inputs or not self.cached_inputs:
          (
              attention_mask,
              loss_mask,
              position_ids,
          ) = _create_ltor_masks_and_position_ids(
              tokens,
              self.eos_id,
              self.reset_position_ids,
              self.reset_attention_mask,
              self.eod_mask_loss,
          )
          if not self.create_inputs:
              self.cached_attention_mask = attention_mask
              self.cached_loss_mask = loss_mask
              self.cached_position_ids = position_ids
              self.cached_inputs = True
      else:
          attention_mask = self.cached_attention_mask
          loss_mask = self.cached_loss_mask
          position_ids = self.cached_position_ids
      loss_mask[labels == -1] = 0.0
      tokens[tokens == -1] = 0
      labels[labels == -1] = 0
  
      # Negative index comes when we pad the last batch in MegatronPretrainingBatchSampler
      # We make the loss_mask zero to mask out loss from these samples
      if idx < 0:
          logging.debug(
              "Got negative index. Masking loss from this sample"
          )
          loss_mask = torch.zeros_like(loss_mask)
  
      if self.get_attention_mask_from_fusion:
          return {
              "tokens": tokens,
              "labels": labels,
              "loss_mask": loss_mask,
              "position_ids": position_ids,
          }
      else:
          return {
              "tokens": tokens,
              "labels": labels,
              "attention_mask": attention_mask,
              "loss_mask": loss_mask,
              "position_ids": position_ids,
          }
  
imports: import os
  import time
  import numpy
  import torch
  from omegaconf.dictconfig import DictConfig
  from nemo.collections.nlp.data.language_modeling.megatron.base_dataset_utils import get_datasets_weights_and_num_samples, get_train_valid_test_split_
  from nemo.collections.nlp.data.language_modeling.megatron.blendable_dataset import BlendableDataset
  from nemo.collections.nlp.data.language_modeling.megatron.indexed_dataset import deallocate_indexed_dataset_memory
  from nemo.collections.nlp.data.language_modeling.megatron.indexed_dataset import make_dataset
  from nemo.core import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 5 for calling the GPTDataset obj's underlying member method code with example usage: obj.__getitem__(idx) and returns: dict, dict