math-skill 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.en-US.md +42 -30
  2. package/README.md +18 -6
  3. package/agents/math-critic.en.md +6 -6
  4. package/agents/math-critic.md +6 -6
  5. package/commands/ask.en.md +6 -1
  6. package/commands/ask.md +6 -1
  7. package/design-patterns/attention/equivariant-attention.en.md +8 -2
  8. package/design-patterns/attention/equivariant-attention.md +7 -1
  9. package/design-patterns/attention/geometry-aware-attention.en.md +2 -2
  10. package/design-patterns/attention/geometry-aware-attention.md +1 -1
  11. package/design-patterns/attention/information-bottleneck-attention.en.md +32 -12
  12. package/design-patterns/attention/information-bottleneck-attention.md +32 -12
  13. package/design-patterns/attention/projection-attention.en.md +3 -3
  14. package/design-patterns/attention/projection-attention.md +2 -2
  15. package/design-patterns/attention/spectral-attention.en.md +19 -5
  16. package/design-patterns/attention/spectral-attention.md +18 -4
  17. package/design-patterns/compression/leverage-score-selection.en.md +13 -13
  18. package/design-patterns/compression/leverage-score-selection.md +13 -13
  19. package/design-patterns/compression/low-rank-kv-cache.en.md +39 -12
  20. package/design-patterns/compression/low-rank-kv-cache.md +38 -12
  21. package/design-patterns/compression/spectral-token-pruning.en.md +16 -14
  22. package/design-patterns/compression/spectral-token-pruning.md +16 -14
  23. package/design-patterns/compression/topology-preserving-compression.en.md +10 -10
  24. package/design-patterns/compression/topology-preserving-compression.md +10 -10
  25. package/design-patterns/loss/constraint-penalty.en.md +8 -4
  26. package/design-patterns/loss/constraint-penalty.md +9 -6
  27. package/design-patterns/loss/contrastive-loss.en.md +37 -11
  28. package/design-patterns/loss/contrastive-loss.md +38 -12
  29. package/design-patterns/loss/information-bottleneck-loss.en.md +5 -5
  30. package/design-patterns/loss/information-bottleneck-loss.md +6 -6
  31. package/design-patterns/loss/orthogonality-loss.en.md +24 -17
  32. package/design-patterns/loss/orthogonality-loss.md +24 -18
  33. package/design-patterns/loss/variational-loss.en.md +4 -4
  34. package/design-patterns/loss/variational-loss.md +5 -5
  35. package/design-patterns/overview.en.md +36 -0
  36. package/design-patterns/overview.md +36 -0
  37. package/design-patterns/representation/equivariant-split.en.md +4 -4
  38. package/design-patterns/representation/equivariant-split.md +4 -5
  39. package/design-patterns/representation/manifold-representation.en.md +12 -12
  40. package/design-patterns/representation/manifold-representation.md +13 -14
  41. package/design-patterns/representation/shared-private-decomposition.en.md +12 -7
  42. package/design-patterns/representation/shared-private-decomposition.md +12 -9
  43. package/design-patterns/representation/subspace-alignment.en.md +12 -12
  44. package/design-patterns/representation/subspace-alignment.md +12 -12
  45. package/design-patterns/routing/graph-routing.en.md +11 -11
  46. package/design-patterns/routing/graph-routing.md +11 -11
  47. package/design-patterns/routing/moe-routing.en.md +12 -12
  48. package/design-patterns/routing/moe-routing.md +12 -14
  49. package/design-patterns/routing/optimal-transport-routing.en.md +5 -5
  50. package/design-patterns/routing/optimal-transport-routing.md +6 -6
  51. package/design-patterns/routing/spectral-clustering-routing.en.md +26 -15
  52. package/design-patterns/routing/spectral-clustering-routing.md +26 -17
  53. package/knowledge-base/differential-geometry/connection.en.md +17 -2
  54. package/knowledge-base/differential-geometry/connection.md +17 -2
  55. package/knowledge-base/differential-geometry/curvature.en.md +14 -1
  56. package/knowledge-base/differential-geometry/curvature.md +14 -1
  57. package/knowledge-base/differential-geometry/geodesic.en.md +16 -2
  58. package/knowledge-base/differential-geometry/geodesic.md +16 -2
  59. package/knowledge-base/differential-geometry/index.en.md +52 -0
  60. package/knowledge-base/differential-geometry/index.md +52 -0
  61. package/knowledge-base/differential-geometry/manifold.en.md +15 -2
  62. package/knowledge-base/differential-geometry/manifold.md +15 -2
  63. package/knowledge-base/differential-geometry/metric-tensor.en.md +16 -2
  64. package/knowledge-base/differential-geometry/metric-tensor.md +16 -2
  65. package/knowledge-base/differential-geometry/tangent-space.en.md +17 -3
  66. package/knowledge-base/differential-geometry/tangent-space.md +17 -3
  67. package/knowledge-base/information-geometry/fisher-metric.en.md +24 -5
  68. package/knowledge-base/information-geometry/fisher-metric.md +24 -5
  69. package/knowledge-base/information-geometry/index.en.md +45 -0
  70. package/knowledge-base/information-geometry/index.md +45 -0
  71. package/knowledge-base/information-geometry/natural-gradient.en.md +17 -3
  72. package/knowledge-base/information-geometry/natural-gradient.md +17 -3
  73. package/knowledge-base/lie-theory/equivariance.en.md +18 -3
  74. package/knowledge-base/lie-theory/equivariance.md +18 -3
  75. package/knowledge-base/lie-theory/group-action.en.md +16 -2
  76. package/knowledge-base/lie-theory/group-action.md +16 -2
  77. package/knowledge-base/lie-theory/index.en.md +52 -0
  78. package/knowledge-base/lie-theory/index.md +52 -0
  79. package/knowledge-base/lie-theory/lie-algebra.en.md +17 -2
  80. package/knowledge-base/lie-theory/lie-algebra.md +17 -2
  81. package/knowledge-base/lie-theory/lie-group.en.md +17 -3
  82. package/knowledge-base/lie-theory/lie-group.md +17 -3
  83. package/knowledge-base/lie-theory/representation.en.md +17 -2
  84. package/knowledge-base/lie-theory/representation.md +17 -2
  85. package/knowledge-base/matrix-analysis/index.en.md +49 -0
  86. package/knowledge-base/matrix-analysis/index.md +49 -0
  87. package/knowledge-base/matrix-analysis/low-rank-approximation.en.md +20 -7
  88. package/knowledge-base/matrix-analysis/low-rank-approximation.md +20 -7
  89. package/knowledge-base/matrix-analysis/matrix-perturbation.en.md +13 -1
  90. package/knowledge-base/matrix-analysis/matrix-perturbation.md +13 -1
  91. package/knowledge-base/matrix-analysis/positive-semidefinite.en.md +20 -6
  92. package/knowledge-base/matrix-analysis/positive-semidefinite.md +20 -6
  93. package/knowledge-base/matrix-analysis/projection.en.md +14 -1
  94. package/knowledge-base/matrix-analysis/projection.md +14 -1
  95. package/knowledge-base/matrix-analysis/spectral-decomposition.en.md +14 -1
  96. package/knowledge-base/matrix-analysis/spectral-decomposition.md +14 -1
  97. package/knowledge-base/optimization/constrained-optimization.en.md +17 -3
  98. package/knowledge-base/optimization/constrained-optimization.md +17 -3
  99. package/knowledge-base/optimization/convex-optimization.en.md +15 -2
  100. package/knowledge-base/optimization/convex-optimization.md +15 -2
  101. package/knowledge-base/optimization/index.en.md +50 -0
  102. package/knowledge-base/optimization/index.md +50 -0
  103. package/knowledge-base/optimization/lagrangian-duality.en.md +18 -4
  104. package/knowledge-base/optimization/lagrangian-duality.md +18 -4
  105. package/knowledge-base/optimization/proximal-method.en.md +15 -1
  106. package/knowledge-base/optimization/proximal-method.md +15 -1
  107. package/knowledge-base/optimization/riemannian-optimization.en.md +18 -4
  108. package/knowledge-base/optimization/riemannian-optimization.md +18 -4
  109. package/knowledge-base/overview.en.md +20 -8
  110. package/knowledge-base/overview.md +20 -8
  111. package/knowledge-base/probability/concentration-inequality.en.md +16 -2
  112. package/knowledge-base/probability/concentration-inequality.md +16 -2
  113. package/knowledge-base/probability/entropy.en.md +19 -3
  114. package/knowledge-base/probability/entropy.md +18 -2
  115. package/knowledge-base/probability/fisher-information.en.md +17 -3
  116. package/knowledge-base/probability/fisher-information.md +17 -3
  117. package/knowledge-base/probability/index.en.md +51 -0
  118. package/knowledge-base/probability/index.md +51 -0
  119. package/knowledge-base/probability/information-bottleneck.en.md +18 -2
  120. package/knowledge-base/probability/information-bottleneck.md +18 -2
  121. package/knowledge-base/probability/kl-divergence.en.md +15 -2
  122. package/knowledge-base/probability/kl-divergence.md +15 -2
  123. package/knowledge-base/topology/euler-characteristic.en.md +15 -2
  124. package/knowledge-base/topology/euler-characteristic.md +15 -2
  125. package/knowledge-base/topology/fundamental-group.en.md +16 -2
  126. package/knowledge-base/topology/fundamental-group.md +16 -2
  127. package/knowledge-base/topology/index.en.md +48 -0
  128. package/knowledge-base/topology/index.md +48 -0
  129. package/knowledge-base/topology/persistent-homology.en.md +17 -2
  130. package/knowledge-base/topology/persistent-homology.md +17 -2
  131. package/lenses/spectral.en.md +1 -1
  132. package/lenses/spectral.md +1 -1
  133. package/lenses/topological.en.md +1 -1
  134. package/lenses/topological.md +1 -1
  135. package/package.json +5 -5
  136. package/references/agentic-workflow.en.md +2 -2
  137. package/references/books/abstract-algebra.en.md +12 -12
  138. package/references/books/abstract-algebra.md +9 -9
  139. package/references/books/algebraic-geometry-rising-sea.en.md +2 -2
  140. package/references/books/differential-geometry.en.md +16 -16
  141. package/references/books/differential-geometry.md +14 -14
  142. package/references/books/matrix-analysis.en.md +3 -3
  143. package/references/books/matrix-analysis.md +24 -24
  144. package/references/books/micro-lie-theory.en.md +1 -1
  145. package/references/books/optimization-ml.en.md +15 -15
  146. package/references/books/optimization-ml.md +14 -14
  147. package/references/books/smooth-manifolds.en.md +3 -3
  148. package/references/books/smooth-manifolds.md +6 -6
  149. package/references/gpu-friendly-math.en.md +21 -8
  150. package/references/gpu-friendly-math.md +19 -4
  151. package/references/skill-index.en.md +105 -0
  152. package/references/skill-index.md +105 -0
  153. package/skills/math-research-activator/SKILL.en.md +70 -112
  154. package/skills/math-research-activator/SKILL.md +60 -100
