class_docstr: Creates a dataset to use for the task of joint intent
  and slot classification with pretrained model.
  
  For a dataset to use during inference without labels, see
  IntentSlotDataset.
class_docstr_tok: ["Creates","a","dataset","to","use","for","the","task","of","joint","intent","and","slot","classification","with","pretrained","model",".","For","a","dataset","to","use","during","inference","without","labels",",","see","IntentSlotDataset","."]
code: def truncate_and_pad(
      max_seq_length,
      ignore_start_end,
      with_label,
      pad_label,
      tokenizer,
      all_slots,
      all_subtokens,
      all_input_mask,
      all_loss_mask,
      all_subtokens_mask,
      all_input_ids,
      all_segment_ids,
  ):
      too_long_count = 0
  
      for i, subtokens in enumerate(all_subtokens):
          if len(subtokens) > max_seq_length:
              subtokens = [tokenizer.cls_token] + subtokens[
                  -max_seq_length + 1 :
              ]
              all_input_mask[i] = [1] + all_input_mask[i][
                  -max_seq_length + 1 :
              ]
              all_loss_mask[i] = [1 - ignore_start_end] + all_loss_mask[
                  i
              ][-max_seq_length + 1 :]
              all_subtokens_mask[i] = [0] + all_subtokens_mask[i][
                  -max_seq_length + 1 :
              ]
  
              if with_label:
                  all_slots[i] = [pad_label] + all_slots[i][
                      -max_seq_length + 1 :
                  ]
              too_long_count += 1
  
          all_input_ids.append(
              [tokenizer.tokens_to_ids(t) for t in subtokens]
          )
  
          if len(subtokens) < max_seq_length:
              extra = max_seq_length - len(subtokens)
              all_input_ids[i] = all_input_ids[i] + [0] * extra
              all_loss_mask[i] = all_loss_mask[i] + [0] * extra
              all_subtokens_mask[i] = (
                  all_subtokens_mask[i] + [0] * extra
              )
              all_input_mask[i] = all_input_mask[i] + [0] * extra
  
              if with_label:
                  all_slots[i] = all_slots[i] + [pad_label] * extra
  
          all_segment_ids.append([0] * max_seq_length)
  
      logging.info(f"{too_long_count} are longer than {max_seq_length}")
      return (
          all_slots,
          all_subtokens,
          all_input_mask,
          all_loss_mask,
          all_subtokens_mask,
          all_input_ids,
          all_segment_ids,
      )
  
imports: from typing import Dict, Optional
  import numpy
  from nemo.collections.nlp.data.data_utils import get_stats
  from nemo.collections.nlp.data.dialogue.dataset.dialogue_dataset import DialogueDataset
  from nemo.core.neural_types import ChannelType, LabelsType, MaskType, NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 6 for calling the DialogueBERTDataset obj's underlying member method code with example usage: obj.truncate_and_pad(max_seq_length, ignore_start_end, with_label, pad_label, tokenizer, all_slots, all_subtokens, all_input_mask, all_loss_mask, all_subtokens_mask, all_input_ids, all_segment_ids) and returns: all_slots,  all_subtokens,  all_input_mask,  all_loss_mask,  all_subtokens_mask,  all_input_ids,  all_segment_ids