Elamur Research

Playing Text-Adventure Games with Graph-Based Deep Reinforcement Learning

Paper · 2019 · Prithviraj Ammanabrolu and Mark Riedl

Summary

A text adventure tells a player what they can see and asks them to type what they want to do. To complete a quest, the player may need to remember an object from a room they have left, find a route back, and work out which command will use it. A learning agent faces those problems together. The latest description gives it only a partial view, and the game can recognize many commands that make little sense in the current situation. Prithviraj Ammanabrolu and Mark Riedl study whether an agent can learn to play faster by organizing what it discovers in a knowledge graph.

Their agent, KG-DQN, builds that graph as it plays. It extracts relationships from the game’s prose and adds others with rules suited to room descriptions and movement. The graph can retain where the player found an item and how rooms connect after those facts have dropped out of the current description. It serves two jobs. It gives priority to commands involving known and related objects, and it provides a source of information for the neural network that estimates how much future reward a move could bring. The full agent also learns from walkthroughs of related games before it starts reinforcement learning. In that preliminary task, it treats the current observation as context and the expert’s next command as the answer, a form of question answering.

The authors test the approach on small and large games generated with the same household theme in TextWorld. In the small game, KG-DQN and LSTM-DQN, the strongest baseline, both earn the highest possible reward of 5. The results section reports that KG-DQN converges 40% faster there. On the large game, no agent reaches the maximum reward of 10 in the learning results, and LSTM-DQN takes more than 300 episodes to settle at the same reward level as KG-DQN. The graph-based variants have similar convergence rates, which leads the authors to identify the graph they share as the likeliest contributor to faster learning.

The agents can earn similar rewards while taking very different routes through a quest. After training, the full KG-DQN completes the small game in an average of 73.7 steps and the large game in 265.9, close to LSTM-DQN’s averages of 72.4 and 260.3. The comparisons that remove command pruning or walkthrough pretraining give longer solutions wherever those variants are reported. The result is a faster route to learning a policy with comparable quest length on the tested games. The walkthroughs transfer some information about which moves are worth trying on a new layout, and the agent still learns that particular game by interacting with it.

Deep dive: Playing Text-Adventure Games with Graph-Based Deep Reinforcement Learning

How KG-DQN learns to play text adventures by building a graph from game descriptions, narrowing its choices, and learning from walkthroughs. · about 38 minutes to read

The problem and its context

What a room description leaves out

An agent in a text adventure has to make decisions about a world it mostly encounters through descriptions. The simulator keeps track of the full world, including objects and locations currently out of sight. The agent receives a textual observation after it acts. The observation may describe a room, report the result of an attempted action, or mention a feature that will matter much later. The distinction between what the simulator knows and what the player can read is the source of partial observability in the paper’s setup.

Consider the objects involved in opening a lock with a key. The command needs the right objects, and the player may acquire the relevant information at different points in the game. A key seen earlier can matter when a lock appears later, even if the description of the lock says nothing about the key. Where that item was found can matter as much as its name. The player also needs to know which relationships have changed. Where the player is standing can change on each move. A route discovered between rooms can remain relevant well after the player has left both rooms. A record that treats every fact as equally temporary would throw away the route, while a record that treats every fact as equally persistent would accumulate obsolete information about the player.

The task brings together the interpretation of incoming language, the retention of useful context, and the choice of an outgoing command. From the paper’s perspective, this makes games a way to study agents that must learn about an environment through communication and do something to it through the same interface. The incoming text concerns a world that can change. The outgoing text is an action that can bring about a change, fail, or produce information useful on a later turn. Its value depends on what has already happened and what progress it makes possible.

The paper formalizes the setting as a partially observable Markov decision process. The hidden state belongs to the simulator, and an observation is evidence about that state. An agent can act on the evidence it has accumulated, including the results of earlier decisions. That history matters because the same sort of room description can occur during very different stages of a quest. A move useful before collecting an item may be redundant after collecting it. The graph is the authors’ way of giving part of that history an explicit structure that the agent can use again.

The other difficulty is the size of the action space. Commands can combine verbs and object names, including pairs of objects for actions such as using a key with a lock. Increasing the number of objects therefore increases the number of combinations the agent could try. Some commands, including commands for movement or inspection, require no object. The object-taking commands create the larger search problem because knowing a verb and several object names supplies many possible pairings.

The experiments make a particularly important distinction between commands recognized by the parser and commands admissible in the current situation. The agent can choose from a game-wide dictionary recognized by the parser. A command in that dictionary can refer to something the player cannot currently reach or to a combination with little prospect of advancing the quest. TextWorld can supply the admissible commands for the current situation, and the authors withhold that list from the learning agents. That keeps the choice about where to search within the agent’s own decision procedure.

The two problems reinforce one another. If the agent remembers little about earlier observations, it has less evidence for ruling out unpromising combinations. If it explores mostly unpromising combinations, it receives fewer examples of actions that earn reward. Useful exploration can involve a move that is immediately unremarkable, such as reaching a room where a needed object can be found. The eventual reward must then help the agent learn something about decisions made earlier. The authors want to make this search more directed while keeping a way to try commands whose usefulness has yet to become apparent.

How earlier agents scored or eliminated actions

The paper discusses an earlier LSTM-DQN agent that encodes the current observation with a recurrent neural network. An LSTM reads a sequence and maintains an internal state as it processes it. In this predecessor, the encoded observation is used to score the command verb and the associated object arguments. The resulting scores are averaged to estimate the value of the action. That decomposition provides a way to score a command through its parts, making it an appropriate baseline for the new architecture. Language Understanding for Text-based Games Using Deep Reinforcement Learning

