← COMP5511 全部讲次
Q08

Final 往年卷|H CNN 与神经网络

往年期末卷 H CNN 与神经网络:F25、F24、Y24、L24 原题按专题整理,逐题折叠推算答案、英文答法与回查页码。非官方。

手机上宽表格可左右滑动;自测答案默认收起,点击题目下方按钮查看。

使用边界:期末复习,非官方材料。考试安排按课程公告整理,正式要求以讲师通知和课堂公告为准。本页按往年期末卷的题目整理,题面按题库里的转述和解答重写、措辞可能与原卷不同,往年卷没有官方答案,解答均为推算答案;往年卷只说明以前怎么出题,不代表今年的题目和分值。

复习资料:考试安排与范围地图 · 专家系统与推荐系统 · Agent 与生成式 AI

先做题再看解析:G 往年卷:搜索、逻辑、概率 · H 往年卷:CNN 与神经网络 · I 往年卷:延伸与简答 · J 判断 1–25 · K 判断 26–50 · L 选择题 · M 问答:搜索、逻辑、概率 · N 问答:回归、聚类、神经网络 · O 问答:CNN、RNN 与拓展 · P 期中后新内容

怎么做:先只看题面,用英文作答,写出公式和每一步,再展开核对;解析里的数值照底稿,页码为 PDF 页序。

原卷的网络图和曲线图在这里改写成文字或表格,题面为整理后的转述。卷积约定按 L07:卷积核不翻转,直接对位相乘求和。

H CNN 与神经网络

H1 · Convolution and max pooling (F24 Q4, 9 marks)

The input is 5×5 with rows [7,2,3,3,8], [4,5,3,8,4], [3,3,2,8,4], [2,8,7,2,7], [5,4,4,5,4]. The kernel is 3×3 and every row is [1,0,−1]. Stride 1, no padding.

(1) Compute the convolution output. (2) Apply 3×3 max pooling with stride 1 to the output of (1), padding the border with zeros.

H1 · 查看答案与解析

答案(推算答案):

(1) 输出边长 (5−3)/1+1 = 3。核的中间一列是 0,每个窗口只要算「左列三数之和 − 右列三数之和」,左上角 = (7+4+3) − (3+3+2) = 6。

列 1 列 2 列 3
行 1 6 −9 −8
行 2 −3 −2 −3
行 3 −3 0 −2

(2) 补完是 5×5,滑出来仍是 3×3。补的是 0 不是负无穷,所以边上全负的窗口最大值是 0。

列 1 列 2 列 3
行 1 6 6 0
行 2 6 6 0
行 3 0 0 0

English: The output side length is (N + 2P − F)/S + 1 = (5 − 3)/1 + 1 = 3. Because the middle column of the kernel is zero, each entry is the sum of the left column of the window minus the sum of its right column; the top-left entry is (7+4+3) − (3+3+2) = 6. For max pooling, zero padding makes the input 5×5, so the output is still 3×3, and windows containing only negative values on the border give 0.

易错点:padding 补 0,窗口里的 0 会参与取最大;题目没要求先过 ReLU,不要多加这一步。

回查:L07 p.21–40(卷积尺寸);L07 p.42–44(pooling)。

H2 · Convolution output (Y24 Q29)

The input is 4×4 with rows [1,1,2,4], [5,4,7,6], [3,0,1,2], [1,2,3,1]. The kernel is 3×3 with rows [1,2,1], [3,0,2], [0,1,1]. Stride 1, padding 0, bias 0. Compute the output feature map.

H2 · 查看答案与解析

答案(推算答案):

  • 输出边长 (4−3)/1+1 = 2,输出 2×2。
  • 左上窗口 = 1×1 + 1×2 + 2×1 + 5×3 + 4×0 + 7×2 + 3×0 + 0×1 + 1×1 = 35。
  • 输出 2×2 是 [35, 36] / [36, 32]。

公式:输出边长 = (N + 2P − F)/S + 1,输出通道数 = 核的个数 K;卷积参数 = (F²×C_in + 1)×K,池化没有可训练参数。L07 的例子:32×32×3 输入、10 个 5×5 核、S=1、P=2,输出 32×32×10,参数 (25×3+1)×10 = 760。

English: With N = 4, F = 3, S = 1 and P = 0, the output is 2×2. Multiply each 3×3 window element-wise by the kernel and sum: the top-left entry is 35, and the output is [35, 36] / [36, 32].

易错点:卷积核不翻转,直接对位相乘求和。

回查:L07 p.21–40。

H3 · Neural network concepts (F25 Q5, 20 marks)

底稿只有各小题的转述:

