code: def _add_speaker_and_signal(
      header, source, mask_role, gtype, special_tokens
  ):
      TURN_TOKEN = special_tokens["turn_start"]
      END_SIGNAL = special_tokens["end_of_turn"]
      LABEL_START = special_tokens["label_start"]
      END_NAME_SIGNAL = special_tokens["end_of_name"]
  
      """Add speaker and start/end signal on each round."""
      BEGIN_SIGNAL = ""
      conversation = header
      for i, sentence in enumerate(source):
          sentence_from = sentence["from"]
          role_token = TURN_TOKEN
          if gtype is None:
              sentence["value"] = (
                  BEGIN_SIGNAL
                  + role_token
                  + sentence_from
                  + END_NAME_SIGNAL
                  + sentence["value"]
                  + END_SIGNAL
              )
          elif gtype == "VALUE_TO_TEXT":
              sentence["value"] = (
                  BEGIN_SIGNAL
                  + role_token
                  + sentence_from
                  + END_NAME_SIGNAL
                  + (
                      response_value_formater(
                          sentence["label"],
                          LABEL_START,
                          END_NAME_SIGNAL,
                      )
                      if "label" in sentence
                      else ""
                  )
                  + sentence["value"]
                  + END_SIGNAL
              )
          elif gtype == "TEXT_TO_VALUE":
              sentence["value"] = (
                  BEGIN_SIGNAL
                  + role_token
                  + sentence_from
                  + END_NAME_SIGNAL
                  + sentence["value"]
                  + END_SIGNAL
                  + (
                      response_value_formater(
                          sentence["label"],
                          LABEL_START,
                          END_NAME_SIGNAL,
                      )
                      if "label" in sentence
                      else ""
                  )
              )
          else:
              raise ValueError(
                  f"source type {gtype} not supported, only 'VALUE_TO_TEXT' and 'TEXT_TO_VALUE' are supported"
              )
          conversation += sentence["value"]
          # if the last turn is not masked, add next token start token to the end, which will be included for loss calculation
          if sentence_from != mask_role and i == len(source) - 1:
              conversation += TURN_TOKEN
      return conversation
  
file_path: NeMo/nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py
imports: import copy
  import torch
  from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec
  from nemo.collections.nlp.data.language_modeling.megatron.gpt_sft_dataset import GPTSFTDataset
  from nemo.utils import logging
label_desc: Use image node_id 6 for calling a global function with example usage: _add_speaker_and_signal(header, source, mask_role, gtype, special_tokens) and returns: conversation