Case-based reasoning for better generalization in textual reinforcement learning

Mattia Atzeni, Shehzaad Zuzar Dhuliawala, Keerthiram Murugesan, Mrinmaya Sachan

TL;DR

Researchers have developed a hybrid reinforcement learning (RL) agent that uses Case-Based Reasoning (CBR) to master text-based games. By storing successful past experiences as "cases" and retrieving them to solve novel situations, the agent achieves state-of-the-art results and shows remarkable resilience to "out-of-distribution" shifts that typically cripple purely neural models.

What Problem Does This Paper Address?

Reinforcement learning agents often struggle with generalization. In text-based games (TBGs)—think Zork or Adventure—an agent must navigate complex worlds using only text descriptions. While modern neural agents can learn to play specific games, they are notoriously sample-inefficient (often taking 10x more steps than a human) and fail miserably when moved to a slightly different environment.

The core issue is that standard deep RL agents are "forgetful" in a structural sense; they bake their knowledge into millions of weights rather than explicitly remembering what worked before. When faced with a new room or a new object, they can't easily say, "This looks like that time I used a key on a chest in the previous level."

Methods

The authors propose a framework inspired by the classic cognitive science cycle of Case-Based Reasoning:

The Case-Based Reasoning framework for textual RL, illustrating the Retrieve, Reuse, Revise, and Retain cycle.
  1. Retrieve: When the agent faces a new state, it looks through a "case memory" for the most similar past situation.
  2. Reuse: It takes the action that worked in that past case and maps it to the current context (e.g., "unlocking a wooden door" becomes "unlocking a metal door").
  3. Revise: If the retrieved action is valid, the agent tries it. If not, it falls back to a standard neural RL policy (the "Revise" step).
  4. Retain: If an action leads to a positive reward, the agent stores this new experience in its memory.

Technical Innovations:

  • Seeded Graph Attention: The agent represents the game state as a knowledge graph. To create a compact "fingerprint" of a situation, it uses a graph attention mechanism that "seeds" its focus on the specific entities involved in an action, ensuring the representation is context-aware.
  • Vector Quantization (VQ): To make the memory searchable and scalable, the authors use VQ to discretize continuous neural representations into "KD codes." This prevents the memory from exploding in size and allows for efficient similarity lookups.
  • Symbolic Action Reuse: Since TBG actions are often template-based (e.g., take [object]), the agent can symbolically swap entities from a past successful case into the current state.

Datasets

The approach was evaluated on two major benchmarks:

  1. TextWorld Commonsense (TWC): A set of games requiring the agent to tidy up a house using commonsense knowledge. It features "in-distribution" and "out-of-distribution" (OOD) settings to test generalization.
  2. Jericho: A suite of 33 classic interactive fiction games (like Zork, Enchanter, and Detective) that vary in difficulty from "possible" to "extreme."

Key Insights and Ideas

  • Memory as a Buffer Against Distribution Shift: The most striking finding is how CBR handles OOD scenarios. While standard neural agents saw a 35% drop in performance when moved to unseen environments, the CBR-enhanced agents only dropped by 6%.
  • Discretization is a Feature, Not a Bug: Using Vector Quantization to turn "fuzzy" neural vectors into discrete codes didn't just save memory; it made retrieval more stable. Ablation studies showed that storing raw continuous vectors led to "memory OOM" (out of memory) errors and poorer retrieval.
  • Hybrid Strength: The CBR system acts as a high-precision "shortcut." When the agent is in familiar territory, it uses the memory. When it's lost, the underlying neural agent takes over to explore, eventually feeding new successful cases back into the memory.

Key Results

  • State-of-the-Art: The CBR agent (specifically the "BiKE + CBR" variant) achieved the best results on 24 out of 33 Jericho games, strictly outperforming all previous baselines in 18 of them.
  • Sample Efficiency: In the TextWorld environments, CBR agents converged to high scores significantly faster than their purely neural counterparts.
Learning curves demonstrating that adding CBR to various baselines improves sample efficiency and final performance.
  • Qualitative Success: Visualization of the learned representations (via t-SNE) showed that the retriever successfully clustered similar objects (e.g., different types of clothing or containers) together, even if it hadn't seen those specific items during training.

Limitations and Future Work

  • Template Dependency: The current "Reuse" logic relies on actions having a clear template structure. Adapting this to purely free-form, natural language action spaces remains a challenge.
  • Memory Management: While VQ helps, the paper notes that very long-running games might still face challenges in deciding which cases are "stale" and should be evicted from memory.
  • Complex Mapping: The current system uses a relatively simple symbolic mapping for action reuse. More complex scenarios might require a more sophisticated "analogy engine" to map past solutions to current problems.

The authors suggest that future work could explore more advanced "Retain" functions—perhaps using the agent's own uncertainty to decide which experiences are worth remembering.

Summary updated

BibTeX
@inproceedings{atzeni2022case,
  author = {Mattia Atzeni and Shehzaad Zuzar Dhuliawala and Keerthiram Murugesan and Mrinmaya Sachan},
  title = {{Case-based reasoning for better generalization in textual reinforcement learning}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=ZDaSIkWT-AP},
}
Figure