Year: 2021

Abstract:
Since reward functions are hard to specify, recent work has focused on learning policies from human feedback. However, such approaches are impeded by the expense of acquiring such feedback. Recent work proposed that agents have access to a source of information that is effectively free: in any environment that humans have acted in, the state will already be optimized for human preferences, and thus an agent can extract information about what humans want from the state (Shah et al., 2019). Such learning is possible in principle, but requires simulating all possible past trajectories that could have led to the observed state. This is feasible in gridworlds, but how do we scale it to complex tasks? In this work, we show that by combining a learned feature encoder with learned inverse models, we can enable agents to simulate human actions backwards in time to infer what they must have done. The resulting algorithm is able to reproduce a specific skill in MuJoCo environments given a single state sampled from the optimal policy for that skill.

heading: 1 INTRODUCTION
text: As deep learning has become popular, many parts of AI systems that were previously designed by hand have been replaced with learned components. Neural architecture search has automated architecture design (Zoph & Le, 2017; Elsken et al., 2019), population-based training has automated hyperparameter tuning (Jaderberg et al., 2017), and self-supervised learning has led to impressive results in language modeling (Devlin et al., 2019; Radford et al., 2019; Clark et al., 2020) and reduced the need for labels in image classification (Oord et al., 2018; He et al., 2020; Chen et al., 2020). However, in reinforcement learning, one component continues to be designed by humans: the task specification. Handcoded reward functions are notoriously difficult to specify (Clark & Amodei, 2016; Krakovna, 2018), and learning from demonstrations (Ng et al., 2000; Fu et al., 2018) or preferences (Wirth et al., 2017; Christiano et al., 2017) requires a lot of human input. Is there a way that we can automate even the specification of what must be done?
It turns out that we can learn part of what the user wants simply by looking at the state of the environment: after all, the user will already have optimized the state towards their own preferences (Shah et al., 2019). For example, when a robot is deployed in a room containing an intact vase, it can reason that if its user wanted the vase to be broken, it would already have been broken; thus she probably wants the vase to remain intact.
However, we must ensure that the agent distinguishes between aspects of the state that the user couldn’t control from aspects that the user deliberately designed. This requires us to simulate what the user must have done to lead to the observed state: anything that the user put effort into in the past is probably something the agent should do as well. As illustrated in Figure 1, if we observe a Cheetah balancing on its front leg, we can infer how it must have launched itself into that position. Unfortunately, it is unclear how to simulate these past trajectories that lead to the observed state. So far, this has only been done in gridworlds, where all possible trajectories can be considered using dynamic programming (Shah et al., 2019).
Our key insight is that we can sample such trajectories by starting at the observed state and simulating backwards in time. To enable this, we derive a gradient that is amenable to estimation through backwards simulation, and learn an inverse policy and inverse dynamics model using supervised
∗Work done at the Center for Human-Compatible AI, UC Berkeley.
learning to perform the backwards simulation. Then, the only remaining challenge is finding a reward representation that can be meaningfully updated from a single state observation. To that end, rather than defining the reward directly on the raw input space, we represent it as a linear combination of features learned through self-supervised representation learning. Putting these components together, we propose the Deep Reward Learning by Simulating the Past (Deep RLSP) algorithm.
We evaluate Deep RLSP on MuJoCo environments and show that it can recover fairly good performance on the task reward given access to a small number of states sampled from a policy optimized for that reward. We also use Deep RLSP to imitate skills generated using a skill discovery algorithm (Sharma et al., 2020), in some cases given just a single state sampled from the policy for that skill.
Information from the environment state cannot completely replace reward supervision. For example, it would be hard to infer how clean Bob would ideally want his room to be, if the room is currently messy because Bob is too busy to clean it. Nonetheless, we are optimistic that information from the environment state can be used to significantly reduce the burden of human supervision required to train useful, capable agents.

heading: 2 METHOD
text: In this section, we describe how Deep RLSP can learn a reward function for high dimensional environments given access only to a simulator and the observed state s0.
Notation. A finite-horizon Markov Decision Process (MDP)M = 〈S,A, T , r,P, T 〉 contains a set of states S and a set of actions A. The transition function T : S × A × S 7→ [0, 1] determines the distribution over next states given a state and an action, and P is a prior distribution over initial states. The reward function r : S 7→ R determines the agent’s objective. T ∈ Z+ is a finite planning horizon. A policy π : S ×A 7→ [0, 1] specifies how to choose actions given a state. Given an initial state distribution, a policy and the transition function, we can sample a trajectory τ by sampling the first state from P , every subsequent action from π, and every subsequent state from T . We denote the probability distribution over trajectories as 〈P, π, T 〉 and write τ ∼ 〈P, π, T 〉 for the sampling step. We will sometimes write a single state s instead of a distribution P if the initial state is deterministic. The goal of reinforcement learning (RL) is to find a policy π∗ that maximizes the expected cumulative reward Eτ∼〈P,π,T 〉 [∑T t=1 r(st) ] .
We use φ : S → Rn to denote a feature function (whether handcoded or learned) that produces a feature vector of length n for every state. The reward function r is linear over φ if it can be expressed in the form r(s) = θTφ(s) for some θ ∈ Rn. We assume that some past trajectory τ−T :0 = s−Ta−T . . . a−1s0 produced the observed state s0.

