Do LLMs Just Pick the Most Likely Next Word?

If you ask people this question, nine out of ten will probably say yes.

“Transformers train on massive amounts of data, run it through complex mechanisms like Attention, and ultimately use statistics to pick the most plausible next word.”

That answer is only half right. If Large Language Models (LLMs) really just picked the single “highest probability word” every single time to finish a sentence, the fluent, highly creative AI we see today simply wouldn’t exist.

Open up Gemini or ChatGPT right now and type this in:

Finish this sentence: “Yesterday morning, I woke up and…”

If the LLM mathematically selected the most likely word every time, you’d get the exact same response on every attempt. But in reality, it gives you a slightly different answer every time you ask.

The Transformer architecture does incredible things, but the real magic happens at the very end of inference — right after all the complex internal calculations are done, and just before the next token hits your screen.

This split second is when the LLM decides what to say, choosing which path to walk down among countless branching futures. It’s almost like standing at the crossroads of a multiverse.

Today, we’re going to dig into how this final stage of inference works and see exactly how sampling parameters like Temperature, Top-k, and Top-p operate in that crucial last millisecond.

1. The Big Picture: The LLM Inference Pipeline & the Final Split Second

Before we talk about sampling parameters, let’s map out the overall pipeline of how an LLM generates a word. We’ll keep it conceptual rather than diving too deep into the nitty-gritty of Transformer math.

When you type in a prompt, roughly the following sequence happens under the hood:

  • Tokenize: Your text is chopped into smaller pieces (tokens) that the model can digest.
  • Embedding: These pieces are converted into numeric vectors the model can understand.
  • Attention & MLP: Through the Attention mechanism, the model figures out the context and relationships between words. The Multi-Layer Perceptron (MLP) then pulls up the knowledge the model has learned.
  • Final Hidden State: All of this context and understanding is compressed into a final, dense vector.
  • LM Head: This compressed vector is projected across the entire vocabulary dictionary the model knows.
  • Logits: The model calculates a “logit” — a raw score indicating how suitable every single word in its massive dictionary is to be the next word.

By this point, the model has assigned a score to every token in its vocabulary, effectively ranking how likely each token is to come next. In other words, it knows exactly who the #1 most likely word is.

But as we established earlier, the LLM doesn’t just pick that obvious winner. Doing so often reduces diversity and can make long-form text repetitive.

2. The Limits of a “First-Place Only” World

Technically, in that final step, those raw Logit scores are passed through a function called Softmax, which converts them into statistical probabilities. Simply put, it transforms the scores so that the probabilities of every word — from 1st place to dead last — add up perfectly to 1.0 (or 100%).

This process doesn’t change the rankings. First place is still first place; second place is still second place. Only the scale of the values changes.

The most intuitive way for the model to pick an answer is just to grab the #1 token (a method known as Greedy Search).

But doing this completely kills the model’s creativity. You’d get the exact same words and the exact same results for a given prompt, every single time. Even humans don’t always speak using the most predictable, mathematically probable words.

Another massive problem: if you ask a model to write a long article using only this method, the text will become agonizingly repetitive, often getting stuck in endless loops repeating the exact same sentence forever.

3. Probability-Based Sampling

To fix this, we use Random Sampling. The idea is to respect the 1st place winner, but also give 2nd place, 3rd place, and even the token in last place a fighting chance. Of course, 1st place gets the biggest advantage. Second place gets the next biggest, and so on.

Imagine taking every word the LLM knows and building a massive roulette wheel. If the model has a vocabulary of 10,000 words, it’s a roulette wheel with 10,000 slots.

The key here is that the width of each slot is sized to match the probability the model calculated. If the #1 word has a 50% probability, it takes up half the entire roulette wheel. If the #2 word is at 10%, it gets 1/10th of the wheel, while the word in dead last gets a sliver so microscopic it’s practically invisible.

Now, you spin the wheel, and whatever word the “gods of probability” land on is your final result. With this setup, the 1st and 2nd place words are still highly likely to be picked, but the chance of drawing something else isn’t zero. This breathes life and creativity into the model.

