Counting to Explore and Generalize in Text-based Games

Xingdi Yuan, Marc-Alexandre Côté, Alessandro Sordoni, Romain Laroche, Remi Tachet des Combes, Matthew J. Hausknecht, Adam TrischlerarXiv 2018

Abstract

We propose a recurrent Reinforcement Learning (RL) agent with an episodic exploration mechanism that helps discover good policies in text-based game environments. We show promising results on a set of generated text-based games of varying difficulty where the goal is to collect a coin located at the end of a chain of rooms. In contrast to previous text-based RL approaches, we observe that our agent learns policies that generalize to unseen games of greater difficulty.

Introduction

Text-based games, such as the classic Zork, present a unique set of challenges for standard Reinforcement Learning agents. These environments are fundamentally Partially Observable Markov Decision Processes (POMDPs), where the agent must interpret textual descriptions of its immediate surroundings rather than having access to the full state of the world.

The primary obstacles include a combinatorial action space, where commands must be generated from a large vocabulary, and extremely sparse rewards, where an agent may wander through dozens of rooms before encountering a point-scoring item. Furthermore, standard agents often struggle with generalization, effectively memorizing specific paths in training environments but failing when faced with even minor map variations. This research aims to bridge the gap between path memorization and generalizable exploration strategies.

Methodology

To address these challenges, we introduce the LSTM-DRQN (Deep Recurrent Q-Network). This architecture leverages recurrence to maintain a history of the agent's trajectory, which is crucial for navigating partially observable environments.

The LSTM-DRQN architecture, featuring a Representation Generator to encode text and an Action Scorer to maintain history and predict Q-values.

The model consists of two main components:

  1. Representation Generator: Uses an LSTM to encode textual observations into dense vectors.
  2. Action Scorer: Employs a second LSTM to maintain a "history" of previous steps ($h_{t-1}$), allowing the agent to remember its past actions and observations.

Episodic Count-Based Exploration

The core innovation is the introduction of an episodic count-based exploration bonus. Unlike cumulative bonuses that reward global rarity across all training episodes, the episodic bonus rewards the agent for visiting a state for the first time within the current episode. By resetting the counter at the start of every new game, the agent is incentivized to exhaustively search its current environment, effectively using its recurrent memory to avoid backtracking and push into unknown territory.

Experimental Setup

Experiments were conducted using the TextWorld framework to procedurally generate "Coin Collector" games. The task requires the agent to navigate a chain of rooms to find and pick up a coin. Difficulty is modulated in two ways:

  • Mode: Easy (linear path), Medium (one distractor room per path node), and Hard (two distractors per node, creating a complex branching structure).
  • Level: Defined by the length of the optimal path, ranging from L5 to L30.

Key Results and Generalization

The proposed agent, DQN++ (incorporating the episodic bonus), demonstrated significant improvements over vanilla DQN and DRQN baselines, particularly in "Hard" mode where baselines failed to learn.

Performance comparison showing average rewards and steps across training (L10) and test levels (L5-L30). DQN++ shows near-perfect zero-shot generalization.

A standout result is the agent's zero-shot generalization capability. An agent trained exclusively on 500 different L10 games was able to solve L30 games—which are three times longer and significantly more complex—with near-perfect efficiency without any additional training. This suggests the agent learned a general navigation heuristic rather than specific map layouts.

Discussion

Analysis of the agent's behavior in complex maps revealed the emergence of sophisticated strategies, such as a "wall-following" heuristic where the agent explores exits in a consistent order to ensure coverage. The combination of recurrence and episodic rewards provides both the capacity for memory and a functional reason to utilize it. Training on a diverse distribution of structurally similar games further prevents overfitting, forcing the agent to internalize the underlying logic of navigation.

Limitations and Future Work

While successful, the current approach has limitations. The "Coin Collector" maps are acyclic (trees); the learned strategies might struggle in environments with cycles where the agent could return to a previous state via a different path. Additionally, the command syntax remains simple (verb + object), and the environments are deterministic. Future work will explore "multi-hop" logic tasks—such as finding keys to unlock distant doors—and more linguistically complex environments to further test long-term planning and linguistic reasoning.

Summary updated

BibTeX
@misc{yuan2018counting,
  author = {Xingdi Yuan and Marc-Alexandre Côté and Alessandro Sordoni and Romain Laroche and Remi Tachet des Combes and Matthew J. Hausknecht and Adam Trischler},
  title = {{Counting to Explore and Generalize in Text-based Games}},
  year = {2018},
  eprint = {1806.11525},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1806.11525},
}
Figure