(5.1) An image must be classified into one of five cat classes. Which output layer and loss would you use? (2 marks) (5.2) Derive the derivatives of sigmoid and tanh. (4 marks) (5.3) Is it a good idea to initialise a sigmoid network with large positive weights? (4 marks) (5.4) The training set lists all dogs first and then all cats. Should it be shuffled before training? (5 marks) (5.5) The test inputs and labels are shuffled together. Does the accuracy change? (5 marks)

H3 · 查看答案与解析

答案(推算答案):

(5.1) 按互斥多分类处理:softmax 输出加交叉熵。one-hot 时 CE = −log p_true。

(5.2) σ′(z) = e⁻ᶻ/(1+e⁻ᶻ)² = σ(z)(1−σ(z));tanh′(z) = [(eᶻ+e⁻ᶻ)² − (eᶻ−e⁻ᶻ)²]/(eᶻ+e⁻ᶻ)² = 4/(eᶻ+e⁻ᶻ)² = 1 − tanh²(z)。sigmoid 最大导数 .25,tanh 最大导数 1,都在 z=0;绝对值很大时导数接近零。

(5.3) 一般不好。大权重让预激活绝对值很大,sigmoid 输出接近 0 或 1,导数很小,反向梯度衰减。所有隐藏单元完全相同初始化还有对称性问题。通常用适当尺度的随机初始化。

(5.4) 普通独立样本分类通常应该打乱,且特征与标签成对打乱。否则连续 batch 可能全是同一类,梯度估计不能代表总体,更新带有次序偏向并可能振荡。时间序列等任务另有顺序约束。

(5.5) 对固定模型、正常评估模式、逐样本独立且确定的预测,不改变:只是把正确/错误指示量重新排序,总和相同,a₁=a₂。若只打乱 X 不打乱 y,配对破坏,结果会变。

English:

(5.1) Mutually exclusive multiclass classification uses softmax with cross-entropy. For a one-hot target, CE = −log p_true.

(5.2) Differentiating σ(z) = (1+e⁻ᶻ)⁻¹ gives σ′(z) = e⁻ᶻ/(1+e⁻ᶻ)² = σ(z)(1−σ(z)). Applying the quotient rule to tanh gives tanh′(z) = 1 − tanh²(z). Sigmoid has maximum derivative 0.25 and tanh has maximum derivative 1, both at zero.

(5.3) Generally no. Large weights can create large-magnitude pre-activations, pushing sigmoids toward saturation and making derivatives small. This weakens gradient flow. Identical hidden-unit initialization also creates symmetry, preventing units from learning distinct features. Appropriately scaled random initialization is preferable.

(5.4) Usually yes for ordinary independent classification examples, keeping each input paired with its label. Class-sorted batches can give unrepresentative gradients and order-dependent updates. Shuffling, often each epoch, improves batch mixing.

(5.5) For a fixed model in proper evaluation mode with independent deterministic predictions, jointly permuting test examples and their labels leaves aggregate accuracy unchanged: a₁=a₂. The same correctness indicators are merely reordered. Shuffling inputs without their labels breaks correspondence.

易错点:(5.3) 大正权重不保证每个输入都正饱和,输入符号和偏置也有影响;(5.4) 不能机械打乱所有数据,时间序列内部顺序要保留。

回查:L06 p.30、43、47–48(5.1);L06 p.19、38(5.2);L06(5.3)。

H4 · Forward pass, backpropagation and learning rates (F25 Q6, 25 marks)

A network has inputs i₁, i₂, a hidden layer h₁, h₂ (before activation) followed by ReLU to give h₃ = ReLU(h₁), h₄ = ReLU(h₂), and outputs o₁, o₂. The output layer has no activation. The weight wₐᵦ connects unit a to unit b of the next layer.

连接 权重 连接 权重
i₁→h₁ w₁₁ = 1 h₃→o₁ w₃₁ = .5
i₁→h₂ w₁₂ = −.5 h₃→o₂ w₃₂ = −1
i₂→h₁ w₂₁ = .5 h₄→o₁ w₄₁ = −.5
i₂→h₂ w₂₂ = −1 h₄→o₂ w₄₂ = 1

Biases: b₁ = .5 (h₁), b₂ = −.5 (h₂), b₃ = −1 (o₁), b₄ = .5 (o₂). Input i₁ = 2, i₂ = −1; targets t₁ = 1, t₂ = .5.