Article illustration

However, there is a terrifying trap hidden in this roulette system.

It’s a characteristic of language model probability distributions known as the “High probability head + Unreliable tail.”

Let’s say your prompt is: “I want to visit a famous city like”

A typical model’s vocabulary contains anywhere from tens of thousands to over a hundred thousand words. If you look at the probability distribution after Softmax, the top few words (the “head”) hold perfectly logical probabilities for the context: “Paris” (45%), “London” (25%), “Rome” (15%).

The problem is the endless “tail” that follows. Glued to the roulette wheel are tens of thousands of junk tokens that have absolutely nothing to do with the context — words like “apple” (0.0001%), “spaceship” (0.00001%), or even meaningless strings of random letters — each holding a microscopic fraction of a percent.

Because their probability isn’t exactly zero, if you keep spinning that roulette wheel enough times, eventually the ball is going to land on one of these bizarre tokens from the unstable tail.

Imagine you’re spinning the wheel and a totally random, nonsensical token gets picked. Because of the autoregressive nature of Transformers, this bad output immediately becomes part of the next input. The context gets hopelessly tangled, and the quality of the entire output collapses.

In short: we need Random Sampling to give the model creativity, but we also desperately need a safety mechanism to control it.

Enter our sampling parameters: Temperature, Top-p, and Top-k.

4. Temperature: Shaking Up the Logit Space

The first control mechanism we’ll look at is Temperature, which sculpts the overall shape of the probability distribution. Temperature rescales the logits before Softmax.

Think of it as a dial that decides whether to amplify or reduce the gap between the “rich” (high probability tokens) and the “poor” (low probability tokens).

  • Low Temperature (Below 1.0): “The Cold, Conservative Choice” When you set the Temperature below 1.0 (e.g., 0.5), it widens the wealth gap in the probabilities. The probabilities that were already high get even higher, and the small ones sink even lower. Even if the original gap between 1st and 2nd place was small, passing it through a low temperature gives the #1 word absolute dominance. The probabilities of lower-ranked words flatline. As a result, the top words take up massive chunks of the roulette wheel, making them overwhelmingly likely to be chosen. The model outputs safe, consistent, and highly predictable text. This is fantastic when factual accuracy is paramount, like when coding, solving math problems, or translating text.
  • High Temperature (Above 1.0): “The Free-Spirited Artist” Conversely, turning up the heat shrinks the inequality gap. The crushing dominance of the #1 word is reduced, while the suppressed probabilities of the 2nd, 3rd, 4th, and even lower-tier words are pulled up. Because a much wider variety of words now have a fighting chance on the roulette wheel, the model starts spitting out unpredictable, fresh, and creative ideas.

5. Top-K: The Cutthroat Survival Audition

Even if you tweak the overall highs and lows with Temperature, you still have tens of thousands of low-probability words lingering in the tail. No matter how low you drop the temperature, those probabilities never truly hit zero.

To completely amputate this tail and stabilize the sampling process, we use Top-k.

The mechanism works exactly like a survival reality show.

The model ranks every single word candidate in descending order of probability. Then, it keeps only the top ‘K’ words that you set, and ruthlessly deletes the tens of thousands of words that didn’t make the cut.

For example, if you set K=50, the top 50 words survive — no matter how high or low their actual probabilities are. The model then takes the probabilities of those surviving 50 words, mathematically readjusts them so they equal 100%, and builds a brand new roulette wheel using only them. Since everyone from rank 51 onwards was evicted, the surviving 50 split the remaining space proportionally.

This entirely eliminates the risk of picking those weird, context-destroying tokens deep in the tail.

The Limitation:

However, Top-k has a fatal flaw: it is painfully inflexible.

Sometimes you have a “narrow context” where there are realistically only 2 or 3 valid next words (like “Yes” or “No”). Other times, you have an “open-ended context,” like writing a novel, where hundreds of different words would work perfectly fine.

