docstr: generate batch records
docstr_tok: ["generate","batch","records"]
code: def _prepare_batch_data(
      self, examples: List, batch_size: int, phase: str = None
  ) -> Generator:
      """generate batch records"""
      batch_records, max_len = [], 0
      for index, example in enumerate(examples):
          if phase == "train":
              self.current_example = index
          record = self._convert_example_to_record(
              example, self.max_seq_len, self.tokenizer, phase
          )
          max_len = max(max_len, len(record.token_ids))
          if self.in_tokens:
              to_append = (
                  len(batch_records) + 1
              ) * max_len <= batch_size
          else:
              to_append = len(batch_records) < batch_size
          if to_append:
              batch_records.append(record)
          else:
              yield self._pad_batch_records(batch_records, phase)
              batch_records, max_len = [record], len(record.token_ids)
  
      if batch_records:
          yield self._pad_batch_records(batch_records, phase)
  
imports: from collections import namedtuple
  from typing import Callable, Generator, Generic, List
  import numpy
  from paddlehub.utils.log import logger
  from paddlehub.compat.task import tokenization
  from paddlehub.compat.task.batch import pad_batch_data
label_desc: Use image node_id 5 for calling the BaseNLPReader obj's underlying member method code with example usage: obj._prepare_batch_data(examples, batch_size, phase) without return types