(6.1) Compute the forward pass. (6.2) Compute the loss MSE = [(o₁−t₁)² + (o₂−t₂)²]/2. (6.3) Update w₂₁ with learning rate .1. (6.4) Four training-loss curves were obtained with learning rates .4, .00002, .008 and .0003. The curves are: A (red) unstable early and stuck at a poor plateau; B (blue) decreases extremely slowly; C (green) decreases fast but keeps oscillating; D (orange) fairly stable with the lowest final loss. Match each curve to its learning rate.

H4 · 查看答案与解析

答案(推算答案):

(6.1) h₁、h₂ 是激活前,h₃、h₄ 是 ReLU 之后,h₁ 到 h₃ 只是一次激活,不是多一层权重。

  • h₁ = 2×1 + (−1)×.5 + .5 = 2,h₂ = 2×(−.5) + (−1)×(−1) − .5 = −.5
  • h₃ = ReLU(2) = 2,h₄ = ReLU(−.5) = 0
  • o₁ = .5×2 − .5×0 − 1 = 0,o₂ = −1×2 + 1×0 + .5 = −1.5

(6.2) MSE = [(−1)² + (−2)²]/2 = 2.5。

(6.3) w₂₁ 连着输入 i₂ 和 h₁,h₁ 同时影响两个输出,两条路的梯度要相加。∂L/∂o₁ = o₁−t₁ = −1,∂L/∂o₂ = o₂−t₂ = −2;h₁ > 0,ReLU 导数为 1;i₂ = −1。

  • ∂L/∂w₂₁ = [(−1)×.5 + (−2)×(−1)] × 1 × (−1) = −1.5
  • w₂₁ 新值 = .5 − .1×(−1.5) = .65

(6.4) 按图形判断,不用计算:

曲线 学习率 理由
A 红 .4 最大,前期不稳,停在较差的平台
B 蓝 .00002 最小,下降极慢
C 绿 .008 下降快但一直震荡
D 橙 .0003 较稳,最终 loss 最低

English: (6.1) h₁ = 2, h₂ = −.5, h₃ = 2, h₄ = 0, o₁ = 0, o₂ = −1.5. (6.2) MSE = [(−1)² + (−2)²]/2 = 2.5. (6.3) h₁ affects both outputs, so the gradient sums both paths: ∂L/∂w₂₁ = [(−1)(.5) + (−2)(−1)] × 1 × (−1) = −1.5, and the new w₂₁ = .5 − .1 × (−1.5) = .65. (6.4) A = .4, B = .00002, C = .008, D = .0003. An excessive learning rate causes unstable updates; a very small rate learns too slowly. The intermediate rate gives a better balance of progress and stability.

易错点:输出层图上没有画 sigmoid,不额外加。梯度依赖 MSE 前面的系数 1/2;换一个损失写法,常数会变,别死记 .65。

回查:L06 p.44–48(反向传播);L04b p.27(学习率)。

H5 · Parameters, output layer and a composite activation (F24 Q6, 24 marks)

(6.1) Count the parameters, including biases, of a fully connected 4→10→3 network. (6.3) Three mutually exclusive risk levels must be predicted. Which output layer and loss would you use? Also differentiate the composite activation h = x·log(1 + tanh(eˣ)).

H5 · 查看答案与解析

答案(推算答案):

(6.1) (4+1)×10 + (10+1)×3 = 50 + 33 = 83。

(6.3) 三类互斥用 softmax 输出加交叉熵。

复合激活求导:令 u = tanh(eˣ),先用乘法法则,再逐层链式。按自然对数:

h′ = ln(1+u) + x · [1/(1+u)] · (1−u²) · eˣ = ln(1 + tanh(eˣ)) + x·eˣ·(1 − tanh(eˣ))

第二步用了 (1−u²)/(1+u) = 1−u。这个结果用数值微分核对过。

English: (6.1) A dense layer from n_in inputs to n_out outputs has (n_in+1)n_out parameters, so the network has 40+10+30+3 = 83 parameters. (6.3) Softmax outputs with cross-entropy loss, because the three classes are mutually exclusive. Derivative: assuming natural logarithm, let u = tanh(eˣ). By the product rule and the chain rule, h′ = ln(1+u) + x·eˣ·(1−u²)/(1+u) = ln(1 + tanh(eˣ)) + x·eˣ·(1 − tanh(eˣ)).

易错点:原卷没写对数底,答卷上先写 assuming natural logarithm;如果是 logₐ,第二项还要除以 ln a。输入节点没有偏置参数。

回查:L06、L07(参数数);L06 p.29–30(softmax)。

H6 · Titanic network gradients (Y24 Q34)

Inputs: age 34, sex 1, class 4; true label y = 1. Hidden layer (ReLU): upper unit weights [.6, .1, .7], bias 0; lower unit weights [.2, .3, .2], bias .1. Output: weights [.5, −1.3] on (upper, lower), bias .05, sigmoid with binary cross-entropy.

