docstr: Create an example by concatenating text and answer.
  Truncation is carried out when needed, but it is performed only on the prompt side.
  BOS, EOS, and SEP, are added if specified.
docstr_tok: ["Create","an","example","by","concatenating","text","and","answer",".","Truncation","is","carried","out","when","needed",",","but","it","is","performed","only","on","the","prompt","side",".","BOS",",","EOS",",","and","SEP",",","are","added","if","specified","."]
code: def _process_example(self, example):
      """
      Create an example by concatenating text and answer.
      Truncation is carried out when needed, but it is performed only on the prompt side.
      BOS, EOS, and SEP, are added if specified.
      """
      prompt_template_values = []
      for c in self.prompt_template_keys:
          try:
              prompt_template_values.append(example[c].strip(" "))
          except KeyError as e:
              if c == self.label_key and self.is_test:
                  # allow missing label during testing, if user only wants to do inference without calculating metrics
                  prompt_template_values.append("")
              else:
                  raise e
  
      template_strings, template_strings_keys = self._separate_template(
          prompt_template_values
      )
      template_ids = [
          self.tokenizer.text_to_ids(s) for s in template_strings
      ]
      context_ids, answer_ids = self._multiple_truncation(
          template_ids, template_strings_keys
      )
  
      if self.virtual_tokens:
          # (@adithyare) we are going to insert "pad/eos" tokens in the beginning of the text and context
          # these pad/eos tokens are placeholders for virtual tokens
          context_ids = [
              self.tokenizer.eos_id
          ] * self.virtual_tokens + context_ids
  
      input_ids = context_ids
      answer_start_idx = len(input_ids)
  
      # Adds bos token in the start
      if self.add_bos:
          context_ids = [self.tokenizer.bos_id] + context_ids
          input_ids = [self.tokenizer.bos_id] + input_ids
          answer_start_idx += 1
  
      # Adds sep token between text/prompt and answer
      if self.add_sep:
          context_ids = context_ids + [self.sep_id]
          input_ids = input_ids + [self.sep_id]
          answer_start_idx += 1
  
      input_ids = input_ids + answer_ids
  
      # Only training need to consider eos token
      if self.add_eos:
          input_ids = input_ids + [self.tokenizer.eos_id]
  
      if len(input_ids) > self.max_seq_length:
          logging.warning(
              f"Input ids length {len(input_ids)} exceed max sequence length {self.max_seq_length}"
          )
          input_ids = input_ids[: self.max_seq_length]
          answer_ids = input_ids[answer_start_idx:]
  
      # store metadata in dataset, in case user may have keys required in the prediction json files
      metadata = {
          k: v
          for k, v in example.items()
          if k not in self.prompt_template_keys
      }
  
      processed_example = {
          "input_ids": input_ids,
          "answer_start_idx": answer_start_idx,
          "context_ids": context_ids,
          "context_length": len(context_ids),
          "answer_ids": answer_ids,
          "metadata": metadata,
          "token_count": len(input_ids),
      }
  
      return processed_example
  
imports: import re
  from typing import List, Mapping, Optional
  import datasets
  import numpy
  import torch
  from datasets import load_dataset
  from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec
  from nemo.collections.nlp.data.language_modeling.megatron.dataset_utils import get_samples_mapping
  from nemo.collections.nlp.data.language_modeling.text_memmap_dataset import JSONLMemMapDataset
  from nemo.core.classes import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 8 for calling the GPTSFTDataset obj's underlying member method code with example usage: obj._process_example(example) and returns: processed_example