liveBook · Manning

From scratch implementation

As explained in Learn Generative AI with PyTorch

A development approach in which a model is implemented and trained directly rather than being treated as a prebuilt black box.

From-scratch implementation means constructing a model’s components and training it directly rather than treating a prebuilt model as a black box. The payoff is a clearer view of how the architecture works and more control over how it is used. section 1.4

Start with a small GAN

Build a generator that creates samples and a discriminator that tries to distinguish them from real data. Train the pair to produce points along an exponential-growth curve, then try a different shape or a sequence of multiples of five. Small targets make the competing networks and their training behavior easier to inspect. section 3.0

For a text-generating GPT model, work through the pipeline in order:

  • Choose a trainable size: sequence length, embedding dimension, decoder-block count, and dropout rates affect output quality and training speed. section 12.1
  • Clean the text, tokenize it, assign token IDs, and form input sequences with targets shifted one token ahead. For example, an input (t0, t1, t2) has target (t1, t2, t3). section 12.1
  • Train the model, then turn a prompt into token IDs, predict further tokens iteratively, and convert the result back to text. section 12.1

Scale is a practical boundary. A GPT-2XL-sized model can be constructed but calls for enormous data and computing resources to train. A roughly five-million-parameter version with three decoder blocks and a 256-dimensional embedding can instead be trained on a regular computer. Training from scratch starts with random parameters; fine-tuning starts with pretrained weights. section 12.0 section 1.4

The same build-and-adapt approach extends to music generation: keep a GPT-style architecture, but select its decoder layers, attention heads, embedding dimension, and input length for the new task. section 14.3

How Learn Generative AI with PyTorch covers it

How deep it goes
Works through GAN construction and a GPT training pipeline, while deferring from-scratch training of very large language models.
Examples
Uses exponential-growth points, multiples-of-five sequences, Hemingway-style text, and music generation as implementation targets.
What it assumes
Assumes rudimentary deep-learning knowledge for GAN construction while teaching the model-building details directly.
What you can do after
Build it from scratch: configure and train smaller generative models, then generate samples or prompted text with them.
How it connects
Connects generator–discriminator training, Transformer hyperparameters, next-token prediction, pretrained weights, and fine-tuning.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.