0%

现在来学习一下 Claude Code 的架构与设计思想。

一下子也看不完,准备持续记录笔记,对哪里感兴趣就先看哪;互联网上,各种 CC 源码报告充斥着无数自相矛盾的 LLM 幻觉,真是越看越红温,不如用自己的 CC 专门读几个方向的代码。

阅读全文 »

Assignment 1, Writeup

包含:

  1. Byte-pair encoding (BPE) tokenizer
  2. Transformer language model (LM)
  3. The cross-entropy loss function and the AdamW optimizer
  4. The training loop, with support for serializing and loading model and optimizer state

Byte-Pair Encoding (BPE) Tokenizer

Problem (unicode1): Understanding Unicode (1 point)

(a) What Unicode character does chr(0) return?

Null 字符。

(b) How does this character’s string representation (__repr__()) differ from its printed representation?

交互环境下输入 chr(0) 就是调用 __repr__(),看到 ‘\x00’。print(chr(0)) 什么都不显示。

阅读全文 »

Lecture 2 (一)

几个表格,快速回顾知识

缩写 全称 中文含义 常见解释
B Batch size 批大小 一次并行送进模型的样本数
H Heads 注意力头数 Multi-Head Attention 里的头数
T Time steps / Sequence length 时间步 / 序列长度 序列中 token 的数量
D Dimension / Hidden size 特征维度 / 隐藏维度 向量长度、embedding 维度
V Vocabulary size 词表大小 不同 token 的总数
d Head dim 每个 head 的维度 D / H
阅读全文 »

Lecture 1

第一次课程包括实现 Byte-Pair Encoding (BPE) tokenizer。

tokenizer 不应该使用字节级别操作,因为会导致长 sequence。

如果 tokenizer 使用 word-based tokenization 会导致 vocabulary size 过大。

因此采用 BPE。核心逻辑是把经常一起出现的 byte 凑成一个新组合,并反复执行这个过程:

  1. 把每个字节(Byte)都看作一个独立的 Token。
  2. 看看哪两个 Token 挨在一起出现的次数最多。
  3. 把这对 Token 合并成一个新的 Token。
  4. 重复这个过程直到达到合适的词表大小。

基本代码实现如下。

阅读全文 »

由于基础薄弱,希望调研也能作为笔记来帮助我个人进行复习,我额外记录了一些名词解释、新知识,而不是单独写论文的总结,所以内容可能有点啰嗦。

调研了以下优秀的论文。

阅读全文 »

简单记一下笔记

Detecting hallucinations in large language models using semantic entropy | Nature

作者想出了一种办法,可以检测大语言模型的一种幻觉:捏造(confabulation)。因为一个想法在语义层面(meaning level)可以计算不确定性,而不是只在特定的词序列上计算。类似于:同一个想法可以用很多不同方式表达。

阅读全文 »

Paper

On the Role of Attention Heads in Large Language Model Safety

ICLR 2025

Methods

Previous research has shown that there are safety parameters in LLM. This paper focuses on the attention heads.

Ships (Safety Head Important Score)

Ships helps to qualify the impact of a specific attention head on safety. As shown in the formula, it calculates the KL divergence between two output distributions: one with all attention heads and another with a head ablated.

$q_{\mathcal{H}}$ is harmful queries. $\theta_{\mathcal{O}}$ is the parameters of original attention heads. $\theta_{h_{i}^{l}}$ is the parameters of the $i$-th attention head in layer $l$. $\setminus$ is the ablation operation.

How to ablate an attention head? The paper proposes two methods.

阅读全文 »

Aspirant学长希望学习钢琴、架子鼓。本文档旨在帮助Aspirant学长快速回顾他可能遗忘的基础乐理,建立起接下来练习钢琴的基础。

本文档也许也可以帮助程序员或相关人员以相对熟悉的风格了解乐理知识。欢迎阅读!

⚠️ 笔者并非音乐专业的学生,请留心笔记中的疏忽与错误!本人能力实在有限,以下内容仅供回顾参考和快速对乐理有个初步了解。

致谢

Deep-sea同学是一名很优秀的音乐专业学生,她为本文档提供了很多建议与指导。

工具使用

abcjs,用于绘制五线谱。

正在从网上引入abcjs……请等待加载完毕。

阅读全文 »

未加偏差修正的 EMA:

  • $\theta_t$ :当前模型参数
  • $\theta^{EMA}_t$ :EMA 参数(在影子模型(shadow model)里)
  • $\beta \in [0,1)$ :衰减系数接近 1 (越接近 1,衰减得越慢,历史参数影响保持更久,EMA 越平滑)
  • 直觉:靠前的参数权重小,靠后的参数权重大
阅读全文 »