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
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










