arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2605.17398cs.CLcs.LG
收藏

MiniGPT:从第一原理重新构建GPT

MiniGPT: Rebuilding GPT from First Principles

Department of Computer Science(计算机科学系);The University of Texas at Austin(德克萨斯大学奥斯汀分校)

Jibin Joseph

AI总结:

本文提出MiniGPT,一个基于PyTorch从头实现的GPT风格自回归语言模型,旨在在研究nanoGPT设计后,从第一原理重新构建GPT核心流程,同时保持模型和训练代码独立编写。MiniGPT实现了词嵌入、位置嵌入、因果多头自注意力、预层归一化Transformer块、残差连接、前馈MLP层、下一词交叉熵训练(教师强制)、验证跟踪、检查点选择和自回归文本生成。

摘要:

本文提出了MiniGPT,一个基于PyTorch从头实现的GPT风格自回归语言模型。目的是在研究nanoGPT设计后,从第一原理重新构建GPT核心流程,同时保持模型和训练代码独立编写。MiniGPT实现了词嵌入、位置嵌入、因果多头自注意力、预层归一化Transformer块、残差连接、前馈MLP层、下一词交叉熵训练(教师强制)、验证跟踪、检查点选择以及自回归文本生成。本文在Tiny Shakespeare数据集上评估了该实现,使用字符级分词。一个基线模型在3000次训练迭代后达到验证损失1.7236。一个更强的10.77M参数配置,使用更大的上下文长度和改进的训练设置,达到最佳验证损失1.4780,并生成具有可识别莎士比亚风格对话结构的文本。MiniGPT并未引入新的语言模型架构。相反,它记录了从原始文本到训练好的字符级生成的清晰且可重复的实现路径,包括设计选择、训练行为、生成质量以及实际限制。

英文摘要:

This paper presents MiniGPT, a compact from-scratch implementation of GPT-style autoregressive language modeling in PyTorch. The aim is to rebuild the core GPT pipeline from first principles after studying the design of nanoGPT by Andrej Karpathy, while keeping the model and training code independently written in a single notebook. MiniGPT implements token and positional embeddings, causal multi-head self-attention, pre-LayerNorm Transformer blocks, residual connections, feed-forward MLP layers, next-token cross-entropy training (teacher forcing), validation tracking, checkpoint selection, and autoregressive text generation. This paper evaluates the implementation on Tiny Shakespeare dataset using character-level tokenization. A baseline 0.83M-parameter model reaches a validation loss of 1.7236 after 3000 training iterations. A stronger 10.77M-parameter configuration, using a larger context length and improved training settings, reaches a best validation loss of 1.4780 and generates text with recognizable Shakespeare-style dialogue structure. MiniGPT does not introduce a new language-model architecture. Instead, it documents a clear and reproducible implementation path from raw text to trained character-level generation, including design choices, training behavior, generation quality, and practical limitations.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