The Deep Reinforcement Relevance Network, or DRRN, supplies another precedent. It encodes an action and a state separately, then estimates the value of their pairing through an interaction between the two encodings. This is relevant when a command is a text string that ought to have its own representation. KG-DQN follows the broad separation of state encoding from action encoding. In the related-work discussion, the authors describe both predecessors as lacking explicit conditioning on earlier observations and as leaving the action space unpruned. The concern is that a good scoring network can still spend much of its experience on low-value trials when it searches a large command dictionary.

The Action Eliminating Network illustrates a different response to the search problem. As the authors describe it, that network learns from emulator feedback which actions to rule out in a given state and restricts consideration to likely candidates. It offers a precedent for making exploration more efficient by removing choices. KG-DQN derives its preliminary ranking from the relationships its own agent has accumulated. The basis for exclusion can therefore reflect something learned in another room or on an earlier turn. Feedback from the game still trains the value estimator, and the graph supplies a separate source of evidence about which actions deserve that estimator’s attention.

The paper also draws on work outside game playing. It describes a story-ending system that used commonsense relations from ConceptNet and attention over a graph to inform a prediction. The relevant precedent is turning a collection of relationships into a vector suited to a neural decision. KG-DQN’s relationships come from the particular game being explored. They describe such things as rooms, exits, and objects, and they change when the player moves or learns something. The graph provides a place to store those facts, while attention governs how their representations contribute to the estimate the agent uses to act.

Finally, prior work on expressing different language tasks in a question-answering format motivates the training scheme. A walkthrough already contains an observation followed by the action an expert chose. The authors use that pairing to teach parts of the agent what kinds of command tend to fit particular observations. Reinforcement learning can then use the game’s feedback to refine those parts and to train the graph-based decision mechanism. The Natural Language Decathlon

The method, step by step

From a turn of play to a decision

KG-DQN stands for Knowledge Graph DQN, where DQN is a deep Q-network. The network estimates the return associated with an action, including reward the action may make possible later. Each turn gives it two sources of evidence about the situation. One is the latest game text, encoded as a sequence. The other is the graph, updated with information derived from that text and the preceding action. The agent also uses the graph before value scoring, to make a shortlist from the command dictionary. In the full variant, walkthrough training supplies initial values for selected network weights before these turns of reinforcement learning begin.

How KG-DQN handles a turn of play

The steps in order.

How KG-DQN handles a turn of playStep 1: Read the game’s latest observation1. Read the game’s latest observationStep 2: Update relationships in the world graph2. Update relationships in the world graphStep 3: Rank commands by objects and graph paths3. Rank commands by objects and graph pathsStep 4: Encode the graph and current observation4. Encode the graph and current observationStep 5: Encode candidate commands and estimate their values5. Encode candidate commands and estimate their valuesStep 6: Choose a command with occasional random exploration6. Choose a command with occasional random explorationStep 7: Store game feedback and train from replay7. Store game feedback and train from replay

The paper describes the interaction in the following formal terms.

⟨S, T, A, Ω, O, R, γ⟩

The angle brackets enclose the elements of the partially observable decision process. S is the set of underlying environment states. T describes how likely the possible transitions between those states are, conditional on the situation and action. A refers to the material from which text commands are formed in the formal description. In the implementation, the paper also uses A for the dictionary of complete commands. Ω is the set of observations. O gives the conditional probabilities of receiving observations. R is the reward function, and γ discounts future reward. Later, the discussion of action-space size uses O for objects. The meaning there follows from its role in the count.

The symbol for the state also has two related uses. A true environment state is the simulator’s full situation. The state fed to the value estimator is a vector assembled from information the agent can observe or has stored. The vector is what the agent can actually use to make a decision. In particular, the simulator’s list of currently admissible actions is outside that representation. The shortlist computed by the agent is its own estimate of where useful actions might be found.

Recording facts and deciding which persist

The graph uses RDF triples, records containing a subject, a relationship, and an object. The endpoints are entities or labels drawn from the game, and the relationship runs from the subject to the object. For example, a chamber can have a bed stand. This can be stored as an edge pointing from the chamber to the bed stand with a label for possession or containment. The information that a chamber lies east of a basement can occupy a different edge. The labels and directions allow the graph to store that the entities stand in a particular relationship.

The general extraction component is Stanford’s Open Information Extraction, or OpenIE. It derives relation triples from observations. The authors add hand-written rules because game descriptions have regularities that a general extractor may miss. A description can mention a northern exit without giving the room as the subject of the same statement. A rule attaches the exit to the current room. The identity of that room lets the graph preserve a more useful fact than a detached mention of north. The combination of a general extractor and rules tailored to recurring forms is the paper’s use of information extraction.

The special rules cover room contents, entrances and exits, movement between rooms, and the changing relationships of the player. When the text describes an item in the chamber, the graph can attach it to the room through a possession relation. When a player moves east from the basement into the chamber, the movement command supplies the direction linking the two locations. That connection depends on the action the player just took in conjunction with the resulting observation. It need not be fully written out in the new room description. OpenIE supplies other triples from the text.

A special node identifies the player. Its outgoing relations are refreshed as the player acts, with a special provision for inventory relations, which are retained by this clearing rule. The effect is to treat immediate context differently from facts intended to last. If the player leaves a room, the graph can keep its exits and contents for future reference while updating the relationships associated directly with the player. The rooms and their contents can therefore stay connected in memory even as the location under discussion changes.

An item remembered in the graph is evidence that the agent encountered it, and its old relationship to a room may still be valuable. Whether the item is immediately accessible is a different question. The graph represents discoveries in a form useful for decisions, and its rules determine which discoveries carry forward. It does not attempt to reconstruct the simulator’s full state. The authors aim for a small collection of hand-written rules that can recur across games, alongside triples from the general extractor.

Shortlisting commands

