class_docstr: NSP Reader.
docstr: Padding batch records and construct model's inputs.
docstr_tok: ["Padding","batch","records","and","construct","model","'s","inputs","."]
code: def _pad_batch_records(self, batch_records, is_infer):
      """
      Padding batch records and construct model's inputs.
      """
      batch = {}
      batch_token_ids = [record.token_ids for record in batch_records]
      batch_type_ids = [record.type_ids for record in batch_records]
      batch_pos_ids = [record.pos_ids for record in batch_records]
      batch_tgt_start_idx = [
          record.tgt_start_idx for record in batch_records
      ]
      batch_label = [record.label for record in batch_records]
  
      if self.attention_style == "unidirectional":
          batch["token_ids"] = pad_batch_data(
              batch_token_ids, pad_id=self.pad_id
          )
          batch["type_ids"] = pad_batch_data(
              batch_type_ids, pad_id=self.pad_id
          )
          batch["pos_ids"] = pad_batch_data(
              batch_pos_ids, pad_id=self.pad_id
          )
          tgt_label, tgt_pos, label_pos = mask(
              batch_tokens=batch_token_ids,
              vocab_size=self.vocab_size,
              bos_id=self.bos_id,
              sent_b_starts=batch_tgt_start_idx,
              labels=batch_label,
              is_unidirectional=True,
          )
          attention_mask = self._gen_self_attn_mask(
              batch_token_ids, batch_tgt_start_idx
          )
      else:
          batch_mask_token_ids, tgt_label, tgt_pos, label_pos = mask(
              batch_tokens=batch_token_ids,
              vocab_size=self.vocab_size,
              bos_id=self.bos_id,
              eos_id=self.eos_id,
              mask_id=self.mask_id,
              sent_b_starts=batch_tgt_start_idx,
              labels=batch_label,
              is_unidirectional=False,
          )
          if not is_infer:
              batch_token_ids = batch_mask_token_ids
          batch["token_ids"] = pad_batch_data(
              batch_token_ids, pad_id=self.pad_id
          )
          batch["type_ids"] = pad_batch_data(
              batch_type_ids, pad_id=self.pad_id
          )
          batch["pos_ids"] = pad_batch_data(
              batch_pos_ids, pad_id=self.pad_id
          )
          attention_mask = self._gen_self_attn_mask(
              batch_token_ids, is_unidirectional=False
          )
  
      batch["attention_mask"] = attention_mask
      batch["label_pos"] = label_pos
  
      if not is_infer:
          batch_label = (
              np.array(batch_label).astype("int64").reshape([-1, 1])
          )
          batch["label"] = batch_label
          batch["tgt_label"] = tgt_label
          batch["tgt_pos"] = tgt_pos
  
      batch_data_id = [record.data_id for record in batch_records]
      batch["data_id"] = (
          np.array(batch_data_id).astype("int64").reshape([-1, 1])
      )
      return batch
  
file_path: PaddleHub/modules/text/text_generation/plato2_en_base/readers/nsp_reader.py
imports: from collections import namedtuple
  import numpy
  from .dialog_reader import DialogReader
  from ..utils import pad_batch_data
  from ..utils.args import str2bool
  from ..utils.masking import mask
label_desc: Use image node_id 6 for calling the NSPReader obj's underlying member method code with example usage: obj._pad_batch_records(batch_records, is_infer) and returns: batch