Node.js 从零构建 LLM 开源教程:用 TypeScript 实现注意力机制与训练循环
该项目提供了一套在 Node.js/TypeScript 环境中从零构建大语言模型的完整教程,涵盖数据加载、嵌入层、注意力机制及 Transformer 块等核心组件。所有代码均封装为可运行的 GitHub 包,旨在通过非 Python 语言的重新实现帮助开发者深入理解模型底层原理,消除“黑盒”认知障碍。
报道正文

Building an LLM in NodeJS
The from-scratch guide to building large language models in NodeJS and TypeScript.Start with Chapter 2
Learn how large language models actually work by building one from scratch in Node.js and TypeScript.
No black boxes
We’ll build every layer, from attention mechanisms to the training loop.
From scratch
Dataset, dataloader, attention, transformer block, GPT, and the training loop built up chapter by chapter.
Runnable
Every chapter has a runnable entry point in the @node-llm/chapters package, all on GitHub.
Interactive
Soon
Live WebGPU demos from the @node-llm/playground package are embedded throughout.
作者发帖说明(HN):
I wanted to understand transformers at a level where nothing is magic, so I'm building a ChatGPT-style model from first principles in TypeScript. Why not Python? I've found that reimplementing concepts in a different language forces me to grasp the nuance of the implementation. Chapters cover dataloaders, embeddings, and the attention mechanism so far. Feedback welcome if anything's unclear.