Alignment, Safety & Security: RLHF, DPO & Guardrails
AI Alignment ensures model behaviors correspond to human values, safety guidelines, and intended business policies. Reinforcement Learning from Human Feedback (RLHF) uses human preference ratings to train a reward model that fine-tunes the generator. RLAIF uses AI-generated preference feedback. Direct Preference Optimization (DPO) simplifies alignment by optimizing preferences directly on text pairs without a separate reward model.
Constitutional AI trains models to adhere to a written set of principles through self-critique. Security challenges include Prompt Injection (crafting malicious inputs that override system rules), Jailbreaks (bypassing safety filters), and PII leaks. Red Teaming involves adversarial testing to identify vulnerabilities before deployment.
Exercise
Write an input sanitization function to block common prompt injection patterns, and construct a DPO preference dataset pair.
Check your understanding
What is the difference between RLHF and DPO?Show answerHide answer
Answer
RLHF trains an intermediate reward model to score outputs; DPO directly optimizes the model's loss function on preferred vs. rejected response pairs without a separate reward model.What is Prompt Injection?Show answerHide answer
Answer
An attack vector where untrusted user input contains malicious instructions designed to hijack the model's system prompt rules.