heading: 2.1 IDEALIZED ALGORITHM
text: We first explain what we would ideally do, if we had a handcoded a feature function φ and an enumerable (small) state space S that affords dynamic programming. This is a recap of Reward Learning by Simulating the Past (RLSP; Shah et al., 2019).
We assume the human follows a Boltzmann-rational policy πt(a | s, θ) ∝ exp(Qt(s, a; θ)), where the Q values are computed using soft value iteration. Marginalizing over past trajectories, yields a distribution over the observed state p(s0 | θ) = ∑ s−T ...a−1
p(τ = s−Ta−T . . . a−1s0 | θ). We compute the maximum likelihood estimate, argmaxθ ln p(s0 | θ), via gradient ascent, by expressing the gradient of the observed state as a weighted combination of gradients of consistent trajectories (Shah et al., 2019, Appendix B):
∇θ ln p(s0 | θ) = E τ−T :−1 ∼ p(τ−T :−1|s0,θ) [∇θ ln p(τ | θ)] (1)
∇θ ln p(τ | θ) is a gradient for inverse reinforcement learning. Since we assume a Boltzmann-rational human, this is the gradient for Maximum Causal Entropy Inverse Reinforcement Learning (MCEIRL; Ziebart et al., 2010). However, we still need to compute an expectation over all trajectories that end in s0, which is in general intractable. Shah et al. (2019) use dynamic programming to compute this gradient in tabular settings.

heading: 2.2 GRADIENT AS BACKWARDS-FORWARDS CONSISTENCY
text: Approximating the expectation. For higher-dimensional environments, we must approximate the expectation over past trajectories p(τ−T :−1 | s0, θ). We would like to sample from the distribution, but it is not clear how to sample the past conditioned on the present. Our key idea is that just as we can sample the future by rolling out forwards in time, we should be able to sample the past by rolling out backwards in time. Note that by the Markov property we have:
p(τ−T :−1 | s0, θ) = −1∏
t=−T p(st | at, st+1, . . . s0, θ)p(at | st+1, at+1, . . . s0, θ)
= −1∏ t=−T p(st | at, st+1, θ)p(at | st+1, θ)
Thus, given the inverse policy π−1t (at | st+1, θ), the inverse dynamics T −1t (st | at, st+1, θ), and the observed state s0, we can sample a past trajectory τ−T :−1 ∼ p(τ−T :−1 | s0, θ) by iteratively applying π−1 and T −1, starting from s0. Analogous to forward trajectories, we express the sampling as τ−T :−1 ∼ 〈s0, π−1, T −1〉. Thus, we can write the gradient in Equation 1 as Eτ−T :−1 ∼ 〈s0,π−1,T −1〉 [∇θ ln p(τ | θ)].
Learning π, π−1 and T −1. In order to learn π−1, we must first know π. We assumed that the human was Boltzmann-rational, which corresponds to the maximum entropy reinforcement learning objective (Levine, 2018). We use the Soft Actor-Critic algorithm (SAC; Haarnoja et al., 2018) to estimate the policy π(a | s, θ), since it explicitly optimizes the maximum entropy RL objective. Given the forward policy π(a | s, θ) and simulator T , we can construct a dataset of sampled forward trajectories, and learn the inverse policy π−1 and the inverse dynamics T −1 using supervised learning. Given these, we can then sample τ−T :−1, allowing us to approximate the expectation in the gradient. In general, both π−1 and T −1 could be stochastic and time-dependent. Estimating the gradient for a trajectory. We now turn to the term within the expectation, which is the inverse reinforcement learning gradient given a demonstration trajectory τ = s−Ta−T . . . s0. Assuming that the user is Boltzmann-rational, this is the MCEIRL gradient (Ziebart et al., 2010), which can be written as (Shah et al., 2019, Appendix A):
∇θ ln p(τ | θ) =
( 0∑
t=−T φ(st)
) −F−T (s−T )+
−1∑ t=−T
( E
s′t+1∼T (·|st,at)
[ Ft+1(s′t+1) ] −Ft+1(st+1) ) (2)
F is the expected feature count under π, that is, F−t(s−t) , Eτ−t:0 ∼ 〈s−t,π,T 〉 [∑0 t′=−t φ(st′) ] .
The first term computes the feature counts of the demonstrated trajectory τ , while the second term computes the feature counts obtained by the policy for the current reward function θ (starting from
the initial state s−T ). Since r(s) = θTφ(s), these terms increase the reward of features present in the demonstration τ and decrease the reward of features under the current policy. Thus, the gradient incentivizes consistency between the demonstration and rollouts from the learned policy.
The last term is essentially a correction for the observed dynamics: if we see that st, at led to st+1, it corrects for the fact that we “could have” seen some other state s′t+1. Since this correction is zero in expectation (and expensive to compute), we drop it for our estimator.
Gradient estimator. After dropping the last term in Equation 2, expanding the definition of F , and substituting in to Equation 1, our final gradient estimator is:
∇θ ln p(s0 | θ) = E τ−T :−1 ∼ 〈s0,π−1,T −1〉
[( 0∑
t=−T φ(st) ) − E τ ′ ∼ 〈s−T ,π,T 〉 [( 0∑ t=−T φ(s′t) )]] (3)
Thus, given s0, θ, π, T , π−1, and T −1, computing the gradient consists of three steps:
1. Simulate backwards from s0, and compute the feature counts of the resulting trajectories. 2. Simulate forwards from s−T of these trajectories, and compute their feature counts. 3. Take the difference between these two quantities.
This again incentivizes consistency, this time between the backwards and forwards trajectories: the gradient leads to movement towards “what the human must have done” and away from “what the human would do if they had this reward”. The gradient becomes zero when they are identical.
It may seem like the backwards and forwards trajectories should always be consistent with each other, since π−1 and T −1 are inverses of π and T . The key difference is that s0 imposes constraints on the backwards trajectories, but not on the forward trajectories. For example, suppose we observe s0 in which a vase is unbroken, and our current hypothesis is that the user wants to break the vase. When we simulate backwards, our trajectory will contain an unbroken vase, but when we simulate forwards from s−T , π will break the vase. The gradient would then reduce the reward for a broken vase and increase the reward for an unbroken vase.

