In RLHF you need the gradient of J(θ) = E[R(y)], where y is a token sequence sampled from the policy LLM π_θ and R is a reward model's score treated as a black box. Which gradient estimator fits this setting, and why?
Show the answer and explanation
Correct answer: B, The score-function (REINFORCE) estimator E[R(y)·∇θ log π_θ(y)]: it needs only the rewards and log-probabilities of sampled sequences, never ∂R/∂y, which does not exist for discrete tokens.
Explanation Calculus & Gradients
The log-derivative (score-function) trick moves the gradient inside the expectation without ever differentiating R: ∇θ E[R(y)] = Σ_y R(y)·∇θ π_θ(y) = Σ_y R(y)·π_θ(y)·∇θ log π_θ(y) = E[R(y)·∇θ log π_θ(y)].
You sample sequences, score them, and weight each sequence's log-probability gradient (the sum of its per-token log-prob gradients) by its reward. R can be any black box: a reward model, a unit-test pass rate, a human rating. This is REINFORCE, the root of the policy-gradient methods used in RLHF.
Its weakness is variance. Because E[∇θ log π_θ(y)] = 0, subtracting a baseline b that does not depend on the sampled y (a learned value estimate, or the mean reward of the other samples drawn for the same prompt) keeps the estimator unbiased while reducing variance: E[(R(y) − b)·∇θ log π_θ(y)].
| Score function | Reparameterisation | |
|---|---|---|
| Needs ∂R/∂y | no | yes |
| Sample space | discrete or continuous | continuous, z = μ + σ·ε |
| Variance | high, needs a baseline | usually low |
| Typical use | RL, RLHF, discrete latents | VAEs, continuous policies |
Why the others fail: reparameterisation needs a differentiable path from θ through the sample to R, but tokens are discrete, so there is no y = μ + σ·ε form (Gumbel-softmax relaxations exist, but they are biased and still need a differentiable R). The formula with ∇θR(y) differentiates the wrong factor, since R does not depend on θ except through the sample. Score-function estimates are unbiased even with a black-box R, so fine-tuning on the best samples (rejection-sampling fine-tuning) is a useful complement, not the only option.
Interview tip: derive the trick in one line (∇π = π·∇log π) and name baselines or group-normalised rewards as the standard variance fix.