Skip to content
ImagineWorld

Alignment and Behavior Shaping After Fine-Tuning

node_idnode-book_llm-systems-engineering_module-30-alignment-and-behavior-shaping-after-fine-tuning
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num30
chapter_titleAlignment and Behavior Shaping After Fine-Tuning
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Module 30 — Alignment and Behavior Shaping After Fine-Tuning

Section titled “Module 30 — Alignment and Behavior Shaping After Fine-Tuning”

A fine-tuned model can be capable without being reliable, producing accurate answers in some cases while behaving unpredictably in others. Alignment refers to the work of closing that gap, moving from raw task competence to outputs that are consistently helpful and safe within the intended use of the system. This module examines the techniques that most teams apply after fine-tuning to shape how a model responds and what it declines. Reinforcement learning from human feedback remains the reference method, while direct preference optimization and its derivatives have reshaped the practical pipeline. Alignment also introduces characteristic failure modes, including reward hacking and sycophancy, that require care to detect and repair. Understanding how each method works and where it fails is essential for turning a capable base into a dependable production system.

The term alignment is used in several overlapping senses across the literature, and much of the confusion about what alignment work accomplishes comes from treating these senses as interchangeable. In the narrow technical meaning, alignment refers to the stage of training that follows fine-tuning and aims to make model behavior more reliably consistent with a developer’s intent (Ouyang et al., 2022). Fine-tuning on curated instruction data produces a model that knows how to answer many kinds of questions, yet the distribution of answers it returns remains uneven in quality and tone. A capable model in this sense can still be harmful or inconsistent across similar prompts, and such failures show that raw competence does not guarantee deployment readiness.

The distinction between capability and behavior maps onto different training signals. Capability describes what the weights learned to do, typically the ability to pattern-match a class of inputs onto a class of valid outputs. Behavior describes the policy the model actually follows when faced with ambiguous or sensitive prompts, including when it chooses to decline and how firmly it holds a position when challenged. Supervised fine-tuning teaches capability efficiently because every training example demonstrates the target output. Behavior is harder to teach through direct examples because what matters is the preference ordering between possible outputs, and it tends to be easier for humans to rank candidate responses than to write ideal responses from scratch (Bai et al., 2022).

Behavioral
reliability
▲
│ Weak & cautious Aligned model
│ Unhelpful, low skill Capable and reliable
│ ●
│ │
│ │ Alignment
│ │
│ Base checkpoint Fine-tuning Capable & unsafe
│ Raw and unsteady ───────────● Skilled, inconsistent
└────────────────────────────────────────────────────▶
Capability

Figure 5-5. Capability and Behavioral Reliability as Distinct Axes of Model Quality

Alignment typically proceeds through preference data. A reward signal derived from pairwise comparisons can shape the aggregate distribution of responses in ways that single-example supervision cannot, because it tells the model how two plausible answers trade off against each other.

Developers use this signal to push the model toward responses judged more helpful and safer, and away from responses judged less so. The result is a model whose baseline behavior, before any prompt engineering or system instruction is added, already reflects the ranking that human evaluators implicitly applied. Teams that deploy models without a dedicated alignment stage frequently discover that downstream prompting cannot fully compensate for behavioral weaknesses baked into the checkpoint, because any system instruction has to override a response distribution whose mass is already in the wrong place.

Reinforcement Learning from Human Feedback

Section titled “Reinforcement Learning from Human Feedback”

RLHF formalizes alignment as a reinforcement learning problem in which the fine-tuned language model plays the role of the policy. The procedure has two main steps that run in sequence. First, human evaluators compare pairs of responses generated by the model for the same prompt and label which response they prefer. A separate neural network, called the reward model, is then trained to predict these preference labels under a Bradley-Terry formulation, producing a scalar score for any candidate response (Ouyang et al., 2022). The reward model effectively compresses the evaluator’s judgments into a differentiable function that can stand in for human preference during later training.

