1. Home
  2. 3Blue1Brown

Nov 19, 2024

How AI chatbots work by predicting the next word

7 min → 1:36

Overview

3Blue1Brown explains how large language models predict words, why the Transformer architecture was a critical breakthrough, and what it takes to train these massive systems.

3 things to know

Chatbots write full replies by guessing next words

Large language models work by calculating the chance of what word comes next in a sequence, and chatbots build entire responses by repeating that guessing process over and over.

More

Chatbots generate entire responses by repeatedly applying this process.

▶ Watch at 0:37

A 2017 network design reads all words at once

Introduced in 2017, the Transformer network design made scaling up language models possible by handling all the words in a text at the same time instead of one by one.

More

This was a crucial innovation for scaling up models.

▶ Watch at 3:17

Weighing nearby words separates river banks from financial banks

An attention step inside the Transformer lets a language model weigh how important different words are in a text to grasp context and tell a river bank apart from a financial bank.

More

The key component of the Transformer.

Also in this episode

Guessing next words in internet text teaches models reasoning

Initial training feeds a language model huge amounts of internet text with the simple goal of guessing the next word, which teaches the system grammar, facts, and reasoning skills.

Human graders rate model answers to make chatbots safer

Human evaluators rate and fix a language model's answers during a secondary training phase so the system becomes more helpful, harmless, and matched to what users prefer.

More

This feedback further tunes the model to be more helpful, harmless, and aligned with user preferences.

Training tweaks billions of number settings inside language models

Language models hold billions of changeable number values called parameters, and training adjusts these internal settings to make the system better at predicting words.

More

The training process adjusts these parameters to improve the model's prediction accuracy.

Quotes

“A large language model is a sophisticated mathematical function that predicts what word comes next for any piece of text.”

▶ Watch at 0:37

“The scale of computation involved in training a large language model is mind-boggling.”

▶ Watch at 3:17

Full summary

Episode Overview

  • Large Language Models (LLMs) are fundamentally sophisticated next-word prediction engines that generate text one word at a time based on probabilities.
  • Training an LLM is a massive undertaking that involves two main steps: pre-training on vast amounts of internet text and fine-tuning with human feedback (RLHF) to align the model's behavior.
  • The "Transformer" architecture, with its core "Attention" mechanism, was a critical breakthrough that enabled the parallel processing and contextual understanding required to build today's massive models.
  • The scale of data, parameters (billions of tunable "dials"), and computation required to train a modern LLM is astronomical, far beyond human capacity.

Key Concepts

  • Next-Word Prediction: The core function of an LLM is to calculate the probability of what the next word in a sequence should be. Chatbots generate entire responses by repeatedly applying this process.
  • Parameters/Weights: These are the billions of tunable numerical values inside the model. The training process adjusts these parameters to improve the model's prediction accuracy.
  • Pre-training: The initial training phase where the model learns grammar, facts, and reasoning skills by processing enormous amounts of text from the internet, with the simple goal of predicting the next word.
  • Reinforcement Learning with Human Feedback (RLHF): A secondary training phase where human evaluators rate and correct model outputs. This feedback further tunes the model to be more helpful, harmless, and aligned with user preferences.
  • Transformer Architecture: A neural network design introduced in 2017 that processes all words in a text simultaneously (in parallel), rather than one by one. This was a crucial innovation for scaling up models.
  • Attention Mechanism: The key component of the Transformer. It allows the model to weigh the importance of different words in the input text to understand context and refine the meaning of words (e.g., distinguishing "river bank" from "financial bank").

Quotes

  • At 00:37 - "A large language model is a sophisticated mathematical function that predicts what word comes next for any piece of text." - A concise, foundational definition of what an LLM does at its core.
  • At 3:17 - "The scale of computation involved in training a large language model is mind-boggling." - This statement introduces a powerful analogy illustrating the immense computational power required, estimating it would take a single person over 100 million years to perform the same calculations.

Takeaways

  • An LLM's seemingly intelligent responses are generated by a simple, repeated process: predicting the most probable next word based on the preceding text.
  • The model's vast capabilities are not explicitly programmed; they are an emergent property that arises from automatically tuning billions of parameters on trillions of text examples.
  • The "Attention" mechanism is the key innovation that allows models to understand how words relate to each other across a text, giving them a powerful grasp of context.
  • Modern chatbots undergo a two-stage training process: first learning about the world from raw text, and then learning how to be a helpful assistant through human feedback.
  • The process is probabilistic, not deterministic. By allowing the model to occasionally pick less-likely words, it can generate different, more creative, and natural-sounding responses to the same prompt.

Watch the full episode 7 min

Read along with the audio summary

Training a large language model takes so much computation that a single person would need over a hundred million years to do the math. This episode, released on November nineteenth, twenty twenty four, explains how these models work.

The secret behind chatbot conversations is simple next word prediction. A large language model, or L L M, is a mathematical function that calculates the probability of what word comes next in a sequence.

Billions of tiny dials inside the model make those predictions accurate. The model contains billions of tunable numerical values called parameters, or weights, which act like dials that get adjusted during training to improve prediction accuracy.

To set those dials, the model starts with a massive phase called pretraining. By processing enormous amounts of internet text with the sole goal of predicting the next word, the model tunes its billions of parameters across trillions of examples.

Raw internet text is not enough, which leads to a second training phase using human feedback. In a process called Reinforcement Learning with Human Feedback, or R L H F, human evaluators rate and correct the outputs to make the model more helpful, harmless, and aligned with user preferences.

Scaling this up required a breakthrough in twenty seventeen called the Transformer architecture. The Transformer is a neural network design that processes all words in a text simultaneously, in parallel, making today's massive scale possible.

Inside the Transformer, the attention mechanism gives the model a grasp of context. Attention lets the model weigh the importance of different words across the input text, refining their meaning so it can tell a river bank apart from a financial bank.

Remember that a chatbot's capabilities emerge from a two stage training process and an attention mechanism that grasps context, all driving a probabilistic system that predicts the next word. Because the model occasionally picks less likely words, it can generate different, more creative, and natural sounding responses to the very same prompt.

More from 3Blue1Brown

Related Episodes