liveBook · Manning

Noise

As explained in Deep Learning with PyTorch, Second Edition

Noise is variation, content, or data treated as unwanted, irrelevant, or distinct from the signal, pattern, or structure of interest.

Noise is random variation added to data. In a diffusion model, it is not an accidental flaw: adding it gradually breaks down an image’s structure, and learning to remove it provides a way to generate new images. The forward process adds noise; the reverse process starts from noise and restores structure step by step. section 10.3 section 10.10

A noise schedule controls each forward step. At timestep t, beta determines how much of the previous data is retained and how much random noise is added: xₜ = √(1 − βₜ)xₜ₋₁ + √βₜ ε. A linear schedule increases beta over time. The process can also be computed directly from the original data at a chosen timestep using cumulative products of 1 − beta. section 10.5

def diffuse_points(points, beta):
    new_mean = torch.sqrt(1-beta) * points
    noise = torch.randn(points.shape)
    perturbation = torch.sqrt(beta) * noise
    points = new_mean + perturbation
    return points, noise

This PyTorch function makes one forward step with torch.randn noise and returns that noise alongside the changed points. section 10.5

Watch a pattern disappear

Start with 2D points arranged as a PyTorch logo. Add scheduled noise to one point to see how it moves, then diffuse every point. Across 1,000 steps, the original pattern becomes unrecognizable. section 10.5

To learn the reverse process, a neural network receives noisy data and its timestep and predicts the noise used to produce it. Training compares that prediction with the actual noise using mean squared error. During generation, repeated predictions guide the removal of noise from an initially noisy sample. section 10.6 section 10.6.1

def get_loss(model, x, t):
    x_noisy, noise = forward_diffusion_sample(x, t)    #1
    noise_pred = model(x_noisy, t)              #2
    return F.mse_loss(noise, noise_pred)    #3

The loss function creates a noisy sample, predicts its noise, and measures mean squared error against the noise actually added. section 10.6.1

Noise can also serve a different purpose: data augmentation. Random Gaussian noise added to a CT training sample creates a variation of that sample. As with other augmentations, the result should still be representative of the original training case. section 14.6.1

Listing 14.17 Adding random Gaussian noise
if 'noise' in augmentation_dict:
  noise_t = torch.randn_like(augmented_chunk)
  noise_t *= augmentation_dict['noise']

  augmented_chunk += noise_t

This augmentation generates noise with torch.randn_like, scales it by a configured amount, and adds it to the CT chunk. section 14.6.1

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Works through scheduled forward noise, noise-prediction training, and Gaussian augmentation code; leaves the sinusoidal embedding implementation elsewhere.
Examples
Shows a 2D PyTorch-logo pattern dissolving over timesteps, a noise-prediction loss function, and Gaussian noise added to CT data.
What it assumes
Uses PyTorch tensors and neural-network training while introducing diffusion through a plain-language analogy and 2D-point example.
What you can do after
Build it from scratch with PyTorch: add scheduled noise, train a model to predict it, or add Gaussian noise to CT samples.
How it connects
Connects noise to diffusion models, noise schedules, mean squared error, denoising, and data augmentation.

Also explained in

Compare how 11 books explain noise →

Related concepts

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