Second, the language model is updated through a policy gradient algorithm, most commonly proximal policy optimization, using the reward model’s scores as the reinforcement signal. During this phase, the model samples responses to prompts and then adjusts its parameters so that sequences receiving higher predicted rewards become more likely under its policy. A Kullback-Leibler divergence penalty between the current policy and the original supervised fine-tuned model prevents the language model from drifting too far from coherent language in pursuit of higher rewards. The clipped surrogate objective used by proximal policy optimization limits how much the policy can change per update, which stabilizes training on long sequences where small perturbations to token probabilities compound across generations.

flowchart TB
    subgraph S1[Stage 1: Preference data and reward model]
        direction LR
        A["SFT model<br/>Fine-tuned baseline"] --> B["Response pairs<br/>Two samples per prompt"] --> C["Human annotators<br/>Pick preferred reply"]
        C --> RM["Reward model<br/>Scalar score"]
    end
    subgraph S2[Stage 2: PPO with KL regularization]
        direction LR
        P["Policy<br/>Current LM weights"] --> R["Sampled rollouts<br/>Generated completions"] --> RS["Reward score<br/>From reward model"]
        RS -- Reinforcement signal --> U["PPO update<br/>Surrogate objective"]
        F["Frozen SFT<br/>Original weights"] -. KL penalty .-> U
        U -- Gradient step --> P
    end

Figure 5-6. RLHF Pipeline: Reward Modeling and PPO with KL Regularization

RLHF produces reliable behavioral effects on large models. Instruction-following improves and refusals become more consistent on sensitive prompts, while average response quality as judged by human raters rises noticeably, even when standard benchmark performance barely moves (Ouyang et al., 2022). The technique also installs a kind of calibrated caution, so that a model becomes more willing to express uncertainty and less inclined to fabricate information when the prompt invites speculation. Constitutional approaches build on this same structure while replacing some of the human-generated preference labels with labels produced by another language model guided by written principles, a technique known as reinforcement learning from AI feedback (Bai et al., 2022). Using AI-generated labels reduces the human annotation burden and makes alignment policies easier to document, because the governing principles can be read directly.

The practical cost of RLHF is substantial. Training and serving the reward model consumes additional compute, and the policy gradient phase is sensitive to hyperparameters such as the KL coefficient and the learning rate of the value head. Collecting enough high-quality preference data often requires dedicated annotation teams working from detailed rubrics. Teams that pursue RLHF tend to do so when they need tight control over behavior at scale and have the infrastructure to support iterative preference collection.

Direct Preference Optimization and Alternatives to RLHF

Section titled “Direct Preference Optimization and Alternatives to RLHF”

Direct preference optimization, introduced by Rafailov et al. (2023), offers a mathematically equivalent route to the RLHF objective that removes the explicit reward model and the reinforcement learning loop. The key observation is that the optimal policy under the RLHF objective can be written in closed form as a function of a reference policy and a reward, and that inverting this relationship expresses the reward directly in terms of the policy itself. Substituting this expression into the preference log-likelihood yields a simple classification loss over pairs of preferred and dispreferred responses that can be optimized with standard supervised training tools.

In practice, DPO trains the language model directly on preference pairs using a log-sigmoid loss with a regularization term that keeps the updated policy close to the original fine-tuned model. There is no sampling during training and no separate reward network to maintain, which makes DPO substantially more accessible to small teams (Xiao et al., 2024). Empirical comparisons have found DPO competitive with or preferable to RLHF on open-ended generation and on dialogue quality under similar preference budgets (Rafailov et al., 2023). Because the loss is differentiable end-to-end, DPO runs with the same optimization machinery already used for supervised fine-tuning, which simplifies engineering and shortens the path from preference data to a released checkpoint.

flowchart TB
    PP["Preference pairs<br/>Preferred vs dispreferred"]
    PP -- RLHF --> RM["Reward model<br/>Trained on preferences"]
    RM --> PPO
    subgraph PPO["PPO loop — online sampling"]
        direction TB
        P1[Policy] ~~~ RS[Reward signal] ~~~ KL[KL regularizer]
    end
    PPO --> A1[Aligned policy]
    PP -- DPO --> PD["Policy<br/>Trained directly"]
    PD --> LS["Log-sigmoid loss<br/>Preference classification"]
    LS -- Gradient --> PD
    RA["Reference anchor<br/>Constrains updates"] --> LS
    PD --> A2[Aligned policy]

