liveBook · Manning

Training dataset

As explained in Build a Text-to-Image Generator (from Scratch)

A training subset is the portion of a dataset supplied to a model for learning its parameters or representations.

A training dataset is the portion of data supplied to a model so it can learn parameters or representations. It may contain translations, images and labels, image–caption pairs, or text–image pairs. Training data differs from test data, which is held out for evaluation. section 2.4 section 3.2.2

Prepare a training dataset by moving from raw records to model-ready batches:

  • Select examples and associated targets, such as German–English translations, clothing labels, or image–caption pairs. section 2.4 section 4.1
  • Standardize inputs: convert images to tensors, resize them, normalize their ranges, and tokenize captions or labels when needed. section 3.2.2 section 4.1.1
  • Create training targets aligned with the task. Captioning shifts tokens by one position, while denoising compares predicted noise with injected ground-truth noise. section 4.1.1 section 5.3.1
  • Increase usable variety with image augmentation, then batch and shuffle examples for training. section 3.2.2 section 6.3.3
  • Keep test examples separate and apply compatible preprocessing without training-only augmentation. section 3.2.2 section 4.2

Image captioning

Flickr 8k supplies roughly 8,000 images with five human captions per image. A preparation pipeline resizes images to 3 × 128 × 128, tokenizes captions, adds <start> and <end>, and turns “two bears fight” into input [<start>, two, bears, fight] and target [two, bears, fight, <end>]. section 4.1.1 section 4.2.1

Diffusion training

A FashionMNIST training dataset contains grayscale clothing images and labels for ten clothing categories. Images are converted to tensors, normalized to [-1, 1], batched, noised at randomly selected time steps, and passed to a denoising U-Net whose error updates its parameters. section 6.3.3 section 5.3.1

import torchvision.transforms as transforms

trainset.transform = transforms.Compose(
    [transforms.ToTensor(),
    transforms.Resize((32, 32),antialias=True),
    transforms.RandomHorizontalFlip(p=0.5),
    transforms.RandomResizedCrop((32, 32), scale=(0.8, 1.0),
                 ratio=(0.75, 1.3333333333333333), 
                 interpolation=2,antialias=True),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

Inspect a PyTorch transformation pipeline that converts images to tensors, resizes and augments them, then normalizes their values for training. section 3.2.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Explains preparation through transformations, splits, batching, target construction, and training loops, but defers dataset governance and collection methods.
Examples
Uses translation pairs, Flickr 8k captions, FashionMNIST clothing images, denoising batches, and large-scale text–image pairs.
What it assumes
Assumes basic machine-learning model training and Python objects, while teaching tensor conversion, normalization, tokenization, splitting, and batching.
What you can do after
Build it from scratch by transforming raw examples, creating targets, splitting evaluation data, batching inputs, and feeding a training loop.
How it connects
Connects dataset preparation with test set, data augmentation, batching, overfitting, transformers, diffusion models, and contrastive learning.

Also explained in

Compare how 36 books explain training dataset →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.