@overrides
def _create_batches(self, instances: Iterable[Instance], shuffle: bool) -> Iterable[Batch]:
instances = ensure_list(instances)
if shuffle:
random.shuffle(instances)
grouped_instances = group_by_count(instances, self._batch_size, None)
// The last group might have not been full, so we check if any of the instances
// are None, which is how group_by_count pads non-complete batches.
grouped_instances[-1] = [instance for instance in grouped_instances[-1] if instance is not None]
return (Batch(batch) for batch in grouped_instances)
@classmethod
def from_params(cls, params: Params) -> "BasicIterator":
batch_size = params.pop_int("batch_size", 32)