To see why a shortlist is attractive, consider the scale implied by combining verbs with object pairs. The paper expresses the growth as follows.

A = O(|V| × |O|²)

Here A denotes the size of the action space in the count. The outer O(…) is order notation, describing how the number grows. V denotes the action verbs, and the inner O denotes the distinct interactive objects. The bars give the number of members in each collection, × indicates multiplication, and the exponent ² reflects the allowance for a verb with two object arguments. This is a description of growth under the paper’s command assumption. Commands that need fewer arguments, such as a movement or inspection command, need fewer choices to specify.

The agent ranks the available command strings against its graph at the current turn. A command gets +1 for each object it names that appears in the graph. A command with two objects can receive an additional +1 if a valid directed path connects those objects in the graph. The scoring rule favors a command that names things the agent has encountered, with additional weight when the graph joins those things. The agent retains the top k commands, where k denotes the size of the shortlist. The paper uses Aₜ for the restricted action set at turn t.

The directed-path check supplies a coarse signal. A connection can make a pair of objects a better candidate for examination. The score contains no term for how much reward a particular verb will earn when used with that pair. It can give a known key and a related lock a high priority, while the value network still has to learn which command involving them is helpful. Similarly, an object-free command has no object matches to collect under the stated rule, even though moving or inspecting can be important to progress. The ranking is a heuristic for allocating search, and later decisions use evidence beyond that ranking.

The authors explicitly allow exploration outside the shortlist. The graph is built from experience, so it can be thin precisely when the agent needs to discover an unfamiliar entity or an unfamiliar combination. A rule that recognizes previously seen objects will naturally favor those objects. Random exploration from the full dictionary gives a command a route into the agent’s experience even when it receives little support from the current graph. The learner can then observe its outcome and update both its record of the world and its estimates of value.

Encoding the graph and the current description

The same graph that ranks commands is passed to a neural encoder. Each node has a feature vector derived from its label. For a label containing several tokens, the encoder averages the corresponding word embeddings. The features describe the language used to name the node, and the graph’s adjacency matrix supplies the pattern of connections. The matrix records which nodes are adjacent and determines the neighborhoods used for the attention computation.

H = {h₁, h₂, …, hₙ},  hᵢ ∈ ℝ^F

H is the collection of node feature vectors. Each hᵢ is the vector for node i, and the subscripts index individual nodes through n, the number of nodes, denoted N in the paper’s prose. ∈ means that the vector belongs to the indicated space. ℝ^F is the space of real vectors with F features. The braces delimit the collection and the ellipsis stands for the intervening nodes.

Attention gives the encoder a learned way to weight information from a node’s neighbors. The paper uses graph attention, with a scoring mechanism related to earlier attention work in translation. For a node and a particular neighbor, the first step is a compatibility score computed from their features. The adjacency structure determines the candidates for this computation. The authors use third-order neighborhoods in that structure. Neural Machine Translation by Jointly Learning to Align and Translate

eᵢⱼ = LeakyReLU(p · W(hᵢ ⊕ hⱼ))

eᵢⱼ is the unnormalized attention score from node i to node j. hᵢ and hⱼ are the respective node vectors. ⊕ joins their coordinates by concatenation. W is a learned linear transformation, and p is a learned vector that is combined with the transformed features through the dot product ·. LeakyReLU is the nonlinear activation applied to the resulting scalar. The paper lists W with shape 2F × F and p with 2F entries. Its written score uses a joined input, so the operand layout would need to be settled before treating those dimensions and that expression as literal implementation notation.

A compatibility score on its own says little about how much information should pass from one neighbor relative to another. The next operation makes the scores for a neighborhood comparable by normalizing them together.

αᵢⱼ = exp(eᵢⱼ) / ∑ₖ∈𝒩 exp(eᵢₖ)

αᵢⱼ is the normalized weight node i assigns to neighbor j. exp denotes the exponential function. eᵢⱼ and eᵢₖ are the unnormalized scores for the indicated pairs. 𝒩 is the neighborhood of node i defined using the graph adjacency, and k runs over that neighborhood in the sum ∑. The slash indicates division by the total over the neighborhood. This operation is a softmax. A neighbor’s weight depends on its score in relation to the others available to the same node.

The graph calculation uses multiple heads, meaning independent versions of the attention computation. Each can learn a separate weighting of the features. The resulting representations are joined and projected into the vector used for the graph.

gₜ = f(W_g (∥ₖ₌₁ᴷ σ(∑ⱼ∈𝒩 αᵢⱼ⁽ᵏ⁾ W⁽ᵏ⁾hⱼ)) + b_g)

gₜ is the graph vector at turn t. K is the number of attention heads and k indexes them, beginning at 1. The superscript (k) identifies the parameters and coefficients for that head. For a node i, each head adds contributions from the neighbors j in 𝒩. Each contribution is the neighbor feature vector hⱼ transformed by the head’s learned W⁽ᵏ⁾ and weighted by αᵢⱼ⁽ᵏ⁾. ∑ adds the contributions, and σ denotes the activation applied to a head’s aggregate. ∥ concatenates the head outputs. W_g and b_g are the weight and bias of the graph output layer, and f denotes an output activation. The equation retains the node index inside the aggregate while the prose describes a single graph vector. The paper gives the attention and output projection but does not separately specify how the remaining node dimension is reduced.

Attention operates on the node features and graph neighborhood in these equations. The broader architecture uses the graph together with an encoding of the present text. This arrangement gives current language and accumulated facts separate routes into the decision. A persistent room relation can be present through the graph even when the newest text omits it. Wording in the current observation can also affect the state representation even if OpenIE and the rules fail to turn that wording into a triple.

