百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gpt-go

> 编程语言
开源

Tiny GPT在纯Go中从零开始执行,优化用于理解. 被训练了儒勒·凡尔纳的书.

640 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Tiny GPT在纯Go中从零开始执行,优化用于理解. 被训练了儒勒·凡尔纳的书.

gpt-go

Simple GPT implementation in pure Go. Trained on favourite Jules Verne books.

What kind of response you can expect from the model:

Mysterious Island.
Well.
My days must follow

Or this:

Captain Nemo, in two hundred thousand feet weary in
the existence of the world.

How to run

bash
$ go run .

It takes about 40 minutes to train on MacBook Air M3. The trained weights will be saved to model-1.234M file. If you rerun the model, it will pick up the saved weights and continue training. The loss should decrease each time, indicating that the model is learning something useful.

You can train on your own dataset by pointing the data.dataset variable to your text corpus.

To run in chat-only mode once the training is done:

bash
$ go run . -chat

How to understand

You can use this repository as a companion to the Neural Networks: Zero to Hero course. Use git checkout to see how the model has evolved over time: naive, bigram, multihead, block, residual, full.

In main_test.go you will find explanations starting from basic neuron example:

go
// Our neuron has 2 inputs and 1 output (number of columns in weight matrix).
// Its goal is to predict next number in the sequence.
input := V{1, 2} // {x1, x2}
weight := M{
    {2}, // how much x1 contributes to the output
    {3}, // how much x2 contributes to the output
}

All the way to self-attention mechanism:

…

Design choices

No batches.
I've given up the complexity of the batch dimension for the sake of better understanding. It's far easier to build intuition with 2D matrices, rather than with 3D tensors. Besides, batches aren't inherent to the transformer architecture. For better gradient smoothing gradient accumulation was tried. The effect was negligible, so it was removed as well.

Removed gonum.
The gonum.matmul gave us ~30% performance boost, but it brought additional dependency. We're not striving for maximum efficiency here, rather for radical simplicity. Current matmul implementation is quite effective, and it's only 40 lines of plain readable code.

Papers

You don't need to read them to understand the code :)

Attention Is All You Need
Deep Residual Learning
DeepMind WaveNet
Batch Normalization
Deep NN + huge data = breakthrough performance
OpenAI GPT-3 paper
Analyzing the Structure of Attention

Credits

Many thanks to Andrej Karpathy for his brilliant Neural Networks: Zero to Hero course.

Thanks to @itsubaki for his elegant autograd package.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Go

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言