class_docstr: NSP Reader.
code: def _mix_negative_sample(self, reader, neg_pool_size=2**16):
      def gen_from_pool(pool):
          num_samples = len(pool)
          if num_samples == 1:
              # only one sample: it is impossible to generate negative sample
              yield pool[0]._replace(label=1)
              return
          self.global_rng.shuffle(pool)
          for i in range(num_samples):
              pool[i] = pool[i]._replace(label=1)
              j = (i + 1) % num_samples
              idx_i = pool[i].tgt_start_idx
              idx_j = pool[j].tgt_start_idx
              field_values = {}
              field_values["token_ids"] = (
                  pool[i].token_ids[:idx_i] + pool[j].token_ids[idx_j:]
              )
              field_values["type_ids"] = (
                  pool[i].type_ids[:idx_i] + pool[j].type_ids[idx_j:]
              )
              field_values["pos_ids"] = list(
                  range(len(field_values["token_ids"]))
              )
              neg_record = self.Record(
                  **field_values,
                  tgt_start_idx=idx_i,
                  data_id=-1,
                  label=0,
              )
              pool.append(neg_record)
              assert len(neg_record.token_ids) <= self.max_seq_len
          self.global_rng.shuffle(pool)
          for record in pool:
              yield record
  
      def __wrapper__():
          pool = []
          for record in reader():
              pool.append(record)
              if len(pool) == neg_pool_size:
                  for record in gen_from_pool(pool):
                      yield record
                  pool = []
          if len(pool) > 0:
              for record in gen_from_pool(pool):
                  yield record
  
      return __wrapper__
  
file_path: PaddleHub/modules/text/text_generation/plato2_en_large/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 4 for calling the NSPReader obj's underlying member method code with example usage: obj._mix_negative_sample(reader, neg_pool_size) and returns: __wrapper__