Programming Fundamentals · Algorithms Behind AI

Greedy and Sampling: Two Personalities When AI Picks Words

Always picking the biggest is greedy decoding; rolling dice by probability is sampling—the algorithms behind Temperature. Compare sentences from both strategies yourself

THE QUESTION THIS PAGE ANSWERS

ANSWER FIRST

What is the key idea behind “Greedy and Sampling: Two Personalities When AI Picks Words”?

Always picking the biggest is greedy decoding; rolling dice by probability is sampling—the algorithms behind Temperature. Compare sentences from both strategies yourself

DECISION RULE

Make the claim earn its place. Use this page as a decision aid, not a definition to memorize. Connect the idea to one real task, one observable result, and one failure that would change your mind.

TRY NEXT

Write one question you could answer with evidence after trying this idea.

WATCH FOR

A conclusion that sounds complete but leaves the key assumption untested.

Same starter · two personalities

The starter is fixed: “The weekend plan is”. Play the top machine first: greedy mode (temperature=0), always the longest probability bar. Hit “Regenerate” three times, watch the stacked results below—even one different character?

😤 Greedy mode

temperature = 0
The weekend plan is
Candidates each step—it always takes the longest bar
No dice, no suspense: highest probability wins

Now the bottom machine: sampling mode—each step rolls a weighted die. At 0.7 click thrice and see if results differ; then try 1.2—watch the bar shapes: higher temperature flattens them, so rare words get a better shot.

🎲 Sampling mode

Roll by probability
temperature
The weekend plan is
Probabilities after temperature—dice roll on these
Same candidate table, dice pick the path—each run may fork differently
Concept card · the ledger of two personalities

😤 Greedy: take the biggest right now

Fast, stable, reproducible—ten thousand runs, same sentence. Fatal blind spot: local best each step may not sum to global best. Pick the smoothest first word and the whole line may hit a dead end. The fix? Next lesson’s Beam Search is the antidote—cliffhanger for now.

🎲 Sampling: leave a door for randomness

Trade certainty for diversity. Roll by probability: high-prob words win often (still fluent); low-prob words occasionally surface (surprises). Temperature is the “surprise” budget: higher T flattens the distribution so rare words dare to show.

Interview one-liner: temperature = 0 is greedy decoding—fully deterministic; higher T flattens softmax so the model dares low-prob words—diversity and “going off the rails” rise together. That knob in the LLM Fundamentals Part sits between greedy and sampling.
You’ve met greedy people in life: at a buffet every round they grab the priciest plate—salmon, steak, king crab—until the stomach’s full and the signature wagyu carving never happens. Step-best ≠ whole-best; stomachs are finite, and so is the context window.

The algorithmic cost curve in “Same starter · two personalities”

“The starter is fixed: “The weekend plan is”.” is not asking you to memorize steps. It trains you to spot repeated work: as the input grows, how many comparisons, moves, or recursive calls does the program perform?

Find repeated work before declaring something fast

Break “Now the bottom machine : sampling mode—each step rolls a weighted die .” into three questions: how input size changes, what each round does, and whether the next round can shrink its search space. Big-O describes growth, not an exact time on every machine; constants, memory, and data distribution still matter.

  • Greedy = pick the highest probability each step : three runs, identical—fast and reproducible, but may miss a better whole
  • Sampling = roll by probability : three runs, three flavors—trade certainty for diversity
  • Temperature is the knob between them : T=0 is greedy; higher T flattens the distribution and dares rarer words

Theoretical optimum is not always practical optimum

When AI writes an algorithm, trace a small input by hand and benchmark progressively larger inputs. That turns “Trade certainty for diversity .” from a slogan into a performance claim you can check.

From “Same starter · two personalities” to “Concept card · the ledger of two personalities”

“Same starter · two personalities” grounds the problem in “The starter is fixed: “The weekend plan is”. Play the top machine first : greedy mode (temperature=0), always the longest probability bar. Hit “Regenerate” three times , watch the stacked results below—even one…”. “Concept card · the ledger of two personalities” then moves it toward “Fast, stable, reproducible —ten thousand runs, same sentence. Fatal blind spot: local best each step may not sum to global best . Pick the smoothest first word and the whole line may hit a dead end. The fix? Ne…”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.

Carry the judgment into the next situation

For a real task, find the repeated work first, ask how input size changes, and use a small benchmark to verify the theoretical judgment. Complexity should not become a label detached from the situation.

  • “Same starter · two personalities”: The starter is fixed: “The weekend plan is”. Play the top machine first : greedy mode (temperature=0), always the longest probability bar. Hit “Regenerate” three times , watch the stacked results below—even one…
  • “Concept card · the ledger of two personalities”: Fast, stable, reproducible —ten thousand runs, same sentence. Fatal blind spot: local best each step may not sum to global best . Pick the smoothest first word and the whole line may hit a dead end. The fix? Ne…
  • “The closing point”: Greedy’s pit gets filled next lesson : Beam Search—look a few steps ahead before choosing

The final “The closing point” brings the discussion to “Greedy’s pit gets filled next lesson : Beam Search—look a few steps ahead before choosing”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.

What this lesson wants to share

  • Greedy = pick the highest probability each step: three runs, identical—fast and reproducible, but may miss a better whole
  • Sampling = roll by probability: three runs, three flavors—trade certainty for diversity
  • Temperature is the knob between them: T=0 is greedy; higher T flattens the distribution and dares rarer words
  • Choose by task: reproduce experiments, write code, extract data → T=0; brainstorm or copy → raise T
  • Greedy’s pit gets filled next lesson: Beam Search—look a few steps ahead before choosing
Mark as learned Your reading progress updates automatically
← PreviousNext →

Keep reading

The next useful article in the thread.

ARTICLE DISCUSSION

Leave one useful thought here.

Keep the idea that clicked, the question that stayed open, or a small note for the next learner.

Discussing Greedy and Sampling: Two Personalities When AI Picks Words Algorithms Behind AI
3discussionsArticle discussion · synced with the Circle
View in the learning circle
AM
Asha MorganContent editor
INSIGHTField note

I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.

ARTICLE DISCUSSION7 helpful
LH
Lin HarperIndie developer
INSIGHTInsight

After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.

ARTICLE DISCUSSION5 helpful
KM
Kiki MooreProduct operations
QUESTIONQuestion

When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.

ARTICLE DISCUSSION4 helpful