现在来学习一下 Claude Code 的架构与设计思想。
一下子也看不完,准备持续记录笔记,对哪里感兴趣就先看哪;互联网上,各种 CC 源码报告充斥着无数自相矛盾的 LLM 幻觉,真是越看越红温,不如用自己的 CC 专门读几个方向的代码。
现在来学习一下 Claude Code 的架构与设计思想。
一下子也看不完,准备持续记录笔记,对哪里感兴趣就先看哪;互联网上,各种 CC 源码报告充斥着无数自相矛盾的 LLM 幻觉,真是越看越红温,不如用自己的 CC 专门读几个方向的代码。
包含:
(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)) 什么都不显示。
第一次课程包括实现 Byte-Pair Encoding (BPE) tokenizer。
tokenizer 不应该使用字节级别操作,因为会导致长 sequence。
如果 tokenizer 使用 word-based tokenization 会导致 vocabulary size 过大。
因此采用 BPE。核心逻辑是把经常一起出现的 byte 凑成一个新组合,并反复执行这个过程:
基本代码实现如下。
Detecting hallucinations in large language models using semantic entropy | Nature
作者想出了一种办法,可以检测大语言模型的一种幻觉:捏造(confabulation)。因为一个想法在语义层面(meaning level)可以计算不确定性,而不是只在特定的词序列上计算。类似于:同一个想法可以用很多不同方式表达。
On the Role of Attention Heads in Large Language Model Safety
ICLR 2025
Previous research has shown that there are safety parameters in LLM. This paper focuses on the attention heads.
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.
未加偏差修正的 EMA:
看到这个帖子后有点害怕,弃用了 gitalk。更换了新的评论插件。