Overview

1 Understanding reasoning models

The chapter introduces reasoning in large language models as a practical capability: instead of jumping straight to an answer, a model can generate intermediate steps that help it solve harder tasks like logic puzzles, math problems, coding challenges, and agentic workflows. It frames the book as a hands-on, code-first guide to building these capabilities from an already trained base model, with an emphasis on understanding how reasoning methods work, how to evaluate them, and when they are worth the extra complexity.

It then clarifies what reasoning means in this context. Here, reasoning is not a philosophical claim about machine minds, but an engineering description of models producing step-by-step internal or visible deliberation, often associated with chain-of-thought. The text contrasts this with ordinary LLM behavior, which is driven by autoregressive token prediction and statistical pattern matching, and explains that although reasoning-style outputs can look human-like, they are not the same as deterministic rule-based logic.

The chapter also reviews the standard LLM pipeline of pre-training and post-training, then introduces the main ways reasoning is improved: inference-time compute scaling, reinforcement learning, and distillation. It emphasizes the difference between pattern matching and logical reasoning using simple examples, shows why some seemingly correct answers come from learned associations rather than explicit rules, and explains why building reasoning models from scratch is valuable for understanding trade-offs in accuracy, cost, latency, and task suitability. The roadmap ahead starts from a conventional LLM, adds evaluation, and then develops reasoning improvements through both inference methods and training methods.

A simplified illustration of how a conventional, non-reasoning LLM might respond to a question with a short answer.
A simplified illustration of how a reasoning LLM might tackle a multi-step reasoning task using a chain-of-thought. Rather than just recalling a fact, the model combines several intermediate reasoning steps to arrive at the correct conclusion. The intermediate reasoning steps may or may not be shown to the user, depending on the implementation.
Overview of a typical LLM training pipeline. The process begins with an initial model initialized with random weights, followed by pre-training on large-scale text data to learn language patterns by predicting the next token. Post-training then refines the model through instruction fine-tuning and preference fine-tuning, which enables the LLM to follow human instructions better and align with human preferences.
Example responses from a language model at different training stages. The prompt asks for a summary of the relationship between sleep and health. The pre-trained LLM produces a relevant but unfocused answer without directly following the instructions. The instruction-tuned LLM generates a concise and accurate summary aligned with the prompt. The preference-tuned LLM further improves the response by using a friendly tone and engaging language, which makes the answer more relatable and user-centered.
Three approaches commonly used to improve reasoning capabilities in LLMs. These methods (inference-compute scaling, reinforcement learning, and distillation) are typically applied after the conventional training stages (initial model training, pre-training, and post-training with instruction and preference tuning), but reasoning techniques can also be applied to the pre-trained base model.
Contradictory premises lead to a logical inconsistency. From "All birds can fly" and "A penguin is a bird," we infer "Penguin can fly." This conclusion conflicts with the established fact "Penguin cannot fly," which results in a contradiction.
An illustrative example of how a language model (GPT-4o in ChatGPT) appears to "reason" about a contradictory premise.
Token-by-token generation in an LLM. At each step, the LLM takes the full sequence generated so far and predicts the next token, which may represent a word, subword, or punctuation mark depending on the tokenizer. The newly generated token is appended to the sequence and used as input for the next step. This iterative decoding process is used in both standard language models and reasoning-focused models.
A high-level roadmap of what we build in this book. We start with a conventional LLM, add evaluation methods so that we can measure progress, and then explore two broad families of reasoning improvements, namely, inference techniques and training techniques.
A detailed roadmap of the chapter-level substeps. After loading the base model, we cover benchmark-based and judgment-based evaluation, then inference-time methods such as advanced text generation and voting plus self-refinement, and finally training-time methods based on reinforcement learning and distillation.

Summary

  • Conventional LLM training occurs in several stages:
    • Pre-training, where the model learns language patterns from vast amounts of text.
    • Instruction fine-tuning, which improves the model's responses to user prompts.
    • Preference tuning, which aligns model outputs with human preferences.
  • Reasoning methods are applied on top of a conventional LLM.
  • Reasoning in LLMs refers to improving a model so that it explicitly generates intermediate steps (chain-of-thought) before producing a final answer, which often increases accuracy on multi-step tasks.
  • Reasoning in LLMs is different from rule-based reasoning and it also likely works differently than human reasoning; currently, the common consensus is that reasoning in LLMs relies on statistical pattern matching.
  • Pattern matching in LLMs relies purely on statistical associations learned from data, which enables fluent text generation but lacks explicit logical inference.
  • Improving reasoning in LLMs can be achieved through:
    • Inference-time compute scaling, enhancing reasoning without retraining (e.g., chain-of-thought prompting).
    • Reinforcement learning, training models explicitly with reward signals.
    • Supervised fine-tuning and distillation, using examples from stronger reasoning models.
  • Building reasoning models from scratch provides practical insights into LLM capabilities, limitations, and computational trade-offs.

FAQ

What does “reasoning” mean for an LLM in this chapter?In this chapter, reasoning means an LLM generating intermediate steps before giving its final answer. These steps may be visible to the user or hidden inside tags like <think>...</think>.
How is a “reasoning model” different from a conventional LLM?A reasoning model is an LLM that has been improved through prompting or training so it produces intermediate reasoning steps. This often improves performance on complex tasks like math, coding, and logic puzzles.
What is chain-of-thought (CoT) reasoning?Chain-of-thought is a style of intermediate-step generation where the model works through a problem step by step. It makes the reasoning process more explicit, even if those steps are not always shown to the user.
Does LLM reasoning work like human reasoning?Not exactly. The book uses “reasoning” in an engineering sense, but current LLMs do not reason the same way humans do. Their reasoning is probabilistic and based on learned patterns, not conscious thought or deterministic logic.
What are the two main stages of conventional LLM training?Conventional LLM training is usually split into pre-training and post-training. Pre-training learns language patterns from massive text data, while post-training improves instruction following and response preferences.
What is the goal of pre-training in an LLM?The goal of pre-training is next-token prediction: learning to predict the next word or token in text. This helps the model learn general language patterns and basic capabilities.
What are the three common approaches for improving LLM reasoning?The chapter identifies three broad approaches: inference-time compute scaling, reinforcement learning, and distillation. These methods help improve reasoning either without changing weights, by training with reward, or by transferring reasoning ability to smaller models.
How is pattern matching different from logical reasoning?Pattern matching relies on statistical associations learned from training data, while logical reasoning uses intermediate steps and rules to draw conclusions from facts. Pattern matching can produce fluent answers, but it does not guarantee consistency or correctness.
Why can an LLM sometimes seem to reason correctly without explicit logic?An LLM may appear to reason because it has seen many similar examples during training and learned strong statistical associations. It is simulating reasoning through patterns rather than explicitly applying rule-based logic.
Why build reasoning models from scratch?Building reasoning models from scratch helps you understand how they work, how they differ from standard LLMs, and what trade-offs they involve. It also helps in designing evaluations, debugging failures, and choosing when extra reasoning is worth the added cost and latency.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Reasoning Model (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Reasoning Model (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Reasoning Model (From Scratch) ebook for free