Implement the core DPO algorithm: compute sequence log probabilities, the DPO loss with a frozen reference model, and a gradient-based parameter update that increases the margin between chosen and rejected sequences.
Your team wants to align a language model to human preferences without the complexity of RLHF. DPO reformulates the preference learning problem as a simple classification loss over pairs of (chosen, rejected) responses. Given a policy model and a frozen reference model, DPO adjusts the policy so that chosen responses become more likely relative to rejected ones, while staying close to the reference. You're given a SimpleLanguageModel with embedding and output projection. Implement the sequence log probability computation, the DPO loss formula, and a gradient step that updates only the policy model's parameters. The reference model must remain frozen throughout training.
Ask me about the code, bugs, or concepts.
I'll guide you in plain English, no code output.
Budget: 50K tokens per lab