heading: 2.3 LEARNING A LATENT MDP
text: Our gradient still relies on a feature function φ, with the reward parameterized as r(s) = θTφ(s). A natural way to remove this assumption would be to instead allow θ to parameterize a neural network, which can then learn whatever features are relevant to the reward from the RLSP gradient.
However, this approach will not work because the information contained in the RLSP gradient is insufficient to identify the appropriate features to construct: after all, it is derived from a single state. If we were to learn a single unified reward using the same gradient, the resulting reward would likely be degenerate: for example, it may simply identify the observed state, that is R(s) = 1[s = s0].
Thus, we continue to assume that the reward is linear in features, and instead learn the feature function using self-supervised learning (Oord et al., 2018; He et al., 2020). In our experiments, we use a variational autoencoder (VAE; Kingma & Welling, 2014) to learn the feature function. The VAE encodes the states into a latent feature representation, which we can use to learn a reward function if the environment is fully observable, i.e., the states contain all relevant information.
For partially observable environments recurrent state space models (RSSMs; Karl et al., 2017; Doerr et al., 2018; Buesing et al., 2018; Kurutach et al., 2018; Hafner et al., 2019; 2020) could be used instead. These methods aim to learn a latent MDP, by computing the states using a recurrent model over the observations, thus allowing the states to encode the history. For such a model, we can imagine that the underlying POMDP has been converted into a latent MDP whose feature function φ is the identity. We can then compute gradients directly in this latent MDP.

heading: 2.4 DEEP RLSP
text: Putting these components together gives us the Deep RLSP algorithm (Algorithm 1). We first learn a feature function φ using self-supervised learning, and then train an inverse dynamics model T −1, all using a dataset of environment interactions (such as random rollouts). Then, we update θ using
Algorithm 1 The DEEP RLSP algorithm. The initial dataset of environment interactions D can be constructed in many different ways: random rollouts, human play data, curiosity-driven exploration, etc. The specific method will determine the quality of the learned features.
procedure DEEP RLSP({s0}, T ) D ← dataset of environment interactions Initialize φe, φd, π, π−1, T −1, θ randomly. φe, φd ← SelfSupervisedLearning(D) . Train encoder and decoder for latent MDP Initialize experience replay E with data in D. T −1 ← SupervisedLearning(D) . Train inverse dynamics T ← 1 . Start horizon at 1 for i in [1..num_epochs] do
π ← SAC(θ) . Train policy π−1 ← SupervisedLearning(φe, E) . Train inverse policy θ ← θ + α × COMPUTEGRAD({s0}, π, T , π−1, T −1, T , φe) . Update θ if gradient magnitudes are sufficiently low then
T ← T + 1 . Advance horizon return θ, φe procedure COMPUTEGRAD({s0}, π, T , π−1, T −1, T , φe) {τbackward} ← Rollout({s0}, π−1, T −1, T ) . Simulate backwards from s0 φbackward ← AverageFeatureCounts(φe, {τbackward}) . Compute backward feature counts {s−T } ← FinalStates({τbackward}) {τforward} ← Rollout({s−T }, π, T , T ) . Simulate forwards from s−T φforward ← AverageFeatureCounts(φe, {τforward}) . Compute forward feature counts Relabel {τbackward}, {τforward} and add them to E. return φbackward − φforward
Equation 3, and continually train π, and π−1 alongside θ to keep them up to date. The full algorithm also adds a few bells and whistles that we describe next.
Initial state distribution P . The attentive reader may wonder why our gradient appears to be independent of P . This is actually not the case: while π and T are independent of P , π−1 and T −1 do depend on it. For example, if we observe Alice exiting the San Francisco airport, the corresponding π−1 should hypothesize different flights if she started from New York than if she started from Tokyo.
However, in order to actually produce such explanations, we must train π−1 and T −1 solely on trajectories of length T starting from s−T ∼ P . We instead train π−1 and T −1 on a variety of trajectory data, which loses the useful information in P , but leads to several benefits. First, we can train the models on exactly the distributions that they will be used on, allowing us to avoid failures due to distribution shift. Second, the horizon T is no longer critical: previously, T encoded the separation in time between s−T and s0, and as a result misspecification of T could cause bad results. Since we now only have information about s0, it doesn’t matter much what we set T to, and as a result we can use it to set a curriculum (discussed next). Finally, this allows Deep RLSP to be used in domains where an initial state distribution is not available.
Note that we are no longer able to use information about P through π−1 and T −1. However, having information about P might be crucial in some applications to prevent Deep RLSP from converging to a degenerate solution with s−T = s0 and a policy π that does nothing. While we did not find this to be a problem in our experiments, we discuss a heuristic to incorporate information about s−T into Deep RLSP in Appendix C.
Curriculum. Since the horizon T is no longer crucial, we can use it to provide a curriculum. We initially calculate gradients with low values of T , to prevent compounding errors in our learned models, and making it easier to enforce backwards-forwards consistency, and then slowly grow T , making the problem harder. In practice, we found this crucial for performance: intuitively, it is much easier to make short backwards and forwards trajectories consistent than with longer trajectories; the latter would likely have much higher variance.
Multiple input states. If we get multiple independent s0 as input, we average their gradients.
Experience replay. We maintain an experience replay buffer E that persists across policy training steps. We initialize E with the same set of environment interactions that the feature function and inverse dynamics model are trained on. When computing the gradient, we collect all backward and forward trajectories and add them to E. To avoid compounding errors from the inverse dynamics model, we relabel all transitions using a simulator of the environment. Whenever we’d add a transition (s, a, s′) to E, we initialize the simulator at s and execute a to obtain s̃ and add transition (s1, a, s̃) to E instead.

