English
An autoregressive language model assigns probabilities to token sequences by predicting each token from preceding tokens: p(x₁:T) = Πₜ p(xₜ|x₍<t₎). Tokens are units defined by a tokenizer and need not be whole words or single characters. Predicting text can require useful representations of syntax, facts, and relationships, but next-token training alone does not specify every behavior of a deployed assistant.
Separate the pretrained model, its post-training, its inference procedure, and the surrounding application. Instruction examples and preference feedback can change model parameters; a prompt and retrieved documents change the context; a tool can perform a calculation or query an external system. These mechanisms provide different information and different grounds for trusting an answer.
A foundation model is pretrained for reuse across a range of downstream tasks through prompting, adaptation, or integration into larger systems. The category includes language, vision, speech, and multimodal models. It describes a pattern of reuse, not a guarantee of universal competence. Transfer learning existed before the term; scale and reusable interfaces expanded the range of practical applications.
Prerequisites: Training and evaluation (§5.2), deep-learning architectures (§5.3), and basic probability (§2.5). RL (§5.4) helps explain some post-training methods, but is not required to understand every language model.
From Word Vectors to Generalist Systems
Language modeling has long used context. An n-gram model estimates a word or token from a limited preceding window, while smoothing handles sparse counts. Sparse features, grammars, probabilistic models, and learned distributed representations coexisted before the transformer. The historical problem was how to share evidence across related contexts while handling long dependencies and limited data.
Neural language models learned vector representations before word2vec. Word2vec’s 2013 methods made learning useful word vectors from local prediction objectives efficient at larger scale. Their usual static embedding assigns one vector to a word type, so different senses are not separately represented by the lookup alone. Some analogies correspond to useful vector relationships; this is not a general theorem that semantic relations are linear or reliably recovered by vector arithmetic.
The 2014 sequence-to-sequence work used recurrent encoder–decoder models for variable-length mappings. Bahdanau, Cho, and Bengio’s attention work let a decoder consult different encoder positions instead of relying solely on one fixed summary. The transformer in 2017 reorganized these interactions around attention. The change concerned information access and parallel computation, not the first recognition that context affects meaning.
BERT used bidirectional context in masked-token prediction, while the original GPT used left-to-right language modeling. Both investigated reusing pretrained representations for downstream tasks. GPT-2 and GPT-3 expanded autoregressive modeling and studied transfer through text prompts, including demonstrations supplied in context. In-context learning changes the model’s computation for a particular input without the usual gradient update to its weights; its success depends on the task, model, examples, and prompt.
Scaling studies, including Kaplan’s work and Chinchilla (§5.3), examined how to allocate parameters, data, and training compute. Their findings made the training budget explicit. They did not establish that one parameter count determines competence, or that improving a text-prediction loss guarantees factual reliability. Open-weight releases also enabled independent adaptation and experiments, subject to the information and licensing provided with each release.
Instruction tuning and preference training changed how pretrained models responded to requests. InstructGPT documented a pipeline using demonstrations, preference comparisons, a reward model, and policy optimization. DPO later derived a direct preference objective under a related regularized formulation. These methods train behavior from particular examples and judgments; they do not remove disagreements about what a good response is or independently certify its truth.
Retrieval, tool use, and additional inference computation expanded the design space beyond a single model call. A system can search documents, run generated code, generate multiple candidates, or use a checker to select or revise an answer. Longer deliberation and repeated sampling are not equivalent to a specified search algorithm. Their benefit depends on whether the additional computation obtains useful evidence or identifies mistakes.
The resulting application has several independently changeable parts: model weights, prompt and context, retrieval, decoding, tools, and verification. This explains why a model benchmark and an application evaluation can give different results. Historical progress in models and progress in the systems built around them should be distinguished when comparing capabilities.
Architecture, Training, Adaptation, and Evaluation
The Transformer and Its Scaling Properties
A transformer turns token embeddings and positional information into contextual representations. In one attention head, queries and keys produce scores, softmax converts the permitted scores to weights, and those weights combine value vectors. With scalar values 2 and 10 and weights 0.75 and 0.25, the result is 4. This is a weighted computation, not a probability that a source statement is true. Multiple heads provide different learned projections, followed by further mixing and nonlinear computation.
In a causal decoder, the representation at position t may use positions up to and including t, and is trained to predict token t+1. A mask prevents access to later target tokens. The entire training sequence is already available, so many position-wise losses can be computed in parallel. During ordinary autoregressive generation, the next token must be selected before the following prediction can use it. Training parallelism does not remove this generation dependency.
Cross-entropy training increases the probability assigned to observed targets. For a fixed target distribution, minimizing cross-entropy is equivalent to minimizing its KL divergence to the model, up to the target entropy. In practice this is estimated from finite selected data. Tokenization, document boundaries, filtering, and which positions contribute loss all change the learning problem.
Dense attention requires quadratic pairwise work in sequence length for fixed feature dimensions. FlashAttention changes memory access and computation scheduling to avoid storing the full attention matrix in high-bandwidth memory while computing exact attention. It does not turn all-pairs attention into linear arithmetic work. During generation, a key–value cache stores previous projections, trading memory for avoided recomputation. Context capacity, successful use of distant information, and inference latency are separate measurements.
Transformer blocks also contain residual connections, normalization, and position-wise feed-forward transformations; attention alone is not the whole model. Mixtures of experts can increase total parameter capacity while activating selected experts for each token, but routing, load balance, memory, and communication remain costs. Model size by itself is therefore an incomplete description of inference work.
Pretraining, Fine-tuning, and Alignment
Pretraining determines much of the model’s initial repertoire. Data selection includes domains, languages, duplicates, quality criteria, document boundaries, and contamination checks. More tokens and more independently useful information are not the same thing. The tokenizer also affects which patterns are easy to express and how much context and computation a piece of text consumes.
Supervised instruction tuning trains on examples of requests and responses. A preference-based pipeline may instead collect comparisons, fit a reward model, and optimize the policy against that model with a reference-policy penalty. Such a penalty limits incentives to move far from the reference under the chosen objective; it does not guarantee that reward hacking, factual error, or sycophancy is prevented. Human judgments can themselves reflect ambiguity, limited expertise, and presentation preferences.
Direct Preference Optimization fits a policy using preferred and dispreferred responses and their probability ratios relative to a reference model. It avoids separately fitting and optimizing an explicit reward model in the original setup. The labels, coverage, and objective still matter, so a simpler training pipeline is not evidence that preference misspecification has disappeared.
Adaptation methods change different parts of a system:
| Method | What changes | What it can supply |
|---|---|---|
| Prompting or in-context examples | Input context | Task instructions, demonstrations, and temporary information |
| Retrieval-augmented generation | Documents selected into context | Evidence from an external collection, subject to retrieval and reading quality |
| Fine-tuning, including LoRA | Model parameters or added trainable parameters | Learned changes in behavior or task performance from training examples |
| Tool use | Computation or access outside the model | A calculation, database result, or action governed by the tool’s interface |
LoRA trains low-rank parameter updates; it reduces some training costs without making the base model’s storage and computation disappear. Retrieval does not guarantee that a source is correct, current, or faithfully used. A tool result provides evidence only for what the tool actually checked. Combining methods is useful when each addresses an identified failure, with the complete system evaluated afterward.
Evaluation: What Models Can and Cannot Do
Define the evaluated system: model and version, prompt, context, tools, sampling, retries, and computation budget. A one-attempt answer and a result selected from many attempts are different measurements. Benchmarks such as MMLU, HumanEval, and mathematical problem sets test particular tasks under particular scoring rules; their names do not supply a general capability guarantee.
For a toy illustration, if independently sampled candidates each succeed with probability p, the probability that at least one of k candidates succeeds is 1−(1−p)^k. With p=0.2 and k=5, it is about 67.2%, compared with 20% for one attempt. This is an opportunity for a selector, not the success rate of an actual system unless it can identify the correct candidate. Evaluation must include the checker’s errors, candidate dependence, and total cost.
Inspect contamination, near-duplicate tasks, prompt sensitivity, distribution changes, and per-category errors. Calibration compares stated probabilities with observed correctness under a defined task; token probabilities are not automatically calibrated probabilities that a proposition is true. Different phrasings can divide probability among equivalent answers. Verbal confidence also requires empirical calibration rather than being accepted at face value.
For grounded answers, test whether cited passages support the claims, not only whether citations exist. For generated code, tests provide evidence for tested behavior and may miss specification errors. For structured output, constrained decoding can enforce a format while leaving its contents wrong. Evaluate retrieval, generation, verification, and any external action together, because an error at one stage can invalidate otherwise correct later work.
What Studying This Changes
You should be able to locate a proposed improvement in the system: changing weights, supplying context, allocating more inference work, obtaining external evidence, or checking an output. These interventions solve different problems and have different costs.
Build a small document-question-answering task with answerable and unanswerable questions. Compare a base prompt, supplied passages, and a retrieval pipeline using the same questions. Inspect retrieval misses, unsupported claims, and abstentions separately. A higher overall score is more informative when you can identify which stage improved.
For a difficult task, compare one attempt with several attempts under a fixed total budget and a specified selection method. Record latency and cost alongside correctness. This makes the capability–reliability distinction concrete: producing a correct candidate sometimes is different from reliably delivering a correct final result.
Resources
Books and Texts
Jurafsky and Martin’s online Speech and Language Processing connects tokenization, language modeling, and neural architectures to the broader history of NLP. Use the deep learning texts in §5.3 for any missing background. Bommasani et al.’s “On the Opportunities and Risks of Foundation Models” explains the 2021 framing of foundation models; its examples should be read in that historical context.
Read papers in order of dependency: the transformer for architecture, BERT and GPT-3 for different training and adaptation settings, scaling-law and Chinchilla papers for compute allocation, then InstructGPT and DPO for preference-based training. For each paper, write down the objective, data, evaluation, and comparison being made. A result for one of these choices is not automatically a result for all language models.
| Resource | Role | Type |
|---|---|---|
| Jurafsky & Martin, Speech and Language Processing (3rd ed., free) | LM and transformer foundations | Entry |
| Bommasani et al., “On the Opportunities and Risks of Foundation Models” (free) | Comprehensive framing report | Entry |
| Vaswani et al., “Attention Is All You Need” (2017, free) | Transformer landmark paper | Depth |
| Brown et al., GPT-3 paper (2020, free) | Few-shot prompting experiments | Depth |
| Kaplan et al., scaling laws paper (2020, free) | Scaling relationships | Depth |
| Hoffmann et al., Chinchilla paper (2022, free) | Compute-optimal training | Depth |
| Ouyang et al., InstructGPT paper (2022, free) | RLHF alignment pipeline | Depth |
| Rafailov et al., DPO paper (2023, free) | Direct preference optimization | Depth |
| Transformer architecture reference: Phuong & Hutter (2022, free) | Precise architectural reference | Reference |
| Chip Huyen, AI Engineering (paid) | Foundation-model application engineering | Practice |
Courses and Lectures
Stanford CS336: Language Modeling from Scratch covers data, architecture, training infrastructure, and evaluation for learners prepared to implement a model. Karpathy’s Zero to Hero provides a smaller starting project. The Hugging Face LLM Course covers tokenizers, pretrained models, and training tools. These serve different goals: implementing training and building an application require overlapping but different skills.
| Course | Platform | Type |
|---|---|---|
| Stanford CS336 Language Modeling from Scratch | cs336.stanford.edu | Depth |
| Berkeley LLM Agents course (free) | rdi.berkeley.edu | Depth |
| Hugging Face LLM Course (free) | huggingface.co/learn/llm-course | Practice |
| Hugging Face Agents Course (free) | huggingface.co/learn | Practice |
| Cohere LLM University (free) | docs.cohere.com | Auxiliary |
| Karpathy LLM-adjacent modules from Neural Networks: Zero to Hero (free) | YouTube | Auxiliary |
Practice, Tools, and Current Sources
Use nanoGPT to inspect a training loop; use Transformers, PEFT, and TRL for experiments with pretrained models and adaptation. LM-Evaluation-Harness and HELM help organize evaluation, while vLLM is useful for studying inference serving and KV-cache management. Check the exact model, tokenizer, task implementation, and library version behind a reported score.
For an application experiment, compare a local model or hosted models on the same task set. Hold prompts, tool access, retry policy, and evaluation rules fixed, and record cost and latency. Human-preference leaderboards can suggest models to examine, but their participants, prompts, and judging procedures need not match your users. A small, well-specified evaluation is more informative than an unexplained overall ranking.
| Resource | Platform | Type |
|---|---|---|
| Karpathy, nanoGPT (free) | GitHub | Practice |
| OpenAI Cookbook (free; API usage may be paid) | GitHub / cookbook.openai.com | Practice |
| Anthropic Cookbook (free; API usage may be paid) | GitHub | Practice |
| Prompt Engineering Guide (free) | dair.ai / promptingguide.ai | Auxiliary |
| Hugging Face Transformers / TRL (free) | huggingface.co | Practice |
| LM-Evaluation-Harness (free) | GitHub / EleutherAI | Practice |
| HELM (free) | crfm.stanford.edu/helm | Reference |
| Human-preference evaluation: Arena | arena.ai | Auxiliary |
| vLLM (free) | vllm.ai | Practice |
| Experiment tracking with Weights & Biases (free tier) | wandb.ai | Auxiliary |
Traps
| Trap | Why it misleads | Better response |
|---|---|---|
| Treating API access as an explanation | A response hides training, prompting, decoding, and external system choices. | Describe the full inference setup and which component supplies each piece of evidence. |
| Comparing scores without budgets or selection rules | Retries, tools, and candidate selection can change performance substantially. | Compare complete procedures at a stated cost and evaluate the selector. |
| Treating factual error as either inevitable everywhere or solved by prompting | Error rates depend on task, evidence, training, and checking; fluent output alone is insufficient. | Measure unsupported claims and test retrieval, verification, and abstention. |
| Ignoring pretraining and adaptation data | Coverage, duplication, filtering, and labels shape what can be learned. | Examine data provenance and evaluate unfamiliar cases. |
| Treating preference training as a complete reliability measure | Approval and correctness can diverge, and the application may perform actions beyond answering. | Evaluate intended outcomes and the permissions and checks around actions. |
| Equating open weights with full transparency | Weights may be available without training data, complete recipes, or an understood mechanism. | Identify which artifacts are available and which conclusions they support. |
中文
自回归语言模型通过根据前序 token 预测各个 token,为序列分配概率:p(x₁:T) = Πₜ p(xₜ|x₍<t₎)。Token 是分词器定义的单位,不一定是完整单词或单个字符。预测文本可能需要形成关于语法、事实与关系的有用表示,但下一个 token 训练目标并不规定部署助手的全部行为。
应区分预训练模型、后训练、推断程序与外围应用。指令例子和偏好反馈可以改变模型参数;提示与检索文档改变上下文;工具可以执行计算或查询外部系统。这些机制提供不同信息,也为信任答案提供不同依据。
基础模型经过预训练,供多种下游任务通过提示、适配或集成到更大系统中复用。它包括语言、视觉、语音与多模态模型。这描述一种复用方式,并不保证普遍胜任所有任务。迁移学习早于这个术语;规模与可复用接口扩展了实际应用范围。
前置知识:训练与评估(§5.2)、深度学习架构(§5.3)、基本概率(§2.5)。强化学习(§5.4)帮助解释部分后训练方法,并非理解所有语言模型的前提。
从词向量到通用系统
语言建模长期以来就使用上下文。N-gram 模型根据有限前序窗口估计单词或 token,平滑方法处理稀疏计数。在 transformer 之前,稀疏特征、文法、概率模型与学习得到的分布式表示已经共存。历史问题是怎样在相关上下文之间共享证据,同时处理长依赖与有限数据。
神经语言模型早于 word2vec 就已学习向量表示。2013 年的 word2vec 方法使通过局部预测目标学习有用词向量,可以更高效地扩展到较大规模。通常的静态嵌入为一个词类型分配一个向量,因此仅凭查表并不分别表示不同词义。某些类比对应有用的向量关系,但这不构成语义关系必然线性,或向量运算总能可靠恢复关系的一般定理。
2014 年的序列到序列工作使用循环编码器—解码器处理可变长映射。Bahdanau、Cho 与 Bengio 的注意力工作允许解码器查阅不同编码器位置,而不只依赖一个固定摘要。2017 年的 transformer 围绕注意力重新组织这些交互。变化在于信息访问与并行计算,并非首次认识到上下文影响词义。
BERT 在遮盖 token 预测中使用双向上下文,最初的 GPT 则使用从左到右的语言建模。二者都研究复用预训练表示完成下游任务。GPT-2、GPT-3 扩展了自回归建模,研究通过文本提示迁移,包括在上下文中提供示范。上下文学习改变模型针对某个输入的计算,而不进行通常意义上的权重梯度更新;效果取决于任务、模型、示例和提示。
Kaplan 工作与 Chinchilla 等缩放研究(§5.3)考察参数、数据和训练计算的分配,使训练预算成为明确变量。它们没有确立某个参数数量就能决定能力,也没有证明文本预测损失改善保证事实可靠性。开放权重发布还支持独立适配与实验,但须考虑具体发布所提供的信息及许可。
指令微调与偏好训练改变了预训练模型回应请求的方式。InstructGPT 记录了示范、偏好比较、奖励模型和策略优化组成的流程;DPO 后来在相关正则化设定下推导出直接偏好目标。这些方法根据特定例子与判断训练行为,并不消除对何为好回答的分歧,也不独立认证其真实性。
检索、工具使用及额外推断计算,把设计空间扩展到单次模型调用之外。系统可以搜索文档、运行生成的代码、产生多个候选,或用检查器选择和修改答案。更长推演与重复采样不等同于某个指定搜索算法,其收益取决于额外计算是否获得有用证据或识别错误。
由此形成的应用包含多个可以分别改变的部分:模型权重、提示与上下文、检索、解码、工具和验证。这解释了为什么模型基准与应用评估可能得到不同结果。比较能力时,应区分模型自身的进步与围绕模型构建系统的进步。
架构、训练、适配与评估
Transformer 及其缩放性质
Transformer 把 token 嵌入与位置信息转换为上下文表示。在一个注意力头中,查询与键产生分数,softmax 把允许位置的分数变成权重,再用权重组合值向量。若标量值为 2、10,权重为 0.75、0.25,结果就是 4。这是加权计算,并不表示某个来源语句为真的概率。多个头提供不同的学习投影,之后还有混合与非线性计算。
在因果解码器中,位置 t 的表示可以使用直到且包含 t 的位置,并被训练去预测 token t+1。掩码阻止访问更后面的目标 token。训练时整段序列已经可用,因此许多位置的损失可以并行计算;普通自回归生成时,必须先选出下一个 token,后续预测才能使用它。训练并行没有消除生成依赖。
交叉熵训练提高观测目标的概率。对于固定目标分布,最小化交叉熵等价于最小化该分布到模型的 KL 散度,两者相差目标熵。实际中则从有限、经过选择的数据估计。分词方式、文档边界、过滤,以及哪些位置参与损失,都改变学习问题。
在特征维度固定时,稠密注意力的成对计算量随序列长度平方增长。FlashAttention改变内存访问和计算调度,在计算精确注意力的同时避免把完整注意力矩阵存入高带宽内存;它没有把所有位置对之间的注意力变成线性算术量。生成时,键值缓存保存此前投影,以内存换取减少重复计算。上下文容量、有效利用远处信息的能力,以及推断延迟,是不同测量。
Transformer 块还包含残差连接、归一化与逐位置前馈变换,注意力并不是整个模型。混合专家可以增加总参数容量,同时每个 token 只激活选定专家,但路由、负载平衡、内存和通信仍有成本。因此,仅凭模型大小不能完整描述推断工作。
预训练、微调与对齐
预训练决定模型初始能力的重要部分。数据选择涉及领域、语言、重复项、质量标准、文档边界和污染检查。更多 token 不等于更多独立有用的信息。分词器也影响哪些模式容易表达,以及一段文本消耗多少上下文与计算。
监督式指令微调使用请求与回答的示范。基于偏好的流程则可以收集比较、拟合奖励模型,再带着参考策略惩罚优化策略。这样的惩罚在选定目标下限制远离参考模型的激励,却不保证阻止奖励利用、事实错误或迎合。人的判断本身也可能受到歧义、知识不足与表达偏好的影响。
直接偏好优化使用偏好与非偏好回答,以及它们相对于参考模型的概率比,来拟合策略。在原始设置中,它不必单独拟合并优化一个显式奖励模型。但标签、覆盖范围和目标仍重要,因此训练流程更简单不意味着偏好设定偏差已经消失。
不同适配方法改变系统的不同部分:
| 方法 | 改变什么 | 能提供什么 |
|---|---|---|
| 提示或上下文示例 | 输入上下文 | 任务指令、示范与临时信息 |
| 检索增强生成 | 选入上下文的文档 | 外部集合中的证据,效果取决于检索与阅读质量 |
| 微调,包括 LoRA | 模型参数或额外可训练参数 | 根据训练例子学出的行为或任务表现变化 |
| 工具使用 | 模型之外的计算或访问 | 计算结果、数据库结果,或受工具接口约束的动作 |
LoRA 训练低秩参数更新,可以减少部分训练成本,但不会消除基础模型的存储与计算。检索不保证来源正确、及时或被忠实使用;工具结果只为工具实际检查的内容提供证据。若各种方法分别处理已识别的失败,再评估完整系统,它们的组合才有明确依据。
评估:模型能做什么,不能做什么
先定义被评估系统:模型与版本、提示、上下文、工具、采样、重试和计算预算。一次作答与从多次尝试中选择的结果,是不同测量。MMLU、HumanEval、数学题集等基准,在特定评分规则下测试特定任务;名称本身不提供一般能力保证。
一个玩具例子中,如果独立采样的候选各以概率 p 成功,那么 k 个候选至少一个成功的概率为 1−(1−p)^k。取 p=0.2、k=5,结果约为 67.2%,而一次尝试只有 20%。这只是选择器可以利用的机会;除非系统能够识别正确候选,否则它不等于实际系统成功率。评估还须计入检查器错误、候选之间的依赖及总成本。
检查污染、近重复任务、提示敏感性、分布变化与分类别错误。校准在明确任务下比较所报概率与观测正确率;token 概率不会自动成为命题为真的校准概率。不同措辞还会把概率分散到等价答案之间。口头自信同样需要经验校准,不能直接相信。
对于依据资料回答的系统,应检验引用段落是否支持主张,而不只检查有没有引用。对于生成代码,测试为测到的行为提供证据,可能漏掉规格错误;对于结构化输出,约束解码可以强制格式,内容仍可能错误。应一起评估检索、生成、验证与外部动作,因为某阶段出错会使后续原本正确的工作失去依据。
学习这一部分会改变什么
学完后,应能指出一项改进作用于系统哪里:改变权重、提供上下文、分配更多推断计算、获取外部证据,还是检查输出。这些干预解决不同问题,成本也不同。
建立一个小型文档问答任务,包含可回答与资料不足的问题。用相同问题比较基础提示、直接提供段落和检索流程,分别检查检索遗漏、缺少支持的主张与弃答。知道哪个阶段改善后,整体分数提高才更有解释力。
对困难任务,在固定总预算和明确选择方法下,比较一次尝试与多次尝试。同时记录正确率、延迟与成本。这样就能具体理解能力与可靠性的区别:有时产生正确候选,与稳定交付正确最终结果,是不同成就。
资源
书籍与文本
Jurafsky 与 Martin 的在线 Speech and Language Processing 将分词、语言建模和神经网络架构与 NLP 的发展联系起来。缺少的深度学习基础可以参考 §5.3 的教材。Bommasani 等人的 “On the Opportunities and Risks of Foundation Models” 解释了 2021 年提出的基础模型框架;其中的实例应放在当时的背景下阅读。
按知识依赖阅读论文:先用 Transformer 论文理解架构,用 BERT 和 GPT-3 理解不同的训练与适配设置,再用缩放定律和 Chinchilla 论文理解算力分配,最后阅读 InstructGPT 和 DPO,理解偏好训练。阅读每篇论文时,写出其目标、数据、评估和比较对象。对其中某种选择得到的结果,不会自动适用于所有语言模型。
| 资源 | 作用 | 类型 |
|---|---|---|
| Jurafsky & Martin, Speech and Language Processing(第 3 版,免费) | 语言模型和 Transformer 基础 | 入门 |
| Bommasani et al., “On the Opportunities and Risks of Foundation Models”(免费) | 综合框架报告 | 入门 |
| Vaswani et al., “Attention Is All You Need”(2017,免费) | Transformer 里程碑论文 | 深入 |
| Brown et al., GPT-3 paper(2020,免费) | 少样本提示实验 | 深入 |
| Kaplan et al., scaling laws paper(2020,免费) | 缩放关系 | 深入 |
| Hoffmann et al., Chinchilla paper(2022,免费) | 计算最优训练 | 深入 |
| Ouyang et al., InstructGPT paper(2022,免费) | RLHF 对齐流水线 | 深入 |
| Rafailov et al., DPO paper(2023,免费) | 直接偏好优化 | 深入 |
| Transformer architecture reference: Phuong & Hutter(2022,免费) | 精确架构参考 | 参考 |
| Chip Huyen, AI Engineering(付费) | 基础模型应用工程 | 实践 |
课程与讲座
Stanford CS336: Language Modeling from Scratch 涵盖数据、架构、训练基础设施和评估,适合已准备好实现模型的学习者。Karpathy 的 Zero to Hero 提供规模较小的起步项目。Hugging Face LLM Course 介绍分词器、预训练模型与训练工具。这些材料服务于不同目标:实现训练与开发应用所需的技能有交集,但并不完全相同。
| 课程 | 平台 | 类型 |
|---|---|---|
| Stanford CS336 Language Modeling from Scratch | cs336.stanford.edu | 深入 |
| Berkeley LLM Agents course(免费) | rdi.berkeley.edu | 深入 |
| Hugging Face LLM Course(免费) | huggingface.co/learn/llm-course | 实践 |
| Hugging Face Agents Course(免费) | huggingface.co/learn | 实践 |
| Cohere LLM University(免费) | docs.cohere.com | 辅助 |
| Karpathy LLM-adjacent modules from Neural Networks: Zero to Hero(免费) | YouTube | 辅助 |
实践、工具与当前资料
用 nanoGPT 检查训练循环;用 Transformers、PEFT 和 TRL 进行预训练模型与适配实验。LM-Evaluation-Harness 和 HELM 有助于组织评估,vLLM 则可用于研究推断服务和 KV 缓存管理。核对一个分数时,需要明确具体模型、分词器、任务实现和库版本。
做应用实验时,在同一组任务上比较本地模型或托管模型。固定提示、工具权限、重试策略和评估规则,记录成本与延迟。人类偏好排行榜可以提供候选模型,但其参与者、提示和评判过程未必与你的用户相同。一个定义清楚的小型评估,比没有解释的总排名更有参考价值。
| 资源 | 平台 | 类型 |
|---|---|---|
| Karpathy, nanoGPT(免费) | GitHub | 实践 |
| OpenAI Cookbook(免费;API 使用可能付费) | GitHub / cookbook.openai.com | 实践 |
| Anthropic Cookbook(免费;API 使用可能付费) | GitHub | 实践 |
| Prompt Engineering Guide(免费) | dair.ai / promptingguide.ai | 辅助 |
| Hugging Face Transformers / TRL(免费) | huggingface.co | 实践 |
| LM-Evaluation-Harness(免费) | GitHub / EleutherAI | 实践 |
| HELM(免费) | crfm.stanford.edu/helm | 参考 |
| 人类偏好评估:Arena | arena.ai | 辅助 |
| vLLM(免费) | vllm.ai | 实践 |
| Experiment tracking with Weights & Biases(免费层) | wandb.ai | 辅助 |
陷阱
| 误区 | 为什么会误导 | 更好的做法 |
|---|---|---|
| 把 API 使用当作解释 | 回答隐藏了训练、提示、解码与外部系统选择。 | 描述完整推断设置,以及每项证据由哪个组件提供。 |
| 比较分数却不说明预算和选择规则 | 重试、工具与候选选择可能大幅改变表现。 | 在明确成本下比较完整流程,并评估选择器。 |
| 把事实错误视为处处必然或靠提示即可解决 | 错误率取决于任务、证据、训练与检查,流畅输出本身不够。 | 测量无依据主张,检验检索、验证与弃答。 |
| 忽视预训练与适配数据 | 覆盖、重复、过滤与标签塑造可学习内容。 | 检查数据来源,评估不熟悉的案例。 |
| 把偏好训练当作完整可靠性措施 | 认可可能偏离正确性,应用也可能执行回答之外的动作。 | 评估预期结果,以及动作周围的权限和检查。 |
| 把开放权重等同于完全透明 | 权重可用不等于训练数据、完整训练方法或机制解释也可用。 | 明确有哪些产物可用,以及它们支持哪些结论。 |