docstr: Pad sequences and convert them to numpy.
code: def pad_and_convert_to_numpy(
      self,
      tokens,
      output_tokens,
      masked_positions,
      masked_labels,
      masked_spans=None,
      np_rng=None,
  ):
      """Pad sequences and convert them to numpy."""
      bart_decoder_in = [self.bos_id] + tokens
      bart_decoder_out = tokens + [self.eos_id]
  
      if masked_spans is not None:
          # construct bart input by collapsing multiple <mask> into one, and delete randomly
          bart_input = []
          (start_index, end_index) = (0, None)
          for span in masked_spans:
              end_index = span.index[0]
              bart_input.extend(output_tokens[start_index:end_index])
              # delete mask with probability delete_mask_prob
              if np_rng.rand() >= self.delete_mask_prob:
                  bart_input.append(self.mask_id)
  
              # the next start index is the token after the last span token
              start_index = span.index[-1] + 1
  
          # Add the remaining tokens to the BART input
          bart_input.extend(output_tokens[start_index:])
      else:
          bart_input = output_tokens
  
      # Some checks.
      # Encoder-side padding mask.
      num_tokens = len(bart_input)
      padding_length = self.max_seq_length - num_tokens
      assert padding_length >= 0
      assert len(masked_positions) == len(masked_labels)
  
      # Tokens..
      filler = [self.pad_id] * padding_length
      tokens_enc = np.array(bart_input + filler, dtype=np.int64)
  
      # Decoder-side padding mask.
      num_tokens_dec = len(bart_decoder_in)
      padding_length_dec = self.max_seq_length - num_tokens_dec
      assert padding_length_dec >= 0
      filler_dec = [self.pad_id] * padding_length_dec
      tokens_dec_in = np.array(
          bart_decoder_in + filler_dec, dtype=np.int64
      )
  
      # Create attention masks
      enc_mask = (tokens_enc != self.pad_id).astype(np.int64)
      dec_mask = (tokens_dec_in != self.pad_id).astype(np.int64)
  
      # Labels mask.
      labels = bart_decoder_out + ([-1] * padding_length_dec)
      labels = np.array(labels, dtype=np.int64)
  
      # Loss mask
      loss_mask = ([1] * num_tokens_dec) + ([0] * padding_length_dec)
      loss_mask = np.array(loss_mask, dtype=np.int64)
  
      return (
          tokens_enc,
          tokens_dec_in,
          labels,
          enc_mask,
          dec_mask,
          loss_mask,
      )
  
file_path: NeMo/nemo/collections/nlp/data/language_modeling/megatron/bart_dataset.py
imports: import numpy
  from nemo.collections.nlp.data.language_modeling.megatron.dataset_utils import create_masked_lm_predictions, get_samples_mapping
  from nemo.collections.nlp.data.language_modeling.megatron.t5_dataset import T5Dataset
label_desc: Use image node_id 4 for calling the BARTDataset obj's underlying member method code with example usage: obj.pad_and_convert_to_numpy(tokens, output_tokens, masked_positions, masked_labels, masked_spans, np_rng) and returns: tokens_enc,  tokens_dec_in,  labels,  enc_mask,  dec_mask,  loss_mask