heading: 3 EXPERIMENTS

heading: 3.1 SETUP
text: To demonstrate that Deep RLSP can be scaled to complex, continuous, high-dimensional environments, we use the MuJoCo physics simulator (Todorov et al., 2012). We consider the Inverted Pendulum, Half-Cheetah and Hopper environments implemented in Open AI Gym (Brockman et al., 2016). The hyperparameters of our experiments are described in detail in Appendix B. We provide code to replicate our experiments at https://github.com/HumanCompatibleAI/deep-rlsp.
Baselines. To our knowledge, this is the first work to train policies using a single state as input. Due to lack of alternatives, we compare against GAIL (Ho & Ermon, 2016) using the implementation from the imitation library (Wang et al., 2020). For each state we provide to Deep RLSP, we provide a transition (s, a, s′) to GAIL.
Ablations. In Section 2.2, we derived a gradient for Deep RLSP that enforces consistency between the backwards and forwards trajectories. However, we could also ignore the temporal information altogether. If an optimal policy led to the observed state s0, then it is probably a good bet that s0 is high reward, and that the agent should try to keep the state similar to s0. Thus, we can simply set θ = φ(s0)||φ(s0)|| , and not deal with π −1 and T −1 at all.
How should we handle multiple states s10, . . . , s N 0 ? Given that these are all sampled i.i.d. from rollouts of an optimal policy, a natural choice is to simply average the feature vectors of all of the states, which we call AverageFeatures. Alternatively, we could view each of the observed states as a potential waypoint of the optimal policy, and reward an agent for being near any one of them. We implement this Waypoints method as R(s) = maxi φ(si0)
||φ(si0)|| · φ(s). Note that both of these ablations
still require us to learn the feature function φ.
Feature learning dataset. By default, we use random rollouts to generate the initial dataset that is used to train the features φ and the inverse model T −1. (This is D in Algorithm 1.) However, in the inverted pendulum environment, the pendulum falls very quickly in random rollouts, and T −1 never learns what a balanced pendulum looks like. So, for this environment only, we combine random rollouts with rollouts from an expert policy that balances the pendulum.

heading: 3.2 GRIDWORLD ENVIRONMENTS
text: As a first check, we consider the gridworld environments in Shah et al. (2019). In these stylized gridworlds, self-supervised learning should not be expected to learn the necessary features. For example, in the room with vase environment, the two door features are just particular locations, with no distinguishing features that would allow self-supervised learning to identify these locations as important. So, we run Algorithm 1 without the feature learning and instead use the pre-defined feature function of the environments. With this setup we are able to use Deep RLSP to recover the desired behavior from a single state in all environments in which the exact RLSP algorithm is able to recover it. However, AverageFeatures fails on several of the environments. Since only one state is provided, Waypoints is equivalent to AverageFeatures. It is not clear how to apply GAIL to these environments, and so we do not compare to it. Further details on all of the environments and results can be found in Appendix A.

heading: 3.3 SOLVING THE ENVIRONMENTS WITHOUT ACCESS TO THE REWARD FUNCTION
text: First we look at the typical target behavior in each environment: balancing the inverted pendulum, and making the half-cheetah and the hopper move forwards. Additionally we consider the goal of making the cheetah run backwards (that is, the negative of its usual reward function). We aim to use Deep RLSP to learn these behaviors without having access to the reward function.
We train a policy using soft actor critic (SAC; Haarnoja et al., 2018) to optimize for the true reward function, and sample either 1, 10 or 50 states from rollouts of this policy to use as input. We then use Deep RLSP to infer a reward and policy. Ideally we would evaluate this learned policy rather than reoptimizing the learned reward, since learned reward models can often be gamed (Stiennon et al., 2020), but it would be too computationally expensive to run the required number of SAC steps during each policy learning step. As a result, we run SAC for many more iterations on the inferred reward function, and evaluate the resulting policy on the true reward function (which Deep RLSP does not have access to).
Results are shown in Table 1. In Hopper, we noticed that videos of the policies learned by Deep RLSP looked okay, but the quantitative evaluation said otherwise. It turns out that the policies learned by Deep RLSP do jump, as we might want, but they often fall down, terminating the episode; in contrast GAIL policies stand still or fall over slowly, leading to later termination and explaining their better quantitative performance. We wanted to also evaluate the policies without this termination bias, and so we evaluate the same policies in an environment that does not terminate the episode, but provides a negative reward instead; in this evaluation both Deep RLSP and AverageFeatures perform much better. We also provide videos of the learned policies at https://sites.google.com/view/ deep-rlsp, which show that the policies learned by Deep RLSP do exhibit hopping behavior (though with a strong tendency to fall forward).
GAIL is only able to learn a truly good policy for the (very simple) inverted pendulum, even though it gets states and actions as input. Deep RLSP on the other hand achieves reasonable behavior (though clearly not expert behavior) in all of the environments, using only states as input. Surprisingly, the AverageFeatures method also performs quite well, even beating the full algorithm on some tasks, though failing quite badly on Pendulum. It seems that the task of running forward or backward is very well specified by a single state, since it can be inferred even without any information about the dynamics (except that which is encoded in the features learned from the initial dataset).

