# Reinforcement learning

> Learning by trial and error, guided by rewards for good outcomes.

- Level: Intermediate
- Topics: AI
- URL: https://tidbit.legios.com.ar/reinforcement-learning/
- In Spanish: [Aprendizaje por refuerzo](https://tidbit.legios.com.ar/es/reinforcement-learning/)

**Reinforcement learning** (RL) is a way of training AI where nobody shows the system the right answers. Instead, an **agent** acts in some environment (a game, a simulation, a conversation), gets a **reward** when things go well and a penalty when they go badly, and gradually learns which actions lead to more reward. It is trial and error, repeated millions of times.

Its most famous success came in 2016, when DeepMind's AlphaGo beat Lee Sedol, one of the world's best players of Go, a board game long thought too subtle for computers. AlphaGo improved partly by playing against itself over and over. RL is also used to train robots to walk or grasp, to control cooling in data centers, and in many game-playing systems.

For today's chatbots, RL matters in two ways. **RLHF** (reinforcement learning from human feedback) is a step where people compare pairs of answers, a separate model learns their preferences, and the chatbot is then trained to produce answers that preference model scores well. It is a big part of why assistants sound helpful and polite. More recently, RL on problems with checkable answers, like math and code, has been used to train models that reason step by step. The classic risk is **reward hacking**: the agent finds a loophole that earns points without doing what you actually wanted, so the reward has to be designed with care.

## An analogy

Like training a dog with treats. You never explain the rule; you reward the behavior you want, and the dog figures out what earns the treat. If you reward the wrong thing by accident, it will learn that instead.

## Keep in mind

- Learns from rewards and penalties, not from labeled answers.
- AlphaGo's 2016 win at Go is the landmark example.
- RLHF uses human preferences to shape how chatbots respond.
- A badly designed reward gets gamed: reward hacking.

## Go deeper

- [Reinforcement learning on Wikipedia](https://en.wikipedia.org/wiki/Reinforcement_learning)
- [Illustrating RLHF (Hugging Face)](https://huggingface.co/blog/rlhf)
- [What is reinforcement learning? (IBM)](https://www.ibm.com/think/topics/reinforcement-learning)

## Related terms

- [Training and inference](https://tidbit.legios.com.ar/training-and-inference/): Training builds the model once; inference is using it, millions of times a day.
- [Artificial intelligence](https://tidbit.legios.com.ar/artificial-intelligence/): Getting computers to do things that, until recently, only people could do.
- [AI agent](https://tidbit.legios.com.ar/ai-agent/): An LLM that can take actions, check the results and keep going until the job is done.
- [Data center](https://tidbit.legios.com.ar/data-center/): A building full of servers where the internet, the cloud and AI actually run.
- [Chatbot](https://tidbit.legios.com.ar/chatbot/): A program you talk to by typing or speaking, as if it were a person.
