Reinforcement learning trains an agent through trial and error — rewarding good actions and penalizing bad ones — a fundamentally different paradigm from the supervised learning most people first encounter.
The Core Loop
state = environment.reset()
for step in range(max_steps):
action = agent.choose_action(state) # policy: what to do given the current state
next_state, reward, done = environment.step(action)
agent.learn(state, action, reward, next_state) # update the policy based on outcome
state = next_state
if done:
break
Key Concepts
- Policy — the agent’s strategy for choosing actions given a state
- Reward signal — the ONLY feedback the agent gets; no labeled “correct” actions, just numerical reward or penalty after the fact
- Exploration vs exploitation — the fundamental tension between trying new actions (exploration) to potentially discover something better, versus repeating known-good actions (exploitation)
Why It’s Different from Supervised Learning
Supervised learning trains on labeled examples of correct answers directly. RL never sees a “correct answer” at all — it only learns from delayed, sometimes sparse reward signals, and must credit-assign reward back to earlier actions that contributed to it, a genuinely harder learning problem. This is exactly why RL famously mastered games (Go, Atari, StarCraft) where a clear reward signal (winning) exists, but is trickier to apply to problems without such a clean, quantifiable feedback signal.
RL’s Modern Relevance: RLHF
Reinforcement Learning from Human Feedback (RLHF) is exactly how modern LLMs are fine-tuned to be more helpful and less harmful — human preference rankings between model outputs become the reward signal that shapes the model’s behavior beyond its initial pretraining.