📚 从零开始构建大模型
This report presents the forensic synthetic code analysis of datawhalechina/happy-llm, a Jupyter Notebook project with 33,329 GitHub stars. SynthScan v2.0 examined 44,018 lines of code across 97 source files, recording 184 pattern matches distributed across 11 syntactic categories. The overall adjusted score of 5.5 places this repository in the Low AI signal band.
The scanner applied 160+ deterministic lexical heuristics, multi-line block detectors, abstract syntax tree depth profilers, and a cross-file Jaccard similarity matrix to construct a statistically normalised synthetic code estimate. All matches are individually weighted by severity coefficient and contextual multiplier before summation, and the resulting headline score is temporally discounted to account for the repository's development history relative to the commercial emergence of large language model coding tooling (November 2022 onward).
This chart maps the temporal evolution of the adjusted synthetic code score across successive scan runs. An upward trajectory indicates ongoing incorporation of AI-generated code or expanding LLM-assisted scaffolding; a stable or declining trajectory may reflect active human refactoring, code removal, or the adoption of stricter authorship policies. The dashed secondary line (right axis) independently tracks total raw pattern hit count, which can diverge from the normalised score when codebase size changes significantly between scans.
Classifies detected patterns by their diagnostic confidence and structural impact. CRITICAL patterns (coefficient 10) represent definitive synthetic signatures — hallucinated imports, explicit LLM attribution metadata — virtually never produced by human authors. HIGH (5) indicates strong structural tells such as cross-file repetition or cross-linguistic idioms. MEDIUM (2) covers recognisable conversational padding and AI-specific vocabulary. LOW (1) captures subtle indicators like tautological comments and generic boilerplate that require density to carry independent signal.
This horizontal bar chart decomposes the repository's raw synthetic code score by top-level directory, allowing you to pinpoint precisely which modules or components carry the highest AI authorship density. Directories with disproportionately high scores relative to their size warrant targeted manual review: concentrated AI signatures often trace back to mass-generated configuration layers, auto-ported test suites, LLM-scaffolded boilerplate classes, or entire subsystems authored under heavy copilot assistance. Use this view to prioritise your human code-review effort.
The scanner identified 184 distinct pattern matches across 11 syntactic categories. Each entry below represents a discrete location in the source code where the engine recorded a statistically significant AI authorship indicator. Expand any category row to inspect the individual file paths, line numbers, code snippets, and the lexical context (CODE, COMMENT, or STRING) in which each match was detected.
Reading the findings table: The Severity column indicates the diagnostic confidence level (CRITICAL / HIGH / MEDIUM / LOW). The Context column identifies whether the match occurred inside executable code, an inline comment, or a string literal — comment-context matches receive a ×1.5 weight because LLMs systematically over-annotate. The ⚡ bolt icon marks clustered matches: three or more patterns within a 10-line window, each receiving an additional ×1.5 density multiplier as dense clusters constitute far stronger evidence of synthetic authorship than isolated hits.
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| LOW | docs/chapter8/opd/02-demo-async.py | 17 | CODE | |
| LOW | docs/chapter8/opd/01-demo-sync.py | 17 | CODE | |
| LOW | docs/chapter8/search-r1/analyse.py | 11 | CODE | |
| LOW | docs/chapter8/retool/analysis.py | 12 | CODE | |
| LOW | docs/chapter8/retool/sandbox.py | 43 | CODE | |
| LOW | docs/chapter8/retool/eval.py | 24 | CODE | |
| LOW | docs/chapter6/code/download_dataset.py | 2 | CODE | |
| LOW | docs/chapter6/code/download_dataset.py | 3 | CODE | |
| LOW | docs/chapter6/code/pretrain.py | 6 | CODE | |
| LOW | docs/chapter6/code/pretrain.py | 12 | CODE | |
| LOW | docs/chapter6/code/pretrain.py | 16 | CODE | |
| LOW | docs/chapter6/code/pretrain.py | 17 | CODE | |
| LOW | docs/chapter6/code/pretrain.py | 30 | CODE | |
| LOW | docs/chapter6/code/pretrain.py | 31 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 6 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 11 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 12 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 13 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 19 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 21 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 23 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 23 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 33 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 34 | CODE | |
| LOW | docs/chapter7/Agent/demo.py | 2 | CODE | |
| LOW | docs/chapter7/Agent/demo.py | 2 | CODE | |
| LOW | docs/chapter7/Agent/demo.py | 2 | CODE | |
| LOW | docs/chapter7/Agent/web_demo.py | 3 | CODE | |
| LOW | docs/chapter7/Agent/web_demo.py | 3 | CODE | |
| LOW | docs/chapter7/Agent/web_demo.py | 3 | CODE | |
| LOW | docs/chapter7/Agent/src/core.py | 5 | CODE | |
| LOW | docs/chapter7/Agent/src/core.py | 5 | CODE | |
| LOW | docs/chapter7/Agent/src/core.py | 5 | CODE | |
| LOW | docs/chapter7/Agent/src/core.py | 5 | CODE | |
| LOW | docs/chapter7/Agent/src/core.py | 5 | CODE | |
| LOW | docs/chapter7/Agent/src/core.py | 5 | CODE | |
| LOW | docs/chapter7/Agent/src/core.py | 7 | CODE | |
| LOW | docs/chapter7/Agent/src/utils.py | 2 | CODE | |
| LOW | docs/chapter7/Agent/src/utils.py | 3 | CODE | |
| LOW | docs/chapter7/RAG/VectorBase.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/VectorBase.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/VectorBase.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/VectorBase.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/VectorBase.py | 14 | CODE | |
| LOW | docs/chapter7/RAG/LLM.py | 11 | CODE | |
| LOW | docs/chapter7/RAG/LLM.py | 11 | CODE | |
| LOW | docs/chapter7/RAG/LLM.py | 11 | CODE | |
| LOW | docs/chapter7/RAG/LLM.py | 11 | CODE | |
| LOW | docs/chapter7/RAG/Embeddings.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/Embeddings.py | 13 | CODE | |
| LOW | docs/chapter7/RAG/Embeddings.py | 13 | CODE | |
| LOW | docs/chapter7/RAG/Embeddings.py | 13 | CODE | |
| LOW | docs/chapter7/RAG/Embeddings.py | 13 | CODE | |
| LOW | docs/chapter7/RAG/utils.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/utils.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/utils.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/utils.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/utils.py | 12 | CODE | |
| LOW | docs/chapter7/RAG/utils.py | 17 | CODE | |
| LOW | docs/chapter5/code/ddp_pretrain.py | 3 | CODE | |
| 17 more matches not shown… | ||||
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| MEDIUM | README.md | 66 | > 第八章聚焦 GRPO、OPD、Search-R1 与 ReTool。更多 Agentic RL 算法、训练代码与实验实践,可以前往作者持续维护的另一个仓库 [agentic-rl-lab](https://github.com/KMnO | CODE |
| MEDIUM | README_en.md | 58 | > Chapter 8 focuses on GRPO, OPD, Search-R1, and ReTool. For more Agentic RL algorithms, training code, and hands-on exp | CODE |
| MEDIUM | docs/学习与环境准备.md | 96 | 正文重点讲解 GRPO 与 OPD 的同步版,异步版保留相同算法和数据对齐方式;Search-R1 与 ReTool 按数据、协议、环境、rollout、训练和评测拆成多文件工程。想继续学习更多 Agentic RL 算法与实验,可以阅读作 | CODE |
| MEDIUM | docs/chapter8/第八章 大模型强化学习.md | 40 | > **扩展阅读:** 如果你希望继续了解更多 Agentic RL 算法与可运行实践,可以阅读作者维护的另一个开源项目 [agentic-rl-lab](https://github.com/KMnO4-zx/agentic-rl-lab | CODE |
| MEDIUM | docs/chapter8/第八章 大模型强化学习.md | 46 | > **代码来源:** 本节依据作者开源仓库 [agentic-rl-lab/01-grpo](https://github.com/KMnO4-zx/agentic-rl-lab/tree/main/01-grpo) 中的 `01-dem | CODE |
| MEDIUM | docs/chapter8/第八章 大模型强化学习.md | 539 | > **代码来源:** 本节依据作者开源仓库 [agentic-rl-lab/02-opd/general-opd](https://github.com/KMnO4-zx/agentic-rl-lab/tree/main/02-opd/g | CODE |
| MEDIUM | docs/chapter8/第八章 大模型强化学习.md | 1063 | > **代码来源:** 本节依据作者开源仓库 [agentic-rl-lab/03-search-r1](https://github.com/KMnO4-zx/agentic-rl-lab/tree/main/03-search-r1) | CODE |
| MEDIUM | docs/chapter8/第八章 大模型强化学习.md | 2242 | > **代码来源:** 本节依据作者开源仓库 [agentic-rl-lab/05-retool](https://github.com/KMnO4-zx/agentic-rl-lab/tree/main/05-retool) 中的完整多文 | CODE |
| MEDIUM | docs/chapter8/第八章 大模型强化学习.md | 3152 | > **继续学习:** 受篇幅和章节定位限制,本章集中介绍了 GRPO、OPD、Search-R1 与 ReTool,仍有许多 Agentic RL 方法和交互环境无法逐一展开。如果你希望继续学习 OPSD、DAPO、GSPO、ALFWor | CODE |
| MEDIUM | docs/chapter8/第八章 大模型强化学习.md | 3165 | 10. Agentic-RL Lab (不要葱姜蒜). [agentic-rl-lab](https://github.com/KMnO4-zx/agentic-rl-lab). | CODE |
| MEDIUM | docs/chapter8/opd/README.md | 3 | > **代码来源:** 本目录代码引用并整理自本章作者维护的 [agentic-rl-lab](https://github.com/KMnO4-zx/agentic-rl-lab) 中的 [02-opd](https://github.c | CODE |
| MEDIUM | docs/chapter8/search-r1/README.md | 3 | > **代码来源:** 本目录代码引用并整理自本章作者维护的 [agentic-rl-lab](https://github.com/KMnO4-zx/agentic-rl-lab) 中的 [03-search-r1](https://gi | CODE |
| MEDIUM | docs/chapter8/search-r1/search.py | 28 | "(https://github.com/KMnO4-zx/agentic-rl-lab)" | CODE |
| MEDIUM | docs/chapter8/grpo/README.md | 3 | > **代码来源:** 本目录代码引用并整理自本章作者维护的 [agentic-rl-lab](https://github.com/KMnO4-zx/agentic-rl-lab) 中的 [01-grpo](https://github. | CODE |
| MEDIUM | docs/chapter8/retool/README.md | 3 | > **代码来源:** 本目录代码引用并整理自本章作者维护的 [agentic-rl-lab](https://github.com/KMnO4-zx/agentic-rl-lab) 中的 [05-retool](https://githu | CODE |
| MEDIUM⚡ | docs/chapter7/第七章 大模型应用.md | 93 | ## 7.2 RAG | COMMENT |
| MEDIUM⚡ | docs/chapter7/第七章 大模型应用.md | 95 | ### 7.2.1 RAG 的基本原理 | COMMENT |
| MEDIUM⚡ | docs/chapter7/第七章 大模型应用.md | 103 | ### 7.2.2 搭建一个 RAG 框架 | COMMENT |
| MEDIUM | docs/chapter7/第七章 大模型应用.md | 440 | #### Step 6: Tiny-RAG Demo | STRING |
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| LOW⚡ | docs/chapter7/第七章 大模型应用.md | 107 | #### Step 1: RAG流程介绍 | COMMENT |
| LOW | docs/chapter7/第七章 大模型应用.md | 139 | #### Step 2: 文档加载和切分 | COMMENT |
| LOW | docs/chapter7/第七章 大模型应用.md | 237 | #### Step 3: 向量化 | COMMENT |
| LOW | docs/chapter7/第七章 大模型应用.md | 337 | #### Step 4: 数据库与向量检索 | COMMENT |
| LOW | docs/chapter7/第七章 大模型应用.md | 381 | #### Step 5: 大模型模块 | COMMENT |
| LOW | docs/chapter7/第七章 大模型应用.md | 440 | #### Step 6: Tiny-RAG Demo | STRING |
| LOW⚡ | docs/chapter7/第七章 大模型应用.md | 546 | #### Step 1 : 初始化客户端和模型 | STRING |
| LOW⚡ | docs/chapter7/第七章 大模型应用.md | 565 | #### Step 2: 定义工具函数 | STRING |
| LOW | docs/chapter7/第七章 大模型应用.md | 640 | #### Step 3: 构造 Agent 类 | STRING |
| LOW | docs/chapter7/第七章 大模型应用.md | 738 | #### Step 4: 运行 Agent | STRING |
| LOW | docs/chapter5/第五章 动手搭建大模型.md | 748 | #### Step 1: 安装和导入依赖库 | COMMENT |
| LOW | docs/chapter5/第五章 动手搭建大模型.md | 774 | #### Step 2: 加载训练数据 | COMMENT |
| LOW | docs/chapter5/第五章 动手搭建大模型.md | 798 | #### Step 3: 创建配置文件 | COMMENT |
| LOW | docs/chapter5/第五章 动手搭建大模型.md | 848 | #### Step 4: 训练 BPE Tokenizer | COMMENT |
| LOW⚡ | docs/chapter5/第五章 动手搭建大模型.md | 908 | #### Step 5: 使用训练好的 Tokenizer | COMMENT |
| LOW | …r/s1-vllm-thinking-budget/output/output_1754208752.txt | 1969 | ### Step 1: Understanding the Critical Points | COMMENT |
| LOW | …r/s1-vllm-thinking-budget/output/output_1754208752.txt | 1995 | ### Step 2: Behavior of the Polynomial | COMMENT |
| LOW | …r/s1-vllm-thinking-budget/output/output_1754208752.txt | 2009 | ### Step 3: Symmetry and Roots | COMMENT |
| LOW | …r/s1-vllm-thinking-budget/output/output_1754208752.txt | 2029 | ### Step 4: Final Calculation | COMMENT |
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| LOW | docs/chapter8/第八章 大模型强化学习.md | 2543 | except Exception: | CODE |
| LOW | docs/chapter8/retool/reward.py | 48 | except Exception: # math_verify 对怪异输入可能抛异常,一律按不等价处理 | CODE |
| MEDIUM | docs/chapter5/第五章 动手搭建大模型.md | 791 | print(f"Error decoding JSON in line {line_num}") | CODE |
| LOW⚡ | docs/chapter5/第五章 动手搭建大模型.md | 917 | except Exception as e: | CODE |
| MEDIUM⚡ | docs/chapter5/第五章 动手搭建大模型.md | 918 | print(f"Error loading tokenizer: {e}") | CODE |
| MEDIUM | docs/chapter5/第五章 动手搭建大模型.md | 1099 | print(f"Error decoding JSON in line {line_num}") | CODE |
| LOW | docs/chapter5/第五章 动手搭建大模型.md | 1204 | except Exception as e: | CODE |
| MEDIUM | docs/chapter5/第五章 动手搭建大模型.md | 1205 | print(f"Error loading tokenizer: {e}") | CODE |
| MEDIUM | docs/chapter5/code/train_tokenizer.py | 27 | print(f"Error decoding JSON in line {line_num}") | CODE |
| LOW | docs/chapter5/code/train_tokenizer.py | 132 | except Exception as e: | CODE |
| MEDIUM | docs/chapter5/code/train_tokenizer.py | 133 | print(f"Error loading tokenizer: {e}") | CODE |
| LOW | Extra-Chapter/CDDRS/readme.md | 160 | except Exception as e: | CODE |
| MEDIUM | Extra-Chapter/CDDRS/readme.md | 161 | print(f"Error reading {file_path}: {e}") | CODE |
| LOW | Extra-Chapter/generation-method/llm_generation.py | 149 | except Exception as e: | CODE |
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| LOW | docs/chapter8/opd/01-demo-sync.py | 256 | CODE | |
| LOW | docs/chapter8/search-r1/rollout.py | 320 | CODE | |
| LOW | docs/chapter8/search-r1/train.py | 484 | CODE | |
| LOW | docs/chapter8/search-r1/search.py | 137 | CODE | |
| LOW | docs/chapter8/search-r1/search.py | 230 | CODE | |
| LOW | docs/chapter8/search-r1/search.py | 424 | CODE | |
| LOW | docs/chapter8/search-r1/eval.py | 222 | CODE | |
| LOW | docs/chapter8/grpo/02-demo-async.py | 434 | CODE | |
| LOW | docs/chapter8/grpo/01-demo-sync.py | 386 | CODE | |
| LOW | docs/chapter8/retool/rollout.py | 346 | CODE | |
| LOW | docs/chapter8/retool/train.py | 457 | CODE | |
| LOW | docs/chapter8/retool/eval.py | 141 | CODE | |
| LOW | docs/chapter8/retool/reward.py | 26 | CODE | |
| LOW | docs/chapter6/code/finetune.py | 87 | CODE | |
| LOW | docs/chapter7/RAG/utils.py | 34 | CODE | |
| LOW | docs/chapter7/RAG/utils.py | 61 | CODE | |
| LOW | docs/chapter5/code/dataset.py | 65 | CODE | |
| LOW | docs/chapter5/code/train_tokenizer.py | 17 | CODE |
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| HIGH⚡ | docs/chapter7/第七章 大模型应用.md | 555 | api_key="YOUR_API_KEY", # 替换为你的 API Key | STRING |
| HIGH⚡ | docs/chapter7/第七章 大模型应用.md | 563 | > **注意:** 你需要将 `YOUR_API_KEY` 替换为你从 [SiliconFlow](https://cloud.siliconflow.cn/i/ybUFvmqK) 或其他服务商获取的有效 API Key。 | STRING |
| HIGH | docs/chapter7/第七章 大模型应用.md | 746 | api_key="YOUR_API_KEY", # 替换为你的 API Key | STRING |
| HIGH | Extra-Chapter/CDDRS/readme.md | 80 | api_key="your-api-key-here", | CODE |
| HIGH | Extra-Chapter/CDDRS/readme.md | 786 | api_key='your-api-key', | STRING |
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| LOW | docs/chapter8/第八章 大模型强化学习.md | 612 | def completion_teacher_logprobs( | CODE |
| LOW | docs/chapter8/第八章 大模型强化学习.md | 779 | def completion_teacher_logprobs( | CODE |
| LOW | docs/chapter8/opd/02-demo-async.py | 194 | async def completion_teacher_logprobs_async( | CODE |
| LOW | docs/chapter8/opd/01-demo-sync.py | 182 | def completion_teacher_logprobs(teacher_client, prompt_ids: list[int], completion_ids: list[int]): | CODE |
| LOW | docs/chapter8/search-r1/train.py | 165 | def weight_micro_batch_for_global_mean( | CODE |
| LOW | docs/chapter8/search-r1/search.py | 563 | def resolve_search_concurrency(backend: str, value: int | None) -> int: | CODE |
| LOW | docs/chapter8/retool/train.py | 164 | def weight_micro_batch_for_global_mean( | CODE |
| LOW | docs/chapter8/retool/eval.py | 193 | async def evaluate_problem_text_only( | CODE |
| LOW | docs/chapter5/code/k_model.py | 378 | def _left_pad_by_attention_mask( | CODE |
| LOW | Extra-Chapter/CDDRS/readme.md | 246 | def _compute_semantic_discrepancy(self, embeddings: np.ndarray) -> List[float]: | CODE |
| LOW | Extra-Chapter/CDDRS/readme.md | 283 | def _enforce_length_constraints(self, chunks: List[str]) -> List[str]: | CODE |
| LOW | Extra-Chapter/CDDRS/readme.md | 423 | def compute_document_length_factor(chunk_length: int, avg_length: int = 100) -> float: | STRING |
| LOW | Extra-Chapter/CDDRS/readme.md | 437 | def compute_term_significance(term_freq: int, doc_length_factor: float) -> float: | STRING |
| LOW | Extra-Chapter/CDDRS/readme.md | 559 | def _compute_knowledge_scores(self, key_info: Dict[str, Tuple[str, float]]) -> List[float]: | STRING |
| LOW | Extra-Chapter/text-data-processing/readme.md | 932 | def test_simple_bpe_tokenizer(): | CODE |
| LOW | Extra-Chapter/s1-vllm-thinking-budget/s1.py | 28 | def run_thinking_budget_sample(llm_model, tokenizer, user_input, thinking_budget): | CODE |
| LOW | Extra-Chapter/s1-vllm-thinking-budget/readme.md | 41 | def run_thinking_budget_sample(llm_model, tokenizer, user_input, thinking_budget): | CODE |
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| HIGH | docs/chapter7/第七章 大模型应用.md | 259 | 获取文本的嵌入向量表示 Args: text (str): 输入文本 model (str): 使用的模型名称 Returns: | STRING |
| HIGH | docs/chapter7/RAG/Embeddings.py | 36 | 获取文本的嵌入向量表示 Args: text (str): 输入文本 model (str): 使用的模型名称 Returns: | STRING |
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| LOW | docs/chapter6/code/pretrain.py | 180 | CODE | |
| LOW | docs/chapter5/code/k_model.py | 16 | CODE | |
| LOW | docs/chapter5/code/k_model.py | 248 | CODE | |
| LOW | docs/chapter5/code/k_model.py | 307 | CODE | |
| LOW | docs/chapter5/code/k_model.py | 677 | CODE | |
| LOW | docs/chapter2/code/transformer.py | 98 | CODE | |
| LOW | docs/chapter2/code/transformer.py | 151 | CODE | |
| LOW | docs/chapter2/code/transformer.py | 192 | CODE |
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| LOW | docs/chapter8/search-r1/eval.py | 293 | def update_progress(completed: int) -> None: | CODE |
| LOW | docs/chapter6/code/pretrain.py | 36 | logger = logging.getLogger(__name__) | CODE |
| LOW | docs/chapter6/code/finetune.py | 40 | logger = logging.getLogger(__name__) | CODE |
| Severity | File | Line | Snippet | Context |
|---|---|---|---|---|
| LOW | docs/chapter5/code/k_model.py | 61 | def forward(self, x): | COMMENT |
| LOW | docs/chapter2/第二章 Transformer架构.md | 301 | # 注意力计算 | COMMENT |