GenAI Course · Module 7 · Session 24

Decoding Strategies & the LLM Landscape

⏱ 14 min read🎯 Intermediate🖼 2 diagrams🧪 2 live demos🐍 Python code

A language model does not give one answer; it gives a probability for every possible next token. How we pick from those probabilities is called decoding, and it decides whether the output is boring, creative, repetitive or random. Then we will take a tour of today’s major LLMs.

In this session

  • Greedy, beam search, top-k, top-p (nucleus), temperature and repetition penalty
  • A live playground to see how each setting changes the choice
  • Recommended settings for facts, chat, creative writing and code
  • The LLM landscape: GPT, Claude, Gemini, Llama, Mistral, Qwen, DeepSeek, Gemma, GPT-OSS
  • Reasoning models, context windows, multimodality and tool calling

01Greedy and beam search

Suppose the prompt is “The best time to drink chai is”. The model scores every token. The simplest strategy, greedy decoding, always picks the single most likely token. It is fast and repeatable, but can be dull and sometimes gets stuck repeating itself.

Beam search keeps the top B partial sentences (beams) at every step and finally returns the one with the highest total probability. It finds better overall sentences than greedy, which helps translation and summarisation, but it is slower and tends to produce safe, generic text.

…drink chai isstart “in” 0.45 “early” 0.30 “when” 0.10 ✕ “in the” 0.45×0.8 “in winter” 0.45×0.1 ✕ “early morning” 0.30×0.9 = 0.36= 0.27 Beam width 2: only the 2 best partial sentences survive each step
Beam search compares whole partial sentences, not just the next token.

02Sampling: temperature, top-k and top-p

Chatbots usually sample: they pick the next token randomly, but in proportion to its probability. Three knobs control this randomness:

Demo · Sampling playground

Prompt: “The best time to drink chai is …”

Repetition penalty

Models sometimes loop: “chai is good, chai is good, chai is good…”. A repetition penalty (for example 1.1–1.3) lowers the score of tokens that have already appeared, so the model moves on. Similar settings are called frequency and presence penalties in some APIs.

Use caseTemperatureTop-pNotes
Facts, extraction, classification0 – 0.31.0Near-greedy; repeatable answers
Code0.1 – 0.30.95Small randomness avoids loops
Chat assistant0.5 – 0.80.9Natural but focused
Creative writing, brainstorming0.8 – 1.10.9 – 0.95More variety; check facts
Translation, summaries (seq2seq)beam search, 4 beams–Often with a length penalty
decoding_settings.py
# model and tok loaded as in Session 23
inputs = tok("The best time to drink chai is", return_tensors="pt").to(model.device)

greedy   = model.generate(**inputs, max_new_tokens=20, do_sample=False)
beam     = model.generate(**inputs, max_new_tokens=20, num_beams=4, early_stopping=True)
creative = model.generate(**inputs, max_new_tokens=20, do_sample=True,
                          temperature=0.9, top_k=50, top_p=0.9, repetition_penalty=1.2)

for out in (greedy, beam, creative):
    print(tok.decode(out[0], skip_special_tokens=True))

03The LLM landscape

There are two big groups: closed models you use through an API, and open-weight models you can download and run yourself. This field changes every few months, so always check the latest versions on each provider’s site.

FamilyMade byWeightsKnown for
GPT (and o-series reasoning)OpenAIClosedChatGPT; strong general and reasoning models
GPT-OSSOpenAIOpen (Apache-2.0)OpenAI’s open-weight reasoning models (20B and 120B)
ClaudeAnthropicClosedWriting, coding, long documents, safety focus
GeminiGoogleClosedVery long context, native multimodal
GemmaGoogleOpenSmall, efficient open models
LlamaMetaOpen (custom license)The most widely used open family
Mistral / MixtralMistral AIOpen and closedEfficient models; mixture-of-experts
QwenAlibabaOpenStrong multilingual and coding models, many sizes
DeepSeekDeepSeekOpenLarge MoE models; DeepSeek-R1 popularised open reasoning

04Reasoning, context, multimodality and tools

When choosing a model, compare these four capabilities alongside price and speed.

05Summary

06Quick quiz

1. Lowering temperature from 1.0 to 0.3 makes output…

2. Top-p = 0.9 means…

3. The model keeps repeating a phrase. Which setting helps?

4. Reasoning models are especially good at…

5. A bank must keep customer data inside its own servers. Best fit?

07References

Created by Ajeetkumar