liveBook · Manning

Sequence prediction

As explained in Learn Generative AI with PyTorch

A learning setup where a model predicts the next element in an ordered sequence from earlier elements.

Sequence prediction trains a model to predict the next element from earlier elements in an ordered sequence. In text, the elements are often tokens, so the model learns how word order and context shape what comes next. section 8.0 section 8.1.1

A basic text-prediction pipeline works as follows:

  • Tokenize text into individual words or other tokens. section 8.0
  • Map each token to an integer index and arrange the indexes into sequences of a chosen length. section 8.0
  • Shift the input sequence by one token to create the target sequence. section 8.0
  • Generate text iteratively by appending each predicted token to the growing prompt. section 8.0

Recurrent models such as LSTMs process sequence information step by step, while Transformers use attention to relate elements across long distances and support parallel training. Both approaches address sequence-to-sequence prediction, but Transformers are better suited to large-scale text modeling. section 9.0 section 8.0

Generating a sentence

Given the prompt “Anna and the,” an LSTM predicts the most likely next token, appends it to the prompt, and repeats the process until the desired length is reached. Temperature changes prediction randomness, while top-K sampling restricts choices to the most probable tokens. section 8.0

How Learn Generative AI with PyTorch covers it

How deep it goes
Explains tokenization, indexing, shifted targets, iterative generation, and sampling, but does not derive the underlying training mathematics.
Examples
Uses indexed text windows, the “Anna and the” prompt, and temperature or top-K sampling.
What it assumes
Assumes basic deep-learning familiarity while teaching tokenization, integer indexing, and sequence preparation.
What you can do after
Build and operate an LSTM text generator that predicts and appends tokens sequentially.
How it connects
Connects sequence prediction with tokenization, word embeddings, recurrent neural networks, LSTMs, attention, Transformers, and text generation.

Also explained in

Compare how 3 books explain sequence prediction →

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.