If you lock K=50, the model is forced to keep 50 candidates alive even when there are clearly only 2 right answers, unnecessarily introducing noise. On the flip side, in an open context where it should be flexing its imagination, it’s artificially suffocated to just 50 options.

6. Top-P: The Pursuit of Flexibility

To elegantly solve Top-k’s fixed-cutoff problem, Top-p stepped onto the scene.

Instead of just chopping the list at a hard rank (like the top 50), Top-p cuts off the candidates based on “Cumulative Probability” — meaning it adds the probabilities together as it goes down the list.

If that sounds a bit dense, let’s break it down. Imagine you set your P value to 0.9 (or 90%).

  1. First, the model sorts the words from highest to lowest probability.
  2. It starts dropping them into a “probability bucket,” starting with 1st place, adding their probabilities together as it goes.
  3. The exact second the total probability inside the bucket hits 90%, the model slams the door. Any remaining words (the tail) are tossed out. “Bucket is full, try again next time.”

Let’s look at why this simple shift makes the model incredibly flexible:

  • Obvious Answers (High Confidence): What if the #1 word alone has an 85% probability, and #2 has 6%? The model drops both into the bucket, hitting 91%. That instantly crosses the 0.9 threshold! So, it naturally leaves only 2 candidates and trashes the rest. It perfectly prevents context collapse in narrow situations.
  • Diverse Expressions (Low Confidence): What if the probabilities are super fragmented? Say 1st place is 5%, 2nd is 4%, 3rd is 3.5%, and so on. To reach that 90% cumulative threshold, the model has to keep scooping dozens or even hundreds of words into the bucket. The candidate pool dynamically widens, allowing the model to maximize its creativity to fit the situation.

By dynamically adjusting the size of the candidate pool based on its own confidence, Top-p has cemented itself as a top-tier sampling technique.

7. The Rise of Min-P

Of course, the research hasn’t stopped there. Min-p has recently gained popularity in open-weight LLM communities because it adapts the cutoff relative to the model’s confidence.

So, what is Min-p?

If Top-p uses the “sum of cumulative probability” as its threshold, Min-p sets the cutoff based on a relative ratio to the top word’s probability.

Let’s say you set Min-p to 0.05 (5%).

If the model is highly confident and the #1 word has an 80% probability, the cutoff becomes 5% of that 80% (which is 4%). Any token with a raw probability below 4% is considered part of the tail and thrown away.

Conversely, if the context is wide open and the #1 word only has a 20% probability, the cutoff drastically drops to 1% (5% of 20%).

In short, the cutoff dynamically scales in direct proportion to “how confident the #1 token is.”

Many users of recent open-weight models report that Min-p often produces more coherent outputs in certain settings, although the optimal sampling strategy remains model-dependent.

8. Practical Combinations in the Wild

So, how do you actually use these parameters in the real world? First, you need to understand how the specific framework you’re using applies them.

Some frameworks apply them in the order of Temperature -> Top-k -> Top-p -> Final Sampling, while others might use a totally different sequence. Some APIs don’t even let you touch Top-k at all.

Just because an API gives you all these dials doesn’t mean you should crank them all at once. Temperature, Top-p, and Min-p are all pulling towards the exact same goals: controlling “randomness” and “creativity.”

If you tweak all of them simultaneously, it becomes literally impossible to figure out which variable actually changed your output.

In practice, many systems use Temperature and Top-p together. However, when experimenting, it’s often easier to tune one parameter at a time to understand its individual effect.

When writing code or extracting hard facts, drop the Temperature close to 0 to lock in consistency. When you’re writing a novel or brainstorming marketing copy, leave Temperature at 1.0 and open up the Top-p or Min-p values to unleash the model’s full potential. This keeps your variables isolated and your results much easier to control.

Wrapping Up

If you’ve ever played around with LLM APIs, you’ve likely seen the classic advice: “To reduce randomness, lower temperature and top-p; to increase creativity, raise them.” More often than not, people just slide these values around blindly without knowing why.

Hopefully, this post gave you a clear look under the hood at how these numbers actually shape what an LLM says, and helps you master your own inference parameters going forward!