Final 自拟练习|P 期中后新内容
自拟练习 P 期中后新内容:L08 推荐系统、Agent 讲座、生成式 AI 与 Tutorial 6–7,英文题干,逐题折叠中文解析、英文作答与回查页码。非官方。
手机上宽表格可左右滑动;自测答案默认收起,点击题目下方按钮查看。
使用边界:期末复习,非官方材料。考试安排按课程公告整理,正式要求以讲师通知和课堂公告为准。本页全部是自拟练习,覆盖期中之后的 L08、Agent 讲座、生成式 AI 和 Tutorial 6–7,不是往年卷,也不是预测卷。
复习资料:考试安排与范围地图 · 专家系统与推荐系统 · Agent 与生成式 AI
先做题再看解析:G 往年卷:搜索、逻辑、概率 · H 往年卷:CNN 与神经网络 · I 往年卷:延伸与简答 · J 判断 1–25 · K 判断 26–50 · L 选择题 · M 问答:搜索、逻辑、概率 · N 问答:回归、聚类、神经网络 · O 问答:CNN、RNN 与拓展 · P 期中后新内容
怎么做:先只看题面,用英文作答;计算题写出公式和代入,再展开核对。解析里的数值都用 python 复算过,页码为 PDF 页序。
P 期中后新内容
全部为自拟题,题号与底稿一致;计算题数值与复习页 R06 的演算不同。
P1 · Recommendation paradigms (multiple choice)
A recommender suggests movies to Alice by finding users whose past ratings are similar to hers and recommending what they liked. Which paradigm is this?
(A) Content-based
(B) Knowledge-based
(C) Collaborative filtering
(D) Expert system
P1 · 查看答案与解析
答案:C。用的是其他用户的评分(社区数据);基于内容用物品特征,基于知识用知识模型。
English: (C) Collaborative filtering. It relies on community data: users who had similar tastes in the past will have similar tastes in the future.
回查:L08 p.22–23、p.26。
P2 · Transformer components (multiple choice)
Which of the following is NOT one of the four Transformer components listed in the lecture?
(A) Input embeddings
(B) Positional encoding
(C) A recurrent hidden state passed from position t−1 to t
(D) Feed-forward network
P2 · 查看答案与解析
答案:C。四组件是输入嵌入、位置编码、自注意力、前馈网络;逐位置传隐藏状态是 RNN。
English: (C). The four components are input embeddings, positional encoding, self-attention and the FFN; passing a hidden state from t−1 to t is how an RNN works.
回查:L10 p.48、p.50。
P3 · Agent levels (multiple choice)
An agent reads an error message, decides to edit a file, runs the tests and decides the next step from the result. According to the five-level model, this is mainly:
(A) L1 Chat
(B) L2 Workflow
(C) L3 Tool invocation / ReAct
(D) L5 Self-evolutionary
P3 · 查看答案与解析
答案:C。看结果再决定下一步是 ReAct 的 Think → Act → Observe,对应 L3;L2 的流程由人预先画好。
English: (C) L3. The agent follows a ReAct loop and decides the next action from the observation; in an L2 workflow the steps are fixed in advance by a human.
回查:L09a p.9–11、p.15。
P4 · In-context learning (multiple choice)
In in-context learning, what happens to the model parameters when demonstrations are added to the prompt?
(A) They are fine-tuned on the demonstrations
(B) They stay unchanged
(C) Only the last layer is updated
(D) They are re-initialised
P4 · 查看答案与解析
答案:B。ICL 靠提示里的示范完成任务,不做任何梯度更新。
English: (B). In-context learning uses demonstrations in the prompt only; no parameters are updated.
回查:L10 p.59、p.64–65;L04a p.24。
P5 · True or false with a reason (true/false)
(a) BPR treats every unobserved item as a negative example and fits it to 0, just like pointwise fitting of a 0/1 matrix.
(b) For the same test set, RMSE is always greater than or equal to MAE.
(c) In NeuMF, the GMF branch and the MLP branch share one set of user and item embeddings.
(d) Few-shot prompting requires updating the weights of the language model.
P5 · 查看答案与解析
答案:
(a) 错。BPR 只要求交互过的物品排在没交互过的前面,不把「?」拟合成 0;两个未交互物品之间不比较。
(b) 对。RMSE 先平方再平均,大误差的权重更高;只有各条误差绝对值都相同时两者才相等。
(c) 错。NeuMF 让两支各学一套嵌入,每个用户、每个物品有两套向量。
(d) 错。提示(FS、1S、0S)不更新权重,只改变输入。
English: (a) False. BPR does not treat unobserved items as negatives with a target of 0. It only requires an interacted item to be ranked above a non-interacted one, and two unobserved items are not compared. (b) True. RMSE squares the errors before averaging, so it is never smaller than MAE; the two are equal only when all absolute errors are the same. (c) False. NeuMF learns different sets of embeddings for the GMF branch and the MLP branch. (d) False. Prompting, including few-shot prompting, does not update the weights; only the input changes.
回查:(a) L08 p.39–40;(b) L08 p.34;(c) L08 p.48;(d) L10 p.59、p.63。
P6 · Matrix factorisation with biases (calculation)
With d = 3, user i has pᵢ = (2, −1, 1) and item j has qⱼ = (1.5, 0.5, 2).
(a) Compute r̂ᵢⱼ without biases.
(b) Add user bias bᵢᵖ = −0.4 and item bias bⱼᵠ = 0.3.
(c) The observed rating is rᵢⱼ = 4. What is this cell’s squared error under (b)?
P6 · 查看答案与解析
答案:
(a) r̂ᵢⱼ = 2 × 1.5 + (−1) × 0.5 + 1 × 2 = 3 − 0.5 + 2 = 4.5。
(b) r̂ᵢⱼ = 4.5 − 0.4 + 0.3 = 4.4。用户偏置为负,说明这个用户打分偏低;物品偏置为正,说明这个物品整体评价偏高。
(c) (4 − 4.4)² = 0.16。
English: (a) r̂ᵢⱼ = pᵢᵀqⱼ = 2(1.5) + (−1)(0.5) + 1(2) = 4.5. (b) r̂ᵢⱼ = pᵢᵀqⱼ + bᵢᵖ + bⱼᵠ = 4.4; the user tends to rate low and the item is generally rated well. (c) (4 − 4.4)² = 0.16.
回查:L08 p.31、p.32、p.35。
P7 · MAE and RMSE (calculation)
Five test ratings are (3, 5, 2, 4, 1) and the predictions are (3.5, 4, 2, 2.5, 1.5). Compute MAE and RMSE, and explain which record makes RMSE larger than MAE.
P7 · 查看答案与解析
答案:误差绝对值 (0.5, 1, 0, 1.5, 0.5),和为 3.5,MAE = 3.5/5 = 0.7。平方和 0.25 + 1 + 0 + 2.25 + 0.25 = 3.75,RMSE = √(3.75/5) = √0.75 ≈ 0.866。第四条误差 1.5 平方后是 2.25,把 RMSE 拉到 MAE 之上。
English: MAE = 3.5/5 = 0.7; RMSE = √(3.75/5) = √0.75 ≈ 0.866. RMSE is larger because squaring gives more weight to the largest error, 1.5 in the fourth record.
回查:L08 p.34。
P8 · BPR loss (calculation)
There are five items. User u has interacted with i₂ and i₅ only. The model scores are ŷᵤ₁ = 0.5, ŷᵤ₂ = 2.0, ŷᵤ₃ = 1.2, ŷᵤ₄ = −0.5, ŷᵤ₅ = 0.8.
(a) List all training triples (u, i, j) for this user.
(b) Compute the BPR loss for each triple and the total (ignore regularisation).
(c) Which triple contributes most, and why?
P8 · 查看答案与解析
答案:
(a) 交互过的 i ∈ {i₂, i₅},没交互过的 j ∈ {i₁, i₃, i₄},共 2 × 3 = 6 个三元组:(u, i₂, i₁)、(u, i₂, i₃)、(u, i₂, i₄)、(u, i₅, i₁)、(u, i₅, i₃)、(u, i₅, i₄)。
(b) 每个三元组的损失是 −ln σ(ŷᵤᵢ − ŷᵤⱼ):
| 三元组 | 分差 | σ | 损失 |
|---|---|---|---|
| (i₂, i₁) | 1.5 | 0.8176 | 0.2014 |
| (i₂, i₃) | 0.8 | 0.6900 | 0.3711 |
| (i₂, i₄) | 2.5 | 0.9241 | 0.0789 |
| (i₅, i₁) | 0.3 | 0.5744 | 0.5544 |
| (i₅, i₃) | −0.4 | 0.4013 | 0.9130 |
| (i₅, i₄) | 1.3 | 0.7858 | 0.2410 |
合计 ≈ 2.360。
(c) (u, i₅, i₃) 最大:交互过的 i₅(0.8)低于没交互过的 i₃(1.2),排反了,σ 小于 0.5。
English: (a) Positives i₂, i₅ and negatives i₁, i₃, i₄ give 2 × 3 = 6 triples. (b) Each contributes −ln σ(ŷᵤᵢ − ŷᵤⱼ); the total is about 2.360. (c) (u, i₅, i₃) contributes most because the observed item i₅ is scored below the unobserved item i₃, so the pair is in the wrong order.
回查:L08 p.40–41。
P9 · NDCG@4 (calculation)
The true relevance scores of the top-4 items in the model’s ranking are (0, 2, 1, 2).
(a) Compute DCG@4, the ideal DCG@4 and NDCG@4.
(b) If the first two items are swapped, giving (2, 0, 1, 2), what is the new NDCG@4?
P9 · 查看答案与解析
答案:
(a) 增益 2^rel − 1 依次为 0、3、1、3;折损 log₂(i + 2) 依次为 1、1.585、2、2.322(i 从 0 起,第 1 位 i=0,折损 log₂2 = 1)。 DCG@4 = 0/1 + 3/1.585 + 1/2 + 3/2.322 ≈ 0 + 1.893 + 0.5 + 1.292 = 3.685。 理想顺序 (2, 2, 1, 0):IDCG@4 = 3/1 + 3/1.585 + 1/2 + 0 ≈ 3 + 1.893 + 0.5 = 5.393。 NDCG@4 ≈ 3.685/5.393 ≈ 0.683。
(b) (2, 0, 1, 2):DCG@4 = 3 + 0 + 0.5 + 1.292 = 4.792,NDCG@4 ≈ 4.792/5.393 ≈ 0.889。越靠前的位置折损越少。
English: (a) Gains 2^rel − 1 are 0, 3, 1, 3 and discounts log₂(i + 2) are 1, 1.585, 2, 2.322, so DCG@4 ≈ 3.685. The ideal order (2, 2, 1, 0) gives IDCG@4 ≈ 5.393, so NDCG@4 ≈ 0.683. (b) DCG@4 ≈ 4.792 and NDCG@4 ≈ 0.889; higher positions are discounted less.
回查:L08 p.43。
P10 · Implicit feedback and BPR (short answer)
State the three characteristics of implicit feedback and explain why a pairwise method such as BPR suits this kind of data.
P10 · 查看答案与解析
答案:没有负反馈、天然有噪声、数值多是频次(偏好与置信度要分开)。没交互的物品可能是不喜欢,也可能是没见过,逐点拟合成 0 会学成「没见过 = 不喜欢」。BPR 只要求交互过的排在没交互过的前面,推荐本身也是排序。
English: Implicit feedback has no negative feedback, is inherently noisy, and its values usually reflect frequency, so preference and confidence must be separated. A missing interaction may mean “not interested” or “not seen”, so fitting unobserved items to 0 is misleading. BPR is pairwise: it only requires an observed item to score higher than an unobserved one for the same user, which matches recommendation as a ranking problem.
回查:L08 p.36–41。
P11 · Why Transformers (short answer)
Give the two limitations of RNNs stated in the lecture and explain how the Transformer addresses them.
P11 · 查看答案与解析
答案:RNN 不能并行(t 要等 t−1);长上下文差(相隔 k 个位置的 token 有 k 次机会被从隐藏状态抹掉)。Transformer 用自注意力让每个位置直接看所有位置,顺序由位置编码提供,各位置可同时计算。
English: RNNs cannot be parallelised, because position t waits for t−1, and they handle long contexts poorly: tokens k positions apart give k chances for information to be erased from the hidden state. The Transformer uses self-attention so every position attends to all others directly, capturing long-range dependencies, and positional encoding keeps order, so all positions are computed in parallel.
回查:L10 p.48、p.50。
P12 · Prompt, context or harness (short answer)
An LLM system gives a poor answer. For each case, say which layer you would fix first and why: (a) the task description is vague; (b) the answer lacks evidence; (c) the system keeps calling the same tool in a loop.
P12 · 查看答案与解析
答案:(a) 改 Prompt:任务、标准、约束、格式没写清,模型不知道要做什么。(b) 补 Context:模型没收到相关证据,要求它引用也不会凭空生出证据,要收集、筛选、整理输入。(c) 查 Harness:工具调用打转属于运行和控制层的问题,要由 harness 限制重试次数、时间和成本,并检查结果。
English: (a) Fix the prompt first: state the task, criteria, constraints and format clearly. (b) Fix the context: the model needs the relevant evidence in its input, and asking for citations does not create evidence. Collect, select, organise and update the inputs. (c) Fix the harness: the harness runs tools, controls permissions, time, cost and retries, and checks the results, so a tool loop is a harness problem.
回查:L10 p.75–78;L09a p.5。
P13 · LLM, RAG and agent (open-ended)
Compare an LLM, a RAG system and an AI agent. For a task such as “compare two study tools on cost and privacy and produce a report”, which would you choose and what risks remain?
P13 · 查看答案与解析
答案(开放题,一种答法):LLM 只根据输入生成文字;RAG 先检索外部资料再生成,输出仍是一段回答;Agent 在 LLM 外加了记忆、工具和循环,能检索、起草、核对后再决定下一步。这个任务要查价格页和隐私政策、起草表格、对照来源核结论,选 Agent。剩下的风险:资料可能过时或被投毒,模型仍会幻觉,harness 的检查只降低风险,分享前要有人审。
English: An LLM is a stateless text-to-text model. A RAG system retrieves external documents before generating, but still only returns an answer. An agent is an orchestration layer around the LLM with memory and tools; it acts and loops on feedback. I would use an agent, because the task needs several steps: retrieving pricing pages and privacy policies, drafting a table and checking each claim against its source. Risks remain: documents may be outdated or poisoned, the model may hallucinate, and harness checks reduce risk without guaranteeing correctness, so a human should review the report.
回查:L09a p.3–4;L10 p.66、p.70、p.72–73、p.77、p.97。
这组材料已读完,可以回课程页选择配套资料或练习:COMP5511 课程页。
个人整理的学习笔记,不是官方材料;数字与结论以课件和讲师为准。