テンソル:軸・階数・モデルの重みブロック
予測と観察の証跡を記録した後のみ支援を利用できる。
前提条件
第 23 日を完了すること。行列の shape が不安なら記載の回復リンクを使う。
学習目標
テンソルを軸の数を階数とする n 次元配列として記述し、モデルのテンソルのバッチ・時間・チャネル軸を名付け、shape (V x d) のテーブル E からの埋め込み参照が shape (B, T, d) の出力になることを追跡する。
手順
スカラーは階数 0、ベクトルは階数 1、行列は階数 2、埋め込み系列のバッチは shape (B, T, d) の階数 3 テンソル:バッチ軸・時間軸・チャネル軸。埋め込み参照は行の gather であり、shape (B, T) の ids が shape (V, d) のテーブル E を参照して (B, T, d) の出力を作る。重み行列は階数 2 のテンソル、バッチと時間を持つ隠れ状態は階数 3 である。
演習と予測記録
語彙 V = 50000、埋め込み幅 d = 512 の小さなモデルがある。予測せよ:(a) テーブル E のスカラー重み数;(b) shape (B=2, T=3) の ids を参照したときの出力 shape;(c) その出力が保持する float32 の値の個数とバイト数。
重み数は V * d。参照結果は (batch, time) の各位置に d ベクトルが1つずつ入る。float32 は1値 4 バイト。
(a) E は 50000 * 512 = 25,600,000 個のスカラー重みを持つ。(b) 出力 shape は (2, 3, 512):2*3 = 6 個のトークン位置それぞれが 512 ベクトルに置き換わる。(c) 出力は 2*3*512 = 3072 個の float32 を持ち、3072 * 4 = 12,288 バイト。バッチ軸と時間軸は参照が行ベクトルの前に追加する新しい軸である。
台帳が (V, d) と (B, T) から (B, T, d) を自力で導き、2つの要素数を正確に計算し、各軸の物理的意味(どの項目・どの位置・どの特徴か)を述べられる。
公式ソースリソースと権利証跡
NumPy Reference: The N-dimensional array (ndarray)
該当セクション・タイムスタンプ: ndarray.ndim / ndarray.shape and axis ordering
検証バージョンと日付: NumPy 2.x documentation (Verified: 2026-10-30)
Primary semantics for ndarray shape, strides, reshape orders, and view-versus-copy behavior used in tensor memory accounting.
Basic Python
Shape, stride, and memory-ledger exercises are fully explained with local runnable examples.
比較対象候補リソースと選定評価 (2)
Equivalent tensor semantics in the framework used later in the curriculum; NumPy reference selected to keep Days 22-24 dependency-free.
Selected as co-primary for Day 24: the broadcasting rules page pairs with the ndarray attribute reference.
Essence of Linear Algebra
該当セクション・タイムスタンプ: Chapter 3 review: a matrix is a rank-2 tensor
検証バージョンと日付: 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)
Established textbook/lecture approach, strong mathematical rigor alongside 3Blue1Brown visual intuition.
Theoretical determinant-free proof structure is mathematically elegant but less aligned with computational tensor engineering.