heading: 3.4 LEARNING SKILLS FROM A SINGLE STATE
text: We investigate to what extent Deep RLSP can learn other skills where the reward is not clear. Evaluation on these tasks is much harder, because there is no ground truth reward. Therefore we evaluate qualitatively how similar the policies learned by Deep RLSP are to the original skill. We also attempted to quantify similarity by checking how quickly a discriminator could learn to distinguish between the learned policy and the original skill, but unfortunately this metric was not conclusive (results are reported in Appendix D.1). Unlike the previous case, we do not reoptimize the learned reward and only look at the policies learned by Deep RLSP.
We consider skills learned by running Dynamics-Aware Unsupervised Discovery of Skills (DADS; Sharma et al., 2020). Since we are not interested in navigation, we remove the “x-y prior” used to get directional skills in DADS. We run DADS on the half-cheetah environment and select all skills that are not some form of running. This resulted in two skills: one in which the cheetah is moving forward making big leaps (“jumping”) and one in which it is slowly moving forward on one leg (“balancing”). As before we roll out these policies and sample individual states from the trajectories to provide as an input for Deep RLSP. We then evaluate the policy learned by Deep RLSP. Since the best evaluation here is to simply watch what the learned policy does, we provide videos of the learned policies at https://sites.google.com/view/deep-rlsp. We also provide visualizations in Appendix D.2.
The first thing to notice is that relative to the ablations, only Deep RLSP is close to imitating the skill. None of the other policies resemble the original skills at all. While AverageFeatures could perform well on simple tasks such as running, the full algorithm is crucial to imitate more complex behavior.
Between Deep RLSP and GAIL the comparison is less clear. Deep RLSP can learn the balancing skill fairly well from a single state, which we visualize in Figure 2 (though we emphasize that the videos are much clearer). Like the original skill, the learned policy balances on one leg and slowly moves forward by jumping, though with slightly more erratic behavior. However, the learned policy sometimes drops back to its feet or falls over on its back. We suspect this is an artifact of the short horizon (T ≤ 10) used for simulating the past in our algorithm. A small horizon is necessary to avoid compounding errors in the learned inverse dynamics model, but can cause the resulting behavior to be more unstable on timescales greater than T . We see similar behavior when given 10 or 50 states. GAIL leads to a good policy given a single transition, where the cheetah balances on its front leg and head (rather than just the front leg), but does not move forward very much. However, with 10 or 50 transition, the policies learned by GAIL do not look at all like balancing.
However, the jumping behavior is harder to learn, especially from a single state. We speculate that here a single state is less informative than the balancing state. In the balancing state, the low joint velocities tell us that the cheetah is not performing a flip, suggesting that we had optimized for this specific balancing state. On the other hand, with the jumping behavior, we only get a single state of the cheetah in the air with high velocity, which is likely not sufficient to determine what the jump looked like exactly. In line with this hypothesis, at 1 state Deep RLSP learns to erratically hop, at 10 states it executes slightly bigger jumps, and at 50 states it matches the original skill relatively closely.
The GAIL policies for jumping are also reasonable, though in a different way that makes it hard to compare. Using 1 or 10 transitions, the policy doesn’t move very much, staying in contact with the ground most of the time. However, at 50 transitions, it performs noticeably forward hops slightly smoother than the policy learned by Deep RLSP.

heading: 4 RELATED WORK
text: Learning from human feedback. Many algorithms aim to learn good policies from human demonstrations, including ones in imitation learning (Ho & Ermon, 2016) and inverse reinforcement learning (IRL; Ng et al., 2000; Abbeel & Ng, 2004; Fu et al., 2018). Useful policies can also be learned from other types of feedback, such as preferences (Christiano et al., 2017), corrections (Bajcsy et al., 2017), instructions (Bahdanau et al., 2019), or combinations of feedback modalities (Ibarz et al., 2018).
While these methods require expensive human feedback, Deep RLSP instead simulates the trajectories that must have happened. This is reflected in the algorithm: in Equation 1, the inner gradient corresponds to an inverse reinforcement learning problem. While we used the MCEIRL formulation (Ziebart et al., 2010), other IRL algorithms could be used instead (Fu et al., 2018).
Learning from observations. For many tasks, we have demonstrations without action labels, e.g., YouTube videos. Learning from Observations (LfO; Torabi et al., 2019; Gandhi et al., 2019) aims to recover a policy from such demonstrations. Similarly to LfO, we do not have access to action labels, but our setting is further restricted to observing only a small number of states.

heading: 5 LIMITATIONS AND FUTURE WORK
text: Summary. Learning useful policies with neural networks requires significant human effort, whether it is done by writing down a reward function by hand, or by learning from explicit human feedback such as preferences or demonstrations. We showed that it is possible to reduce this burden by extracting “free” information present in the current state of the environment. This enables us to imitate policies in MuJoCo environments with access to just a few states sampled from those policies. We hope that Deep RLSP will help us train agents that are better aligned with human preferences.
Learned models. The Deep RLSP gradient depends on having access to a good model of π, T , π−1, and T −1. In practice, it was quite hard to train sufficiently good versions of the inverse models. This could be a significant barrier to practical implementations of Deep RLSP. It can also be taken as a sign for optimism: self-supervised representation learning through deep learning is fairly recent and is advancing rapidly; such advances will likely translate directly into improvements in Deep RLSP.
Computational cost. Imitation learning with full demonstrations can already be quite computationally expensive. Deep RLSP learns several distinct neural network models, and then simulates potential demonstrations, and finally imitates them. Unsurprisingly, this leads to increased computational cost.
Safe RL. Shah et al. (2019) discuss how the exact RLSP algorithm can be used to avoid negative side-effects in RL by combining preferences learned from the initial state with a reward function. While we focused on learning hard to specify behavior, Deep RLSP can also be used to learn to avoid negative side-effects, which is crucial for safely deploying RL systems in the real world (Amodei et al., 2016).
Multiagent settings. In any realistic environment, there is not just a single “user” who is influencing the environment: many people act simultaneously, and the state is a result of joint optimization by all of them. However, our model assumes that the environment state resulted from optimization by a single agent, which will not take into account the fact that each agent will have constraints imposed upon them by other agents. We will likely require new algorithms for such a setting.

