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 的平行四邊形幾何,並能用一句話說明嵌入表的一行 E[token_id] 為什麼是向量。

權威來源資源與權利證明

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.