liveBook · Manning

Batch dimension

As explained in Deep Learning with R, Third Edition

A batch axis is the tensor axis indexing the samples grouped into a batch.

A batch dimension is the first axis of a tensor containing a fixed-size group of samples. Deep learning models process these groups instead of an entire dataset at once. section 2.2.7

MNIST batches

MNIST stores digit images with samples on the first axis. Selecting rows 1–128 creates one batch; selecting rows 129–256 creates the next. Each batch has a batch size of 128, while the remaining axes describe each image. section 2.2.7 section 2.2.5

Read the batch dimension together with the axes describing each sample:

  • Vector data uses shape (samples, features), such as (100000, 3) for people described by age, gender, and income. section 2.2.8
  • Sequence data uses shape (samples, timesteps, features), keeping the batch dimension before the time axis. section 2.2.8
  • Image data uses shape (samples, height, width, channels), with one image represented after the batch axis. section 2.2.8
x <- as.array(c(12, 3, 6, 14, 7))
str(x)

num [1:5(1d)] 12 3 6 14 7

dim(x)

[1] 5

Inspecting tensor shapes makes the number of axes explicit; batch tensors add a leading samples axis to the per-sample structure. section 2.2.2 section 2.2.7

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines the leading samples axis and demonstrates indexing batches, but stops short of explaining batching internals.
Examples
Uses MNIST digit batches of 128 samples and vector, sequence, and image tensor shapes.
What it assumes
Assumes basic tensors and axes while defining batches through concrete MNIST indexing examples.
What you can do after
Evaluate tensor shapes and identify which axis indexes samples in common deep learning data structures.
How it connects
Connects samples axis, tensor shape, rank, features axis, time axis, and image channels.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.