Compute the forward pass and the gradient of the loss with respect to every weight and bias. No update is required.

H6 · 查看答案与解析

答案(推算答案):

  • 隐藏上 = ReLU(34×.6 + 1×.1 + 4×.7) = 23.3,隐藏下 = ReLU(34×.2 + 1×.3 + 4×.2 + .1) = 8
  • z = .5×23.3 − 1.3×8 + .05 = 1.3,p = 1/(1+e⁻¹·³) ≈ .785835
  • sigmoid 加 BCE 的输出梯度 δ = p − y ≈ −.214165;两个隐藏单元输入都为正,ReLU 导数都是 1
梯度 值
输出权重(上、下) δ×[23.3, 8] = [−4.990045, −1.713320]
输出偏置 −.214165
隐藏上偏置 .5δ = −.107083
隐藏下偏置 −1.3δ = .278415
隐藏上权重(年龄、性别、舱等) [−3.640805, −.107083, −.428330]
隐藏下权重(同上) [9.466094, .278415, 1.113658]

顺序:δ 只算一次;输出权重梯度 = δ × 隐藏输出;隐藏单元梯度 = δ × 对应输出权重;隐藏输入权重梯度 = 隐藏单元梯度 × 对应输入。

English: Hidden outputs are 23.3 and 8, so z = 1.3 and p ≈ .785835. For sigmoid with binary cross-entropy, δ = p − y ≈ −.214165. Output-weight gradients are δ times the hidden outputs: [−4.990045, −1.713320]; the output-bias gradient is δ. Each hidden unit’s gradient is δ times its output weight (.5δ and −1.3δ), since both ReLU inputs are positive; multiplying by the inputs gives [−3.640805, −.107083, −.428330] and [9.466094, .278415, 1.113658].

易错点:题目没要求更新就不减学习率;δ = p − y 只在 sigmoid 配 BCE 时成立。

回查:L06 p.44–48(反向传播);L06 p.30、43、47–48(sigmoid 配 BCE)。

H7 · Network with a skip connection (L24 Q6)

Input x = 1, target t = .1. The network is z₁ = σ(w₀¹x), z₂ = σ(w₀²x), z₃ = ReLU(w₁³z₁ + w₂³z₂), z₄ = σ(w₁⁴z₁ + w₂⁴z₂ + w₃⁴z₃), so z₂ also feeds the output directly. Weights [w₀¹, w₀², w₁³, w₂³, w₁⁴, w₂⁴, w₃⁴] = [0, .3, .4, .5, .8, 1, 0], learning rate η = .01. Use the output error term δ₄ = (z₄ − t)·z₄·(1 − z₄).

Compute the forward pass, then the first-round updates of w₃⁴, w₂³ and w₀².

H7 · 查看答案与解析

答案(推算答案):

  • z₁ = σ(0) = .5,z₂ = σ(.3) ≈ .574443
  • z₃ = ReLU(.4z₁ + .5z₂) ≈ .487221
  • z₄ = σ(.8z₁ + 1·z₂ + 0·z₃) ≈ .726004
  • δ₄ = (z₄ − .1)·z₄·(1 − z₄) ≈ .124526

第一轮更新(本轮所有梯度都用旧权重):

  • w₃⁴ 新 = 0 − .01·δ₄·z₃ ≈ −.000607
  • w₂³ 新 = .5,不变,因为旧 w₃⁴ = 0 把经过 z₃ 的梯度路径截断了
  • w₀² 新 = .3 − .01·δ₄·(w₂⁴ + w₃⁴·w₂³)·z₂(1−z₂) ≈ .299696;z₂ 有直达输出的跳连接,所以梯度不为 0

English: Forward pass: z₁ = .5, z₂ ≈ .574443, z₃ ≈ .487221, z₄ ≈ .726004, and δ₄ ≈ .124526. All gradients use the old weights. New w₃⁴ = 0 − .01·δ₄·z₃ ≈ −.000607. w₂³ stays .5 because the old w₃⁴ = 0 blocks the gradient path through z₃. New w₀² = .3 − .01·δ₄·(w₂⁴ + w₃⁴·w₂³)·z₂(1−z₂) ≈ .299696; its gradient is non-zero because z₂ reaches the output through the skip connection.

易错点:原题 (a) 要求写函数代码,今年考试不写代码,只看懂网络表达式即可。

回查:L06 p.44–48。

下一页 →
Q09 Final 往年卷|I 延伸题与 Y24 简答

个人整理的学习笔记,不是官方材料;数字与结论以课件和讲师为准。