Answer all three questions. Show all derivations. Where code is requested, write clean, runnable pseudocode or Python; partial credit for correct structure. Use ... for math.
(a) Prove that the optimal policy of this constrained objective has the closed form
π∗(y∣x)=Z(x)1πref(y∣x)exp(β1r(x,y)),
and give the expression for Z(x). State clearly why Z(x) is intractable in practice. (8)
(b) Invert the result of (a) to express the reward r(x,y) in terms of π∗, πref, β, and Z(x). Then show that under the Bradley–Terry preference model
P(yw≻yl∣x)=σ(r(x,yw)−r(x,yl)),
the partition function Z(x)cancels, yielding the DPO per-example loss
LDPO=−logσ(βlogπref(yw∣x)πθ(yw∣x)−βlogπref(yl∣x)πθ(yl∣x)).(8)
(c) Compute the gradient ∇θLDPO and interpret the scalar weighting factor: explain, in one or two sentences, how DPO automatically up-weights examples where the implicit reward model is "wrong." (6)
In PPO for LLMs, let rt(θ)=πθold(at∣st)πθ(at∣st) and advantage A^t. The clipped surrogate is
LCLIP(θ)=Et[min(rtA^t,clip(rt,1−ϵ,1+ϵ)A^t)].
(a) For ϵ=0.2 and a single token with A^t=+3, plot/describe the surrogate as a function of rt on [0,2]. Give the exact value of LCLIP at rt=0.5,1.0,1.5. Repeat for A^t=−3. (8)
(b) Explain mathematically why the min makes the objective a pessimistic lower bound, and precisely why clipping is one-sided in its effect (i.e., which direction of policy update is left unconstrained for positive vs. negative advantage). (6)
(c) In RLHF, a learned reward model rϕ is imperfect. The KL penalty coefficient β trades off reward against divergence from πref. A team observes the reward climbing while human ratings fall. Name this failure mode, and state two concrete mitigations tied to quantities in the objective. (4)
A RAG system embeds chunks into unit-normalized vectors and retrieves by cosine similarity.
(a) A query embedding q=(0.6,0.8) (already unit norm). Three chunk embeddings (unnormalized) are
c1=(3,4),c2=(1,0),c3=(−0.8,0.6).
Compute the cosine similarity of q with each, and give the top-1 retrieved chunk. Then show that for unit-normalized vectors, ranking by cosine similarity is equivalent to ranking by (ascending) squared Euclidean distance. (8)
(b) A corpus has 1,000,000 chunks. Exact top-k nearest-neighbour search is O(Nd) per query. Approximate methods (e.g., HNSW) give roughly O(dlogN). For d=768, compute the ratio of operation counts (exact : approximate) and comment on why recall@k can drop below 100%. (4)
(c) Design a hybrid retrieval + reranking pipeline that combines a BM25 sparse score sbm25 and a dense score sdense, then reranks with a cross-encoder. Write the fused score formula (with normalization), state where reranking sits in the pipeline and why a cross-encoder is used only at rerank stage, and name two chunking-strategy choices that materially affect retrieval quality. (8)
Write the objective per prompt x as a functional of π(⋅∣x):
J(π)=∑yπ(y∣x)r(x,y)−β∑yπ(y∣x)logπref(y∣x)π(y∣x).(1 mark for correct setup, KL expanded.)
Maximize subject to ∑yπ(y∣x)=1. Lagrangian:
L=J(π)+λ(1−∑yπ(y∣x)).(1) Differentiate w.r.t. π(y∣x):
r(x,y)−β(logπref(y∣x)π(y∣x)+1)−λ=0.(2 — the "+1" from dπd(πlogπ).)
Solve:
logπref(y∣x)π(y∣x)=β1r(x,y)−1−βλ⇒π∗(y∣x)=πref(y∣x)exp(β1r(x,y))⋅e−1−λ/β.(2) The constant absorbs into normalization; enforcing ∑yπ∗=1 gives
π∗(y∣x)=Z(x)1πref(y∣x)exp(β1r(x,y)),Z(x)=∑yπref(y∣x)exp(β1r(x,y)).(1 for Z.)Z(x) sums over the entire (exponentially large / infinite) space of output sequences y, so it is intractable to compute or sample from exactly. (1)
Under Bradley–Terry, only the difference of rewards enters:
r(x,yw)−r(x,yl)=βlogπref(yw∣x)π∗(yw∣x)−βlogπref(yl∣x)π∗(yl∣x)+=0βlogZ(x)−βlogZ(x).(3)
The βlogZ(x) terms cancel because Z(x) depends only on x, not on y. (1)
Substituting into −logσ(⋅) (negative log-likelihood of the preference), and replacing π∗ with the trainable πθ:
LDPO=−logσ(βlogπref(yw∣x)πθ(yw∣x)−βlogπref(yl∣x)πθ(yl∣x)).(2)
Let u=β(logπref(yw∣x)πθ(yw∣x)−logπref(yl∣x)πθ(yl∣x)), i.e. the difference of implicit rewards r^θ(yw)−r^θ(yl). Since dud(−logσ(u))=−(1−σ(u))=−σ(−u):
∇θLDPO=−βσ(r^θ(yl)−r^θ(yw))[∇θlogπθ(yw∣x)−∇θlogπθ(yl∣x)].(4)
Interpretation (2): The scalar σ(r^θ(yl)−r^θ(yw)) is large (near 1) exactly when the model currently ranks the dispreferred response higher than the preferred one — i.e. the implicit reward is "wrong." So mis-ranked pairs get large gradient weight; correctly-ranked confident pairs get near-zero weight. This is automatic hard-example weighting, no separate reward model needed.
Positive advantage A^t=+3, ϵ=0.2 so clip range [0.8,1.2]:
LCLIP=min(r⋅3,clip(r,0.8,1.2)⋅3).
r=0.5: min(1.5,0.8⋅3=2.4)=1.5 (unclipped term smaller). (1)
r=1.0: min(3,3)=3.0. (1)
r=1.5: min(4.5,1.2⋅3=3.6)=3.6 (clipped). (1)
Shape: rises linearly, then flat ceiling of 3.6 for r≥1.2; below r=0.8 it stays the unclipped line (since min picks smaller). So the objective is capped above for large r. (1)
Because LCLIP=min(unclipped,clipped), it never exceeds the unclipped surrogate — it is a lower bound on the true (unclipped) objective, hence "pessimistic." (2)
Directionality: (4)
For A^t>0 (good action): we want to increase πθ(at), i.e. increase rt. Clipping caps the gain once rt>1+ϵ, so it removes incentive to push rt too high. But decreasing rt (below 1) is not clamped — the gradient still flows. So the constraint is one-sided: it limits over-eager increases, not decreases.
For A^t<0 (bad action): symmetric — clipping limits pushing rt below 1−ϵ, but does not constrain increasing rt. Net effect: only the update direction that would exploit a large ratio to gain surrogate is clamped; the corrective direction remains free.
Failure mode: reward model over-optimization (reward hacking / Goodhart's law) — the policy exploits errors in rϕ, so proxy reward rises while true (human) quality falls. (2)
Two mitigations tied to the objective (2, one each):
Increase β (KL penalty) to keep πθ close to πref, limiting how far it can drift to exploit rϕ.
Early stopping / KL budget (stop when KL(πθ∥πref) exceeds a threshold), or retrain/ensemble the reward model on newly generated on-policy samples to close the exploited gap.
Top-1: c1 (similarity 1.0 — same direction as q). (1)
Equivalence (3): For unit vectors ∥a∥=∥b∥=1,
∥a−b∥2=∥a∥2+∥b∥2−2a⋅b=2−2cos(a,b).
So squared Euclidean distance is a strictly decreasing affine function of cosine similarity; ascending distance order = descending cosine order. Ranking is identical.
Exact: O(Nd)=106⋅768=7.68×108 ops. (1)
Approx: O(dlog2N)=768⋅log2(106)≈768⋅19.93≈1.53×104 ops. (1)
Ratio ≈1.53×1047.68×108≈5.0×104 (≈50,000× fewer ops). (1)
Recall < 100% because ANN graph traversal (HNSW) is heuristic/greedy and may miss true neighbours near cluster boundaries — it trades accuracy for the huge speedup. (1)