The observation branch uses a Sliding Bidirectional LSTM, abbreviated SB-LSTM. Its role is to encode the words of the current observation as a vector, with recurrent processing in both directions. The state layer combines this vector with the vector from graph attention.

sₜ = f(W_l(gₜ ⊕ oₜ) + b_l)

sₜ is the encoded state at turn t. In this equation, oₜ is the vector produced by the SB-LSTM for the observation. Elsewhere the paper uses the same symbol for the observation text. gₜ is the graph vector, and ⊕ concatenates it with the observation vector. W_l and b_l are the learned weights and bias of the state layer. f is the activation applied after the linear projection and bias addition.

Assigning values to commands

A separate LSTM encoder reads an action as a sequence of words. It takes the command’s embeddings and produces an action vector that can be compared with the state vector. The use of an LSTM for encoding a sequence draws on earlier sequence-to-sequence work. The state and command encoders prepare their outputs separately, as in the general organization of the DRRN. Sequence to Sequence Learning with Neural Networks

Q(sₜ, aₜ) = sₜ · aₜ

Q(sₜ, aₜ) is the estimate of the value of choosing action aₜ in state sₜ. On the right of the equality, sₜ and aₜ denote the state and command vectors. The dot · means their dot product, which multiplies corresponding coordinates and adds the products. The score thus depends on how the command’s learned features align with those of the current state. It has a different role from the graph ranking, which counts object mentions and checks paths before this comparison.

Choosing actions to get high return is the job of the control policy. The notation for that policy is:

π(aₜ | sₜ)

π is the policy. aₜ is the command at turn t, sₜ is the state used at that turn, and | marks conditioning. The expression gives the probability of choosing that command given that state. The value estimate informs the policy’s preference for high-return moves. Random choices during exploration prevent those estimates from being the sole basis for acquiring experience.

The Bellman expression in the paper makes the link between a reward now and a value estimate for what can happen afterward.

Qₜ₊₁(sₜ₊₁, aₜ₊₁) = E[rₜ₊₁ + γ maxₐ∈Aₜ Qₜ(s, a) | sₜ, aₜ]

Qₜ₊₁ and Qₜ denote value estimates in the paper’s update notation. sₜ₊₁ and aₜ₊₁ are the next indexed state and action on the left. E denotes expectation, the average under the possible outcomes, conditioned after | on state sₜ and action aₜ. rₜ₊₁ is the observed reward from the transition and γ is the discount factor. max picks the largest Qₜ(s, a) over the candidate commands a in Aₜ. The s inside the maximum is the state used to value those candidate commands. The learning idea is to estimate a move from the immediate outcome plus the discounted value of a promising continuation. The pseudocode specifies a successor candidate set for the replay target. Its index conventions and those of the displayed equations differ, so the training procedure is easier to follow by keeping track of the transition itself.

Exploring and learning from stored transitions

At the start of an episode, the agent resets the simulator and initializes the graph and action dictionary. Each episode can then contribute a sequence of observations, actions, and rewards. The policy can use the estimated values to choose a move, sample randomly from the graph-pruned set, or sample randomly from the full set. The algorithm writes the random choice as nested tests. The outer test against ε₁ enters the exploration branch. Inside that branch, a test against ε₂ decides whether to draw from the full dictionary. When the inner test fails, the draw comes from the pruned set. This lets the learner exploit the concentration of plausible actions in the shortlist while occasionally trying a command that failed to make it there.

The outcome of a move produces a transition. The agent updates the graph, computes candidates for the next turn, and stores information about the transition in a replay buffer. Experience replay lets a learning update reuse past moves alongside more recent ones. This matters when most attempts provide little direct reward and only some supply a clear signal of quest progress. The paper represents a sampled transition in its training discussion as follows.

⟨sₖ, aₖ, rₖ₊₁, sₖ₊₁, Aₖ₊₁, pₖ⟩

The angle brackets delimit the record. k indexes the sampled transition. sₖ and aₖ are its starting state and selected command. rₖ₊₁ is the reward outcome, sₖ₊₁ is the successor state, and Aₖ₊₁ is the successor set of action candidates. pₖ is a priority indicator. The pseudocode assigns priority 1 for positive reward and 0 otherwise. It writes the reward at the index of the originating action. Both reward conventions refer to the observed outcome of that action.

Replay sampling draws a fraction ρ of a batch from positive-reward transitions and a fraction 1 − ρ from the rest. ρ therefore governs how frequently direct examples of progress are revisited relative to other experience. A reward-free move can still influence learning through its connection to later rewards. The sampling rule increases exposure to progress without limiting the buffer to those transitions.

The training discussion presents a temporal-difference expression with the following indices.

L(θ) = rₖ₊₁ + γ maxₐ∈Aₖ₊₁ Q(sₜ, a; θ) − Q(sₜ, aₜ; θ)

L(θ) is the expression labeled as a loss in the training prose. θ denotes the learned parameters, and the semicolon in Q(sₜ, a; θ) marks the dependence of the value function on those parameters. rₖ₊₁ is the sampled reward, γ is the discount, and the maximum runs over the possible commands a in Aₖ₊₁. sₜ and aₜ are the state and command indices written for the value terms. The subtraction gives a signed discrepancy. The pseudocode specifies a distinct target and squares the discrepancy for the gradient update.

yₖ = rₖ + γ maxₐ∈Aₖ₊₁ Q(sₜ, a; θ)

yₖ is the target for replay item k. rₖ is the reward using the pseudocode’s indexing. γ discounts the largest value from the candidate set Aₖ₊₁, with a ranging through that set. Q is the value estimate given the indicated state sₜ, candidate a, and parameters θ. In a continuation target, the candidate values describe the situation after the stored move. The paper prints sₜ in the maximization while using the successor index on the action set, as shown here. When sₖ₊₁ is terminal, meaning the episode has ended, the target is set to rₖ alone.