heading: ACKNOWLEDGMENTS
text: This work was partially supported by Open Philanthropy, AFOSR, ONR YIP, NSF CAREER, NSF NRI, and Microsoft Swiss JRC. We thank researchers at the Center for Human-Compatible AI and the InterACT lab for helpful discussion and feedback.

heading: A GRIDWORLD ENVIRONMENTS
text: Here we go into more detail on the experiments in Section 3.2, in which we ran Deep RLSP on the environment suite constructed in Shah et al. (2019).
In this test suite, each environment comes equipped with an observed state s0, an initial state s−T , a specified reward Rspec, and a true reward Rtrue. A given algorithm should be run on s0 and optionally also s−T and produce an inferred reward Rinferred. This is then added to the specified reward to produce Rfinal = Rspec + λRinferred, where λ is a hyperparameter that determines the weighting between the two. An optimal policy for Rfinal is then found using value iteration, and the resulting policy is evaluated according to Rtrue.
There is no clear way to set λ: it depends on the scales of the rewards. We leverage the fact that Rspec is deliberately chosen to incentivize bad behavior, such that we know λ = 0 will always give incorrect behavior. So, we normalize Rinferred, and then increase λ from 0 until the behavior displayed by the final policy changes.
Since GAIL does not produce a reward function as output, we do not run it here. We do however report results with AverageFeatures (which is equivalent to Waypoints here, because there is only a single observed state).
From left to right, the environments are:
1. Room with vase: Rspec has weight 1 for the purple door feature, and 0 for all other weights. Rtrue additionally has weight -1 for the broken vases feature. Since we observe a state in which the vase is unbroken, we can infer that the human avoided breaking the vase, and so that there should be a negative weight on broken vases. Deep RLSP indeed does this and so avoids breaking the vase. AverageFeatures fails to do so, though this is due to a quirk in the feature encoding. In particular, the feature counts the number of broken vases, and so the inferred θ has a value of zero for this feature, effectively ignoring it. If we change the featurization to instead count the number of unbroken vases, then AverageFeatures would likely get the right behavior.
2. Toy train: In this environment, we observe a state in which an operational train is moving around a track. Once again, Rspec just has weight 1 on the purple door feature. Rtrue additionally has weight -1 on broken vases and trains. Deep RLSP appropriately avoids breaking objects, but AverageFeatures does not.
3. Batteries: We observe a state in which the human has put a battery in the train to keep it operational (s−T has two batteries while s0 only has one). Rspec still has weight 1 on the purple door feature. Rtrue additionally has weight -1 on allowing the train to run out of power. Algorithms should infer that it is good to put batteries in the train to keep it operational, even though this irreversibly uses up the battery. Deep RLSP correctly does this, while AverageFeatures does not. In fact, AverageFeatures incorrectly infers that batteries should not be used up.
4. Apples: We observe a state in which the human has collected some apples and placed them in a basket. Rspec is always zero, while Rtrue has weight 1 on the number of apples in the basket. The environment tests whether algorithms can infer that it is good for there to be apples in the basket. Deep RLSP does this, learning a policy that continues to collect apples
and place them in the basket. AverageFeatures also learns to place apples in the basket, but does not do so as effectively as Deep RLSP, because AverageFeatures also rewards the agent for staying in the original location, leading it to avoid picking apples from the tree that is furthest away.
5. Room with far away vase: This is an environment that aims to show what can’t be learned: in this case, the breakable vase is so far away, that it is not much evidence that the human has not broken it so far. As a result, algorithms should not learn anything significant about whether or not to break vases. This is indeed the case for Deep RLSP, as well as AverageFeatures (though once again, in the latter case, this is dependent on the specific form of the feature).
Overall, Deep RLSP has the same behavior on these environments as RLSP, while AverageFeatures does not.

heading: B ARCHITECTURE AND HYPERPARAMETER CHOICES
text: In this section we describe the architecture choices for the models used in our algorithm and the hyperparameter choices in our experiments. All models are implemented using the TensorFlow framework.
B.1 FEATURE FUNCTION
We use a variational autoencoder (VAE; Kingma & Welling, 2014) to learn the feature function. The encoder and decoder consist of 3 feed-forward layers of size 512. The latent space has dimension 30. The model is trained for 100 epochs on 100 rollouts of a random policy in the environment. During training we use a batch size of 500 and a learning rate of 10−5. We use the standard VAE loss function, but weight the KL-divergence term with a factor c = 0.001, which reduces the regularization and empirically improved the reconstruction of the model significantly. We hypothesize that the standard VAE regularizes too much in our setting, because the latent space has a higher dimension than the input space, which is not the case in typical dimensionality reduction settings.
B.2 INVERSE DYNAMICS MODEL
Our inverse dynamics model is a feed-forward neural network with 5 layers of size 1024 with ReLU activations. We train it on 1000 rollouts of a random policy in the environment for 100 epochs, with a batch size of 500 and a learning rate of 10−5.
Note that the model predicts the previous observation given the current observation and action; it does not use the feature representation. We found the model to perform better if it predicts the residual ot−1 − ot given ot and at instead of directly predicting ot−1. We normalize all inputs to the model to have zero mean and unit variance. To increase robustness, we also add zero-mean Gaussian noise with standard deviation 0.001 to the inputs and labels during training and clip the outputs of the model to the range of values observed during training.
B.3 POLICY
For learning the policy we use the stable-baselines implementation of Soft Actor-Critic (SAC) with its default parameters for the MuJoCo environments (Haarnoja et al., 2018; Hill et al., 2018). Each policy update during Deep RLSP uses 104 total timesteps for the cheetah, 2× 104 for the hopper. We perform the policy updates usually starting from the last iteration’s policy, except in the pendulum environment, where we randomly initialize the policy in each iteration and train it using 5 × 104 iterations of SAC. We evaluate the final reward function generally using 2× 106 timesteps, except for the pendulum, where we use 6× 104.
B.4 INVERSE POLICY
Because the inverse policy is not deterministic, we represent it with a mixture density network, a feed-forward neural network that outputs a mixture of Gaussian distributions (Bishop, 1994).
The network has 3 layers of size 512 with ReLU activations and outputs a mixture of 5 Gaussians with a fixed variance of 0.05.
To update the inverse policy we sample batches with batch size 500 from the experience replay, apply the forward policy and the forward transition model on the states to label the data. We then train the model with a learning rate of 10−4.
B.5 DEEP RLSP HYPERPARAMETERS
We run Deep RLSP with a learning rate of 0.01, and use 200 forward and backward trajectories to estimate the gradients. Starting with T = 1 we increment the horizon when the gradient norm drops below 2.0 or after 10 steps, whichever comes first. We run the algorithm until T = 10.

heading: C HEURISTIC FOR INCORPORATING INFORMATION ABOUT THE INITIAL STATE
text: In Section 2.4 we discussed that it might be necessary for Deep RLSP to have information about the distribution P of the initial state s−T . Since in our setup Deep RLSP can not obtain any information about P through π−1 and T −1, here we present a heuristic to incorporate the information elsewhere. Specifically, we weight every backwards trajectory by the cosine similarity between the final state s−T , and a sample ŝ−T ∼ P . This weights gradient terms higher that correspond to trajectories that are more likely given our knowledge about P and weights trajectories lower that end in a state s−T that has low probability under P . To test whether this modification improves the performance of Deep RLSP, we compared Deep RLSP with this gradient weighting heuristic to Deep RLSP without it as it was presented in the main paper.
First, we ran Deep RLSP with the gradient weighting on the gridworld environments from Shah et al. (2019), described in Section 3.2 and Appendix A. The results are identical to the case when using the heuristics.
Next, we tested on the tasks in the MuJoCo environments described in Section 3.3. We report the results in Table 2, alongside the previously reported results without the gradient weighting. The results are quite similar, suggesting that the gradient weighting does not make much of a difference in these environments.

heading: D ANALYSIS OF THE LEARNED SKILLS
text: D.1 TRAINING A DISCRIMINATOR
In the main text, we focused on visual evaluation of the learned skills, because it is difficult to define a metric that properly measures the similarity between an original skill and one learned by Deep RLSP. In this section, we attempt to quantify the similarity between policies by training a discriminator to distinguish trajectories from the policies. Conceptually, the easier it is to train this discriminator, the more different the two policies are. We could thus use this to check how similar our learned policies are to the original skills.
We train a neural network with a single hidden layer of size 10 with ReLU activation functions. We sample trajectories from both policies and randomly sample trajectory pieces consisting of 5 observations to train the model on. We label the trajectory pieces with a binary label depending on which policy they come from, and then use a cross-entropy loss to train the model. To ensure comparable results, we keep this setup the same for all policies and average the resulting learning curves over 10 different random seeds.
The resulting learning curves are shown in fig. 4. The differences between the learning curves are relatively small overall, suggesting that we cannot draw strong conclusions from this experiment. In addition, while the AverageFeatures and Waypoints ablations can be seen to be extremely bad visually relative to GAIL and Deep RLSP, this is not apparent from the learning curves. As a result, we conclude that this is not actually a good metric to judge performance. (Note that if we were to use the metric, it would suggest that Deep RLSP is best for the balancing learning skill, while for the jumping skill GAIL is better for 1 and 50 states and Deep RLSP is better for 10 states.)
D.2 VISUALIZATION OF LEARNED SKILLS
Here we provide larger visualizations of the skills learned in the experiments discussed in Section 3.4 of the main paper. For each experiment we show the original policy, the states sampled from this policy and given as an input to Deep RLSP, the policy learned by the AverageFeatures ablation, and the policy learned by Deep RLSP in figs. 5 to 10 (on future pages). Again, we emphasize that the visual comparison is easier with videos of the policies which we provide at https://sites. google.com/view/deep-rlsp (including Waypoints and AverageFeatures ablations).

heading: E THINGS WE TRIED THAT DID NOT WORK
text: Here we list a few variations of the Deep RLSP algorithm that we tested on the MuJoCo environments that failed to provide good results.
• We tried to learn a latent state-space jointly with a latent dynamics model using a recurrent state-space model (RSSM). However, we found existing models too brittle to reliably learn a good dynamics model. The reward function and policy learned by Deep RLSP worked in the RSSM but did not generalize to the actual environment.
• We also tried learning a forward dynamics model from the initial set of rollouts, similarly to how we learn an inverse dynamics model, rather than relying on the simulator T . However, we found this to cause a similar issue as the RSSM: the reward function and policy learned by Deep RLSP did not generalize to the actual environment. However, we hope that progress in model-based RL will allow us to implement Deep RLSP using only learned dynamics models in the future.
• Using an mixture density network instead of an MLP to model the inverse dynamics did not improve the performance of the algorithm. We suspect this to be because in the MuJoCo simulator the dynamics and the inverse dynamics are “almost deterministic”.
• Updating the inverse dynamics model and the feature function during Deep RLSP by training it on data from the experience replay did not improve performance and in some cases significantly decreased performance. The decrease in performance seems to have been caused by the feature function changing too much and the training of the other models suffering from catastrophic forgetting as a result.
• In the main paper we evaluated the policies learned by Deep RLSP from jumping and balancing skills. However, we also looked at policies obtained by optimizing for the learned reward. These also showed similarities to the original skills but they were significantly worse then the policies directly learned by Deep RLSP. For the jumping skill the optimized policies jump very erratically, and for the balancing skill they tend to fall over or perform forward flips. This discrepency is a result of the policy updates during Deep RLSP only using a limited number of iterations. It seems like in these experiments the learned reward functions lead to good policies when optimized for weakly but do not produce good policies when optimized for strongly. We saw in preliminary experiments that increasing the number of iterations for updating the policies during Deep RLSP reduces this discrepency. However, the resulting algorithm was computationally too expensive to evaluate with our resources. • We tried running Deep RLSP for longer horizons up to T = 30, but found the results to be
worse than for T = 10 which we reported in the main paper. We hypothesize that this is caused by compounding errors in the inverse transition model. This hypothesis is supported by manually looking at trajectories generated by the inverse transition model. While they look reasonable for short horizons T ≤ 10, compounding errors become significantly bigger for horizons 10 ≤ T ≤ 30.
O ri
gi na
lP ol
ic y
Sa m
pl ed
St at
es
G A
IL
D ee
p R
L SP
Fi gu
re 5:
D ee
p R
L SP
le ar
ni ng
th e
ba la
nc in
g sk
ill fr
om a
si ng
le st
at e.
T he
fir st
ro w
sh ow
s th
e or
ig in
al po
lic y
fr om
D A
D S,
th e
se co
nd ro
w sh
ow s
th e
sa m
pl ed
st at e fr om th is po lic y, th e th ir d ro w is th e G A IL al go ri th m ,a nd th e la st ro w sh ow s th e po lic y le ar ne d by D ee p R L SP .
O ri
gi na
lP ol
ic y
Sa m
pl ed
St at
es
G A
IL
D ee
p R
L SP
Fi gu
re 6:
D ee
p R
L SP
le ar
ni ng
th e
ba la
nc in
g sk
ill fr
om 10
st at
es .T
he fir
st ro
w sh
ow s
th e
or ig
in al
po lic
y fr
om D
A D
S, th
e se
co nd
ro w
sh ow
s th
e sa
m pl
ed st
at es
fr om
th is
po lic
y, th
e th
ir d
ro w
is th
e G
A IL
al go
ri th
m ,a
nd th
e fin
al ro
w sh
ow s
th e
po lic
y le
ar ne
d by
D ee
p R
L SP
.
O ri
gi na
lP ol
ic y
Sa m
pl ed
St at
es
G A
IL
D ee
p R
L SP
Fi gu
re 7:
D ee
p R
LS P
le ar
ni ng
th e
ba la
nc in
g sk
ill fr
om 50
st at
es .T
he fir
st ro
w sh
ow s
th e
or ig
in al
po lic
y fr
om D
A D
S, th
e ne
xt fiv
e ro
w s
sh ow
th e
sa m
pl ed
st at
es fr om th is po lic y, th e se co nd to la st ro w is th e G A IL al go ri th m ,a nd th e la st ro w sh ow s th e po lic y le ar ne d by D ee p R L SP .
O ri
gi na
lP ol
ic y
Sa m
pl ed
St at
es
G A
IL
D ee
p R
L SP
Fi gu
re 8:
D ee
p R
L SP
le ar
ni ng
th e
ju m
pi ng
sk ill
fr om
a si
ng le
st at
e. T
he fir
st ro
w sh
ow s
th e
or ig
in al
po lic
y fr
om D
A D
S, th
e se
co nd
ro w
sh ow
s th
e sa
m pl
ed st
at e
fr om
th is
po lic
y, th
e th
ir d
ro w
is th
e G
A IL
al go
ri th
m ,a
nd th
e la
st ro
w sh
ow s
th e
po lic
y le
ar ne
d by
D ee
p R
L SP
.
O ri
gi na
lP ol
ic y
Sa m
pl ed
St at
es
G A
IL
D ee
p R
L SP
Fi gu
re 9:
D ee
p R
L SP
le ar
ni ng
th e
ju m
pi ng
sk ill
fr om
10 st
at es
.T he
fir st
ro w
sh ow
s th
e or
ig in
al po
lic y
fr om
D A
D S,
th e
se co
nd ro
w sh
ow s
th e
sa m
pl ed
st at
es fr om th is po lic y, th e th ir d ro w is th e G A IL al go ri th m ,a nd th e fin al ro w sh ow s th e po lic y le ar ne d by D ee p R L SP .
O ri
gi na
lP ol
ic y
Sa m
pl ed
St at
es
G A
IL
D ee
p R
L SP
Fi gu
re 10
:D ee
p R
LS P
le ar
ni ng
th e
ju m
pi ng
sk ill
fr om
50 st
at es
.T he
fir st
ro w
sh ow
s th
e or
ig in
al po
lic y
fr om
D A
D S,
th e
ne xt
fiv e
ro w
s sh
ow th
e sa
m pl
ed st
at es
fr om
th is
po lic
y, th
e se
co nd
to la
st ro
w is
th e
G A
IL al
go ri
th m
,a nd
th e
la st
ro w
sh ow
s th
e po
lic y
le ar
ne d
by D
ee p
R L
SP .

Review summaries:
This paper introduces an algorithm, called deep reward learning by simulating the past (deep RLSP), that seeks to infer a reward function by looking at states in demonstration data. An example of this described in the paper is an environment with a vase: if demonstration data shows an intact vase in the presence of an embodied agent then breaking the vase is unlikely to be the intended behavior. Otherwise the vase would already be broken in the demo.