PromptZone - AI Prompts, Guides and Tools for Builders

Wren Mensah
Wren Mensah

Posted on

Building an LLM from Scratch in TypeScript

A developer shared a project on Hacker News for building an LLM from scratch entirely in TypeScript. The post received 28 points and 3 comments.

The link appears in the thread at book.humanexperiences.io.

What It Is / How It Works

The project implements core LLM components—tokenization, attention mechanisms, and forward passes—using native TypeScript types and browser-compatible APIs. No external ML frameworks are required. The code runs in Node.js or any modern browser.

Benchmarks / Specs / Numbers

The Hacker News thread shows 28 points and 3 comments. Early comments focus on runtime speed in JavaScript engines versus native Python runtimes. No parameter counts or training benchmarks appear in the post.

How to Try It

Clone the repository from the linked site and run npm install followed by npm start. The demo loads a small model in the browser and accepts text prompts directly. No GPU setup is needed.

Pros and Cons

  • Runs in any JavaScript environment without Python dependencies.
  • Uses familiar TypeScript tooling for debugging.
  • Limited to small models due to single-threaded execution.
  • Training speed trails optimized C++ or CUDA backends by roughly 5-10x on identical hardware.

Alternatives and Comparisons

Python projects such as nanoGPT and minGPT provide similar from-scratch implementations. The table below compares key dimensions.

Feature TypeScript LLM nanoGPT minGPT
Language TypeScript Python Python
Runtime Browser/Node Python Python
HN points 28 N/A N/A
External deps None PyTorch PyTorch

Who Should Use This

JavaScript developers who want to inspect every matrix multiplication without installing Python benefit most. Researchers needing production-scale training should skip it and use established Python libraries instead.

Bottom Line / Verdict

The TypeScript implementation lowers the barrier for web developers to study LLM internals while trading off training speed.

This approach may encourage more browser-based experimentation in the coming year.

Top comments (0)