L(θ) = (yₖ − Q(sₜ, aₜ; θ))²

L(θ) here is the squared loss in the algorithm. yₖ is the target, Q(sₜ, aₜ; θ) is the prediction for the recorded state and action using the notation of the algorithm, and ² squares the prediction error. The gradient step adjusts the learned parameters θ to reduce that loss. The graph update and command shortlist are produced by rules and discrete lookups. They supply inputs and candidates to this learning procedure, while gradients train the encoders and value calculations that use them.

Learning from walkthroughs before playing

The authors also train parts of the network offline with walkthroughs from related games. An oracle plays each game used for this purpose and produces a trace of observations and suitable actions. The observation supplies the context for an implicit question about what to do next. The oracle’s command is the answer. A trace is therefore supervision for a series of local decisions, while a reinforcement-learning episode gives the agent consequences from decisions it made itself.

The authors adapt DrQA to predict the command from the observation. They train the observation and answer encoders together on those trace pairs. This provides a way to acquire initial weights from successful play before the reinforcement learner has found successful sequences on its own. The source games share a theme with the eventual game used for reinforcement learning. Rooms can have familiar types while standing in different spatial arrangements, and objects and required quest actions can change. The walkthroughs can teach regularities about the meaning of a description and the kinds of actions that fit it. A fixed sequence of moves from one layout is a poor basis for following another.

The transfer uses selected pieces of the trained DrQA system. Weights from its document encoder’s SB-LSTM initialize the observation encoder in KG-DQN. The document encoder’s embedding weights also initialize the graph embedding layer and the embedding layer used by the action encoder. This gives words in a node label and words in a command a starting representation shaped by the observation-to-action task. DrQA starts its embeddings with GloVe and tunes them during walkthrough training. Reading Wikipedia to Answer Open-Domain Questions

The transfer consequently has a narrower scope than training KG-DQN directly on demonstrated world graphs. The graph-attention weights and the full reinforcement learner’s value estimates still have to be acquired through the game interaction described in the paper. An answer produced during the offline task is judged against the expert’s immediate command. During play, estimated value depends on reward across the interaction, and the graph can supply information absent from the current text. The authors released their implementation as KG-DQN.

Experiments and results

Generated games and available information

The experiments use TextWorld’s home theme. Its grammar lets the authors generate different games with the same broad setting. They use different random seeds and form small and large sets of games. The labels cover changes in the size of the world and in the length of the required quest. They also pick up differences in how much text the agent receives and how many commands are in its dictionary. The two settings therefore give a comparison across bundled levels of difficulty.

The small setting has 10 rooms, 20 objects, and a quest length of 5. Its branching factor is 143 and its vocabulary size is 746. An observation contains 67.5 words on average and yields an average of 7.2 new RDF triples. The large setting has 20 rooms, 40 objects, and a quest length of 10. Its branching factor is 562 and its vocabulary size is 819. The corresponding averages are 94.0 words and 10.5 new triples per observation. Branching factor here counts commands in the game’s overall action set. The count of potentially relevant moves at an individual turn depends on where the agent is and what it has discovered.

Quest length records the number of actions required to satisfy the quest. A player may have to move through rooms, locate an item, or investigate what to do before performing a required action. The measured total number of commands can therefore be much greater than the number defining the quest. This is why the authors use both a reward measure and a measure that counts commands. The first records what the player accomplished according to the simulator’s scoring rules. The second includes the work the player did to get there.

TextWorld can provide introductory quest instructions in an observation before ordinary play begins. The learning agents are denied this information and have to discover what advances the quest. They are also denied the admissible-action list that the simulator can compute from the current situation. The distinction matters for interpreting KG-DQN’s pruning. It has a dictionary of recognized commands and derives its own restricted list from text and its graph. The simulator’s current admissibility information is used by the random baseline, which is designed around a different decision rule.

TextWorld gives +1 when a move advances the quest, -1 when it extends the minimum remaining route to completion from the current stage, and 0 in other cases. The maximum reward is 5 in the small setting and 10 in the large setting. A player can take extra steps without changing the reward, depending on the actions it tries. Thus the learning curves can tell whether a policy has settled at a high reward, while the step counts can reveal continued backtracking or exploration within a policy reaching that level.

Walkthrough data and pre-training accuracy

The authors run the question-answering preparation separately for the small and large settings. Each preparation uses 200 generated games from the home theme. Walkthroughs from a randomly chosen 160 games supply training observations and expert commands. The authors tune on 20 development games and evaluate on 20 held-out games. A randomly selected game from the test set subsequently becomes the environment in which the deep Q-network is trained. Held-out performance in question answering and gameplay after reinforcement training are therefore different evaluations with different exposure to the target game.

The question-answering evaluation checks how closely the predicted command agrees with the reference command from the oracle. Exact match counts a prediction as correct when the full answer agrees. The development version of this measure is used for tuning. Precision and recall use token overlap. Precision reflects how much of the predicted answer is supported by the reference tokens, and recall reflects how much of the reference the prediction recovers. F1 combines the token-level measures. These scores describe command prediction on held-out walkthroughs. They do not require the candidate command to be executed and its consequences observed.

For the small held-out games, exact match is 46.20, precision is 56.57, recall is 63.38, and F1 is 57.94. For the large held-out games, exact match is 34.13, precision is 52.53, recall is 64.72, and F1 is 55.06. Recall is higher in the large setting, while exact match, precision, and F1 are lower. The exact-match result shows the difficulty of recovering the whole expert command on a held-out walkthrough. Token overlap captures partial agreement that a complete-match measure misses. A predicted command can reuse an important object name and still differ in the verb or in another argument, which can matter greatly when the command is executed.

