Why Language Models Surprise You @TheCodingTrain
Why Language Models Surprise You  @TheCodingTrain
Uploaded August 2026 | Updated September 2026, 1 week ago
In this video, I explain the softmax function and the concept of temperature in the context of language models and neural networks. I start by revisiting the Markov chain coding challenge, then break down how softmax converts raw neural network outputs (logits) into probabilities, and how temperature can be used to adjust those probabilities making outputs more random (higher temperature) or more deterministic (lower temperature). I also briefly cover top-K and top-P sampling. Everything is demonstrated with p5.js sketches and a transformers.js language model running in the browser. Code: thecodingtrain.com/tracks/transformers-js/transformers-js/softmax-temperature

πŸš€ Watch this video ad-free on Nebula nebula.tv/videos/codingtrain-softmax-and-temperature-explained

p5.js Web Editor Sketches:
πŸ•ΉοΈ Softmax and Temperature Visualization: editor.p5js.org/codingtrain/sketches/G39vTMSkz
πŸ•ΉοΈ Markov Chain with Temperature: editor.p5js.org/codingtrain/sketches/SXqlv6-zI
πŸ•ΉοΈ Markov Chain with Softmax and Temperature: editor.p5js.org/codingtrain/sketches/WNvGNuJHD
πŸ•ΉοΈ LLM with Temperature: editor.p5js.org/codingtrain/sketches/36caiecXD

πŸŽ₯ Previous: youtu.be/KR61bXsPlLU
πŸŽ₯ Next: youtu.be/s2jm2Z22ibA

References:
πŸ““ Softmax function on Wikipedia: en.wikipedia.org/wiki/Softmax_function
πŸ““ Markov Chains explained visually: setosa.io/ev/markov-chains
πŸ““ Web Trigrams by Chris Harrison: chrisharrison.net/index.php/Visualizations/WebTrigrams
πŸ““ Euler's number on Wikipedia: en.wikipedia.org/wiki/E_(mathematical_constant)
πŸ““ p5.js exp() reference: p5js.org/reference/p5/exp
πŸ’» Transformers.js Documentation: huggingface.co/docs/transformers.js
πŸ€— SmolLM2 1.7B on Hugging Face: huggingface.co/HuggingFaceTB/SmolLM2-1.7B
πŸ“• Nature of Code: Genetic Algorithms: natureofcode.com/genetic-algorithms

Videos:
πŸš‚ youtu.be/KR61bXsPlLU
πŸš‚ youtu.be/eGFJ8vugIWA
πŸš‚ youtu.be/ETphJASzYes
πŸš‚ youtu.be/kwcillcWOg0

Related Coding Challenges:
πŸš‚ youtu.be/eGFJ8vugIWA
πŸš‚ youtu.be/s2jm2Z22ibA

Timestamps:
0:00:00 Hello!
0:02:50 Markov chains as language models
0:07:48 From logits to probabilities
0:10:47 The softmax formula
0:14:18 Implementing softmax in p5.js
0:15:59 Weighted selection (sampling)
0:20:20 Temperature
0:23:02 Applying softmax and temperature to the Markov chain
0:28:01 Temperature with a Transformers.js language model
0:31:55 Top-K and Top-P sampling
0:33:38 Goodbye!

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound

πŸš‚ Website: thecodingtrain.com
πŸ‘Ύ Share Your Creation! thecodingtrain.com/guides/passenger-showcase-guide
🚩 Suggest Topics: github.com/CodingTrain/Suggestion-Box
πŸ’‘ GitHub: github.com/CodingTrain
πŸ’¬ Discord: thecodingtrain.com/discord
πŸ’– Membership: youtube.com/thecodingtrain/join
πŸ›’ Store: standard.tv/codingtrain
πŸ–‹οΈ Twitter: twitter.com/thecodingtrain
πŸ“Έ Instagram: instagram.com/the.coding.train

πŸŽ₯ youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
πŸŽ₯ youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA

πŸ”— p5.js: p5js.org
πŸ”— p5.js Web Editor: editor.p5js.org
πŸ”— Processing: processing.org

πŸ“„ Code of Conduct: github.com/CodingTrain/Code-of-Conduct

This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecodingtrain.com/issues/new

#softmax #temperature #languagemodels #machinelearning #transformersjs #markovchain #ngram #logits #probability #weightedselection #sampling #topk #topp #neuralnetworks #eulersnumber #javascript #p5js #transformersjs
Why Language Models Surprise YouCoding Challenge #97: The Book of Pi - Part 1Coding Challenge #140: Pi Approximation with Leibniz SeriesCoding Challenge 165: Slide Puzzle5.5 Wander Steering Behavior - The Nature of CodeCoding Train Stickers 2023 Last Call!More Nature of Code Chapter 2, + 3D Fractals?Welcome (again) to the New Studio - Topics TBDFlocking rule 4? #genuary19Did I finish Nature of Code?Hand Pose Detection with ml5.jsLets Build a Nature of Code 404 Page!
The Coding Train |

Why Language Models Surprise You

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER