Pre-Trained Language Models for Interactive Decision-Making
Junior authors are ordered based on contributions and senior authors † are ordered alphabetically
Abstract
Language model (LM) pre-training is useful in many language processing tasks.
But can pre-trained LMs be further leveraged for more general machine learning problems?
We propose an approach for using LMs to scaffold learning and generalization in general sequential decision-making problems.
In this approach, goals and observations are represented as a sequence of embeddings, and a policy network initialized with a pre-trained LM predicts the next action.
We demonstrate that this framework enables effective combinatorial generalization across different environments and supervisory modalities.
We begin by assuming access to a set of expert demonstrations, and show that initializing policies with LMs and fine-tuning them via behavior cloning improves task completion rates by 43.6% in the VirtualHome environment.
Next, we integrate an active data gathering procedure in which agents iteratively interact with the environment, relabel past “failed” experiences with new goals, and update their policies in a self-supervised loop.
Active data gathering further improves combinatorial generalization, outperforming the best baseline by 25.1%.
Finally, we explain these results by investigating three possible factors underlying the effectiveness of the LM-based policy.
We find that sequential input representations (vs. fixed-dimensional feature vectors) and LM-based weight initialization are both important for generalization.
Surprisingly, however, the format of the policy inputs encoding (e.g. as a natural language string vs. an arbitrary sequential encoding) has little influence.
Together, these results suggest that language modeling induces representations that are useful for modeling not just language, but also goals and plans; these representations can aid learning and generalization even outside of language processing.
Introduction
Language models (LMs) play a key role in machine learning approaches to natural language processing tasks [9].
This includes tasks that are not purely linguistic, and require nontrivial planning and reasoning capabilities [24, 13]: for example, instruction following, vision-language navigation, and visual question answering.
Indeed, some of these tasks are so distant from language modeling that one can ask whether pre-trained LMs can be used as a general framework even for tasks that involve no language at all.
If so, how might these capabilities be accessed in a model trained only to process and generate natural language strings?
Language Model
Task-specific Model
Tokenization
Next action a t
Observation o t History h t Goal g
Tokenization
Tokenization
F 𝜃
F 𝜃 F 𝜃
F 𝜃
F 𝜃 F 𝜃
F 𝜃
F 𝜃 F 𝜃
VirtualHome
BabyAI
Graph partial observation:
Goal predicates: Inside(pancake,stove):
Grid partial observation: Language goal:
Put the green box next to the purple box agent agent
In this paper, we study these questions through the lens of embodied decision-making , investigating the effectiveness of LM pre-training as a general framework for learning policies across a variety of environments.
We propose LID , a framework that uses Pre-Trained L anguage Models for I nteractive
D ecision-Making.
As shown in Figure 1 (right), we encode the inputs to a policy—including observations, goals, and history—as a sequence of embeddings.
These embeddings are passed to a policy network initialized with the parameters of a pre-trained LM, which is fine-tuned to predict actions.
This framework is broadly applicable, accommodating goals and environment states represented as natural language strings, image patches, or scene graphs.
We find that imitation learning using pre-trained LMs as policy initializers improves in-domain performance and enables strong generalization over novel tasks.
For i.i.d.
training and evaluation tasks, this approach yields 20% more successful policies than other baseline methods in VirtualHome [31].
For combinatorial generalization to out-of-distribution tasks, i.e . tasks involving new combinations of goals, states or objects, LM pre-training confers even more benefits: it improves task completion rates by 43.6% for novel tasks (see Figure 3).
These results hold for a variety of environment representations: encoding states as natural language strings, when possible, improves the data-efficiency of training, but even LMs fine-tuned on random environment encodings generalize combinatorially to new goals and states when trained on large enough datasets.
We further examine how our method may be used in environments where expert data is not available, and agents must instead actively gather data.
To do this, we integrate an A ctive D ata G athering ( ADG ) procedure into pre-trained LMs as shown in Figure 2.
Our proposed approach to ADG consists of three parts.
First, exploration collects trajectories using a mix of random actions and actions generated by the current policy.
Exploration is insufficient in this high dimensional problem and most of the trajectories will likely fail to achieve the end goal.
A key insight is that even the failed trajectories contain useful sub-trajectories that solve certain sub-goals, and we relabel these goals in a hindsight relabeling stage.
The relabeled goal describes what was achieved in the extracted sub-trajectory.
The policy update stage samples relabeled trajectories to update the policy.
The active data gathering procedure allows us to train the LM-policy without pre-collected expert data.
It also outperforms reinforcement learning (RL) methods on embodied decision-making tasks and enables more effective generalization to novel tasks.
Finally, we investigate why LID contributes to generalization. We hypothesize three possible causes for the effectiveness of LM-based policy initialization: (1) the use of language-based input encodings , and more generally LMs’ ability to reason about natural language strings; (2) the sequential structure of transformer inputs, in contrast to the fixed-sized observations used by most policy architectures, and (3) task-general inductive bias conferred by weight initialization with LM pretraining.
We investigate (1) by encoding the policy inputs as different types of sequences.
Different input encoding schemes have only a negligible impact on the performance: the effectiveness of language modeling is not limited to utilizing natural strings, but in fact extends to arbitrary sequential encodings.
We study (2) by encoding observations with a single vector embedding, thereby removing its sequential structure.
This operation significantly degrades the model’s performance on novel tasks.
Finally, we investigate (3) by learning the parameters of the policy from scratch.
The success rate after removing the pre-trained LM weights drops by 11 .
2% , indicating that LM pretraining provides useful inductive bias for sequence processing even when sequences are not natural language strings.
To summarize, our work has four main contributions:
• First, we propose to use pre-trained LMs as a general scaffold for interactive decision-making across a variety of environments by converting all policy inputs into sequential data.
Second, we demonstrate that language modeling improves combinatorial generalization in policy learning : initializing a policy with a pre-trained LM substantially improves out-of-distribution performance on novel tasks.
• Third, we integrate an active data gathering procedure into the proposed approach to further enable policy learning on environments without using pre-collected expert data.
Finally, we perform several analyses to explain the generalization capabilities of pre-trained LMs, finding that natural strings are not needed to benefit from LM pre-training, but the sequential input encoding and weight pre-training are important. These results point to
the effectiveness of the proposed framework with pre-trained LMs as a general - purpose framework to promote structured generalization in interactive decision-making.
Related Work
In recent years, word and sentence representations from pre-trained LMs [29, 9, 33] have become ubiquitous in natural language processing [49, 30].
Some of the most successful applications of pre-training lie at the boundary of natural language processing and other domains, as in instruction following [13] and language-guided image retrieval [22].
Learning representations of language.
From nearly the earliest days of the field, natural language processing researchers observed that representations of words derived from distributional statistics in large text corpora serve as useful features for downstream tasks [8, 11].
The earliest versions of these representation learning schemes focused on isolated word forms [25, 28].
However, recent years have seen a number of techniques for training (masked or autoregressive) language models to produce contextualized word representations (which incorporate information neighboring words in sentences and paragraphs) via a variety of masked-word prediction objectives [9, 47].
Applications of pre-trained LMs.
LMs can be fine-tuned to perform language processing tasks other than language modeling by casting those tasks as word-prediction problems.
Successful uses of representations from pre-trained models include syntactic parsing [19] and language-to-code translation [45]; successful adaptations of LM prediction heads include machine translation [49], sentiment classification [6] and style transfer [18].
A number of tasks integrate language and other modalities, including visual question answering and image captioning [48].
Recent works find that image representations can be injected directly into LMs’ embedding layers [42].
Policy learning and LM.
Traditional policy learning methods, such as PPO [37], DQN [27],
DDPG [21], A3C [26], perform well on playing tasks on Atari, OpenAI gym [5], and MuJoCo [41].
Some of them might fail to solve more challenging tasks on embodied environments [31, 39].
Several recent papers [36, 17, 15] propose to use LM for policy learning.
Frozen Pretrained Transformer (FPT)
[23] demonstrates that pre-trained LMs require very little fine-tuning to match the performance of task-specific models on several image classification and numerical sequence processing tasks.
Semi-Supervised Skill Learning with Latent Language (SL) 3 [38] shows that LMs can serve as an effective backbone for hierarchical policies that express plans as natural language strings [2, 4].
In this paper, we focus on building a general framework for decision-making tasks using pre-trained
LMs, even when language is not provided as an input or output.
Decision-Making and Language Modeling 3.1 POMDPs and Policy Learning
We explore the application of LMs to general sequential decision-making tasks in partially observed environments.
These tasks may be formalized as partially observable Markov decision processes (POMDPs).
A POMDP is defined by a set of states, a set of observations, a set of actions, and a transition model T ( s t +1 | s t , a t ) that maps the current state and action to the next state.
Importantly, in a POMDP setting, the observation o t only captures a portion of the underlying state s t , and an optimal decision-making strategy (a policy ) must incorporate both the current observation and the history of previous observations and actions.
In our experiments, policies are parametric models π ϕ ( a t | g, h t , o t ) that output the probability of an action given the goals g , history information h t
= { o 1 , a 1 , · · · , o t − 1 , a t − 1 } , and partial observations o t of the current state s t .
In Figure 1 (right), we show a high-level overview of the proposed method.
We first convert all policy inputs into a sequence and provide them as input to a transformer encoder.
Representations from this encoder model are then passed to a task-specific decoder that predicts actions.
We collect a dataset of N training trajectories D
= { d i } Ni =1 , where each trajectory consists of a goal and a sequence of observations and actions: d i = { g i , o i 1 , a i 1 , · · · , o iT i , a iT i } , where T i is the length of the trajectory.
We then train the policy to maximize the probability of actions we want to achieve a i = { a i 1 , . . .
, a iT i } across trajectories using the cross-entropy loss:
[Equation]
3.2 Language models as policy initializers
Our experiments focus on autoregressive , transformer-based LMs [43].
These models are trained to fit a distribution over a text sequence y =
{ y i } ni
=1 via the chain rule p
( y ) =
p ( y 1 ) (cid:81) ni
=2 p ( y i | y 1 , . . .
, y i − 1 ) .
Each term on the right hand side is parameterized by a transformer network, which accepts the conditioned tokens as input.
Each token passes through a learned embedding layer F θ , then the full conditioned sequence is fed into the LM.
In our work, we use a standard LM, GPT-2, to process the input sequence rather than to predict future tokens.
Both POMDP decision-making and language modeling are naturally framed as sequence prediction tasks, where successive words or actions/observations are predicted based on a sequence of previous words or actions/observations.
This suggests that pre-trained LMs can be used to initialize POMDP policies by fine-tuning them to model high-reward or expert trajectories, as described below.
Approach
We evaluate the effectiveness of pre-trained LMs in solving decision-making tasks across environments.
We use BabyAI [16] and VirtualHome [31] to evaluate the proposed method.
While both environments feature complex goals, the nature of these goals, as well as the state and action sequences that accomplish them, differ substantially across environments (Figure 1 (left)).
4.1 Policy Network
We first examine whether pre-trained LMs provide effective initializers when states and action histories are represented as natural language strings.
We encode the inputs to the policy—including observations, goals, and action histories—as sequences of words.
These word sequences are passed to the LM (using its pre-trained word embedding layer F θ ) and used to obtain contextualized token representations.
Token representations are averaged and used to predict actions.
We design a policy network following the general policy framework proposed in Figure 1.
Environment encodings in VirtualHome.
In VirtualHome, each goal consists of a sequence of predicates and multiplicities, and is translated into a templated English sentence ( e.g . “ Inside(apple, fridge):2 ” becomes “put two apples inside the fridge”).
To encode the agent’s partial observation, we extract a list of currently visible objects, their states ( e.g . “open, clean”), and 3D world coordinates.
We use a fully-connected layer to encode the 3D information and generate a feature representation of each object in the observation.
To encode history, we store information about all previous actions and convert them into templated English sentences ( e.g .
“I have put the plate on the kitchen table and the apple inside the fridge”).
Environment encodings in BabyAI.
The observation by default is a 7 × 7 grid.
We convert the observation into 7 × 7 text descriptions, e.g . “purple ball”, “grey wall”, “open door”, and combine them into a long sentence.
We then convert the history actions into text descriptions, e.g . “turn left” and “go forward”.
We combine the language instruction (without modification) with the observation and history text descriptions, and feed them to the pre-trained LM.
We note that the policy network described above does not strictly require that these encodings take the form of natural language strings—other encodings of the environment as a sequence also work (see Section 7).
This framework could be also generalized to support pixel-based observations using discretization schemes like the one employed in the Vision Transformer [10].
Action prediction.
We pool LM outputs into a “context representation” that is used to predict the next action.
In training, we maximize the probabilities of demonstrated actions.
In inference, we select the valid action with the highest probability.
See Appendix C.1 for details.
VirtualHome and BabyAI have quite different observation spaces, action spaces, and goal spaces; however, we show that embedding policy inputs as sequences and utilizing the pre-trained LM as a policy initializer, enables effective generalization to novel tasks on both environments.
We note that
LID is not limited to VirtualHome and BabyAI, but is straightforwardly applicable to other embodied environments, such as ALFRED [40] and iGibson [39].
4.2 Training
We first examine LID through imitation learning on data collected by experts in Section 4.2.1.
We then show that integrating an active data gathering procedure into LID enables policy learning without using expert data in Section 4.2.2.
We use VirtualHome as an example to explain the data gathering.
4.2.1 Policy Learning with Expert Data
The policy model is first initialized from a pre-trained LM and then fine-tuned on data collected by experts.
We build on the VirtualHome environment to collect a set of expert trajectories using regression planning [20] and create a VirtualHome-Imitation Learning dataset .
Given a task described by goal predicates, the planner generates an action sequence to accomplish this task (See
Appendix E.1 ).
The planner has access to privileged information, such as information about the pre-conditions and effects of each action, allowing an agent to robustly perform tasks in partially observable environments and generate expert trajectories for training and evaluation.
4.2.2 Policy Learning with Active Data Gathering
[Figure]
[Table] [Figure] [Table] [Figure]
hindsight relabeling 1.
Exploration 2.
Hindsight Relabeling Relabel
a
[Figure]
Collecting expert data is sometimes challenging.
It may require privileged information of the environment or human annotations, which can be timeconsuming and difficult to scale.
A promising way to scale up supervision is Hindsight Experience Replay (HER) [3], which allows agents to learn from orders of magnitude more data without supervision.
However, existing HER methods [12] focus on simple tasks with small state/action space and full observability.
They cannot tackle more complicated embodied decision-making tasks, requiring nontrivial planning and reasoning or natural language understanding.
LID with the active data gathering ( LIDADG ) can be used in solving tasks in such environments.
As shown in Figure 2, LID-ADG consists of three stages, i.e . exploration , hindsight relabeling , and policy update .
The key idea is to gradually improve the task success rate by asking the agent to iteratively explore the environment, relabel failure samples, and update its policy using imitation learning.
In the exploration stage, we first randomly sample a goal and an initial state.
We then use a mix of random actions and actions generated by the current policy π ϕ ( a t | g, h t , o t ) to obtain the next action.
We repeat this process until this episode ends.
We collect M trajectories and store them in the replay buffers.
The generated actions in the early stages rarely complete the given task.
However, even the failed trajectories contain useful sub-trajectories that solve certain sub-goals.
In the hindsight relabeling stage, we extract useful sub-trajectories and relabel a goal g ′ for each of them.
We design a goal relabel function f l that generates a goal based on the sequence of observations and actions using hand-designed templates.
In practice, we implement the goal relabel function as a program (see Appendix E.2 ).
The hindsight relabeling stage allows sample-efficient learning by reusing the failure cases.
During policy update , the agent samples the data from the replay buffers and updates its policy network π ϕ .
By interleaving the exploration, hindsight relabeling, and policy update, LID-ADG can gradually improve the policy without requiring pre-collected expert data.
In embodied environments with large action spaces, sparse rewards, and long-horizon planning, RL methods often struggle to obtain stable policy gradients during training.
Our method enables sample-efficient learning from the sparse rewards by relabeling new goals for the bad samples that the agent fails to achieve.
In addition,
LID-ADG leverages the stability of supervised learning in the policy update stage, enabling it to outperform RL approaches on a wide range of decision-making tasks.
Experiment Setup
We evaluate the proposed method and baselines on VirtualHome and BabyAI.
5.1 VirtualHome
VirtualHome is a 3D embodied environment featuring partial observability, large action spaces, and long time horizons.
We evaluate policies’ performance from three aspects: (1) performance on in-distribution tasks; (2) generalization to novel scenes; and (3) generalization to novel tasks.
In-Distribution.
The predicate types and their counts in the goal are randomly sampled from the same distribution as the training data.
The objects are initially placed in the environment according to common-sense layouts ( e.g . plates appear inside the kitchen cabinets rather than the bathtub).
Novel Scenes.
The objects are placed in random positions in the initial environment without commonsense constraints ( e.g . apples may appear inside the dishwasher).
Novel Tasks.
The components of all goal predicates are never seen together during training ( e.g . both plates and fridges appear in training goals, but Inside(plate, fridge) only appears in the test set.
(See Appendix F for more details.)
We evaluate the success rates of different methods on each test set.
A given episode is scored as successful if the policy completes its entire goal within the maximum allowed steps of the environment.
On each of the 3 test subsets, we use 5 different random seeds and test 100 tasks under each seed.
Thus there are 1500 examples used to evaluate each model.
5.2 BabyAI
BabyAI is a 2D grid world environment for instruction following.
Observations in BabyAI are 7 × 7 × 3 grids describing a partial and local egocentric view of the state of the environment.
We evaluate the methods on four representative tasks:
GoToRedBall , GoToLocal , PickupLoc , and
PutNextLocal .
Performing well on the test set requires the models to generalize to new environment layouts and goals, resulting in new combinations of tasks not seen in training.
For each method, we compute success rates over 500 episodes on each task.
Experiments
We first show results of the proposed method and baselines for embodied decision-making tasks using expert data in Section 6.1.
We then show our results when using actively gathered data in Section 6.2.
6.1 Embodied Decision Making with Pre-trained Language Model (LID) 6.1.1 Results on VirtualHome
We evaluate the following methods: [Figure] [Figure] [Table]
LID-Text (Ours) is the proposed method that converts all environments inputs into text descriptions.
The pre-trained LM is fine-tuned for decision-making (conditioned on goals, observations, and histories) as described in Section 4.1.
Recurrent Network .
We compare our method with a recurrent baseline using an LSTM [14] to encode the history information.
The hidden representation from the last timestep, together with the goal and current observation, are used to predict the next action.
MLP and MLP-1 .
We perform additional comparisons with baselines that do not use recurrent networks or pre-trained LMs.
MLP and MLP-1 take the goal, histories, and the current observation as input and send them to the multilayer perceptron neural network (MLP) to predict actions.
MLP-1 has three more average-pooling layers than MLP that average the features of tokens in the goal, history actions, and the current observation, respectively, before sending them to the MLP layer.
Quantitative results .
Each method is trained on 20 K demos from the VirtualHome-Imitation
Learning dataset, and then evaluated on the three test subsets: In-Distribution , Novel Scenes , and
Novel Tasks .
In Figure 3, LID -Text (Ours) , which initializes the policy with a pre-trained LM, has higher success rates than other methods.
This difference is most pronounced in the Novel
Tasks setting, where test tasks require combinatorial generalization across goals that are never seen during training.
Here, LID -Text (Ours) dramatically ( 43 . 6% ) improves upon all baselines.
Such combinatorial generalization is necessary to construct general purpose agents, but is often difficult for existing approaches.
Our results suggest that pre-trained LMs can serve as a computational backbone for combinatorial generalization.
6.1.2 Results on BabyAI
We use the standard training and test data provided by [16].
In BabyAI, performing well on unseen test tasks with new environment layouts and goals requires combinatorial reasoning.
In Table 1, we report the success rate of models trained on different number of demos.
BabyAI-Ori [16] is the method used in the original paper.
LID-Text (Ours) is the proposed method that converts policy inputs into a text sequence.
Given enough training data, i.e . 10K demos, both methods achieve high success rates, but LID -Text (Ours) outperforms BabyAI-Ori with less training data, indicating the proposed method improves sample efficiency when generalizing to novel tasks.
6.2 Pre-trained Language Model with Active Data Gathering (LID-ADG)
We compare LID-ADG , the proposed LM framework for decision-making using actively gathered data (Section 4.2.2), to a variety of baselines that do not use pre-collected expert data on VirtualHome.
Random.
The agent selects the next action randomly from the valid action space at that state.
Goal-Object.
The agent randomly selects an object that in the goal and in the valid action space to interact with.
For example, given a goal of “ Inside(apple, fridge):1 ”, this baseline might choose “grab apple”, “open fridge”, or other actions containing “apple” or “fridge”.
Online RL.
We compare with PPO [37], one of the most commonly used online RL methods.
For fair comparison, we equip PPO with the same main policy network as the proposed method.
Our implementation is [Table] [Table] based on Stable Baselines3 [35].
Hindsight Experience Replay.
We compare with DQN+HER used in [3] and modify its main policy network to be the same as the proposed method.
Quantitative results .
We compare LID-ADG with baselines on VirtualHome in Table 2.
Each experiment is performed 5 times with different random seeds.
The Random baseline is always 0, indicating the tasks in VirtualHome cannot be easily solved by a random policy.
Goal-Object is better than Random because Goal-Object has access to objects in the goal and it samples actions from a much smaller action space.
The online RL baseline, PPO , fails to solve tasks in VirtualHome featured by partially observation, large state/action space, and long-term horizon.
DQN+HER works well on simple tasks on 2D environments, but they cannot tackle VirtualHome tasks neither, requiring nontrivial planning and reasoning.
LID-ADG does not require expert data and can solve the complicated tasks in 3D embodied environments which cannot be easily achieved using RL.
Policy initializer and data provider.
LID-ADG can further be used to initialize the weights for finetuning RL policies and to gather data for offline learning.
As shown in Table 2, directly training RL, e.g . PPO, fails to solve tasks in VirtualHome.
However, after using the policy trained by LID-ADG to initialize the PPO policy, we may effectively learn an interactive policy with good performance.
In
Table 3, PPO (LID-ADG Init) is initialized from LID-ADG and further fine-tuned to solve the tasks in VirtualHome.
After initialization, PPO improves its success rate by 53 .
7% on the In-Distribution setting (See PPO results in Table 2 and Table 3).
In addition, LID-ADG can provide data for offline learning.
LID-ADG saves the relabeled data in replay buffers.
We train Decision Transformer (DT) [7] using the data collected by LID-ADG.
See DT (LID-ADG Data) in Table 3.
Analysis: Understanding the Sources of Generalization
The pre-trained LM policy, fine-tuned on either expert data or actively gathered data, exhibits effective combinatorial generalization.
Is this simply because LMs are effective models of relations between natural language descriptions of states and actions [1], or because they provide a more general framework for combinatorial generalization in decision-making?
We hypothesize and investigate three possible factors to understand the sources of such combinatorial generalization.
We use policies trained on the expert data as an example to explain the experiments.
7.1 Input Encoding Scheme
We first hypothesize that converting environment inputs into natural language contributes to the combinatorial generalization as the LMs are trained on language data.
We explore the role of natural language by investigating three alternative ways of encoding policy inputs to our model without using natural language strings: two in VirtualHome, and one in BabyAI.
BabyAI results are in Appendix A.
Index encoding in VirtualHome.
Rather than natural language strings, LID -Index (Ours) converts policy inputs into integer indices.
LID -Index (Ours) retains the discrete, serial format of the goal, history, and observation, but replaces each word with an integer, and replaces the embedding layer from the pre-trained LM with a new embedding layer trained from scratch.
For example, grab apple is mapped to (5,3) based on the positions of grab and apple in the vocabulary set.
Unnatural string encoding in VirtualHome.
LID -Unnatural
(Ours) replaces the natural language tokens (e.g. converting the goal “ On(fork, table):1 ” to put one fork on the table ) with random ones (e.g. converting On(fork, table) to brought wise character trees fine yet ).
This is done by [Table] randomly permuting the entire vocabulary, mapping each token to a new token.
Such a permutation breaks the semantic information in natural strings.
LID -Index
(Ours) and LID -Unnatural
(Ours) have the same policy network as LID -Text (Ours) .
All are fine-tuned on the expert data.
The averaged results using 5 different random seeds on the Novel Tasks setting are reported in Table 4.
Given few training data, e.g. 100 demos, all the models perform poorly, with success rates lower than 10% .
LID -Text
(Ours) achieves higher success rates than LID -Index
(Ours) and LID -Unnatural
(Ours) when dataset size increases, e.g .
LID -Text (Ours) is around 4% higher than LID -Index
(Ours) and LID -Unnatural
(Ours) with 500 training demos.
When the training dataset is further enlarged, e.g . 20K demos, success rates of all approaches reach similar performance.
This result indicates that the effectiveness of pre-trained LMs in compositional generalization is not unique to natural language strings, but can be leveraged from arbitrary encodings, although adapting the model to arbitrary encodings may require more training data.
7.2 Sequential Input Representation
[Table]
[Table] Next, we explore whether generalization requires the sequential processing mechanisms in transformer-based LMs.
We investigate whether the
LM pre-trained policy will still be effective when the input encoding is not sequential.
No-Seq encodes the goal as a single vector by averaging all goal embeddings.
History and observation features are obtained in the same way.
All features are then sent to the pre-trained LM to predict actions.
As shown in Table 5, removing sequential structure significantly hurts performance on Novel Tasks .
NoSeq achieves good performance on test tasks that are closer to training tasks, but cannot generalize well to more challenging unseen tasks.
Thus, combinatorial generalization in pre-trained LMs may be attributed in part to transformers’ ability to process sequential input representations effectively.
7.3 Favorable Weight Initialization
Finally, we investigate if the favorable weight initialization from LM pre-training enables effective generalization of the proposed model.
No-Pretrain does not initialize the policy using the pre-trained
LM, but instead training the policy on the expert data from scratch.
In Table 5, we find that removing the pre-trained weights can fit the in-domain data and thus performs well on the In-Distribution setting.
However, its success rate is 11 .
2% lower than the proposed model on the Novel Tasks setting, indicating the pre-trained weights are important for effective generalization, but not necessary for effective data fitting.
We further test a baseline, No-FT , that keeps the pre-trained weights of the language model but freezes them while training the rest model on our expert data.
Freezing the pretrained weights without fine-tuning significantly hurts the performance on both settings, suggesting that fine-tuning of the transformer weights is essential for effective combinatorial generalization.
Together, these results suggest that sequential input representations (vs. fixed-dimensional feature vectors) and favorable weight initialization are both important for generalization, however, the input encoding schemes (e.g. as a natural language string vs. an arbitrary encoding scheme) has little influence.
These results point to the potential broader applicability of pre-trained LMs as a computational backbone for compositional embodied decision making, where arbitrary inputs, such as language, images, or grids, may be converted to sequential encodings.
N ov e l
T a s k s
[Figure]
T o L o c a l
[Figure]
I nD i s t
r i bu t i o n
[Figure] [Figure]
c y
E rr o r
G r o und i n g
E rr o r
[Figure]
Qualitative Results
In Figure 4, we show examples of LID -Text (Ours) completing tasks in VirtualHome and BabyAI.
We show two successful examples from VirtualHome on the In-Distribution and Novel Tasks settings, and two successful examples from BabyAI on solving the GoToLocal and PickupLoc tasks.
We only show short trajectories or extract a sub-trajectory for saving space.
Failure case analysis.
In Figure 5, we show some failure cases of the proposed method.
We observed two main types of failure cases: grounding error and policy error.
For failures caused by the grounding error, the agent interacts with a wrong object that is not related to the given goal, e.g .
the agent puts cutlets instead of the salmon inside the fridge.
For failures caused by the policy error, the agent cannot find the target objects or does not interact with them.
The proposed method that converts policy inputs into sequential encodings and feeds them to the general LM framework can accomplish decision-making tasks efficiently, however, there are still challenging tasks that the policy fails to accomplish.
Larger LMs, e.g . GPT-3 [6], may improve the success rate of those challenging tasks.
Conclusion and Broader Impact
In this paper, we introduced LID, a general approach to sequential decision-making that converts goals, histories, and observations into sequences and processes them using a policy initialized with a pre-trained LM.
We integrated an active data gathering procedure into the proposed method to enable policy learning without using expert data.
Our analysis showed that input representation and favorable weight initialization both contribute to the generalization while the input encoding scheme has little influence.
One drawback of the active data gathering is that it relies on hand-designed rules for task relabeling.
More generally, a potential disadvantage of the proposed approach is that biases of the pre-trained LMs may influence its behavior, and further study of LID-based models’ bias is required before they may be deployed in sensitive downstream applications.
Nevertheless, our results demonstrate that LID enables effective combinatorial generalization across different environments, and highlight the promise of LM pre-training for more general decision-making problems.
Appendix
In this appendix, we first show the convolutional encoding in BabyAI in Appendix A. We then describe the environment details in Appendix B and the implementation details of the proposed model in Appendix C.
We show the algorithm of interactive evaluation in Section D and the data gathering procedure in
Appendix E.
The goal predicates used in VirtualHome test subsets are shown in Appendix F.
We visualize the attention weights in language models in Appendix G.
A Convolutional encoding in BabyAI
In the main paper Section 7.1, we explore the role of natural language by investigating two alternative ways of encoding policy inputs in VirtualHome.
In this section, we show the third way of encoding policy inputs in BabyAI.
We test a new model, LID-Conv (Ours) , that converts environment inputs into convolutional embeddings .
We pass the 7 × 7 × 3 grid observation in BabyAI to convolutional layers and obtain a 7 × 7 × d feature map, where d is the feature dimension.
We flatten the feature map and get a sequence of features to describe the observation.
The rest of the model is the same as LID -Text (Ours) .
Table 6 shows the results of policies using the text encoding and convolutional encoding .
LID -Text (Ours) and LID -Conv
(Ours) have similar results given enough training data, but LID -Text (Ours) is slightly better when there are fewer training data.
This conclusion is coincident with the results on VirtualHome.
Different input encoding schemes have only a negligible impact on model performance: the effectiveness of pre-training is not limited to utilizing natural strings, but in fact extends to arbitrary sequential encodings.
[Table]
B Environments
We use BabyAI [16] and VirtualHome [31] to evaluate the proposed method.
While both environments feature complex goals, the nature of these goals, as well as the state and action sequences that accomplish them, differ substantially across environments.
B.1 VirtualHome
VirtualHome is a 3D realistic environment featuring partial observability, large action spaces, and long time horizons.
It provides a set of realistic 3D homes and objects that can be manipulated to perform household organization tasks.
Goal Space.
For each task, we define the goal as a set of predicates and multiplicities.
For example,
Inside(apple, fridge):2 ; Inside(pancake, fridge):1 ; means “put two apples and one pancake inside the fridge”.
In each task, the initial environment (including initial object locations), the goal predicates, and their orders and multiplicities are randomly sampled.
There are 59 different types of predicates in total.
[Table]
Pre-Trained Language Models for Interactive Decision-Making observation into a sequence of image patches as in Vision Transformer
(Dosovitskiy et al., 2020).
P
N
We choose to convert the observations, goal predicates, and history information into token sequences and pass them to a pre-trained language model.
We take the text tokens as an example to explain the proposed method.
Goal.
Each goal consists of a sequence of predicates and multiplicities, and is translated into a templated English sentence ( e.g . “ Inside(apple, fridge):2 ” becomes “put two apples inside the fridge”).
Observation.
To encode the agent’s partial observation, we extract a list of currently visible objects, their states ( e.g . “open, clean”), and3Dworldcoordinates.
Weuseafully-connectedlayerto encode the 3D information and generate a feature representation of each object in the observation.
See Appendix B.1 for more details.
History.
We store information about all previous actions and convert them into templated English sentences ( e.g .
“I have put the plate on the kitchen table and the apple inside the fridge”).
Action prediction.
VirtualHome features a large action space, and the set of valid actions changes as the agent moves through and interacts with the environment.
Each action consists of 1 verb and 1 object.
In training, we maximize the probabilities of the verb and object selected by an expert action.
To produce the verb probabilities, we pool the outputs of the pre-trained LM and pass this “context feature” through a fully-connected layer as shown in Figure 2.
To determine the object probabilities, the model computes the inner product of the context feature with the LM output vectors corresponding to each object in the observation.
This design automatically ﬁlters out objects that are not in the observation and hence cannot be interacted with.
In inference, we select the valid action with the highest joint probability 1 .
[Equation]
4.2. Policy Learning on BabyAI
Wefurtherevaluatetheeffectivenessoftheproposedmethodon BabyAI (Hui et al., 2020).
BabyAI contains program- matically generated natural language instructions, e.g. “put the green ball next to the box on your right” and requires the agent to navigate the world and move objects to target locations.
BabyAIprovidesdemosfor19tasksofincreasing difﬁculty for testing imitation learning and reinforcement learning algorithms.
In our experiments, we compare the
[Table] [Table]
Tokenization
Context feature f c
History h t <walk> [kitchen] …<put> [apple] <in> [cabinet]
Cross-entropy loss
[Table]
entropy loss
Average Pooling
F ! F !
F !
Tokenization INSIDE(pancake, fridge):2 …ON(apple, table):1 Goal g
Tokenization agent kitchen apple fridge cabinet Partial observation o t
Object embeddings … … …
F ! F !
F ! F ! F !
FC FC
[Figure]
Training
Inference
Object probabilities
Pre-trained Language Model (",$,%)
FC (",$,%)
FC
[Figure]
5. Experiments 5.1. Experiments on VirtualHome 5.1.1. E VALUATION M ETRICS
We build three test sets that evaluate policies’ ability from three aspects: (1) performance on in-distribution tasks; (2) generalization to novel to
In-Distribution.
The predicate types and their counts are randomly sampled based on the same distribution as the training data.
There are 2 ⇠ 10 predicates in each task.
The objects are initially placed in the environment according to common-senselayouts; ( e g .platesappearinsidethekitchen cabinets rather than the bathtub).
Even goal predicates are
[Figure]
Observation Space.
The observation in VirtualHome by default is a graph describing a list of objects and their relations in the current partial observation.
Each object has an object name, a state, e.g . open, close, clean , and 3D coordinates.
Action Space.
Agents can navigate in the environment and interact with objects.
To interact with an object, the agent must predict an action name and the index of the interested object, e.g . Open(5) to opening the object with index (5).
The agent can only interact with objects that are in the current observation or execute the navigation actions, such as Walk(bathroom) .
For some actions, such as open , the agent must be close to the object.
There are also strict preconditions for actions, e.g .
the agent must grab an object before it can put the object on a target position.
As a result of these constraints, the subset of actions available to the agent changes at every timestep.
We evaluate the success rates of different methods on VirtualHome.
A given episode is scored as successful if the policy completes its entire goal within T steps, where T = 70 is the maximum allowed steps of the environment.
B.2 BabyAI
BabyAI is a 2D grid world environment designed to evaluate instruction following.
Different from
VirtualHome, the observation in BabyAI by default is a 7 × 7 grid describing a partial and local egocentric view of the state of the environment.
Each tile in the grid contains at most one object, encoded using 3 integer values: one for the object type, one for the object color, and a state for doors indicating whether it is open, closed or locked.
The goals in BabyAI are language instructions, e.g .
“put the blue key next to the purple ball”.
BabyAI has 7 actions, e.g .
“turn left”, “pick up”, and “drop”.
C More implementation Details of LID in VirtualHome
In Appendix C.1, we provide more details of the model architecture used in the main paper Section 4.1.
We then introduce the training detail in Appendix C.2.
f c
Observation o t History h t Goal g
F 𝜃 F 𝜃
FC FC
FC
Name (e.g. “kitchen oven”)
Statevector
Positionvector
FC FC
FC F 𝜃
FC
Token sequence
F 𝜃
Avg pool
Concatenate
For each object in o t
FC (𝑥,𝑦,𝑧) (𝑥,𝑦,𝑧)
Tokenization
ReLU
C.1 Model architecture details in VirtualHome
In this section we provide more details of the policy network we used in VirtualHome.
Our policy model consists of three parts, i.e . inputs, the pre-trained LM, and outputs.
As shown Figure 6, we encode the inputs to the policy—including goal g , history h t , and the current partial observation o t — as sequences of embeddings.
These embeddings are passed to the LM (using its pre-trained embedding layer F θ ) and used to obtain contextualized token representations.
These token representations are averaged to generate a context feature f c , which is then passed to fully-connected layer to predict the next action a t .
The output action in VirtualHome consists of a verb and an object.
For brevity, we omit the time subscript t from now on.
In VirtualHome, the partial observation o of the environment state can be represented as a list of objects in the agent’s view.
We represent each object by its name, e.g . “oven”, a state description, e.g . “open, clean”, and position both in the world and relative to the agent.
In this part, we provide more details of how LID-Text (Ours) encodes the name, state, and position of each object in the observation.
Figure 7 shows the model architecture we used to encode the observation.
Name encoding.
For each object node, we serialize its object name as an English phrase s o .
We extract its tokens and features using the tokenizer and the embedding layer of the pre-trained LM, respectively.
Since one object name might generate several English tokens using the tokenizer from the pre-trained LM, e.g .
the tokens of “kitchencabinet” is [15813 , 6607 , 16212 , 500] , we take the averaged features of all the tokens in the object name and obtain a “name” feature f o, name i for each object node as shown in Figure 7.
State encoding.
Some objects have a state description, e.g .
“oven: open, clean”.
There are six types of object states in the environment: “clean”, “closed”, “off”, “on”, “open”, and “none”.
For each object node, we use a binary vector to represent its state.
Taking the “oven” as an example, if the oven is open and clean, its state vector would be [1 , 0 , 0 , 0 , 1 , 0] .
This state vector is then passed through a fully-connected layer to generate a state feature f
o, state i of object o i .
Position encoding.
To encode the position information of each object o i , we take their world coordinates { o i,x , o i,y , o i,z } and their spatial distance to the agent { a x , a y , a z } to generate a position vector
[ o i,x , o i,y , o i,z , o i,x − a x , o i,y − a y , o i,z − a z ] .
This position vector is then passed through two fully-connected layers with a ReLU layer in the middle to generate a position feature f o, position i of object o i .
The final feature f oi of each object node is obtained by passing the concatenation of its name feature f o, name i , state feature f
o, state i , and position feature f o, position i through a fully connected layer.
The observation at a single step can be written as a set of features { f o 1 , · · · , f oN } , where N is the number of objects in the current observation.
C.2 Training details
Our proposed approach and baselines are trained on Tesla 32GB GPUs.
We train every single model on 1 Tesla 32GB GPU.
All experiments used the AdamW optimizer with the learning rate of 10 − 5 .
We utilize a standard pre-trained language model, GPT-2, in our experiments.
GPT-2 is trained on the
Webtext dataset [34] using the Huggingface library [46].
D Interactive Evaluation
The algorithm for interactive evaluation is shown in Algorithm 1.
[Table]
[Table] [Table]
[Table]
E Data Gathering Details in VirtualHome
In this section, we provide more data gathering details in VirtualHome for training the decisionmaking policies.
We introduce the expert data collection and active data gathering in Appendix E. and Appendix E.2, respectively.
E.1 Expert Data Collection
VirtualHome-Imitation Learning Dataset.
To train the models, we collect a set of expert trajectories in VirtualHome using regression planning (RP) [20].
We follow the implementation of the regression planner used in [32].
Given a task described by goal predicates, the planner generates an action sequence to accomplish this task.
As shown in Figure 8, the agent has a belief about the environment, i.e . an imagined distribution of object locations.
As the agent explores the environment, its belief of the world becomes closer to the real world.
At every step, the agent updates its belief based on the latest observation (see [32]), finds a new plan using the regression planner, and executes the first action of the plan.
If the subtask (described by the goal predicate) has been finished, the agent will select a new unfinished subtask, otherwise, the agent will keep doing this subtask until it finishes.
Similarly to previous work [40, 39, 32], we generate training data using a planner that has access to privileged information, such as full observation of the environment and information about the pre-conditions and effects of each action.
The planner allows an agent to robustly perform tasks in partially observable environments and generate expert trajectories for training and evaluation.
We generate 20 , 000 trajectories for training and 3 , 000 trajectories for validation.
Each trajectory has a goal, an action sequence, and the corresponding observations after executing each action.
[Figure]
E.2 Active Data Gathering
The algorithm for active data gathering is shown in Algorithm 2.
To sample the goal and initial state, we first generate a set of initial states in VirtualHome using the code released by [32].
For each initial state, we are able to get a set of feasible tasks that can be accomplished in this environment.
For example, in an initial state, if the apple is on the kitchen table, a feasible task goal could be “put the apple inside the fridge”.
In contrast, “put the banana inside the fridge” is not a feasible task if there is no banana in the initial state.
We collect 9893 initial states, and randomly sample an initial state and its feasible goal every time when we reset the environment.
After each data collection iteration, we obtain a set of new goals using the goal relabel function.
We save the goal and its corresponding initial state in the replay buffers and use the same strategy to sample the goal and initial state in the next iteration.
The hindsight relabeling stage is the key component for active data gathering.
Here we provide more implementation details of how we relabel “failed” trajectories with new goals in the hindsight relabeling stage.
For each “failed” trajectory, we extract its useful sub-trajectories and relabel a task goal g ′ for it.
We design a goal relabel function f l that generates a goal based on the sequence of observations and actions.
To do this, we first use a hand-designed program to detect what tasks are contained in a “failed” trajectory.
This program find useful tasks based on the keywords in the action list.
For example in Figure 9, the program knows the trajectory containing a task of “ On(apple, kitchen table):1 ” based on the action “ [ put ] < apple >< kitchentable > ”.
The selected sub-trajectories are not always optimal.
We thus design a rule to filter out bad trajectories, i.e . for trajectories with the same goal, selecting the “shorter” ones.
One example is shown in
Figure 10.
Suppose that there are two trajectories having the same goal, e.g . “ On(apple, kitchen table):1 ”.
The first trajectory has actions that are redundant or not related to the task, such as “ [ walk ] < bathroom > ” and “ [ walk ] < kitchen > ” while the second trajectory is more optimal given the goal.
We select the second trajectory and delete the first trajectory from the replay buffer.
Note that the “shorter” does not mean fewer actions, but fewer actions that are not related to the task.
The hindsight relabeling stage allows sample-efficient learning by reusing the failure cases.
The relabeled data are used to train policies in the policy update stage.
Given: a goal relabel function f l ;
Initialize: policy π ϕ ; goal set G ; training replay buffer R train = {} ; validation replay buffer R val = {} ; for iteration=1, N do for example=1, M do Sample a goal g from G and an initial state s 1 ; for t = 1 , T do Sample an action from policy π ϕ ( a t | g, h t , o t ) or sample an action randomly; Execute a t and obtain a new observation
o t +1 ; end Store the trajectory ( o 1 , a 1 , · · · , o T , a T , g ) in the replay buffer R train or R val ; end
Relabel each failure trajectory d = ( o 1 , a 1 , · · · , o T , a T ) in the replay buffers and get new goal g ′ =
f l ( d ) ;
Put new goals g ′ in the goal set G ; for k = 1 , K do repeat Sample data from R train and update policy π ϕ ; until training episode ends ; Get validation accuracy using the data from
R val ; end π ϕ =
π val_best end
Interacted objects Navigation trajectory
Useful sub-trajectory for hindsight relabeling … [walk] <kitchen>; [walk] <kitchentable1>; … ; [walk]< kitchentable>; [put] <apple> <kitchentable>; [walk] <bedroom>; …
Extract the useful sub-trajectory and relabel a task goal:
Action generated by the current policy or random exploration:
[Figure]
open
[Figure] [Figure]
walk
[Figure]
<kitchen cabinet 2> [open] <kitchen cabinet 2> [grab
[Figure]
<apple> [walk] <kitchentable> [put
[Figure]
> [walk] <bedroom> …
On (apple, kitchen table):
[Table] [Table]
F Test Sets in VirtualHome
In this section, we provide more details of each test set.
We first introduce the test sets used for evaluating the proposed model trained on expert data, i.e . LID, in Section F.1.
We then show the test sets used for evaluating the proposed model with active data gathering, i.e . LID-ADG, in Section F.2.
F. LID Test Sets
In Section 6.1, we compared the proposed method and baselines trained on expert data.
In Table 7, we provide a detailed description of each test subset, including the count of goal predicate types and the number of goal predicates in each task.
The In-Distribution setting has 37 goal predicates in total and each task has 2 ∼ 10 goal predicates.
The tasks are drawn from the same distribution as the training tasks.
The Novel Scenes setting also has 37 goal predicates and each task has 2 ∼ 10 goal predicates.
The objects are randomly placed in the initial environment.
The Novel Tasks setting has 22 goal predicates in total and each task has 2 ∼ 8 goal predicates.
The tasks are never seen during training.
[Figure]
[Table]
F. LID-ADG Test Sets
As we have mentioned in the main paper Section one limitation of active data gathering is that it relies on hand-designed rules for task relabeling.
In addition, it is sometimes challenging to define effective rules to extract useful sub-trajectories and get high-quality hindsight labels, especially when trajectories are long and tasks become more complex.
Thus we only relabel short sub-trajectories, where the goal consists of a single goal predicate, e g .
“ On(apple, kitchen table):1 ”.
During testing, we evaluate the success rate of approaches on solving such tasks as well, i e .
the count of the goal predicate equals to 1.
The types of goal predicates are the same as Section F.1, i.e . 37 goal predicates in the In-Distribution setting and the Novel Scenes setting, and 22 goal predicates in the
Novel Tasks setting.
G Visualization of Attention Weights
To better understand how does LM pre-trained policies make decisions, we visualize the attention weights from the self-attention layers of GPT-2 [43] in Figure 11 and Figure 12.
In the inference time, when we are decoding the actions, we save the self-attention weights with respect to different layers and different heads.
Then, we use BertViz library [44] to visualize normalized attention weights.
We show the attention weights from the input to the output of LID-Text (Ours) .
The order of tokens in the input and ouput is observation, goal, and history.
In Figure 11 and Figure 12, the left side is the query side.
The boldness of the lines is proportional with the attention weight.
Figure 11 illustrates the attention weights of a layer named “Head 3 Layer 2”.
We show attention weights on two different tasks.
We find that “Head 3 Layer 2” can capture objects in the goal predicates, such as “wineglass” and “cutleryfork” in the left figure, and “pancake” and “chicken” in the right figure (the figures are cropped for visualization).
Figure 12 illustrates the attention weights of layers named “Head 1 Layer 2” (left) and “Head 4 Layer 11” (right).
Given the goal predicates, history, and the current observation, the policy predicts the next action as “grab milk”.
We find that “Head 1 Layer 2” is able to capture objects in the goal predicates, such as “milk”, “pancake”, and “chicken” while “Head 4 Layer 11” focuses on the interacted object in the predicted action, such as “milk”.
The attention weights from different self-attention layers are significantly different—some selfattention layers assign high attention weight to objects in the goal predicates while some layers focus on the interacted object.
There are also some layers that do not have interpretable meanings.
The attention weights just provide us an intuition of how does the internal language model works, more quantified results are reported in the main paper
[Figure] [Figure]