Vibeleaderboard
Index / tool
Visit github.com
Category
AI Tools
Rank
No. 1538Tools index

Previous survey · No. 1543 ·

Pricing
Open Source
Type
TOOL
Builder
badlogic
GitHub
45 stars
Date

About

Pure TypeScript implementation of GPT-2 — runs the classic transformer entirely in the browser/Node without native deps.

What it does

It turns original GPT-2 checkpoints into a compact tensor layout, then performs text generation one token at a time. The runtime handles byte-pair tokenization, attention, normalization, feed-forward layers, cached keys and values, and either greedy or top-k sampling. Output can stream as tokens arrive.

Why it's ranked here

Its value comes from a small, readable implementation of the complete inference path. Model dimensions come from converted configuration rather than fixed constants, and the command interface exposes useful sampling controls. The narrow scope is also the catch: setup still depends on Python, TensorFlow, downloaded checkpoints, and substantial local storage.

What's good

The code makes inference mechanics unusually concrete. Typed floating-point buffers hold tensors and reusable workspace memory. A key-value cache avoids recomputing earlier attention states. Tensor loading validates magic bytes, format version, dimensions, byte length, and shape consistency. Strict TypeScript checks strengthen the compact implementation.

Tradeoffs

Model preparation is heavier than the runtime. It requires Python, uv, TensorFlow, checkpoint downloads, and a conversion pass before generation works. Weights remain floating point, and the largest documented model needs many gigabytes of memory and disk. The runtime requires Node support for direct TypeScript execution and uses synchronous file loading.

How to use it well

Use it to study GPT-2 inference, inspect transformer mechanics, or run controlled local text-generation experiments from TypeScript. Start with the smallest documented checkpoint, verify types before running, and tune greedy or top-k sampling through command options. It does not train models, provide a hosted service, or eliminate checkpoint preparation.

Technical notes+

gpt-2.ts exports model loading, token encoding, KV-cache and workspace creation, single-token forwarding, sampling, and generation, while also providing the CLI entry point. tensor.ts implements validated loading of the 64-byte little-endian GPT2TNS\0 format plus scalar-loop matrix-vector operations, layer normalization, GELU, and row access. tokenizer.ts implements GPT-2 byte-to-Unicode mapping, BPE merges, caching, encoding, and decoding. convert/download_model.py downloads original checkpoint assets, and convert/convert.py uses TensorFlow and NumPy to write float32 tensor files and a SHA-256 manifest. tsconfig.json enables strict checking with unchecked-index and exact-optional-property safeguards.

Observed

License
MIT
Primary language
TypeScript runtime with Python conversion tooling
Packaging
ES module npm project with TypeScript and Node typings as development dependencies
Interfaces
Command-line interface plus exported TypeScript library functions
Runtime platform
Node.js with built-in TypeScript type stripping
Model preparation
Python tooling managed through uv downloads and converts original TensorFlow checkpoints
Tensor storage
Custom little-endian float32 files with fixed 64-byte headers
Quality checks
TypeScript no-emit checking is configured; no test directory appears in the supplied repository tree

Read from README.md, package.json, gpt-2.ts, tensor.ts, tokenizer.ts, convert/convert.py, convert/download_model.py, tsconfig.json, convert/uv.lock, convert/README.md, convert/pyproject.toml.

What it can do

  • Generate text from prompts

    Text prompt or seed textAI-generated text continuation

  • Complete partial sentences or paragraphs

    Incomplete textCompleted text with natural language flow

  • Run GPT-2 inference in browser

    Text input and model parametersGenerated text response

  • Run GPT-2 inference in Node.js

    Text input and model parametersGenerated text response

  • Process text without external dependencies

    Natural language textAI-processed text output

Tags

gpt-2typescripttransformerllm

Tech Stack

Node.jsTypeScript

Comments (0)

No comments yet

Editorially curated, with community endorsements as a secondary signal. Corrections welcome.