Comparisons and evaluation protocol

The authors compare KG-DQN with Random Command, LSTM-DQN, and BOW-DQN. Random Command samples from the simulator’s admissible moves on each turn. That gives it access to information about what can be attempted in the current state, though its choices within that set are random. LSTM-DQN represents the earlier recurrent approach to scoring commands. BOW-DQN uses a bag of words, representing which words are present without keeping their order as a sequence, and a multilayer feedforward network in place of the recurrent observation encoder. The authors use randomized grid search for the learned baselines, with candidate settings covering such quantities as hidden-state size, discount, replay sampling, exploration, update frequency, learning rate, and replay buffer capacity.

All tested KG-DQN variants have the graph available to the value estimator. One uses walkthrough pretraining and leaves actions unpruned. Another prunes actions and starts without walkthrough pretraining. The full variant includes both. This comparison allows the authors to ask whether a change in convergence is shared by the graph-based systems and whether final route lengths respond to keeping both additions. In the large setting, the experiments use a selection based on performance in the small setting. The reported large-game route-length comparison includes the full variant and the pruned variant without pretraining.

KG-DQN uses 50-dimensional word embeddings and 2 graph-attention heads. A mini-batch contains 16 transitions, and the network takes a gradient step every 5 actions of the agent. For every experiment, the authors average the results from five runs. They assess learning through reward convergence, and they assess play after training by averaging the number of steps needed to finish over 5 episodes with exploration set to 0.1. This keeps a random component during the step-count evaluation. The resulting number counts what happens when the reported policy is executed with that exploration, including commands used to search.

How fast reward converges

On the small game, the KG-DQN variants converge faster than the baselines. The results section describes KG-DQN as converging 40% faster than the baseline. KG-DQN and LSTM-DQN both reach the maximum reward of 5. The comparison concerns how quickly they reach a settled reward level in training, a learning-curve outcome. The paper does not give a corresponding benchmark of elapsed computer time. BOW-DQN is described as weaker than LSTM-DQN and is left out of the learning-curve discussion.

On the large game, the reported KG-DQN variants again converge faster. The authors explain that the comparison shown omits a portion of the LSTM-DQN curve because LSTM-DQN needs over 300 episodes to converge to KG-DQN’s reward level. No agent reaches the possible reward of 10 in the large-game learning results. The ceiling and the eventual learning level are therefore separate quantities in this setting. Reaching the same observed level sooner supports the comparison about convergence, while the missed ceiling describes how much of the scoring task remains unresolved in those curves.

How many commands the trained agents take

The small-game step counts show how much route efficiency can vary even when reward convergence looks similar. LSTM-DQN completes the small game in a mean of 72.4 steps with a standard deviation of 4.6. Full KG-DQN averages 73.7 with a standard deviation of 8.5. BOW-DQN takes 83.1 on average with a standard deviation of 8.0, and Random Command averages 319.8. Among the graph variants, the pretrained agent without pruning averages 131.7 with a standard deviation of 7.7. The pruned agent without pretraining averages 97.3 with a standard deviation of 9.0. The paper reports these means and, where given, standard deviations for the post-training completion measure.

Average steps to finish the small TextWorld home game after training

Full KG-DQN finishes in about as many steps as LSTM-DQN, while either partial KG-DQN variant takes longer.

Average steps to finish the small TextWorld home game after trainingRandom Command: 319.8Random Command319.8BOW-DQN: 83.1BOW-DQN83.1LSTM-DQN: 72.4LSTM-DQN72.4KG-DQN without pruning: 131.7KG-DQN without pruning131.7KG-DQN without walkthrough pre-training: 97.3KG-DQN without walkthrough pre-training97.3Full KG-DQN (this paper): 73.7Full KG-DQN (this paper)73.7
The numbers
System or settingsteps
Random Command319.8
BOW-DQN83.1
LSTM-DQN72.4
KG-DQN without pruning131.7
KG-DQN without walkthrough pre-training97.3
Full KG-DQN (this paper)73.7

On the large game, full KG-DQN takes 265.9 steps on average, with a standard deviation of 9.4. LSTM-DQN takes 260.3 with a standard deviation of 4.5. The pruned KG-DQN without pretraining averages 340 with a standard deviation of 6.4. Random Command averages 2054.8. The large-game figures again put the full graph agent near LSTM-DQN in the length of completed solutions. They also show a longer average route when the pruned graph agent starts without the weights learned from walkthroughs.

Average steps to finish the large TextWorld home game after training

Full KG-DQN is close to LSTM-DQN and takes fewer steps than its counterpart without walkthrough pre-training.

Average steps to finish the large TextWorld home game after trainingRandom Command: 2054.8Random Command2054.8LSTM-DQN: 260.3LSTM-DQN260.3KG-DQN without walkthrough pre-training: 340KG-DQN without walkthrough pre-training340Full KG-DQN (this paper): 265.9Full KG-DQN (this paper)265.9
The numbers
System or settingsteps
Random Command2054.8
LSTM-DQN260.3
KG-DQN without walkthrough pre-training340
Full KG-DQN (this paper)265.9

The authors report an independent t-test for the step-count comparison between LSTM-DQN and full KG-DQN, with p = 0.199. They describe the difference as statistically nonsignificant. The means are slightly lower for LSTM-DQN in the displayed comparisons. The claim for the full system is comparable route length under the protocol, alongside faster reward convergence. The t-test does not establish that the agents have identical route efficiencies.

Human play with and without instructions

The paper also observes human players on the same home quests. They receive numerical score feedback under the same reward function as the agents. Without quest instructions, the people observed did not finish a quest. On the small and large maps, they stopped after 184 and 190 steps on average, respectively. With instructions that gave an idea of the sequence required, players on the large map finished in an average of 23 steps and received the maximum reward. These figures describe different information conditions and include both attempts that ended in completion and attempts that ended when players gave up.

