Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 10 min read How-to mediumAdept

Deep Q-Learning with Space Invaders

Deep Q-Learning replaces the tabular Q-table with a neural network that maps a state to Q-values for every action, making RL feasible for huge state spaces like Atari frames (256^100800 possible observations). The DQN preprocesses frames to 84x84 grayscale and stacks four of them to capture motion, then passes them through three convolutional layers and fully connected layers. Training is stabilized with experience replay (reusing and decorrelating samples), a fixed target network copied every C steps, and Double DQN, which decouples action selection from target evaluation to curb Q-value overestimation. The unit closes with a Colab tutorial that trains a Space Invaders agent using RL-Baselines3 Zoo.

Assumes: Q-Learning basicsneural networksBellman equation

Related posts

  • An Introduction to Deep Reinforcement Learning

    Hugging Face easyNovice

    Deep reinforcement learning trains an agent to act in an environment through trial and error, using rewards as its only feedback, with the goal of maximizing expected cumulative (discounted) return. The core concepts are the state/action/reward loop, the Markov property, observation vs. state, discrete vs. continuous action spaces, discounting with gamma (typically 0.95–0.99), episodic vs. continuing tasks, and the exploration/exploitation tradeoff. The two main ways to learn an optimal policy are policy-based methods, which map states directly to actions or action distributions, and value-based methods, which learn state values and act greedily toward them. It is the first unit of Hugging Face's free Deep RL course, which goes on to train a lunar lander agent with Stable Baselines3.

  • An Introduction to Q-Learning Part 2/2

    Hugging Face mediumAdept

    Q-Learning is an off-policy, value-based reinforcement learning algorithm that uses temporal-difference updates to train a Q-table of state-action values, from which the optimal policy follows directly. The walkthrough covers the four steps of the algorithm: initializing the Q-table, choosing actions with a decaying epsilon-greedy strategy, observing reward and next state, and updating Q(S,A) toward a TD target built from the reward plus the discounted best next-state value. It explains why acting epsilon-greedily while updating greedily makes Q-Learning off-policy, contrasting it with on-policy Sarsa. It then traces two hand-computed training steps in a mouse-and-cheese maze (learning rate 0.1, gamma 0.99) before pointing to a Colab notebook that trains agents on FrozenLake-v1 and Taxi.

  • Jack of All Trades, Master of Some, a Multi-Purpose Transformer Agent

    Hugging Face hardMaster

    JAT (Jack of All Trades) is an open reproduction of DeepMind's Gato: a single GPT-Neo-based Transformer trained by behavioral cloning on a new dataset of expert trajectories from Atari, BabyAI, Meta-World and MuJoCo, plus text and image-caption data. It interleaves observation/reward and action embeddings, using modality-specific encoders (CNN for images, linear layers for continuous and discrete values, ViT for images, GPT-2 tokenization for text), with MSE or cross-entropy losses per modality. Across 157 tasks it averages 65.8% of expert performance, ranging from 14.1% on Atari 57 to 99.0% on BabyAI, with only rudimentary NLP and CV ability. Adding observation prediction as an auxiliary loss helps when weighted around κ=0.005 and hurts at 0.5, and the expert agents, dataset and model are all released on the Hugging Face Hub.

  • Advantage Actor Critic (A2C)

    Hugging Face mediumAdept

    Actor-Critic methods reduce the high variance of Monte-Carlo policy-gradient estimates in Reinforce by pairing a policy network (Actor) with a value network (Critic) that scores the actions taken. A2C stabilizes training further by using the advantage function, which measures how much better an action is than the state's average value. The TD error serves as a practical estimator, so separate Q and V networks aren't needed. The unit closes with a Colab exercise training bipedal and spider walkers in PyBullet with Stable-Baselines3.

  • Mini-R1: Reproduce Deepseek R1 „aha moment“ a RL tutorial

    Hugging Face hardMaster

    Recreates DeepSeek R1's "aha moment" by training Qwen2.5-3B-Instruct with GRPO on the Countdown numbers game, using rule-based format and accuracy rewards in TRL with DeepSpeed ZeRO-3 and vLLM generation on 4x H100s. GRPO drops PPO's value model and instead normalizes rewards within a group of sampled outputs to compute advantages. The DeepSeekMath hyperparameters became unstable after about 150 steps, so the learning rate was lowered to 5e-7 and the KL beta to 0.001. The model learned the output format by step 50 and reached about 50% success by step 450 (roughly 6 hours), shifting around step 200 from verbal reasoning to programmatic trial-and-check search.

The quest for software engineering knowledge.

Look:
Layout: