Concepts / Sampling Strategies for Language Models

Sampling Strategies for Language Models

Most application builders adapt an existing foundation model rather than building one, because training is complex, costly, and often confidential.

  • Programming

Starting From a Model You Did Not Build

Imagine your team has been asked to build a customer-support assistant. Someone proposes a shortcut: skip building anything from the ground up and start with a model that already exists and already handles language well. That shortcut is the normal starting point for building with foundation models. The harder question is what you inherit when you take it. Two models can both be called foundation models and still behave very differently, and the reasons are not always visible from the outside.

Building a foundation model is an expensive and intricate undertaking. The people who know how to do it well are often bound by confidentiality agreements, so the specific know-how is rarely published. An application builder usually cannot inspect the full recipe behind a model, and the growing lack of transparency in training makes it hard to know every design decision that went into a given model. This article is about reasoning well under that limitation: which decisions shape a model, how each one tends to show up in behavior, and how to diagnose a misbehaving model without seeing its full recipe.

Following One Token From Scores to Output

A useful way to make the adaptation problem concrete is to follow a model's life in order. The data it learns from comes first. Its structure and size are fixed by its developer. Its training is often split into a first phase that builds capability and a second phase that shapes behavior. Finally, when you ask it something, it selects an output from the many possibilities it could produce. The last step is the one this article focuses on most, because it is the step that happens every time the model answers.

At the moment of answering, the model has not yet produced a single word. It has produced a set of candidate options, each with a score indicating how well it fits. Those raw scores are converted into a probability distribution, which says how likely each candidate is. Sampling is the step that then picks one candidate from that distribution. The diagram below traces that path for a single choice.

The key consequence is that a candidate with the highest probability is not automatically the output. Sampling is a selection from a distribution, not a lookup of the top entry. This is the first reason sampling can change what you see even when the model, its training, and its prompt stay exactly the same.

What do you think happens?

If a model gives one candidate the highest score, will it always be the word that appears in the response?

  • Yes, the highest-scoring candidate is always output

  • No, sampling selects from the distribution, so a lower-probability candidate can be chosen

Reveal answer
Answer:

No. Sampling selects one candidate from the distribution, so a lower-probability candidate can be chosen.

The source describes sampling as the step that selects one output from many possibilities. Because the choice is made from a distribution, the most likely candidate is not guaranteed to be the one returned. This is why the same question can produce different answers on different runs.

Why Sampling Is Easy to Overlook

Most people attribute a model's behavior to training. When a model is accurate in one area and shaky in another, the instinct is to ask what it was trained on. The source argues that sampling is one of the most underrated concepts in AI. It is the step that turns the model's internal possibilities into the single response you actually read, and it is easy to forget because it happens after everything else has been decided.

The source makes two claims that matter for anyone adapting a model. First, sampling can explain many behaviors that otherwise seem baffling, including hallucinations and inconsistencies. If the same question produces different answers on different runs, the selection step is a prime suspect. Second, choosing the right sampling strategy can significantly improve a model's performance with relatively little effort. Together these make sampling a rare lever: it can change results substantially without retraining anything.

Sampling Controls That Reshape Candidates

Sampling strategies are the settings that govern how that selection is made. Common controls work on the distribution itself. A temperature-style setting makes the distribution more concentrated or more spread out, so the model either leans harder toward its top candidates or gives less likely candidates a larger share. A top-k control keeps only the k most likely candidates and removes the rest from consideration. A top-p control keeps the smallest group of most likely candidates whose probabilities add up to at least p, again removing the remainder. These are standard terms, and the source pack does not define their exact mechanics, so treat the description here as the general idea.

The illustration below uses made-up probabilities for four candidate words after a prompt. It shows what a truncating control does to the candidate set: it removes options before the selection step runs, so the choice is made among fewer and more plausible words.

Read the diagram as a before and after pair. The two lower-ranked candidates, fish and rock, are removed from the set. The surviving candidates have their probabilities adjusted so they still form a valid distribution. The selection step then operates only on cat and dog. Changing a control like this does not alter what the model learned; it alters which of the model's existing possibilities are eligible to be chosen.

The Four Design Decisions

Differences between foundation models trace back to a small set of decisions: training data, model architecture and size, post-training that aligns the model with human preferences, and sampling. Each decision leaves a different fingerprint on the behavior you eventually observe. The table below summarizes what each one controls and what a builder would notice if it were different.

Design decisionWhat it shapesWhat you would notice if it differed
Training dataWhat the model learned and in what proportionsStrength in some domains and weakness in others
Architecture and sizeThe structure and scale the developer fixedThe model's general capacity and the first-glance expectations people form about it
Post-trainingHow the model is aligned with human preferencesWhether it feels cooperative, cautious, or awkward to direct
SamplingHow one output is selected from many possibilitiesRun-to-run variation, hallucinations, and inconsistencies

Four design decisions and their most visible effects

