Large Language Models

Lesson 2 of 5310 minLLM Overview and Core Purpose
In this lesson8 sections

Large language models

A generative language model predicts how text can continue from the context it has received. This lesson separates that prediction process from factual verification, then distinguishes using a trained model from training it.

Imagine a friend begins, "I’m going to make a cup of ________." Coffee and tea are plausible completions because of how the phrase is commonly used.

A familiar phrase has several plausible endings. “I’m going to make a cup of…” can lead to coffee or tea.

A generative language model learns from text to predict the next token in a sequence. A token may be a word or a smaller part of one. The preceding text supplies the context for that prediction.

What is a large language model?

The name describes the scale of the system, the material it models, and the form of its learned representation.

  • Large: The term refers to the scale of the model’s learned parameters and training data. There is no single parameter threshold that defines an LLM. Parameters are numerical values adjusted during training; an individual value does not necessarily correspond to one recognizable linguistic pattern.

  • Language: The model learns patterns in text, including prose, poetry, structured formats such as JSON, and programming languages such as Python.

  • Model: It is a learned mathematical model of language. Generating an answer is different from retrieving a verified record from a database.

A text completion engine

Now that we know what the name means, what does an LLM actually do?

For the autoregressive models followed in this course, the basic task is to predict a distribution over the next token. Generation selects a token from that distribution and continues the sequence. The later output-layer lesson examines that selection step.

Autocomplete is a useful starting analogy. Given "The cat sat on the…", a system might suggest "mat", "floor", or "couch". A large model applies this continuation process across many more patterns of grammar, context, style, and information learned during training.

Large Language Models figure 2

At scale, language-model training can support tasks such as question answering, summarization, translation, and code generation. These capabilities are learned from data rather than supplied as a separate hand-written program for each task.

LLMs are probabilistic, not all-knowing

A plausible continuation and a verified statement answer different questions. The distinction matters whenever an application uses generated text to inform a decision.

An LLM assigns probabilities to possible continuations. A continuation can fit the preceding text while making a factual error; probability alone does not certify that the statement is true.

The model draws on patterns learned during training to produce a plausible response. Unlike a database lookup, that process does not by itself identify a stored record that proves each sentence.

The flexibility of generation allows both useful creative writing and confident errors. A hallucination is incorrect or nonsensical generated content that can still read fluently. Calling it a lie would attribute an intention that the generation process does not establish. For an application, the practical concern is whether the answer is supported.

Two types of prompts

Compare a request with a factual answer to one that invites invention.

Example 1: A knowledge-based prediction

  • Prompt: “The planet closest to the sun is”

  • Likely LLM Output: “Mercury.”

  • Reasoning: This is an illustrative completion of a factual prompt. The example shows how a model can produce the expected answer through prediction; it does not establish the exact token probabilities of any particular model.

Example 2: A generative prediction

  • Prompt: “Once upon a time, in a forest full of talking animals,”

  • Likely LLM Output: “There lived a clever fox named Finn.”

  • Reasoning: This hypothetical continuation has no single correct answer. The model can draw on story patterns, and the invented name Finn does not need to refer to a real animal.

Try both completions in an LLM environment and compare their results. For the first, correctness depends on the factual answer. For the second, assess whether the continuation fits the requested story.

The same prediction process underlies these different uses. To study its mechanics, we will follow one short prompt through the model rather than switch examples at every stage.

Introducing our guide: The prompt

The technical lessons use the prompt "Twinkle, twinkle, little".

Large Language Models figure 3

The familiar continuation is "star". Because the expected word is easy to recognize, the example lets us concentrate on how the model arrives at a prediction.

  • Its short length makes the intermediate representations manageable.

  • It asks for a continuation, which matches the generation task.

  • Its familiar completion helps us check the example while focusing on the process.

The two journeys of a prompt

There are two separate processes to explain: how the trained model uses the prompt, and how training produced its parameters.

Inference: using the trained model

First, we ask: Given the prompt, “Twinkle, twinkle, little”, how does a trained model generate the word “star”?

Inference
Inference
  • Inference uses a pretrained model to generate a response to a new prompt. A chef preparing a dish from a learned recipe is a useful analogy: existing skills are put to work.

  • We will follow how text becomes numbers, how the model relates tokens to their context, and how it selects a final prediction.

Training: learning the model parameters

Next, we ask the bigger question: How did the model learn that “star” was the right word to predict in the first place?

Training changes the parameters. Examples supply a target; the optimization step adjusts model weights.
Training
  • Training adjusts the model so that it learns patterns and capabilities before the prompt is used at inference time. The chef analogy now concerns practice and refinement rather than preparing a particular dish.

  • The training lessons examine pretraining on large text collections and alignment steps intended to make a model more helpful and better at following instructions.

From prediction to representation

A generative language model uses learned parameters to predict text. Inference applies those parameters to a prompt; training is the process that produced them.

The next question is how the prompt becomes an input the model can process.

We will use the same short prompt through both explanations, connecting each new representation back to the original text.

Follow the representation, one step at a time. Text, token identifiers, and embedding vectors are different representations.

The next lesson begins with tokenization and embeddings: the conversion from a string of text to token IDs and vectors.