package/README.en-US.md CHANGED
@@ -18,19 +18,21 @@
18
18
 
19
19
  ## Inspiration
20
20
 
21
- The story of Sophus Lie forging a "dragon-slaying blade" tells us this: the Lie group–Lie algebra machinery invented to solve differential equations ended up becoming the lingua franca for describing symmetry and robot state estimation — the value of a mathematical tool far outlives its original intent, which is exactly the prototype of "cross-domain activation." See [`references/inspiration.md`](references/inspiration.md).
21
+ The story of Sophus Lie forging a "dragon-slaying blade" tells us this: the Lie group–Lie algebra machinery invented to solve differential equations ended up becoming the lingua franca for describing symmetry and robot state estimation — the value of a mathematical tool far outlives its original intent, which is exactly the prototype of "cross-domain activation." See [`references/inspiration.en.md`](references/inspiration.en.md).
22
22
 
23
23
  > The most fascinating thing about mathematics: a tool invented for one problem reveals unforeseen power in an entirely different domain.
24
24
 
25
25
  ---
26
26
 
27
+ > Math Skill does not store mathematics. It activates, routes, and translates mathematics for AI research.
28
+
27
29
  ## Philosophy
28
30
 
29
31
  When you face an AI research problem, this system helps you answer four questions:
30
32
 
31
33
  1. **What mathematical perspective should I use?** → Thinking Lenses
32
- 2. **What specific math do I need?** → Knowledge Base
33
- 3. **How do I turn math into model design?** → Design Translation
34
+ 2. **Which mathematical structures to activate?** → Activation Anchors / Temporary Knowledge Cards
35
+ 3. **How do I turn math into model design?** → Design Translation Prototypes
34
36
  4. **Is it mathematically sound and engineering-feasible?** → Critic
35
37
 
