22 / 90

第 22 天:向量、点积与作为线性映射的矩阵

从几何与数值两个角度学习向量与矩阵:线性组合、点积、矩阵-向量乘积;把每个对象与模型的权重矩阵和嵌入表联系起来。每项活动都在 480 分钟台账中记录预测、观察、复习与恢复。

数学与算法基础 480 活跃分钟(8 小时专注学习)
01 120 分钟

向量:箭头、数列与嵌入

仅在记录预测与观察证据后才可使用协助。

前置要求

完成第 21 天复习;如有缺失概念,使用列出的恢复链接。

学习目标

把向量同时表示为平面上的箭头和有序数列;逐分量计算加法、数乘与线性组合,并把词元嵌入与 d 维向量联系起来。

操作指引

向量 v = (v1, v2, ..., vd) 既是 d 维空间中的箭头,也是一行数字。加法与数乘按分量进行。线性组合 a*v + b*w 把两个向量混合;张成空间(span)是所有可由这种混合到达的点。在语言模型中,每个词元 id 从 shape 为 V x d 的嵌入表 E 中取出一行,该行就是 R^d 中的一个向量。

自主演练与记录

设 v = (1, 2),w = (3, -1)。计算前先预测:(a) v + w;(b) 2*v;(c) 线性组合 2*v - w。然后用手算和代码验证。

独立掌握标准

你的预测表与每个计算分量一致,能描述 v + w 的平行四边形几何,并能用一句话说明嵌入表的行为什么是向量。

权威源资源与权利证明

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Essence of Linear Algebra

作者 / 机构: Grant Sanderson (3Blue1Brown) | 原始出处链接 ↗

对应章节 / 时间戳: Chapters 1-2: Vectors and linear combinations, span and basis vectors

验证版本与日期: 2016-2023 (Verified: 2026-10-30)

入选理由:

Unequaled geometric and visual intuition for vectors, linear transformations, matrix multiplication, and inverses before tensor operations.

来源前置条件:

High-school coordinate geometry

安全回退方案(离线弹性):

Geometric explanations, worked formulas, and coordinate exercises are fully provided as original lesson text.

对比候选资源与选型分析 (2)
MIT OCW 18.06 Linear Algebra (Prof. Gilbert Strang) ↗ compared_alternative [CC BY-NC-SA 4.0]

Established textbook/lecture approach, strong mathematical rigor alongside 3Blue1Brown visual intuition.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Theoretical determinant-free proof structure is mathematically elegant but less aligned with computational tensor engineering.

linking CC BY-NC-SA 4.0 noncommercial share-alike

18.06 Linear Algebra (Prof. Gilbert Strang)

作者 / 机构: MIT OpenCourseWare (Prof. Gilbert Strang) | 原始出处链接 ↗

对应章节 / 时间戳: Lecture 1: The geometry of linear equations (row and column pictures)

验证版本与日期: Spring 2010 (Verified: 2026-10-30)

入选理由:

Established row-picture and column-picture treatment of linear systems, matrix products, and invertibility; rigorous complement to the 3Blue1Brown visual series.

来源前置条件:

High-school algebra and coordinate geometry

安全回退方案(离线弹性):

All row/column-picture derivations and worked examples are written as original lesson text and run offline.