The authors give the oracle’s ideal quest lengths as 5 for the small map and 10 for the large map. They explain that a player who must work out the quest may need to explore and interact with objects first. The gap between the two human conditions illustrates the work involved in discovering the objective. It also helps explain what the learned agents’ post-training step counts include. They reflect following a learned policy under continued exploration in games whose instructions were withheld, instead of executing a known walkthrough.

What the ablations show

What the graph-based agents share

The clearest convergence observation is that the tested KG-DQN variants learn at roughly the same rate even though they differ in pruning and walkthrough initialization. The graph appears in each of them, including the small-game variant that lets the agent consider the unpruned command set. This gives the authors a reason to attribute much of the convergence improvement to graph-based memory. A graph can carry forward relationships that remain useful after the text changes, and the value network can use those relationships when it estimates the return of a move.

The unpruned comparison is especially informative about the graph’s dual role. That variant removes the command-ranking filter while retaining the graph as input to the value estimate. Its fast convergence supports the idea that the representation itself contributes something, beyond the savings from scoring or exploring fewer candidates. The pruned variant without pretraining shows that the offline walkthrough task is also unnecessary for observing the faster convergence in the reported comparison. Together these observations narrow the authors’ account of what is responsible for the shared learning-curve behavior.

The causal claim remains qualified. The graph-based variants share an architecture as well as a memory representation. The comparison to LSTM-DQN changes the way state and action are encoded and combined. A version of the same architecture with the graph channel removed would give a more direct test of the memory contribution within KG-DQN. The paper’s result is a pattern across its comparisons, and the attribution to persistent memory is the authors’ explanation of that pattern.

What changes the length of a learned solution

For the small game, comparing full KG-DQN with the pretrained variant that keeps all commands gives the pruning comparison with walkthrough initialization in place. The full system finishes in 73.7 steps on average, while the unpruned variant takes 131.7. This is consistent with the graph ranking continuing to help after the reward curve has settled. Prioritizing commands involving known, connected objects can reduce how far the player wanders through the command dictionary while executing a policy.

Comparing the full system with the pruned variant without pretraining holds pruning in place. On the small game, the latter averages 97.3 steps. On the large game it averages 340, compared with 265.9 for the full system. The evidence for a walkthrough effect is therefore available in both of the tested sizes. It concerns the route taken after reinforcement training. The agent has already interacted with the target game by the time those routes are measured, so the result supports a contribution from the initialization to later performance.

The combined picture makes sense given the reward rules. Several exploratory moves may leave the score unchanged, so reaching a stable reward does not tell how many such moves remain in the policy’s executions. The graph can help the value network learn from experience sooner. Pruning and walkthrough initialization can additionally change how the trained policy searches among possible moves. Where the full system is compared with one missing component, the stronger result appears in fewer steps to finish. Similar convergence curves thus coexist with noticeably different behavior during play.

What the comparisons leave unresolved

The small-game comparisons remove one addition at a time from the full system. There is no reported graph-based variant with both pruning and pretraining removed. The data therefore allow conditional comparisons, such as what happens when pruning is removed while pretraining is kept. They leave open how those additions interact when both are absent. The large-game experiments are narrower still. They give a route-length comparison for pretraining with pruning in place, and the paper does not report the large-game route length of the unpruned pretrained agent.

There is also no component-level comparison of OpenIE against the additional extraction rules, or of graph attention against another way of aggregating the same graph. The number of new triples per observation describes how much the representation grows from observations in the generated games. It does not establish which extracted facts influence a decision or which ones are accurate. Similarly, the walkthrough accuracy measures establish how closely commands match an oracle in the offline task. The downstream ablation tests the value of transferring those trained weights as a package, so it leaves the contributions of the observation encoder and the embedding initializations unresolved.

Limitations

Limits the authors identify

The authors emphasize that question answering alone leaves part of playing a text adventure unsolved. Walkthroughs show appropriate moves in situations encountered by an oracle. A learner may reach a different situation, lack a relevant fact, or need to make an exploratory move to learn whether an action works. The deployed agent therefore still learns from interaction, and the post-training evaluation keeps a non-zero probability of exploration. The paper’s account of transfer is strongest as an explanation of why the learner makes better use of experience and finds shorter solutions when the pruning mechanism is also in use.

The authors also identify a direct failure mode for graph-based pruning. A quest may require a combination of objects that have not been encountered together, or that have yet to be represented in a helpful way. A command can be necessary and still receive a low score from graph membership and connectivity. Sampling from the full dictionary provides a way to discover such commands. This preserves the opportunity to explore, with the cost that the agent can still spend a turn on an unproductive choice from the larger set.

The paper distinguishes attaining a reward from attaining it in a short sequence. The scoring rules are permissive about some extra exploration, so a graph that helps the agent learn to advance the quest offers no automatic guarantee of a direct route. The large-game convergence result also stops below the available maximum. The authors treat complex games such as Zork as outside what existing approaches can readily handle in their discussion of the problem. Their own evidence comes from generated games under controlled conditions, in keeping with their description of text adventures as a step towards more complex environments.

Limits visible in the experimental design

The games vary in layout, objects, and quests but come from the same home theme. That common grammar makes transfer across games a meaningful test and also bounds the kinds of language and relations the system has to handle. Room, exit, and movement rules fit features of that generator. The experiments leave open how much of the extraction scheme would carry over to a setting with different descriptive conventions, a broader range of actions, or different ways for facts to become obsolete.

