1.3 Deep Learning Paradigms
“The acting was good, but the plot was weak.” Suppose you want to teach a model to answer which part of the film did the reviewer praise? You have the review. Do you also need someone to write an answer? That depends on what you want the model to learn.
Where does the training signal come from?
| Method | What one training example supplies | What the learner can change |
|---|---|---|
| Self-supervised learning | The review itself supplies a target. After “the plot was,” the next word in this review is “weak.” | Increase the probability of the word that actually followed this prefix. |
| Supervised fine-tuning (SFT) | A demonstration pairs the question and review with an answer, “the acting.” | Increase the probability of the demonstrated answer given the prompt. |
| Reinforcement learning (RL) | The model tries an answer. In a simplified task with two allowed answers, a grader awards 1 for the correct aspect and 0 otherwise. | Update the policy to increase the expected reward of its answers. |
The first two methods can use the same next-token loss. The difference is who supplies the target and which positions count. With raw reviews, each next word can be a target. With an assistant demonstration, the review and question can be context while only the answer tokens contribute to the loss. The SFT lesson shows how that choice becomes a loss mask.
What does one surprising word cost?
Shorten each training review to two tokens. Three say acting good, one says acting weak, one says plot good, and three say plot weak. A model that remembers only these counts assigns probability to weak after acting. For an independently observed review ending that way, the loss is nats. Here is the natural logarithm. Averaging this loss over all scored tokens gives the mean next-token cross-entropy.
In the exercise, select acting → weak. Then add one independent training review with those words. The probability rises to and the loss on the same observed token falls to nats. Now switch the first token to plot. Its counts stayed at one good and three weak. A real neural network shares parameters across contexts, so changing one training record can also move predictions elsewhere.
The Python version takes one CPU pass through eight two-token documents. Each contributes one adjacent pair. Counting restarts at every document boundary. There are no special tokens, padding or optimizer steps in this example. Saving the counts and token spellings is enough to reconstruct its predictions.
from collections import Counter
from math import inf, log
reviews = ([("acting", "good")] * 3 + [("acting", "weak")]
+ [("plot", "good")] + [("plot", "weak")] * 3)
def train(records):
counts = Counter()
for record in records:
counts.update(zip(record, record[1:]))
return counts
def score(counts, first, observed):
total = sum(n for (left, right), n in counts.items() if left == first)
if total == 0:
raise ValueError(f"Unseen first token: {first}")
probability = counts[first, observed] / total
return probability, -log(probability) if probability else inf
for records in (reviews, reviews + [("acting", "weak")]):
probability, loss = score(train(records), "acting", "weak")
print(f"{probability:.2f} {loss:.3f}")
The two lines are 0.25 1.386 and 0.40 0.916. With an unseen first token, the model has no observations from which to estimate a distribution. For a known first token and a never-observed ending, it assigns zero probability, giving infinite loss. The decoder-only example shows how a neural model lines up its predictions and targets for a longer sequence.
Does better completion answer the question?
A model can get better at completing acting weak without learning to identify praise. Test it on a pair of new reviews. In the first, the acting is good and the plot is weak. In the second, swap the adjectives. A system that always answers “acting” scores one out of two. Report the result for each praise target and keep the previous system if a candidate loses the ability to identify either target. These two reviews catch one shortcut. A release decision needs held-out reviews across the language and subject matter readers actually use.
Published models illustrate the range of training signals. BERT predicts selected tokens from their surrounding text, while GPT-3 predicts the next token from preceding text. Both make targets from the document. [1] [3] InstructGPT used demonstrations for SFT, human comparisons to fit a reward model, and PPO to optimize sampled answers against that reward. [2] A preference pair can also train a model directly. DPO compares the likelihoods of two recorded answers relative to a reference policy, without a separate learned reward model or online sampling loop. [4]
Quizzes
Quiz 1: If you change the ending to be scored from “good” to “weak,” which training counts change?
None. The counts come from the training reviews. Selecting an observed ending chooses which probability enters the loss.
Quiz 2: An extra “acting weak” training review lowers the loss on that ending. What happens to “acting good”?
Its probability falls from 3/4 to 3/5, so its loss rises. To judge the update, score both endings on separate reviews in proportions representative of the intended use.
Quiz 3: Why include a review that praises the plot in the assistant evaluation?
A model that always answers “acting” can pass every acting-praise example by ignoring the text. Reversing the adjectives changes the correct answer while keeping the same two aspects.
Quiz 4: A reviewer ranked two stored answers. What else would the InstructGPT workflow do that DPO can skip?
InstructGPT fits a separate reward model to comparisons, then scores newly sampled answers during PPO. DPO updates the policy using the stored preferred and rejected answers with a reference policy.
References
- Devlin, J., et al. (2018). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding.
- Ouyang, L., et al. (2022). Training language models to follow instructions with human feedback.
- Brown, T., et al. (2020). Language Models are Few-Shot Learners.
- Rafailov, R., et al. (2023). Direct Preference Optimization: Your Language Model is Secretly a Reward Model.