Show HN: The Smallest LLM in JavaScript A developer published a minimal JavaScript implementation of a language model on GitHub, using a Markov-chain approach to predict the next word from a small training string. The roughly 20-line script builds a lookup table of word transitions and randomly samples successors to generate text, demonstrating the core next-token idea behind large language models without any neural network or dependencies. Created September 20, 2026 04:04 - - Save skorotkiewicz/dedc3b5a857be7d0f2b378334721713c to your computer and use it in GitHub Desktop. the smallest LLM This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters https://github.co/hiddenchars | | const text = "mama dad mama cat dad mama dog"; | | | const words = text.split " " ; | | | const model = {}; | | | for let i = 0; i < words.length - 1; i++ { | | | const a = words i ; | | | const b = words i + 1 ; | | | model a ??= ; | | | model a .push b ; | | | } | | | function next word { | | | const choices = model word ?? words; | | | return choices Math.floor Math.random choices.length ; | | | } | | | function generate start, n = 10 { | | | let word = start; | | | const out = word ; | | | for let i = 0; i < n; i++ { | | | word = next word ; | | | out.push word ; | | | } | | | return out.join " " ; | | | } | | | console.log generate "mama" ; | Author