The implementation assumes a dictionary of parser-recognized commands and a ceiling of two object arguments in an action. The game still presents a substantial selection problem, especially in the large setting. A system choosing from that dictionary can rely on the candidate strings already existing. The study does not test generating unfamiliar command structures or coming up with new verbs as the agent plays. It also does not test how well the object-and-path ranking would work for commands with a more complicated structure than the bound permits.

The transfer protocol needs particular care in interpretation. The QA training and development games are separate from the game chosen for reinforcement learning. The chosen game is therefore new to the transferred weights when reinforcement learning begins. Once training starts, the agent receives observations and rewards from that game and adapts to it. Shorter completion routes after this stage establish something about learning and later acting in that environment. The experiment does not measure how well the frozen policy would play another untouched game on its first attempt.

The persistent graph is an operational representation of what the agent has discovered. The paper measures new triple counts and gameplay outcomes, leaving the graph’s factual accuracy unmeasured. A noisy extractor can supply a mistaken relation, and a persistent edge may record a fact whose timing matters. The rule for the player node illustrates one mechanism for keeping context current. The study does not establish how systematically the remaining graph handles changes to other facts, and the effect of particular errors on pruning or value estimation is unknown.

The reward curves concern learning in the simulator. The claim of faster convergence is supported by the reward reached over training episodes. Encoding a graph, computing attention, and ranking the command dictionary also take computation. The paper supplies no elapsed-time measurements for deciding whether the sample-side improvement yields the same advantage in runtime. Similarly, a lack of statistical significance for the step-count comparison supports a cautious description of comparable observed performance. Establishing equivalence within a specified margin would require evidence beyond the reported test.

Finally, the human comparison shows how much information the quest description can give a player. People with instructions have a different information budget from agents that were denied instructions. People who stopped have a stopping-time measure, whereas agents that finished have a step count to completion after training. These measurements help explain the task, and their conditions limit any ranking of human and agent ability. The most direct comparison in the paper is between trained agents under the shared gameplay protocol.

What came after

The later citing works connect to different parts of the problem KG-DQN makes visible. Some concern interactive decisions or the generation of moves in text games. Others concern what reward-based training encourages in language tasks. A citation establishes that the earlier paper was cited. The titles identify the subjects of these works, while the mechanism of any direct transfer would require information about their methods or how they discuss KG-DQN.

Choosing actions and learning before interaction

The closest topical successor is Yao and colleagues’ 2020 work on generating actions for text-based games. In KG-DQN, the parser-recognized dictionary comes first, and the graph promotes commands that have support from the agent’s discoveries. The later work’s stated subject is the use of learned language predictors to generate actions for exploration. This puts emphasis on where candidates come from. Both problems arise before the agent can learn much from reward, since the agent must try a potentially useful command before it can observe that command’s consequences. The connection is between two interventions on that choice. The citation and title give no basis for attributing KG-DQN’s graph, path scores, or replay scheme to the later system. Keep CALM and Explore

Li and colleagues’ 2022 work places pretraining in the broader setting of interactive decision-making. The distinction made by KG-DQN helps locate the relationship. In the earlier paper, a supervised task teaches some weights from expert decisions on related games, and an agent then adapts by interacting with a new game. The later title similarly puts knowledge acquired before interaction in the service of decisions made during interaction. It gives no details about whether the training material is a walkthrough, whether transfer initializes particular encoders, or whether the system keeps a graph. The supported connection is the use of earlier language training as a resource for later decisions. Interactive Decision-Making with Pre-Trained LMs

Reward, length, and reasoning

Singhal and colleagues’ 2023 work investigates length correlations in reinforcement learning from human feedback, abbreviated RLHF. The relevant question in KG-DQN is how a training reward relates to the length of behavior. In the game, a quest score can stay the same while an agent takes extra actions, which is why the paper separately counts commands to completion. The later title identifies length as something to investigate in a different reward-based setting. It supplies neither the nature of the measured correlation nor its direction. The connection is the need to examine what length measures alongside what a reward measures, with game steps and the later work’s length variable belonging to their respective tasks. A Long Way to Go

Havrilla and colleagues’ 2024 work concerns using reinforcement learning to teach reasoning. KG-DQN gives a concrete earlier instance of training decisions that depend on language input and have consequences beyond the current response. In a text adventure, a command can change the environment and reveal information that matters to a later command. The reasoning study’s title puts the emphasis on reasoning behavior learned through reinforcement. The citation does not establish that it uses text-adventure interaction, a graph, or oracle-based command prediction. The connection is at the level of the training problem, where feedback over a sequence can shape what an agent learns to do with language. Teaching Reasoning with Reinforcement Learning

Generating the quests that agents face

The citing work on automated quest generation concerns the construction of text-adventure tasks. KG-DQN uses generated quests as a source of related games and expert traces. It keeps the problem of building those quests distinct from the agent’s problem of inferring what to do in them. Automated quest generation addresses the former side. It is closely related because variation in quests and layouts is what gives the transfer experiment content. If the same sequence worked everywhere, a walkthrough would offer little evidence about acting on a new situation. The citing entry identifies the topic of quest generation, while leaving the generator’s technique and any reuse of KG-DQN’s graph unspecified. Automated Quest Generation for Text Adventures

Cite

Cite as Prithviraj Ammanabrolu and Mark Riedl. 2019. Playing Text-Adventure Games with Graph-Based Deep Reinforcement Learning. Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers).

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/n19-1358

@inproceedings{ammanabrolu2019playing,
  title = {{Playing Text-Adventure Games with Graph-Based Deep Reinforcement Learning}},
  author = {Prithviraj Ammanabrolu and Mark Riedl},
  booktitle = {Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers)},
  year = {2019},
  doi = {10.18653/v1/n19-1358},
  url = {https://doi.org/10.18653/v1/n19-1358}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/ammanabrolu-2019-playing-text-adventure-games-graph/