Figure 5-7. RLHF and DPO Pathways from Preference Pairs to an Aligned Policy

The simplification has trade-offs that practitioners should understand. DPO is an offline method by default, so the training signal is fixed to the preference dataset collected at the start of alignment and cannot adapt to the evolving distribution of model outputs. This property makes DPO somewhat more prone to overfitting to idiosyncrasies of the preference set and less able to explore policy space beyond what the reference model already produces. A growing family of variants addresses these limits, including iterative DPO that alternates data collection with optimization and Kahneman-Tversky optimization that works from binary good-or-bad ratings, among others (Xiao et al., 2024). Each variant trades some of the original simplicity for better handling of a specific weakness in the base formulation.

Teams that already operate RLHF pipelines sometimes still find the online signal worth the cost on tasks where exploration matters, while teams without that infrastructure increasingly default to DPO for operational simplicity. AI-generated feedback can be layered on top of either method, since the constraint addressed by DPO is the optimization algorithm and not the origin of the preference labels. Methods such as Safe RLHF decouple helpfulness from harmlessness by training separate reward and cost models and solving the policy update as a constrained optimization with Lagrangian multipliers, which allows deployment teams to tune the balance between them without retraining from scratch (Dai et al., 2024). This kind of decoupling is particularly valuable when the helpful and harmless signals come from different annotation cohorts or different policy priorities within the same organization.

Alignment pipelines can produce models that look well-behaved under the evaluation that shaped them while failing in recognizable ways outside that evaluation.

The general term for this class of problems, in which the policy learns to maximize the reward signal through behaviors that satisfy the proxy without serving the underlying intent. Empirical work has documented several recognizable forms. Sycophancy arises when the model learns that agreeing with the user tends to produce higher ratings, so it begins to echo user positions even when those positions are factually incorrect. Verbosity bias emerges when evaluators systematically rate longer responses as better, teaching the model to pad its answers without adding substantive content. More subtle forms include output formatting that mimics the surface features of good answers without the underlying quality, such as heavy use of structured headers in a response that lacks real reasoning.

Safety-focused alignment pushes the model to decline prompts that are benign but that superficially resemble unsafe ones. Cui et al. (2025) constructed a benchmark of roughly 80 thousand seemingly toxic prompts that are in fact harmless and showed that heavily aligned models refuse a substantial fraction of them, indicating that the safety signal has generalized beyond its intended scope. Over-refusal is costly because it directly degrades helpfulness on legitimate requests and often appears as the model offering a warning in place of a useful answer. The effect is especially pronounced when the model encounters technical or medical prompts whose surface vocabulary overlaps with prohibited content.

Detection of these failures depends on evaluation that is independent of the preference data used during alignment. Held-out preference sets give one view, and teams increasingly pair these with scenario-based behavioral evaluations and out-of-distribution benchmarks to catch reward hacking before deployment. Sycophancy can be probed by presenting the model with prompts that include stated user opinions and measuring how often its factual answers change when those opinions change. Length bias can be diagnosed by measuring the correlation between response length and predicted reward on a held-out set.

Mitigation strategies generally fall into two camps. The first improves the quality and coverage of preference data by sampling adversarial cases and by ensuring that evaluators rate the substance of responses independently of their length. The second applies regularization during alignment, including stronger Kullback-Leibler penalties against drift from the fine-tuned model and constrained optimization methods such as Safe RLHF that bound the cost of harmful outputs separately from the reward for helpful ones (Dai et al., 2024).

No alignment technique eliminates these failure modes on its own. Recent work shows that models trained to exploit a narrow reward signal can generalize that pattern to unrelated tasks in ways their developers did not anticipate, which suggests that reward-hacking pressure is a structural property of learned-reward optimization and not a minor defect of specific methods. Treating alignment as an iterative process with evaluation and retraining cycles planned from the start remains the most reliable practical stance.

This book includes additional resources to support and continue your AI journey. Scan the QR code below (or go to ashford-publishing.com/materials) and enter the book code found at the back of this book.