cd /news/large-language-models/show-hn-the-smallest-llm-in-javascri… · home topics large-language-models article
[ARTICLE · art-134918] src=gist.github.com ↗ pub= topic=large-language-models verified=true sentiment=↑ positive

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.

read1 min views2 publishedSep 20, 2026
Show HN: The Smallest LLM in JavaScript
Image: Gist (auto-discovered)

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

── more in #large-language-models 4 stories · sorted by recency
── more on @github 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/show-hn-the-smallest…] indexed:0 read:1min 2026-09-20 ·