Tracing a Symptom to Its Likely Cause

When a model misbehaves, the source recommends diagnosing by symptom. Match run-to-run variation to sampling, domain errors to training data, and conduct problems to post-training. The tree below turns that guidance into a first-question routine: start with the symptom you observe and follow the branch to the decision most likely responsible.

Worked example

Diagnosing an inconsistent support answer

Your customer-support assistant gives three different answers to the same refund-policy question on three separate runs. The answers are all plausible but disagree on the number of days.

  1. 1
    Identify the symptom

    The same question produces different answers on different runs. This is run-to-run variation, not a domain gap, because the answers are plausible rather than consistently wrong.

  2. 2
    Match the symptom to a decision

    The source says to match run-to-run variation to sampling. The selection step is the first suspect.

  3. 3
    Check the more distant causes only if needed

    If the answers were consistently wrong in the same way, training data would become the next suspect, because that pattern points to what the model was exposed to. Conduct problems such as refusing or lecturing would point to post-training.

  4. 4
    Adjust the cheapest lever first

    Because the source says choosing the right sampling strategy can significantly improve performance with little effort, adjusting sampling is the sensible first change. Retraining is not required to test this.

Result

The most likely responsible decision is sampling. Changing the sampling strategy is the first experiment, and the diagnosis would only move upstream if the variation disappeared and a consistent error remained.

Adapting Versus Training From Scratch

The reason application builders adapt an existing model rather than training one is practical. Training is complex, costly, and often confidential, so the specific recipe is rarely available. Adapting a model lets a team start from a capable base and concentrate effort on the application. The comparison below separates the two paths on the dimensions that matter most to a builder.

DimensionAdapting an existing modelTraining from scratch
CostLower, since the expensive base work is already doneHigh, described in the source as expensive and intricate
DataYou inherit the base model's training data and must check whether it covers your domainYou choose the training data yourself
ControlYou inherit architecture, size, and alignment decisions you cannot fully inspectYou control every design decision, including those you choose not to publish
EffortFocused on choosing, adjusting, and diagnosingRequires specialized know-how that is often confidential

Adapting an existing foundation model versus training one from scratch

The central challenge of adaptation is making good decisions with incomplete information. The solution is not to reverse-engineer every detail of a model. It is to understand the broad categories of decision that shape a model, because those categories determine how the model is likely to behave and how it can be adapted. You do not need to know how to train a model in order to use one well.

Common Reasoning Errors When Choosing a Model

  • Common mistake

    Assuming every odd output comes from training

    What it looks like

    A team concludes the model was poorly trained because two runs gave different answers to the same question.

    Why it fails

    Run-to-run variation is a symptom the source associates with sampling, so the training diagnosis points at the wrong decision.

    Do this instead

    Match run-to-run variation to sampling first, and only move upstream if a consistent error remains.

  • Common mistake

    Treating a model with the same name as interchangeable

    What it looks like

    Two models are both called foundation models, so the team assumes they will behave the same on the support task.

    Why it fails

    The source states that two models can both be called foundation models and still behave very differently.

    Do this instead

    Compare the design decisions behind each model, especially training data and post-training, before assuming equivalence.

  • Common mistake

    Expecting sampling to supply missing knowledge

    What it looks like

    A team lowers randomness, expecting the model to suddenly know a specific policy it was never exposed to.

    Why it fails

    Sampling chooses among candidates the model already produces, so it cannot reliably add knowledge the model lacks.

    Do this instead

    Treat domain gaps as a training data question and address them through the adaptation approach rather than through sampling.

  • Common mistake

    Judging size as a measure of quality alone

    What it looks like

    A team picks the largest available model because size is the first thing people ask about.

    Why it fails

    The source treats size as a first-glance signal that shapes expectations, not a complete account of behavior.

    Do this instead

    Evaluate architecture and size together with training data and post-training before deciding.

  • Common mistake

    Believing that a capable model is automatically easy to direct

Practicing the Symptom-to-Decision Routine

MEDIUM

A model answers a medical-product question with confident but wrong specifications that appear nowhere in your documentation. It answers the same question consistently across runs. Which design decision should you investigate first, and why?

Hints
  • Ask whether the answers vary between runs or are consistently wrong.
  • The source ties domain errors to training data.
  • Sampling explains inconsistency, so consistency points away from it.

Key Takeaways

  • Most application builders adapt an existing foundation model because training is complex, costly, and often confidential.
  • Four design decisions shape a model's behavior: training data, architecture and size, post-training, and sampling.
  • Sampling selects one output from a distribution of candidates, so it can explain run-to-run variation and hallucinations and can change results without retraining.
  • When a model misbehaves, diagnose by symptom: run-to-run variation points to sampling, domain errors to training data, and conduct problems to post-training.
  • Avoid reasoning errors such as assuming all odd outputs come from training, treating same-named models as interchangeable, and expecting sampling to supply missing knowledge.

Related concepts

More concepts starting with S