SampleBatch

SampleBatch(samples)

A batch of samples with automatic attribute aggregation.

This class wraps a sequence of samples and provides magic __getattr__ access to aggregate sample attributes. When you access an attribute that exists on the sample type, it automatically aggregates values across all samples in the batch.

NDArray fields are stacked into a numpy array with a batch dimension. Other fields are aggregated into a list.

Parameters

Name Type Description Default
DT The sample type, must derive from PackableSample. required

Attributes

Name Type Description
samples The list of sample instances in this batch.

Examples

>>> batch = SampleBatch[MyData]([sample1, sample2, sample3])
>>> batch.embeddings  # Returns stacked numpy array of shape (3, ...)
>>> batch.names  # Returns list of names

Note

This class uses Python’s __orig_class__ mechanism to extract the type parameter at runtime. Instances must be created using the subscripted syntax SampleBatch[MyType](samples) rather than calling the constructor directly with an unsubscripted class.