Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

LLMs for Engineers

Free · sign in to start and track progress

1 · Inside the transformer

  • 1Tokens and embeddings
  • 2Attention, step by step
  • 3The transformer block

2 · How models are trained

  • 4Pretraining and scaling laws
  • 5Post-training an assistant

3 · Running models in production

  • 6Sampling and hallucination

    Exercise answers

    • Answer: Measure and catch hallucinations in lease extraction
    • Answer: Simulate decoding strategies
  • 7Context windows, KV cache and caching
  • 8Reasoning models and extended thinking
  • 9Choosing and comparing models
CapstoneChoose a model for document extractionReference implementation

Module 3 · Running models in production · Lesson 6

Sampling and hallucination

How a model turns logits into text (temperature, top-k, top-p and their limits in today's APIs), and why models state false things fluently, from pretraining statistics to grading incentives, with grounding checks that catch it.

70 min 2 videos 3 exercises 6-question quiz Answers
Setup for the exercises:Install Claude CodePython with uvRun Hugging Face models on CPU

By the end of this lesson you can

  • Compute next-token probabilities under different temperatures and apply top-p and min-p filtering by hand
  • Explain why temperature 0 is neither deterministic nor a cure for hallucination
  • Explain the statistical and incentive-based causes of hallucination identified by recent research
  • Design and implement a grounding check that verifies quoted evidence against the source document

On this page

  • From logits to a token
  • Worked example
  • What you control in practice
  • Hallucination
  • Why it happens: four causes
  • Engineering against hallucination
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01From logits to a token
  2. 02Hallucination
  3. 03Engineering against hallucination
  4. 04Connections
  5. 05Summary

Sources & further reading

  • Why Language Models HallucinatePaper · Kalai, Nachum, Vempala, Zhang · OpenAI · 2025The clearest current account of why hallucinations arise in pretraining and persist through evaluation. Read Sections 1, 3.3 (arbitrary facts and the singleton rate) and 4 (grading incentives).
  • The Curious Case of Neural Text DegenerationPaper · Holtzman, Buys, Du, Forbes, Choi · 2020Introduces nucleus (top-p) sampling and explains why greedy decoding produces repetitive, degenerate text.
  • Large Legal Fictions: Profiling Legal Hallucinations in Large Language ModelsPaper · Dahl, Magesh, Suzgun, Ho · Stanford · 2024Systematic measurement of legal hallucinations in general-purpose models, with a typology of failure types. Sections 1 and 4.
  • Hallucination-Free? Assessing the Reliability of Leading AI Legal Research ToolsPaper · Magesh, Surani, Dahl, Suzgun, Manning, Ho · Stanford · 2024Preregistered evaluation of commercial retrieval-augmented legal tools, showing grounding reduces but does not remove hallucination.
  • Language Models (Mostly) Know What They KnowPaper · Kadavath et al. · Anthropic · 2022Evidence that models' own probability of being right is often well calibrated, which is what makes abstention possible.
  • Ayinde v London Borough of Haringey [2025] EWHC 1383 (Admin)Lab research · The National Archives (Find Case Law) · 2025The Divisional Court's judgment on fictitious citations put before the courts, with an annex of similar incidents. Essential reading for anyone shipping legal AI in England and Wales.
  • Defeating Nondeterminism in LLM InferenceArticle · Horace He et al. · Thinking Machines Lab · 2025Why the same prompt at temperature 0 can give different outputs on a busy server (kernels that are not batch-invariant), and how to fix it.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 5 more sections
  • 3 hands-on exercises
  • A 6-question quiz
  • Progress, quiz scores and bookmarks