# Show HN: The Smallest LLM in JavaScript

> Source: <https://gist.github.com/skorotkiewicz/dedc3b5a857be7d0f2b378334721713c>
> Published: 2026-09-20 04:05:05+00:00

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