对比候选资源与选型分析 (3)
3Blue1Brown: Essence of Linear Algebra ↗ compared_selected_for_days_22_24 [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Selected as co-primary: geometric visualizations paired with Strang's algebraic rigor.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Determinant-free theoretical treatment is elegant but further from the computational shape accounting required here.

Immersive Linear Algebra (online interactive book) ↗ compared_rejected_for_days_22_24 [Free online (site terms; no OSI/CC license declared)]

Interactive figures are attractive, but the absence of a declared open license makes rights disposition unclear; kept out of the resource set.

02 120 分钟

点积:对齐、投影与注意力分数

独立练习:先记录预测再核对结果;记录证据后才可使用协助。

前置要求

完成上一活动;如受阻,使用列出的恢复链接。

学习目标

计算点积 u.v = sum_i u_i*v_i,把它解释为度量两个向量对齐程度的带尺度投影,并认出它就是注意力中的查询-键分数。

操作指引

把对应分量相乘再求和。几何上 u.v = |u| |v| cos(theta)。对非零向量,符号给出夹角类别:正值为锐角,零为直角(正交),负值为钝角。点积的大小还随两个模长缩放,所以较大的正值本身并不表示同向——方向相似度要看归一化后的余弦。零向量没有定义的角度。注意力分数正是模型权重输出中查询行与键行的点积。

自主演练与记录

设 u = (2, 1, 0),v = (1, 3, 4)。预测:(a) u.v;(b) cos(theta) = u.v / (|u| |v|);(c) 对查询 q = (1, 0, 1) 与键 k1 = (1, 0, 1)、k2 = (0, 1, 0),哪个注意力分数 q.k 更大?

独立掌握标准

无协助下复现全部三个数值结果,解释正交对为何得 0,并指出点积在注意力分数与余弦相似度中的出现位置。

权威源资源与权利证明

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Essence of Linear Algebra

作者 / 机构: Grant Sanderson (3Blue1Brown) | 原始出处链接 ↗

对应章节 / 时间戳: Chapter 7 (Dot products and duality) and Chapter 1 vector arithmetic

验证版本与日期: 2016-2023 (Verified: 2026-10-30)

入选理由:

Unequaled geometric and visual intuition for vectors, linear transformations, matrix multiplication, and inverses before tensor operations.

来源前置条件:

High-school coordinate geometry

安全回退方案(离线弹性):

Geometric explanations, worked formulas, and coordinate exercises are fully provided as original lesson text.

对比候选资源与选型分析 (2)
MIT OCW 18.06 Linear Algebra (Prof. Gilbert Strang) ↗ compared_alternative [CC BY-NC-SA 4.0]

Established textbook/lecture approach, strong mathematical rigor alongside 3Blue1Brown visual intuition.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Theoretical determinant-free proof structure is mathematically elegant but less aligned with computational tensor engineering.

linking CC BY-NC-SA 4.0 noncommercial share-alike

18.06 Linear Algebra (Prof. Gilbert Strang)

作者 / 机构: MIT OpenCourseWare (Prof. Gilbert Strang) | 原始出处链接 ↗

对应章节 / 时间戳: Lecture 3: multiplication as row-column dot products

验证版本与日期: Spring 2010 (Verified: 2026-10-30)

入选理由:

Established row-picture and column-picture treatment of linear systems, matrix products, and invertibility; rigorous complement to the 3Blue1Brown visual series.

来源前置条件:

High-school algebra and coordinate geometry

安全回退方案(离线弹性):

All row/column-picture derivations and worked examples are written as original lesson text and run offline.

对比候选资源与选型分析 (3)
3Blue1Brown: Essence of Linear Algebra ↗ compared_selected_for_days_22_24 [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Selected as co-primary: geometric visualizations paired with Strang's algebraic rigor.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Determinant-free theoretical treatment is elegant but further from the computational shape accounting required here.

Immersive Linear Algebra (online interactive book) ↗ compared_rejected_for_days_22_24 [Free online (site terms; no OSI/CC license declared)]

Interactive figures are attractive, but the absence of a declared open license makes rights disposition unclear; kept out of the resource set.

03 120 分钟

矩阵是空间的线性变换

仅在记录预测与观察证据后才可使用协助。

前置要求

完成上一活动;如受阻,使用列出的恢复链接。

学习目标

用两种方式——行-点积视角与列视角——把矩阵作用于向量,并预测反射、旋转和一般权重矩阵的几何效果。

操作指引

m x d 矩阵乘 d 维向量得到 m 维向量。行视角:每个输出分量是矩阵行与输入的点积。列视角:A*x = x1*col1 + x2*col2 + ...,即矩阵列的线性组合。shape 为 d_out x d_in 的模型权重矩阵 W 就是把隐藏状态向量 x 变换的线性映射,与下面的映射完全相同。权重矩阵也是 2 秩张量;第 23-24 天会把这种 shape 推理推广到更高秩。

自主演练与记录

取 x = (2, 1)。计算前先预测每个矩阵的输出:(a) 反射 A = [[1,0],[0,-1]];(b) 90 度旋转 R = [[0,-1],[1,0]];(c) W = [[2,0],[1,3]],分别用行视角和列视角。

独立掌握标准

书面推导中两种视角给出相同结果,你在计算前预测出翻转与旋转,并写出 W、x、W*x 的 shape(2x2 . 2 -> 2)。

权威源资源与权利证明

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Essence of Linear Algebra

作者 / 机构: Grant Sanderson (3Blue1Brown) | 原始出处链接 ↗

对应章节 / 时间戳: Chapter 3: Linear transformations and matrices

验证版本与日期: 2016-2023 (Verified: 2026-10-30)

入选理由:

Unequaled geometric and visual intuition for vectors, linear transformations, matrix multiplication, and inverses before tensor operations.

来源前置条件:

High-school coordinate geometry

安全回退方案(离线弹性):

Geometric explanations, worked formulas, and coordinate exercises are fully provided as original lesson text.

对比候选资源与选型分析 (2)
MIT OCW 18.06 Linear Algebra (Prof. Gilbert Strang) ↗ compared_alternative [CC BY-NC-SA 4.0]

Established textbook/lecture approach, strong mathematical rigor alongside 3Blue1Brown visual intuition.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Theoretical determinant-free proof structure is mathematically elegant but less aligned with computational tensor engineering.

linking CC BY-NC-SA 4.0 noncommercial share-alike

18.06 Linear Algebra (Prof. Gilbert Strang)

作者 / 机构: MIT OpenCourseWare (Prof. Gilbert Strang) | 原始出处链接 ↗

对应章节 / 时间戳: Lectures 1-2: column picture and elimination as linear maps

验证版本与日期: Spring 2010 (Verified: 2026-10-30)

入选理由:

Established row-picture and column-picture treatment of linear systems, matrix products, and invertibility; rigorous complement to the 3Blue1Brown visual series.

来源前置条件:

High-school algebra and coordinate geometry

安全回退方案(离线弹性):

All row/column-picture derivations and worked examples are written as original lesson text and run offline.

对比候选资源与选型分析 (3)
3Blue1Brown: Essence of Linear Algebra ↗ compared_selected_for_days_22_24 [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Selected as co-primary: geometric visualizations paired with Strang's algebraic rigor.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Determinant-free theoretical treatment is elegant but further from the computational shape accounting required here.

Immersive Linear Algebra (online interactive book) ↗ compared_rejected_for_days_22_24 [Free online (site terms; no OSI/CC license declared)]

Interactive figures are attractive, but the absence of a declared open license makes rights disposition unclear; kept out of the resource set.

04 120 分钟

独立掌握:向量代数与矩阵-向量乘积

独立掌握检查(无 AI 协助)。

前置要求

完成上一活动;如受阻,使用列出的恢复链接。

学习目标

在无助协助下预测并验证线性组合、点积和矩阵-向量乘积;任何错误都要写出指明误用规则的恢复笔记。

操作指引

闭卷进行:先预测,再计算,后比较。若结果出乎意料,记录误用了哪条规则,并记下恢复链接(第 21 天复习或列出的资源)。

自主演练与记录

任务:(a) e1 = (1, 2, 2)、e2 = (2, -1, 2) 的点积 e1.e2;(b) W' = [[1,2],[0,1]]、x = (3, 1) 时的 W'*x;(c) 写出 (b) 的完整 shape 台账。

独立掌握标准

三项预测均经无协助验证;用自己的话写出 shape 台账,并用一句话把 W*x 与作用于隐藏状态的模型权重矩阵联系起来。

权威源资源与权利证明

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Essence of Linear Algebra

作者 / 机构: Grant Sanderson (3Blue1Brown) | 原始出处链接 ↗

对应章节 / 时间戳: Chapters 1-4 review: vectors, combinations, transformations

验证版本与日期: 2016-2023 (Verified: 2026-10-30)

入选理由:

Unequaled geometric and visual intuition for vectors, linear transformations, matrix multiplication, and inverses before tensor operations.

来源前置条件:

High-school coordinate geometry

安全回退方案(离线弹性):

Geometric explanations, worked formulas, and coordinate exercises are fully provided as original lesson text.

对比候选资源与选型分析 (2)
MIT OCW 18.06 Linear Algebra (Prof. Gilbert Strang) ↗ compared_alternative [CC BY-NC-SA 4.0]

Established textbook/lecture approach, strong mathematical rigor alongside 3Blue1Brown visual intuition.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Theoretical determinant-free proof structure is mathematically elegant but less aligned with computational tensor engineering.

linking CC BY-NC-SA 4.0 noncommercial share-alike

18.06 Linear Algebra (Prof. Gilbert Strang)

作者 / 机构: MIT OpenCourseWare (Prof. Gilbert Strang) | 原始出处链接 ↗

对应章节 / 时间戳: Lecture 1-3 problem sets

验证版本与日期: Spring 2010 (Verified: 2026-10-30)

入选理由:

Established row-picture and column-picture treatment of linear systems, matrix products, and invertibility; rigorous complement to the 3Blue1Brown visual series.

来源前置条件:

High-school algebra and coordinate geometry

安全回退方案(离线弹性):

All row/column-picture derivations and worked examples are written as original lesson text and run offline.

对比候选资源与选型分析 (3)
3Blue1Brown: Essence of Linear Algebra ↗ compared_selected_for_days_22_24 [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

Selected as co-primary: geometric visualizations paired with Strang's algebraic rigor.

Linear Algebra Done Right (Sheldon Axler) ↗ compared_rejected_for_curriculum [CC BY-NC (4th edition, Open Access)]

Determinant-free theoretical treatment is elegant but further from the computational shape accounting required here.

Immersive Linear Algebra (online interactive book) ↗ compared_rejected_for_days_22_24 [Free online (site terms; no OSI/CC license declared)]

Interactive figures are attractive, but the absence of a declared open license makes rights disposition unclear; kept out of the resource set.