36
38
  ```
@@ -38,7 +40,7 @@ Problem
38
40
 
39
41
  Thinking Lenses: What perspective fits this problem?
40
42
 
41
- Math Knowledge: What specific tools does this perspective need?
43
+ Activation Anchors: Which math structures to activate? Enter Knowledge Gap Protocol if insufficient
42
44
 
43
45
  Design Translation: How do these tools become model structures / losses / operators?
44
46
 
@@ -52,35 +54,35 @@ Critic: Mathematically sound? Engineering-feasible?
52
54
  | Layer | Role | Directory | Files |
53
55
  |-------|------|-----------|-------|
54
56
  | **Thinking Lenses** | Diagnose problem structure, recommend math perspectives | `lenses/*.md` | 15 |
55
- | **Math Knowledge** | Provide concrete math tools (definitions/theorems/formulas) | `knowledge-base/*/*.md` | 31 |
57
+ | **Activation Anchors** | Activate high-frequency math structures; trigger Knowledge Gap Protocol when insufficient | `knowledge-base/*/*.md` | 31 |
56
58
  | **Design Translation** | Bridge math to AI modules/losses/operators | `design-patterns/*/*.md` | 22 |
57
59
 
58
60
  Supporting layers:
59
61
  - `references/books/*.md`: 7 book distillations for deep context
60
- - `references/gpu-friendly-math.md`: GPU 8-dimension acceptance gate
61
- - `agents/math-critic.md`: Math-engineering dual critic
62
+ - `references/gpu-friendly-math.en.md`: GPU 8-dimension acceptance gate
63
+ - `agents/math-critic.en.md`: Math-engineering dual critic
62
64
 
63
65
  ### 15 Thinking Lenses
64
66
 
65
67
  | Lens | File | Core Perspective |
66
68
  |------|------|-----------------|
67
- | Axiomatization | `lenses/axiomatization.md` | Audit assumptions for consistency/independence/completeness |
68
- | Duality | `lenses/duality.md` | Transform to dual space to expose constraints and invariants |
69
- | Symmetry | `lenses/symmetry.md` | Invariants and conservation laws under transformations |
70
- | Spectral | `lenses/spectral.md` | Eigenvalues/singular values reveal dominant structure |
71
- | Geometric | `lenses/geometric.md` | Metric/curvature/manifold spatial structure |
72
- | Projection | `lenses/projection.md` | Orthogonal decomposition, subspace separation, conflict elimination |
73
- | Variational | `lenses/variational.md` | Constrained extrema, energy minimization |
74
- | Local-to-Global | `lenses/local-to-global.md` | Assemble local properties into global structure |
75
- | Topological | `lenses/topological.md` | Continuous-deformation invariants, connectivity, holes |
76
- | Categorical | `lenses/categorical.md` | Universal properties, functors, natural transformations |
77
- | Perturbation | `lenses/perturbation.md` | Propagation of small perturbations, stability, robustness |
78
- | Causal | `lenses/causal.md` | Correlation ≠ causation, interventions, counterfactuals |
79
- | Game | `lenses/game.md` | Multi-agent strategic interaction, equilibrium, mechanism design |
80
- | Probabilistic | `lenses/probabilistic.md` | Quantify uncertainty, Bayesian updating |
81
- | Algorithmic | `lenses/algorithmic.md` | Complexity, feasibility, parallelism |
82
-
83
- ### Knowledge Base (by math domain)
69
+ | Axiomatization | `lenses/axiomatization.en.md` | Audit assumptions for consistency/independence/completeness |
70
+ | Duality | `lenses/duality.en.md` | Transform to dual space to expose constraints and invariants |
71
+ | Symmetry | `lenses/symmetry.en.md` | Invariants and conservation laws under transformations |
72
+ | Spectral | `lenses/spectral.en.md` | Eigenvalues/singular values reveal dominant structure |
73
+ | Geometric | `lenses/geometric.en.md` | Metric/curvature/manifold spatial structure |
74
+ | Projection | `lenses/projection.en.md` | Orthogonal decomposition, subspace separation, conflict elimination |
75
+ | Variational | `lenses/variational.en.md` | Constrained extrema, energy minimization |
76
+ | Local-to-Global | `lenses/local-to-global.en.md` | Assemble local properties into global structure |
77
+ | Topological | `lenses/topological.en.md` | Continuous-deformation invariants, connectivity, holes |
78
+ | Categorical | `lenses/categorical.en.md` | Universal properties, functors, natural transformations |
79
+ | Perturbation | `lenses/perturbation.en.md` | Propagation of small perturbations, stability, robustness |
80
+ | Causal | `lenses/causal.en.md` | Correlation ≠ causation, interventions, counterfactuals |
81
+ | Game | `lenses/game.en.md` | Multi-agent strategic interaction, equilibrium, mechanism design |
82
+ | Probabilistic | `lenses/probabilistic.en.md` | Quantify uncertainty, Bayesian updating |
83
+ | Algorithmic | `lenses/algorithmic.en.md` | Complexity, feasibility, parallelism |
84
+
85
+ ### Activation Anchors (by math domain)
84
86
 
85
87
  | Domain | Cards |
86
88
  |--------|-------|
@@ -196,11 +198,11 @@ math-skill/
196
198
  │ └── compression/ # Compression (4 patterns)
197
199
  ├── references/ # Reference layer
198
200
  │ ├── books/ # 7 book distillations
199
- │ ├── gpu-friendly-math.md # GPU 8-dimension gate
200
- │ ├── agentic-workflow.md # Collaboration style
201
- │ └── inspiration.md # Inspiration
202
- ├── agents/math-critic.md # Math-engineering dual critic
203
- ├── commands/ask.md # /ask manual entry
201
+ │ ├── gpu-friendly-math.en.md # GPU 8-dimension gate
202
+ │ ├── agentic-workflow.en.md # Collaboration style
203
+ │ └── inspiration.en.md # Inspiration
204
+ ├── agents/math-critic.en.md # Math-engineering dual critic
205
+ ├── commands/ask.en.md # /ask manual entry
204
206
  ├── math_book/ # Local PDFs (not published)
205
207
  └── README.md / LICENSE
206
208
  ```
@@ -225,9 +227,19 @@ Distillation files ship with the npm package. For full-fidelity lookups, place P
225
227
 
226
228
  ## Changelog
227
229
 
230
+ ### v3.1.0 — Activation Anchors & Knowledge Gap Protocol
231
+
232
+ **Repositioning**: from "math knowledge base" to "math activation system" — the knowledge base is not a closed encyclopedia but a collection of activation anchors.
233
+
234
+ - **Core Principle**: Math Skill does not store mathematics; it activates, routes, and translates mathematics for AI research
235
+ - **Knowledge Gap Protocol**: 6-step procedure for generating temporary knowledge cards when existing anchors don't cover the problem (gap identification → lens fallback → candidate localization → temporary card → design translation → upgrade recommendation)
236
+ - **Domain Extension Indexes**: each of the 7 math domains gains an `index.md` with trigger signals, extended concepts, reference directions, and temporary activation rules
237
+ - **Knowledge Card Repositioning**: every card gains "Routing Extensions" and "Extensible Directions" sections, transforming endpoints into routing nodes
238
+ - **Design Pattern Positioning**: new `design-patterns/overview.en.md` declares the library as a math→AI translation prototype collection
239
+
228
240
  ### v3.0.1 — Token Optimization & Bilingual Completion
229
241
 
230
- - **Emoji cleanup**: removed all emoji characters from skill files; GPU rating markers ✅⚠️❌ replaced with text `[v]`/`[~]`/`[x]`, saving ~1,400 tokens
242
+ - **Emoji cleanup**: removed all emoji characters from skill files; GPU rating markers replaced with text `[v]`/`[~]`/`[x]`, saving ~1,400 tokens
231
243
  - **English distillation files**: added EN translations for all 7 book distillation notes (`references/books/*.en.md`) and `commands/ask.en.md`
232
244
  - **Mixed-language routing**: added 5-rule decision system for code-switched input (technical terms excluded from language detection; sentence frame determines primary language)
233
245
  - **GPU dimension abbreviations**: verbose labels `**Dimension N full-name**` compressed to `**DN**` (D1-D8), defined in `gpu-friendly-math.md`, saving ~800-1,000 tokens
package/README.md CHANGED
@@ -24,13 +24,15 @@ Sophus Lie 打造"屠龙刀"的故事告诉我们:为解微分方程发明的
24
24
 
25
25
  ---
26
26
 
27
+ > Math Skill 不存储数学,它激活数学、路由数学,并把数学翻译成 AI 研究设计。
28
+
27
29
  ## 核心理念
28
30
 
29
31
  当你面对一个 AI 研究问题时,这个系统帮你回答四个问题:
30
32
 
31
33
  1. **该用什么数学思想看?** → 思想透镜
32
- 2. **需要查什么具体数学知识?**知识库
33
- 3. **怎么把数学变成模型设计?** → 设计翻译层
34
+ 2. **应该激活哪些数学结构?**激活锚点 / 临时知识卡
35
+ 3. **怎么把数学变成模型设计?** → 设计翻译原型
34
36
  4. **这个设计是否数学上靠谱、工程上可行?** → 批判器
35
37
 
36
38
  ```
@@ -38,7 +40,7 @@ Sophus Lie 打造"屠龙刀"的故事告诉我们:为解微分方程发明的
38
40
 
39
41
  思想透镜:这个问题该用什么视角看?
40
42
 
41
- 数学知识:这个视角需要哪些具体数学工具?
43
+ 激活锚点:应该激活哪些数学结构?不足时进入知识缺口协议
42
44
 
43
45
  设计翻译:这些工具怎么变成模型结构 / loss / 算子?
44
46
 
@@ -52,7 +54,7 @@ Sophus Lie 打造"屠龙刀"的故事告诉我们:为解微分方程发明的
52
54
  | 层 | 职责 | 目录 | 文件数 |
53
55
  |----|------|------|--------|
54
56
  | **思想透镜** | 诊断问题结构,推荐数学视角 | `lenses/*.md` | 15 |
55
- | **数学知识** | 提供具体数学工具(定义/定理/公式) | `knowledge-base/*/*.md` | 31 |
57
+ | **激活锚点** | 激活高频数学结构,不足时触发知识缺口协议 | `knowledge-base/*/*.md` | 31 |
56
58
  | **设计翻译** | 把数学变成 AI 模块/loss/算子 | `design-patterns/*/*.md` | 22 |
57
59
 
58
60
  辅助层:
@@ -80,7 +82,7 @@ Sophus Lie 打造"屠龙刀"的故事告诉我们:为解微分方程发明的
80
82
  | 概率统计 | `lenses/probabilistic.md` | 量化不确定性、贝叶斯更新 |
81
83
  | 算法 | `lenses/algorithmic.md` | 复杂度、可行性、并行性 |
82
84
 
83
- ### 知识库(按数学领域)
85
+ ### 激活锚点(按数学领域)
84
86
 
85
87
  | 领域 | 知识卡片 |
86
88
  |------|---------|
@@ -225,9 +227,19 @@ math-skill/
225
227
 
226
228
  ## 变更日志
227
229
 
230
+ ### v3.1.0 — 激活锚点与知识缺口协议
231
+
232
+ **定位升级**:从"数学知识库"转为"数学激活系统"——知识库不是封闭百科,而是激活锚点集合。
233
+
234
+ - **核心原则**:Math Skill 不存储数学,它激活数学、路由数学,并把数学翻译成 AI 研究设计
235
+ - **知识缺口协议**:当现有锚点不覆盖时,6 步流程生成临时知识卡(缺口识别→透镜回退→候选定位→临时知识卡→设计翻译→升级建议)
236
+ - **领域扩展索引**:7 个数学领域各增 `index.md`,列出触发信号、扩展概念、参考书方向、临时激活规则
237
+ - **知识卡片重定位**:每张卡片增加"路由扩展"和"可扩展方向",从终点变为路由节点
238
+ - **设计模式定位**:新增 `design-patterns/overview.md`,声明为 math→AI 翻译原型集合
239
+
228
240
  ### v3.0.1 — Token 优化与双语补全
229
241
 
230
- - **Emoji 清理**:移除所有 skill 文件中的 emoji 符号,GPU 评级标记 ✅⚠️❌ 替换为文本 `[v]`/`[~]`/`[x]`,节约 ~1,400 tokens
242
+ - **Emoji 清理**:移除所有 skill 文件中的 emoji 符号,GPU 评级标记替换为文本 `[v]`/`[~]`/`[x]`,节约 ~1,400 tokens
231
243
  - **英文蒸馏稿补全**:7 本书蒸馏稿新增英文翻译(`references/books/*.en.md`),`commands/ask.en.md` 新增英文入口
232
244
  - **混合语言路由**:新增 5 条判定规则,解决中英混杂输入的路由问题(技术词不计入语言判定,按句式主框架判定)
233
245
  - **GPU 维度缩写**:八维标签从 `**维度 N 全称**` 压缩为 `**DN**`(D1-D8),定义于 `gpu-friendly-math.md`,额外节约 ~800-1,000 tokens
@@ -92,7 +92,7 @@ The first 15 dimensions cover the core review angles — assumptions, logic, mod
92
92
  - Does the problem belong to the NP-hard or undecidable class? Are approximation or heuristics needed?
93
93
  - Do the numerical methods converge? Is the precision sufficient?
94
94
 
95
- ### 11. Information Structure Review -> probabilistic lens + `knowledge-base/probability/`
95
+ ### 11. Information Structure Review -> probabilistic lens + `../knowledge-base/probability/`
96
96
 
97
97
  - Is the information structure of the problem clear? Is there redundant or missing information?
98
98
  - Can uncertainty be quantified using information entropy, mutual information, etc.?
@@ -132,22 +132,22 @@ The first 15 dimensions cover the core review angles — assumptions, logic, mod
132
132
  - Were multiple candidate structures enumerated (rather than only one)?
133
133
  - If uncertain about which dimensions to review, first invoke `/ask` to have the activator recommend the 3-5 most suitable review dimensions.
134
134
 
135
- ### 17. GPU-Feasibility Review -> `references/gpu-friendly-math.en.md`
135
+ ### 17. GPU-Feasibility Review -> `../references/gpu-friendly-math.en.md`
136
136
 
137
137
  > **Mandatory** when the deliverable involves algorithm/operator/training/GPU design. Corresponds to the second gate of the "dual-acceptance gate."
138
138
 
139
- - Does the deliverable pass the **eight dimensions** of `references/gpu-friendly-math.en.md`? Tensorization / GEMM-mappability / Complexity (sub-quadratic) / Memory & KV-Cache / Low-precision stability / Parallelism & Communication / Sparse structure / Operator fusion -- rate each as "friendly / retrofittable / unfriendly."
139
+ - Does the deliverable pass the **eight dimensions** of `../references/gpu-friendly-math.en.md`? Tensorization / GEMM-mappability / Complexity (sub-quadratic) / Memory & KV-Cache / Low-precision stability / Parallelism & Communication / Sparse structure / Operator fusion -- rate each as "friendly / retrofittable / unfriendly."
140
140
  - Are there structures that are "mathematically beautiful but not computable"? (Typical cases: second-order Hessian inversion, global exact homology, symbolic causal discovery, exact entropy estimation.) Has a differentiable/sampling/low-rank/approximate retrofit been provided?
141
141
  - Are the inverse transforms and numerical components stable (condition number, ill-conditioning)?
142
142
  - Have memory and communication been assessed (KV-Cache, distributed all-reduce, optimizer state precision)?
143
143
 
144
- ### 18. Modern-Math Activation Review -> `references/books/*`
144
+ ### 18. Modern-Math Activation Review -> `../references/books/*.en.md`
145
145
 
146
146
  > **Mandatory** when the deliverable claims to "activate modern mathematics into algorithms." Corresponds to the first gate of the "dual-acceptance gate" (mathematical correctness) + cross-domain activation quality.
147
147
 
148
148
  - Does the work genuinely transfer modern mathematical structures (algebraic geometry / differential geometry / Lie theory / abstract algebra / matrix analysis / optimization), or does it merely recycle classical calculus and linear algebra?
149
149
  - Are the transferred structures mathematically self-consistent, differentiable (or relaxable to differentiable), and backed by correctness guarantees?
150
- - Were the corresponding `references/books/*.md` distilled notes consulted? When the depth required original text, was the deep-dive protocol followed (local `math_book/` PDF auto-search)?
150
+ - Were the corresponding `../references/books/*.en.md` distilled notes consulted? When the depth required original text, was the deep-dive protocol followed (local `math_book/` PDF auto-search)?
151
151
  - Is the transfer a "cross-domain activation" (the structure already exists; only a cross-domain mapping is missing), or is it a forced transplant (borrowing terminology without borrowing structure)?
152
152
  - Does the deliverable simultaneously pass the **dual-acceptance gate**: mathematically correct **AND** (friendly or retrofittable on the eight dimensions)? Are candidates that fail either criterion eliminated?
153
153
 
@@ -170,7 +170,7 @@ The first 15 dimensions cover the core review angles — assumptions, logic, mod
170
170
 
171
171
  ## Output Format
172
172
 
173
- Reports should follow the structure below. Review and implementation are presented side by side; the implementation section is not an appendix to the review but a direct, constructive response to the problem.
173
+ The structure below is the full-report template, not the default response. For short questions, lead with conclusion + fatal/important issues + fix path + verification. Expand every subsection only for full reviews, paper-style reviews, or multi-candidate designs. Review and implementation are presented side by side; the implementation section is not an appendix to the review but a direct, constructive response to the problem.
174
174
 
175
175
  ```
176
176
  ## Review and Implementation Report
@@ -92,7 +92,7 @@
92
92
  - 问题是否属于NP-hard或不可判定类别?是否需要近似或启发式?
93
93
  - 数值方法是否收敛?精度是否足够?
94
94
 
95
- ### 11. 信息结构审视 / Information Structure Review -> probabilistic(概率统计透镜)+ `knowledge-base/probability/`
95
+ ### 11. 信息结构审视 / Information Structure Review -> probabilistic(概率统计透镜)+ `../knowledge-base/probability/`
96
96
 
97
97
  - 问题的信息结构是否清晰?是否存在冗余或缺失的信息?
98
98
  - 是否可以用信息熵、互信息等量化不确定性?
@@ -132,22 +132,22 @@
132
132
  - 是否枚举了多个候选结构(而非只给一个)?
133
133
  - 若不确定该审视哪些维度,先调用 `/ask` 让激活器推荐最合适的 3–5 个审视维度。
134
134
 
135
- ### 17. GPU 可行性审视 / GPU-Feasibility Review -> `references/gpu-friendly-math.md`
135
+ ### 17. GPU 可行性审视 / GPU-Feasibility Review -> `../references/gpu-friendly-math.md`
136
136
 
137
137
  > 产出涉及算法/算子/训练/GPU 设计时为**强制项**。对应「双验收门」的第二道门。
138
138
 
139
- - 产出是否过 `references/gpu-friendly-math.md` 的**八维**?张量化 / GEMM 可映射 / 复杂度(亚二次)/ 显存与 KV-Cache / 低精度稳定 / 并行与通信 / 稀疏结构 / 算子融合——逐项给「友好/可改造/不友好」。
139
+ - 产出是否过 `../references/gpu-friendly-math.md` 的**八维**?张量化 / GEMM 可映射 / 复杂度(亚二次)/ 显存与 KV-Cache / 低精度稳定 / 并行与通信 / 稀疏结构 / 算子融合——逐项给「友好/可改造/不友好」。
140
140
  - 是否存在「数学美但不可算」的结构?(典型:二阶法 Hessian 求逆、全局精确同调、符号因果发现、精确熵估计)——是否给出了可微/采样/低秩/近似改造?
141
141
  - 逆变换/数值部分是否稳定(条件数、病态)?
142
142
  - 显存与通信是否被评估(KV-Cache、分布式 all-reduce、optimizer state 精度)?
143
143
 
144
- ### 18. 现代数学激活审视 / Modern-Math Activation Review -> `references/books/*`
144
+ ### 18. 现代数学激活审视 / Modern-Math Activation Review -> `../references/books/*`
145
145
 
146
146
  > 产出声称「把现代数学激活进算法」时为**强制项**。对应「双验收门」的第一道门(数学正确)+ 跨域激活质量。
147
147
 
148
148
  - 是否真的迁移了现代数学结构(代数几何/微分几何/李理论/抽象代数/矩阵分析/最优化),还是只用了经典微积分/线代打转?
149
149
  - 迁移的结构在数学上是否自洽、可微(或可松弛为可微)、有正确性保证?
150
- - 是否查阅了对应 `references/books/*.md` 蒸馏稿?深度需要原文时是否走了深挖回查协议(本机 `math_book/` PDF 自动搜索)?
150
+ - 是否查阅了对应 `../references/books/*.md` 蒸馏稿?深度需要原文时是否走了深挖回查协议(本机 `math_book/` PDF 自动搜索)?
151
151
  - 迁移是否是「跨领域激活」(结构本就在那里,只差一次跨域映射),还是生搬硬套(只借名词不借结构)?
152
152
  - 产出是否同时通过**双验收门**:数学正确 **AND**(八维友好或可改造)?未同时通过的候选是否被剔除?
153
153
 
@@ -170,7 +170,7 @@
170
170
 
171
171
  ## 输出格式
172
172
 
173
- 建议按以下结构进行报告。审视与实现并列呈现,实现部分不是审视的附属,而是对问题的正面回应。
173
+ 以下结构是完整报告模板,不是默认输出。短问题优先给“结论 + 致命/重要问题 + 修法 + 验证”,只有在用户要求完整审查、论文级审稿或多候选设计时才展开所有小节。审视与实现并列呈现,实现部分不是审视的附属,而是对问题的正面回应。
174
174
 
175
175
  ```
176
176
  ## 审视与实现报告
@@ -4,7 +4,12 @@ description: |
4
4
  Math Research OS entry: auto-diagnose user intent, route to thinking lenses, math knowledge base, or design translation layer.
5
5
  ---
6
6
 
7
- Read and follow `../skills/math-research-activator/SKILL.en.md`.
7
+ ## Language Routing (inline)
8
+
9
+ Determine primary language: judge by sentence frame, verbs, mood particles. AI/math/engineering terms (attention, loss, routing, etc.) do not count as language signals. Code, paths, formulas do not count. When CN/EN ratio is close, follow the previous turn's language; default to Chinese if no context. Explicit "in English/in Chinese" takes priority.
10
+
11
+ - Chinese primary → load `../skills/math-research-activator/SKILL.md`
12
+ - English primary → load `../skills/math-research-activator/SKILL.en.md`
8
13
 
9
14
  Current question:
10
15
  $ARGUMENTS
package/commands/ask.md CHANGED
@@ -5,7 +5,12 @@ description: |
5
5
  English: Math Research OS entry: auto-diagnose user intent, route to thinking lenses, math knowledge base, or design translation layer.
6
6
  ---
7
7
 
8
- `../skills/math-research-activator/SKILL.md` 中的语言路由与混合输入规则判定主语言。英文主语言 → 读取 `../skills/math-research-activator/SKILL.en.md`;中文主语言 → 读取 `../skills/math-research-activator/SKILL.md`。
8
+ ## 语言路由(内联)
9
+
10
+ 判定主语言:看句式、动词、语气词的主框架。AI/数学/工程术语(attention、loss、routing 等)不计入语言判定。代码、路径、公式不计入。中英比例接近时沿用上一轮语言,无上下文默认中文。显式"用英文/用中文"优先。
11
+
12
+ - 中文主语言 → 读取 `../skills/math-research-activator/SKILL.md`
13
+ - 英文主语言 → 读取 `../skills/math-research-activator/SKILL.en.md`
9
14
 
10
15
  当前问题:
11
16
  $ARGUMENTS
@@ -6,12 +6,12 @@ When the input possesses an **explicit symmetry group $G$ action** (rotation, tr
6
6
 
7
7
  ## Mathematical Inspiration
8
8
  - Lenses: [symmetry, categorical (unified framework for group actions)]
9
- - Knowledge: [`../../knowledge-base/probability/concentration-inequality.md` (sample efficiency gains under equivariant constraints -- data equivalence along orbits), `../../knowledge-base/probability/entropy.md` (equivariant constraints reduce output distribution entropy, yielding stronger inductive bias)]
9
+ - Knowledge: [`../../knowledge-base/probability/concentration-inequality.en.md` (sample efficiency gains under equivariant constraints -- data equivalence along orbits), `../../knowledge-base/probability/entropy.en.md` (equivariant constraints reduce output distribution entropy, yielding stronger inductive bias)]
10
10
 
11
11
  ## Required Mathematical Knowledge
12
12
  - **Group Representation Theory Basics**: Linear representation of a group $G$, $\rho: G \to GL(V)$, and irreducible representation decomposition
13
13
  - **Equivariant Map Definition**: $f(g \cdot x) = \rho_{\text{out}}(g) \cdot f(x)$ for all $g \in G$
14
- - **Orbit-Stabilizer Theorem** (see `references/books/abstract-algebra.md` Ch.5): $|orbit| = |G|/|stab|$, giving the parameter sharing multiplier
14
+ - **Orbit-Stabilizer Theorem** (see `../../references/books/abstract-algebra.en.md` Ch.5): $|orbit| = |G|/|stab|$, giving the parameter sharing multiplier
15
15
  - **Schur's Lemma**: An equivariant linear map between irreducible representations is either zero or a scalar multiple
16
16
 
17
17
  ## AI Module Form
@@ -64,6 +64,12 @@ output = mean(softmax((rho(g)@X@W_q) @ (rho(g)@X@W_k).T/sqrt(d)) @ (rho(g)@X@W_v
64
64
  - **D7**: Permutation $\rho(g)$ is extremely sparse and can be encoded as gather indices
65
65
  - **D8**: Group action + linear duality can be fused into a single batched GEMM
66
66
 
67
+ **Quantitative assessment example** (E(3) equivariant, |G|=24 rotation group, d=64, n=512):
68
+ - D3: |G|x standard attention FLOPs = 24 · 2·512²·64 ≈ 805M (vs standard 33.6M)
69
+ - D4: Requires storing |G|=24 copies of intermediate features, 24 · 512 · 64 · 2B ≈ 1.5MB extra memory
70
+ - D6: 24 group elements parallelizable along the batch dimension, ideal speedup 24x
71
+ - D8: ρ(g)·X·W_q three-step fusion into a single batched GEMM
72
+
67
73
  ## Paper Phrasing
68
74
  "We propose an equivariant attention mechanism that constrains attention weights to be group invariants and attention outputs to be group equivariants, directly encoding the inductive bias of symmetry group $G$ into the model architecture without additional data augmentation, achieving a $|G|/|stab|$-fold improvement in parameter efficiency."
69
75
 
@@ -11,7 +11,7 @@
11
11
  ## 需要的数学知识
12
12
  - **群表示论基础**:群 $G$ 的线性表示 $\rho: G \to GL(V)$,不可约表示分解
13
13
  - **等变映射定义**:$f(g \cdot x) = \rho_{\text{out}}(g) \cdot f(x)$,对所有 $g \in G$
14
- - **轨道-稳定子定理**(参见 `references/books/abstract-algebra.md` Ch.5):$|orbit| = |G|/|stab|$,参数共享倍率
14
+ - **轨道-稳定子定理**(参见 `../../references/books/abstract-algebra.md` Ch.5):$|orbit| = |G|/|stab|$,参数共享倍率
15
15
  - **Schur 引理**:不可约表示间的等变线性映射要么为零要么为标量乘
16
16
 
17
17
  ## AI 模块形式
@@ -64,6 +64,12 @@ output = mean(softmax((rho(g)@X@W_q) @ (rho(g)@X@W_k).T/sqrt(d)) @ (rho(g)@X@W_v
64
64
  - **D7[~]**:置换 $\rho(g)$ 极度稀疏,可编码为 gather 索引
65
65
  - **D8[v]**:群作用 + 线性变换可融合为单次 batched GEMM
66
66
 
67
+ **量化评估示例**(E(3) 等变, |G|=24 旋转群, d=64, n=512):
68
+ - D3: |G|× 标准 attention FLOPs = 24 · 2·512²·64 ≈ 805M(vs 标准 33.6M)
69
+ - D4: 需存储 |G|=24 份中间特征,24 · 512 · 64 · 2B ≈ 1.5MB 额外显存
70
+ - D6: 24 个群元素沿 batch 维并行,理想加速比 24x
71
+ - D8: ρ(g)·X·W_q 三步融合为单次 batched GEMM
72
+
67
73
  ## 论文表述方式
68
74
  "我们提出等变注意力机制,通过将注意力权重约束为群不变量、注意力输出约束为群等变量,在不增加数据增强的情况下将对称群 $G$ 的归纳偏置直接编码进模型结构,参数效率提升 $|G|/|stab|$ 倍。"
69
75
 
@@ -6,7 +6,7 @@ When **known geometric relationships** exist between tokens/keys (spatial distan
6
6
 
7
7
  ## Mathematical Inspiration
8
8
  - Lenses: [symmetry (metric invariance), duality (coordinate-system-independent representation)]
9
- - Knowledge: [`../../knowledge-base/information-geometry/fisher-metric.md` (geometric metrics on distribution spaces), `../../knowledge-base/probability/concentration-inequality.md` (concentration behavior under geometric constraints)]
9
+ - Knowledge: [`../../knowledge-base/information-geometry/fisher-metric.en.md` (geometric metrics on distribution spaces), `../../knowledge-base/probability/concentration-inequality.en.md` (concentration behavior under geometric constraints)]
10
10
 
11
11
  ## Required Mathematical Knowledge
12
12
  - **Metric Spaces and Distance Functions**: Euclidean distance, geodesic distance, tree distance, Wasserstein distance
@@ -66,7 +66,7 @@ def manifold_attention(Q, K, V, manifold):
66
66
  - **D8**: Geometric bias can be fused into FlashAttention's online softmax loop (added after $QK^T$, before softmax)
67
67
 
68
68
  ## Paper Phrasing
69
- "We propose geometry-aware attention, which explicitly injects learnable geometric distance bias terms into attention scores, enabling the model to naturally respect the metric structure of the input space. This achieves exponential decay of attention to distant tokens without increasing parameter count, while maintaining compatibility with FlashAttention."
69
+ "We propose geometry-aware attention, which explicitly injects geometric distance bias terms into attention scores, enabling the model to naturally respect the metric structure of the input space. This achieves exponential decay of attention to distant tokens with only a small number of additional geometric bias parameters (zero for fixed bias variants such as ALiBi), while maintaining compatibility with FlashAttention."
70
70
 
71
71
  ## Risks
72
72
  - **Geometric Prior Conflicting with Data**: If geometric distance is inconsistent with semantic relevance (e.g., distant but semantically related tokens in text), strong geometric bias will impair model expressiveness. The bias should be learnable and overridable by content-based attention.
@@ -65,7 +65,7 @@ def manifold_attention(Q, K, V, manifold):
65
65
  - **D8[v]**:几何偏置可融入 FlashAttention 的 online softmax 循环中(加在 $QK^T$ 之后、softmax 之前)
66
66
 
67
67
  ## 论文表述方式
68
- "我们提出几何感知注意力,通过在注意力分数中显式注入可学习的几何距离偏置项,使模型天然尊重输入空间的度量结构,在不增加参数量的情况下将远距离 token 的注意力指数衰减,同时保持与 FlashAttention 的兼容性。"
68
+ "我们提出几何感知注意力,通过在注意力分数中显式注入几何距离偏置项,使模型天然尊重输入空间的度量结构,在仅增加少量几何偏置参数(固定偏置如 ALiBi 则零额外参数)的情况下将远距离 token 的注意力指数衰减,同时保持与 FlashAttention 的兼容性。"
69
69
 
70
70
  ## 风险
71
71
  - **几何先验与数据冲突**:若几何距离与语义相关性不一致(如文本中远距离但语义相关的 token),强几何偏置会伤害模型表达。需让偏置可学习且可被内容注意力覆盖。
@@ -6,7 +6,7 @@ When the attention mechanism needs to **selectively transmit useful information
6
6
 
7
7
  ## Mathematical Inspiration
8
8
  - Lenses: [categorical (information-theoretic framework unifying attention design), variational (constrained variational and Lagrangian duality)]
9
- - Knowledge: [`../../knowledge-base/probability/information-bottleneck.md` (IB objective and variational lower bound), `../../knowledge-base/probability/kl-divergence.md` (implementation of KL regularization), `../../knowledge-base/probability/entropy.md` (mutual information estimation)]
9
+ - Knowledge: [`../../knowledge-base/probability/information-bottleneck.en.md` (IB objective and variational lower bound), `../../knowledge-base/probability/kl-divergence.en.md` (implementation of KL regularization), `../../knowledge-base/probability/entropy.en.md` (mutual information estimation)]
10
10
 
11
11
  ## Required Mathematical Knowledge
12
12
  - **Information Bottleneck Objective**: $\min I(X;Z) - \beta I(Z;Y)$, balancing compression and prediction
@@ -19,27 +19,47 @@ When the attention mechanism needs to **selectively transmit useful information
19
19
 
20
20
  **Scheme A: KL-Regularized Attention (Simplest IB Attention)**:
21
21
  ```python
22
- # KL divergence between attention distribution q(z|x) and uniform prior as IB regularizer
22
+ # Note the semantic direction of KL:
23
+ # KL(attn || uniform) = log(n) - H(attn)
24
+ # Minimizing +beta * KL(attn || uniform) = maximizing H(attn) → pushes toward uniform (max entropy / max compression)
25
+ # This does NOT induce sparsity by itself! Sparsity emerges from the tension with task_loss.
26
+ # For explicit sparsity induction, use an entropy penalty +beta * H(attn) (minimize entropy).
27
+
23
28
  scores = (Q @ K.T) / sqrt(d)
24
29
  attn = softmax(scores)
25
30
  uniform_prior = ones_like(attn) / n
26
- kl_reg = (attn * (log(attn + eps) - log(uniform_prior))).sum(dim=-1).mean()
27
- loss = task_loss + beta * kl_reg
31
+
32
+ # Correct IB compression term: KL(q(z|x) || p(z)), where p(z) is a fixed prior
33
+ # Minimizing this term → compresses information (pushes toward prior); tension with task_loss yields useful attention
34
+ kl_compression = (attn * (log(attn + eps) - log(uniform_prior))).sum(dim=-1).mean()
35
+ # = log(n) - H(attn)
36
+
37
+ # IB objective: min task_loss + beta * I(X;Z), where I(X;Z) ≈ KL(attn || prior)
38
+ loss_ib = task_loss + beta * kl_compression
39
+ # Note: this term alone pushes toward uniform; sparsity arises from the counter-pull of task_loss
40
+
41
+ # Alternative: explicit sparsity induction (not IB compression, but entropy penalty)
42
+ entropy = -(attn * log(attn + eps)).sum(dim=-1).mean()
43
+ loss_sparse = task_loss + beta * entropy # minimize entropy → concentrated attention → implicit Top-K
44
+
28
45
  output = attn @ V
29
46
  ```
30
47
 
31
48
  **Scheme B: Variational Information Bottleneck Attention (VIB-Attention)**:
32
49
  ```python
33
- # Introduce stochastic bottleneck Z ~ q(Z|attention) to limit information throughput
50
+ # Introduce a continuous stochastic bottleneck Z ~ q(Z|context) after value aggregation
34
51
  scores = (Q @ K.T) / sqrt(d)
35
52
  attn = softmax(scores)
36
- mu_z, log_var_z = attn, linear(attn) # mean and learnable variance
37
- z = softmax(mu_z + exp(0.5 * log_var_z) * randn_like(mu_z)) # reparameterization + softmax
38
- kl = 0.5 * (mu_z^2 + exp(log_var_z) - log_var_z - 1).sum(-1).mean() # KL vs prior
39
- output = z @ V
53
+ context = attn @ V
54
+ mu_z, log_var_z = linear_mu(context), linear_logvar(context)
55
+ z = mu_z + exp(0.5 * log_var_z) * randn_like(mu_z) # Gaussian reparameterization
56
+ kl = 0.5 * (mu_z^2 + exp(log_var_z) - log_var_z - 1).sum(-1).mean() # KL[q(z|context)||N(0,I)]
57
+ output = linear_out(z)
40
58
  loss = task_loss + beta * kl
41
59
  ```
42
60
 
61
+ If the bottleneck is applied directly on the attention simplex (e.g., noisy logits followed by softmax), the random variable is logistic-normal / Concrete-like. The closed-form Gaussian KL above no longer applies; use Monte Carlo KL, a Concrete KL approximation, or place the Gaussian KL on pre-softmax logits.
62
+
43
63
  **Scheme C: Mutual Information Maximization Attention (DIM Style)**:
44
64
  ```python
45
65
  # Directly maximize I(Z;Y) via InfoNCE, with KL constraining I(X;Z)
@@ -50,7 +70,7 @@ loss = -info_nce + beta * kl_bottleneck
50
70
  ```
51
71
 
52
72
  ## Implementable Architectures
53
- - **IB-Sparse Attention**: KL regularization serves as a soft constraint on attention sparsity -- larger KL relative to uniform prior leads to more concentrated attention, yielding implicit Top-K selection
73
+ - **IB-Sparse Attention**: The IB compression term KL(attn || uniform) by itself pushes toward uniform (maximum entropy), but its tension with task_loss forces the attention to balance between "compressing all information" and "selectively transmitting useful information," implicitly producing non-uniform attention. For **explicit** sparsity induction (Top-K selection), use an entropy penalty `+beta * H(attn)` (minimize attention entropy → concentration), rather than relying on the IB compression term alone
54
74
  - **IB Interpretation of Dropout**: Dropout is a form of stochastic information bottleneck -- randomly blocking information channels forces the model to learn robust representations. The dropout rate corresponds to the $\beta$ parameter
55
75
  - **Multi-Head Information Allocation**: Different heads learn different information bottlenecks (different $\beta$); some heads transmit global information, others only local information
56
76
 
@@ -61,11 +81,11 @@ loss = -info_nce + beta * kl_bottleneck
61
81
  - **D4**: VIB requires additional $\mu_z$ and $\log\sigma_z$, approximately doubling attention weight memory
62
82
  - **D5**: log/exp in KL computations are stable under bf16 (standard log-softmax tricks)
63
83
  - **D6**: Regularization can be computed in parallel with forward propagation, introducing no serial dependencies
64
- - **D7**: KL regularization implicitly induces attention sparsity, amenable to block-sparse acceleration
84
+ - **D7[~]**: KL regularization by itself does not induce sparsity (pushes toward uniform distribution); for sparsity, use an entropy penalty +beta * H(attn), which then enables block-sparse acceleration
65
85
  - **D8**: KL can be fused into the softmax kernel (FusedSoftmaxKL)
66
86
 
67
87
  ## Paper Phrasing
68
- "We propose information bottleneck attention, which models attention as an information bottleneck variational problem. By maximizing the mutual information between output and target while minimizing redundant information transmission from the input, it achieves theoretically optimal information selection and demonstrates enhanced sparsity and interpretability in experiments."
88
+ "We propose information bottleneck attention, which models attention as an information bottleneck optimization problem. By maximizing the mutual information between output and target while constraining redundant information transmission from the input, the IB compression term by itself pushes toward a uniform distribution (maximum entropy), and its tension with the task loss produces non-uniform attention; explicit sparsity induction requires an additional entropy penalty term."
69
89
 
70
90
  ## Risks
71
91
  - **High Variance of Mutual Information Estimators**: The MINE/NWJ/InfoNCE estimators in Scheme C exhibit high variance in high-dimensional spaces, potentially causing training instability. It is recommended to first validate the basic effect of IB attention with Scheme A (KL regularization) before attempting the full IB objective.
@@ -19,27 +19,47 @@
19
19
 
20
20
  **方案 A:KL 正则化注意力(最简 IB 注意力)**:
21
21
  ```python
22
- # 注意力分布 q(z|x) 与均匀先验的 KL 散度作为 IB 正则
22
+ # 注意 KL 方向的语义:
23
+ # KL(attn || uniform) = log(n) - H(attn)
24
+ # 最小化 +beta * KL(attn || uniform) = 最大化 H(attn) → 推向均匀分布(最大熵/最大压缩)
25
+ # 这本身不诱导稀疏性!稀疏性来自压缩项与 task_loss 的张力。
26
+ # 若需要显式诱导稀疏注意力,应使用熵惩罚 +beta * H(attn)(最小化熵)。
27
+
23
28
  scores = (Q @ K.T) / sqrt(d)
24
29
  attn = softmax(scores)
25
30
  uniform_prior = ones_like(attn) / n
26
- kl_reg = (attn * (log(attn + eps) - log(uniform_prior))).sum(dim=-1).mean()
27
- loss = task_loss + beta * kl_reg
31
+
32
+ # 正确的 IB 压缩项:KL(q(z|x) || p(z)),p(z) 为固定先验
33
+ # 最小化此项 → 压缩信息(推向先验),与 task_loss 的张力产生有用注意力
34
+ kl_compression = (attn * (log(attn + eps) - log(uniform_prior))).sum(dim=-1).mean()
35
+ # = log(n) - H(attn)
36
+
37
+ # IB 目标:min task_loss + beta * I(X;Z),其中 I(X;Z) ≈ KL(attn || prior)
38
+ loss_ib = task_loss + beta * kl_compression
39
+ # 注意:此项单独作用会推向均匀;稀疏性来自 task_loss 的反向拉力
40
+
41
+ # 替代方案:显式稀疏性诱导(非 IB 压缩,而是熵惩罚)
42
+ entropy = -(attn * log(attn + eps)).sum(dim=-1).mean()
43
+ loss_sparse = task_loss + beta * entropy # 最小化熵 → 注意力集中 → 隐式 Top-K
44
+
28
45
  output = attn @ V
29
46
  ```
30
47
 
31
48
  **方案 B:变分信息瓶颈注意力(VIB-Attention)**:
32
49
  ```python
33
- # 引入随机瓶颈 Z ~ q(Z|attention),限制信息通过量
50
+ # 引入随机连续瓶颈 Z ~ q(Z|context),限制 value 聚合后的信息通过量
34
51
  scores = (Q @ K.T) / sqrt(d)
35
52
  attn = softmax(scores)
36
- mu_z, log_var_z = attn, linear(attn) # 均值与可学习方差
37
- z = softmax(mu_z + exp(0.5 * log_var_z) * randn_like(mu_z)) # 重参数化 + softmax
38
- kl = 0.5 * (mu_z^2 + exp(log_var_z) - log_var_z - 1).sum(-1).mean() # KL vs 先验
39
- output = z @ V
53
+ context = attn @ V
54
+ mu_z, log_var_z = linear_mu(context), linear_logvar(context)
55
+ z = mu_z + exp(0.5 * log_var_z) * randn_like(mu_z) # 高斯重参数化
56
+ kl = 0.5 * (mu_z^2 + exp(log_var_z) - log_var_z - 1).sum(-1).mean() # KL[q(z|context)||N(0,I)]
57
+ output = linear_out(z)
40
58
  loss = task_loss + beta * kl
41
59
  ```
42
60
 
61
+ 若瓶颈直接作用在 attention simplex 上(如对 logits 加噪后 softmax),变量分布是 logistic-normal / Concrete 类,不能再使用普通高斯到标准正态的闭式 KL;应使用 Monte Carlo KL、Concrete KL 近似,或把 KL 放在 softmax 前的 logits 高斯变量上。
62
+
43
63
  **方案 C:互信息最大化注意力(DIM 风格)**:
44
64
  ```python
45
65
  # 用 InfoNCE 直接最大化 I(Z;Y),配合 KL 约束 I(X;Z)
@@ -50,7 +70,7 @@ loss = -info_nce + beta * kl_bottleneck
50
70
  ```
51
71
 
52
72
  ## 可实现结构
53
- - **IB-Sparse Attention**:将 KL 正则化为注意力稀疏性的软约束——KL 对均匀先越大 注意力越集中 隐式 Top-K 选择
73
+ - **IB-Sparse Attention**:IB 压缩项 KL(attn || uniform) 本身推向均匀分布(最大熵),但与 task_loss 的张力迫使注意力在"压缩所有信息"与"选择性传递有用信息"之间取舍,从而隐式产生非均匀注意力。若要**显式**诱导稀疏(Top-K 选择),应使用熵惩罚 `+beta * H(attn)`(最小化注意力熵 → 集中化),而非依赖 IB 压缩项
54
74
  - **Dropout 的 IB 解释**:Dropout 是一种随机信息瓶颈——随机阻断部分信息通道,迫使模型学习鲁棒表示。Dropout rate 对应 $\beta$ 参数
55
75
  - **Multi-Head 信息分配**:不同 head 学习不同的信息瓶颈(不同 $\beta$),有的 head 传递全局信息,有的只传递局部信息
56
76
 
@@ -61,12 +81,12 @@ loss = -info_nce + beta * kl_bottleneck
61
81
  - **D4[~]**:VIB 需额外 $\mu_z$ 和 $\log\sigma_z$,约 2x 注意力权重显存
62
82
  - **D5[v]**:KL 中 log/exp 在 bf16 下稳定(标准 log-softmax 技巧)
63
83
  - **D6[v]**:正则项可与前向传播并行,不引入串行依赖
64
- - **D7[v]**:KL 正则隐式诱导注意力稀疏性,可利用 block-sparse 加速
84
+ - **D7[~]**:KL 正则本身不诱导稀疏性(推向均匀分布);若需稀疏,应改用熵惩罚 +beta * H(attn),此时可 block-sparse 加速
65
85
  - **D8[v]**:KL 可融入 softmax kernel(FusedSoftmaxKL)
66
86
 
67
87
  ## 论文表述方式
68
- "我们提出信息瓶颈注意力机制,通过将注意力建模为信息瓶颈优化问题,在最大化输出与目标的互信息的同时最小化输入信息的冗余传递,实现理论上最优的信息选择,并在实验中展现出更强的稀疏性和可解释性。"
88
+ "我们提出信息瓶颈注意力机制,通过将注意力建模为信息瓶颈优化问题,在最大化输出与目标的互信息的同时约束输入信息的冗余传递。IB 压缩项本身推向均匀分布(最大熵),与任务损失的张力产生非均匀注意力;若要显式诱导稀疏性,需额外使用熵惩罚项。"
69
89
 
70
90
  ## 风险
71
91
  - **互信息估计的方差问题**:方案 C 中的 MINE/NWJ/InfoNCE 估计器在高维空间中方差大,可能导致训练不稳定。建议先用方案 A(KL 正则)验证 IB 注意力的基本效果,再尝试完整 IB 目标。
72
- - **$\beta$ 调参困难**:$\beta$ 控制压缩-预测权衡,不同任务最优 $\beta$ 差异大。$\beta$ 过小退化为标准注意力,$\beta$ 过大导致欠拟合。建议自适应 $\beta$ 调度或信息平面监控。
92
+ - **$\beta$ 调参困难**:$\beta$ 控制压缩-预测权衡,不同任务最优 $\beta$ 差异大。$\beta$ 过小退化为标准注意力,$\beta$ 过大导致欠拟合。建议自适应 $\beta$ 调度或信息平面监控。
@@ -6,7 +6,7 @@ When the token/key space dimensionality is too high, the standard attention $Q K
6
6
 
7
7
  ## Mathematical Inspiration
8
8
  - Lenses: [projection, spectral, probabilistic]
9
- - Knowledge: [`../../knowledge-base/probability/concentration-inequality.md` (high-dimensional concentration inequalities provide theoretical explanation for attention collapse), `../../knowledge-base/probability/entropy.md` (entropy of attention distributions as a quality metric)]
9
+ - Knowledge: [`../../knowledge-base/probability/concentration-inequality.en.md` (high-dimensional concentration inequalities provide theoretical explanation for attention collapse), `../../knowledge-base/probability/entropy.en.md` (entropy of attention distributions as a quality metric)]
10
10
 
11
11
  ## Required Mathematical Knowledge
12
12
  - **Johnson-Lindenstrauss Lemma**: High-dimensional point sets can be projected onto an $O(\log n / \epsilon^2)$-dimensional subspace while approximately preserving distances
@@ -31,7 +31,7 @@ scores = (Q @ P_Q) @ (K @ P_K).T / sqrt(r)
31
31
  attn = softmax(scores) @ V
32
32
  ```
33
33
 
34
- 2. **Random Fixed Projection** (guaranteed by the JL Lemma):
34
+ 2. **Random Fixed Projection** (distance-preservation bound when JL conditions hold):
35
35
  ```
36
36
  P = random_gaussian(d, r) / sqrt(r) # fixed, not trained
37
37
  scores = (Q @ P) @ (K @ P).T / sqrt(r)
@@ -61,7 +61,7 @@ scores = (Q @ eigenvecs) @ (K @ eigenvecs).T / sqrt(r)
61
61
  - **D8[~] Retrofittable, needs kernel-level validation**: Projection may be integrated into a FlashAttention-style kernel, but requires kernel-level verification
62
62
 
63
63
  ## Paper Phrasing
64
- "We decompose attention computation into two steps -- low-dimensional subspace projection and projected-space attention -- achieving a $d/r$-fold Key-cache compression (full KV-Cache compression requires separate V compression/reconstruction) while preserving attention quality and guaranteeing Johnson-Lindenstrauss distance preservation."
64
+ "We decompose attention computation into low-dimensional subspace projection and projected-space attention to reduce Key dimensionality; V-cache must be handled separately. With an independent random projection and the sample-size / target-dimension conditions of the Johnson-Lindenstrauss lemma, Euclidean distances of the projected objects can be approximately preserved. This does not automatically guarantee softmax-attention quality, so attention/output error and task metrics must be reported."
65
65
 
66
66
  ## Risks
67
67
  - **Projection Direction Degeneracy**: Learnable projections may collapse onto a few directions (deterioration of the condition number of $P^T P$), causing attention distributions to degenerate. Orthogonal regularization $\|P^T P - I\|_F^2$ is required.