code: def __init__(
      self,
      dataset,
      bucketing_field,
      batch_size=128,
      buckets=10,
      should_shuffle=True,
      ignore_last=False,
      should_trim=False,
      trim_side="right",
  ):
      self.should_shuffle = should_shuffle
      self.bucketing_field = bucketing_field
      self.should_trim = should_trim
      self.trim_side = trim_side
  
      # store our dataset as well
      self.dataset = dataset
  
      field = dataset.get_dataset()[bucketing_field]
      field_lengths = np.apply_along_axis(
          lambda x: np.sign(x).sum(), 1, field
      )
      sorted_idcs = np.argsort(field_lengths)
      self.buckets_idcs = []
      datapoints_per_bucket = len(field) // buckets
      for b in range(buckets):
          start = datapoints_per_bucket * b
          end = (
              datapoints_per_bucket * (b + 1)
              if b < buckets - 1
              else len(sorted_idcs)
          )
          self.buckets_idcs.append(sorted_idcs[start:end])
  
      if should_shuffle:
          self.shuffle(self.buckets_idcs)
  
      self.ignore_last = ignore_last
      self.batch_size = batch_size
      self.total_size = min(map(len, dataset.get_dataset().values()))
      self.bucket_sizes = np.array(
          [x for x in map(len, self.buckets_idcs)]
      )
      self.steps_per_epoch = self._compute_steps_per_epoch()
      self.indices = np.array([0] * buckets)
      self.step = 0
      self.epoch = 0
  
file_path: ludwig/ludwig/data/batcher/bucketed.py
imports: import numpy
  from ludwig.data.batcher.base import Batcher
label_desc: Use image node_id 1 to create a new BucketedBatcher object from inherited base classes: Batcher with example: obj = BucketedBatcher(dataset, bucketing_field, batch_size, buckets, should_shuffle, ignore_last, should_trim, trim_side)