题目:For each of the following learning tasks, fill in the table by stating: • The type of task (regression, binary classification, or multiclass classification) [6] • The number of neurons in the output layer[3] • The activation function of neurons in the output layer[3]
a) To predict a student's final classification letter grade (A, B, C, D, or F) from attendance and assignment scores.
b) To predict the number of bikes rented per hour based on weather and time of day.
c) To predict whether a credit card transaction is fraudulent or legitimate.
题目:Matrix multiplication is performed on the two matrices (𝑨 and 𝑩) shown below.
A =
2
−1
3
4
−2
1
B =
1
−2
2
1
C = A × B =
x
…
…
…
…
…
a. Calculate the top-left element 𝒙 in the matrix 𝑪. [3] b. State the dimensions of the result 𝑪. [2] c. State whether the matrix multiplication can or cannot be performed on the matrix 𝑨 and its transpose, i.e., 𝐴 × 𝐴T. If it can, state the dimensions of the result; if it cannot, explain why. [4] d. State whether the matrix multiplication can or cannot be performed on the matrix 𝑩 and itself, i.e., 𝐵 × 𝐵. If it can, state the dimensions of the result; if it cannot, explain why. [4]
2a左上元素 x:第一行 × 第一列[3]内积
原文要点:C11 = A 的第 1 行 · B 的第 1 列。
详细讲解:矩阵乘法的定义——结果第 i 行第 j 列 = A 的第 i 行与B 的第 j 列的对应元素相乘再相加(内积)。这里 i = j = 1:
x = C11 = (2)(1) + (−1)(2) = 2 − 2 = 0
画出来就是:
"对应元素"的配对规则:A 的列编号 = B 的行编号——A 的第 1 列元素 (2) 配 B 的第 1 行 (1),A 的第 2 列 (−1) 配 B 的第 2 行 (2)。这正对应神经网络里 z = Σi wixi 的求和。
题目·Tut·Lab 关联:Tutorial 3 手算 Dense 前向:z = X @ W + b,其中 X (n,k)、W (k,m);Lab 3 用 numpy 复现 Keras 输出逐位一致。Q3 的 z₆ = 0.1·1 + 0.3·2 + 0.2·1 就是同一个"行×列"运算。
✅ 官方答案核对:a. 2 × 1 + (−1) × 2 = 0;b. 3 × 2;c. Can. The dimensions of the result are 3 × 3;d. Can. The dimensions of the result are 2 × 2。numpy 复算全部一致(C = [[0,−5],[11,−2],[0,5]],A·Aᵀ 对角 5/25/5,B·B = [[−3,−4],[4,−3]])。
Q3 · 前向传播 + 反向传播 [8 分]
4 + 4。给一张 3-4-1 网络,算一个隐藏神经元的输出;再问更新 w₇₆ 需要"谁的 δ、谁的 a"。这是 Unit 2 + Unit 5 的最小闭环。
题目:The network has three input nodes (1–3), three hidden nodes (4–6), and one output node (7). The inputs are x₁ = 1, x₂ = 2, x₃ = 1. Necessary connection weights are given below, where wji denotes the weight connecting node i in the preceding layer to node j in the current layer. w₄₁ = w₄₂ = w₄₃ = 0.1 w₅₁ = w₅₂ = 0.1 w₅₃ = 0.3 w₆₁ = 0.1 w₆₂ = 0.3 w₆₃ = 0.2 All biases b are zero. The hidden nodes use the ReLU activation function.
a) Forward Propagation: Calculate the output a₆ of hidden node 6. [4] b) Backpropagation: To update the weight w₇₆, we need the error term δj of neuron (node number j) ______ and the activation ai of neuron (node number i) ______. [4](Please write the node number as your answers for (b) in each blank.)
题目:a. State which activation function is no longer used in modern neural networks. [2] b. State what specific problem arises during gradient descent calculation when using Sigmoid and Tanh activation functions in deep networks, and briefly explain the reason. [4] c. ReLU is more commonly used compared to Sigmoid and Tanh. Briefly describe two reasons for this. [4]
四条曲线放在一起看
4a被淘汰的:阶跃函数(Step / Heaviside)[2]
原文要点:State which activation function is no longer used.
✅ 官方答案核对:a) Step function or Heaviside step function;b) Vanishing Gradient — When the input z is very large or very small (in the saturation region), the derivatives of Sigmoid and Tanh approach zero. During backpropagation, multiplying these near-zero derivatives layer by layer causes the gradient to shrink exponentially to zero, preventing early layers from updating their weights;c) 任两条:计算更快 / 缓解梯度消失(正输入)/ 稀疏激活 / 经验上在 MLP 和 CNN 表现更好。
Q5 · 读网络图:层数 / 节点 / 神经元 / 参数 [21 分]
7 小问各 3 分。全卷分值最高的题,考的是 Unit 2–3 最基本的"数一数"——但每一问都有一个陷阱。
题目:A neural network is shown in the following diagram, in which weights and biases are not drawn. (You may write the answer as an arithmetic expression.)
a. State the number of layers. [3] b. State the number of nodes. [3] c. State the number of neurons. [3] d. State the number of trainable parameters (weights and biases) in the second hidden layer. [3] e. State the number of Dense layers. [3] f. If the output neuron uses a Sigmoid activation function (suppose the input of activation is any arbitrary value), what is the output range? [3] g. If the output neuron uses a Linear activation function (suppose the input of activation is any arbitrary value), what is the output range? [3]
题目:When classifying grayscale images, each image has 28×28 pixels. Data preprocessing is typically required prior to model training: features are scaled to the range of 0–1, and each example is then reshaped into ______ dimension to match the input dimension of the fully connected layer. For the labels, they are converted into ______ so as to be consistent with the predicted class probabilities.
必要扩展:Keras 也能在模型里用 layers.Flatten() 或 layers.Input(28,28) 自动拉平(Lab 8 就是这么做的),此时数据不用手工 reshape。本题"to match the input dimension of the fully connected layer"指的是手工版。
题目:A neural network is implemented to predict the customer satisfaction rating of a restaurant from its operational and service-related features. The input data has 20,000 examples, each consisting of 8 features (…). The target is the satisfaction rating, recorded as an integer between 1 and 5 (1 = very dissatisfied, 5 = very satisfied). Each rating value represents a discrete satisfaction category, and the categories are mutually exclusive. Some utility code (skeleton) and the main program are shown below.
a. State the dimensions of the input dataset before it is fed into the model. [2] b. Identify the 2 errors/bugs in the program (provide the line number for each) and describe how to fix each of them. [6] c. Suppose we now change the labels to numerical ratings with decimal values (e.g., 4.45). Make 4 changes of code (in 2 lines) to modify the network to perform correct linear predictions. Write down the line numbers and changes. (Assume data loading and preprocessing are properly done.) [12]
原程序(带行号)
# utility(已给、正确)def load_and_prep_data():
... # given correct codedef history_final_values(history):
... # given correct code# Main program
(X_train, y_train), (X_test, y_test) = load_and_prep_data()
model = keras.Sequential([
layers.Dense(32, activation="relu"), # Line 11
layers.Dense(16, activation="relu"), # Line 12
layers.Dense(5, activation="sigmoid") # Line 13 ← bug ①
])
model.compile(optimizer="sgd", # Line 16
loss="binary_crossentropy", metrics=["acc"]) # Line 17 ← bug ②
history = model.fit(X_train, y_train, epochs=20,
verbose=0, validation_data=(X_test, y_test))
print(history_final_values(history))
红色 = 有问题的地方;绿色 = 正确/可保留。Line 14 ])、Line 18 空、Line 19–20 fit 跨两行——官方行号以 # Line N 注释为准。
7a输入形状:(20000, 8)[2]
原文要点:State the dimensions of the input dataset before it is fed into the model.
Line 13: layers.Dense(5, activation="sigmoid")
→ layers.Dense(1, activation="linear") ① 5 → 1 ② "sigmoid" → "linear"(或删掉 activation)
Line 17: loss="binary_crossentropy", metrics=["acc"]
→ loss="mean_squared_error", metrics=["mae"] ③ loss → MSE 或 MAE ④ metrics=["acc"] 删除或改成 mse/mae
逐处理由:① ① units 5 → 1:回归只预测一个数,不再是 5 个类别概率;② ② sigmoid → linear:sigmoid 把输出锁在 (0,1)(Q5f),永远输出不了 4.45;③ ③ bce → MSE/MAE:交叉熵需要概率分布标签,连续值标签只能用距离度量;④ ④ metrics "acc" → 删除或 mse/mae:accuracy 对连续值没有定义(Keras 会报错或输出无意义的 0)。注意 Line 11、12 的 relu 隐藏层不用改——隐藏层激活与输出任务无关;optimizer 也不用改。
题目:A university is building models to predict whether a student will drop out of a course (binary label). They train three different models using the same training and validation sets. After training, they record the classification accuracy of each model:
Model
Training accuracy
Validation accuracy
gap (train − val)
诊断
Model A
96%
60%
+36%
train 高、val 低、gap 大 → 过拟合
Model B
89%
85%
+4%
两者都高、gap 小 → 合适
Model C
57%
51%
+6%
两者都低(接近随机 50%)→ 欠拟合
a. State which model most clearly suffers from underfitting. [2] b. … overfitting. [2] c. State which model is well-fitted. [2] d. Briefly describe two ways to handle overfitting issues. [4] e. If you want the model to ignore useless features by setting their weights to exactly zero. Which regularization method (L1 or L2) should you use? [2]
8a–c诊断:C 欠拟合 · A 过拟合 · B 合适[2+2+2]看两个数
原文要点:State which model suffers from underfitting / overfitting / is well-fitted.
✅ 官方答案核对:a. Model C;b. Model A;c. Model B;d. 任两条:1. Use a simpler model | 2. Early stopping | 3. Collect and use more training data (e.g., data augmentation) | 4. Weight regularization | 5. Dropout | 6. Batch normalization;e. L1。numpy 复算 gap:A +0.36、B +0.04、C +0.06。