{'fraction_non_alphanumeric': 0.03538382453735435, 'fraction_numerical': 0.009709846927119032, 'mean_word_length': 4.619804204782539, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Rewriting History with Inverse RL: Hindsight Inference for Policy Improvement

Multi-task reinforcement learning (RL) aims to simultaneously learn policies for solving many tasks. Several prior works have found that relabeling past experience with different reward functions can improve sample efficiency. Relabeling methods typically ask: if, in hindsight, we assume that our experience was optimal for some task, for what task was it optimal? In this paper, we show that hindsight relabeling is inverse RL, an observation that suggests that we can use inverse RL in tandem for RL algorithms to efficiently solve many tasks. We use this idea to generalize goal-relabeling techniques from prior work to arbitrary classes of tasks. Our experiments confirm that relabeling data using inverse RL accelerates learning in general multi-task settings, including goal-reaching, domains with discrete sets of rewards, and those with linear reward functions.


Introduction
Reinforcement learning (RL) aims to acquire control policies that take actions to maximize their cumulative reward. Existing RL algorithms remain data inefficient, requiring exorbitant amounts of experience to learn even simple tasks (e.g., [7,22]). Multi-task RL, where many RL problems are solved in parallel, has the potential to be more sample efficient than single-task RL, as data can be shared across tasks. Nonetheless, the problem of effectively sharing data across tasks remains largely unsolved.
The idea of sharing data across tasks has been studied at least since the 1990s [4]. More recently, a number of works have observed that retroactive relabeling of experience with different tasks can improve data efficiency. A common theme in prior relabeling methods is to relabel past trials with whatever goal or task was performed successfully in that trial. For example, relabeling for a goalreaching task might use the state actually reached at the end of the trajectory as the relabeled goal, sine the trajectory corresponds to a successful trial for the goal that was actually reached [3,20,31]. However, prior work has presented these goal-relabeling methods primarily as heuristics, and it remains unclear how to intelligently apply the same idea to tasks other than goal-reaching, such as those with linear reward functions.
In this paper, we formalize prior relabeling techniques under the umbrella of inverse RL: by inferring the most likely task for a given trial via inverse RL, we provide a principled formula for relabeling in arbitrary multi-task problems. Inverse RL is not the same as simply assigning each trajectory to the task for which it received the highest reward. In fact, this strategy would often result in assigning most trajectories to the easiest task. Rather, inverse RL takes into account the difficulty of different tasks and the amount of reward that each yields. RL and inverse RL can be seen as complementary tools for maximizing reward: RL takes tasks and produces high-reward trajectories, and inverse RL takes trajectories and produces task labels such that the trajectories receive high reward. Formally, we prove that maximum entropy (MaxEnt) RL and MaxEnt inverse RL optimize the same multi-task objective: MaxEnt RL optimizes with respect to trajectories, while MaxEnt inverse RL optimizes with respect  Figure 1: Hindsight Inference for Policy Improvement (HIPI): Given a dataset of prior experience, we use inverse RL to infer the agent's intentions. We use the relabeled experience with any policy learning algorithm, such as off-policy RL or supervised learning.
to tasks. Unlike prior goal-relabeling techniques, we can use inverse RL to relabel experience for arbitrary task distributions, including sets of linear or discrete rewards. This observation suggests that tools from RL and inverse RL might be combined to efficiently solve many tasks simultaneously. The combination we develop, Hindsight Inference for Policy Improvement (HIPI), first relabels experience with inverse RL and then uses the relabeled experience to learn a policy (see Fig. 1). One variant of this framework follows the same design as prior goal-relabeling methods [3,20,31] but uses inverse RL to relabel experience, a difference that allows our method to handle arbitrary task families. The second variant has a similar flavour to self-imitation behavior cloning methods [12,27,37]: we relabel past experience using inverse RL and then learn a policy via task-conditioned behavior cloning. Both algorithms can be interpreted as probabilistic reinterpretation and generalization of prior work.
The main contribution of our paper is the observation that hindsight relabeling is inverse RL. This observation not only provides insight into success of prior relabeling methods, but it also provides guidance on applying relabeling to arbitrary multi-task RL problems. That RL and inverse RL can be used in tandem is not a coincidence; we prove that MaxEnt RL and MaxEnt inverse RL optimize the same multi-task RL objective with respect to trajectories and tasks, respectively. Our second contribution consists of two simple algorithms that use inverse RL-based relabeling to accelerate RL. Our experiments on complex simulated locomotion and manipulation tasks demonstrate that our method outperforms state-of-the-art methods on tasks ranging from goal-reaching, running in various directions, and performing a host of manipulation tasks.

Prior Work
The focus of our work is on multi-task RL problems, for which a number of algorithms have been proposed over the past decades [8,18,35,41,43]. Existing approaches still struggle to reuse data across multiple tasks, with researchers often finding that training separate models is a very strong baseline [48] and using independently-trained models as an initialization or prior for multi-task models [11,28,36,41]. When applying off-policy RL in the multi-task setting, a common trick is to take experience collected when performing task A and pretend that it was collected for task B by recomputing the rewards at each step. This technique effectively inflates the amount of data available for learning, and a number of prior works have found this technique quite effective [3,20,31,38]. In this paper we show that the relabeling done in prior work can be understood as inverse RL.
If RL is asking the question of how to go from a reward function to a policy, inverse RL asks the opposite question: after observing an agent acting in an environment, can we infer which reward function the agent was trying to optimize? A number of inverse RL algorithms have been proposed [1,33], with MaxEnt inverse RL being one of the most commonly used frameworks [10,19,49]. Since MaxEnt inverse RL can be viewed as an inference problem, we can calculate either the posterior distribution over reward functions, or the maximum a-posteriori (MAP) estimate. While most prior work is concerned with MAP estimates, we follow Hadfield-Menell et al. [17] in using the full posterior distribution. Section 3 discusses how MaxEnt RL and MaxEnt inverse RL are closely connected, with one problem being the dual of the other. It is therefore not a coincidence that many MaxEnt inverse RL algorithms involve solving a MaxEnt RL problem in the inner loop. Our paper proposes the opposite, using MaxEnt inverse RL in the inner loop of MaxEnt RL.
Our work builds on the idea that MaxEnt RL can be viewed as probabilistic inference. This idea has been proposed in a number of prior works [21,23,34,42,[44][45][46] and used to build a number of modern RL algorithms [2,14,15]. Perhaps the most relevant prior work is Rawlik et al. [34], which emphasizes that MaxEnt RL can be viewed as minimizing an KL divergence, an idea that we extend to the multi-task setting.

Preliminaries
This section reviews MaxEnt RL and MaxEnt inverse RL. We start by introducing notation.
Notation We will analyze an MDP M with states s t ∈ S and reward function r(s t , a t ). We assume that actions a t ∈ A are sampled from a policy q(a t | s t ). The initial state is sampled s 1 ∼ p 1 (s 1 ) and subsequent transitions are governed by a dynamics distribution s t+1 ∼ p(s t+1 | s t , a t ). We define a trajectory as a sequence of states and actions: τ = (s 1 , a 1 , · · · ), and write the likelihood of a trajectory under policy q as (1) In the multi-task setting, we will use ψ ∈ Ψ to identify each task, and assume that we are given a prior p(ψ) over tasks. The set of tasks Ψ can be continuous or discrete, finite or infinite; each particular task ψ ∈ Ψ can be continuous or discrete valued. We define r ψ (s t , a t ) as the reward function for task ψ. Our experiments will use both goal-reaching tasks, where ψ is a goal state, as well as more general task distributions, where ψ is the hyperparameters of the reward function MaxEnt RL MaxEnt RL casts the RL problem as one of sampling trajectories with probability proportional to exponentiated reward. Given a reward function r(s t , a t ), we aim to learn a policy that samples trajectories from the following target distribution, p(τ ): The partition function Z is introduced to make p(τ ) integrate to one. The objective function for MaxEnt RL is to maximize the entropy-regularized sum of rewards, which is equivalent to minimizing the reverse KL divergence between the policy's distribution over trajectories, q(τ ), and a target distribution, p(τ ) defined in terms of rewards r t = r(s t , a t ): The partition function does not depend on the policy, so prior RL algorithms have ignored it.
MaxEnt Inverse RL Inverse RL observes previously-collected data and attempts to infer the intent of the actor, which is represented by a reward function r ψ . MaxEnt inverse RL is a variant of inverse RL that defines the probability of trajectory τ being produced for task ψ as Applying Bayes' Rule, the posterior distribution over reward functions is given as follows: While many applications of MaxEnt inverse RL use the maximum a posteriori estimate, arg max ψ [log p(ψ | τ )] in this paper will use the full posterior distribution. While the partition function, an integral over all states and actions, is typically hard to compute, its dual is the MaxEnt RL problem: The striking similarities between MaxEnt RL and MaxEnt inverse RL are not a coincidence. As we will show in the next section, both minimize the same reverse KL divergence on the joint distribution of tasks and trajectories.

Hindsight Relabeling is Inverse RL
We now aim to use the tools of RL and inverse RL to solve many RL problems simultaneously, each with the same dynamics but a different reward function. Given a prior over tasks, p(ψ), the target joint distribution over tasks and trajectories is We can express the multi-task (MaxEnt) RL objective as the reverse KL divergence between the joint trajectory-task distributions: max If we factor the joint distribution as q(τ, ψ) = q(τ | ψ)p(ψ), Eq. 6 is equivalent to maximizing the expected (entropy-regularized) reward of a task-conditioned policy q(τ | ψ): Since the distribution over tasks, p(ψ) is fixed, we can ignore the log Z(ψ) term for optimization. A less common but more intriguing choice is to factor q(τ, ψ) = q(ψ | τ )q(τ ), where q(τ ) is represented non-parametrically as a distribution over previously-observed trajectories, and q(ψ | τ ) is a relabeling distribution. We find the optimal relabeling distribution by first rewriting Eq. 6 and then solving for the optimal relabeling distribution, ignoring terms that do not depend on ψ: The key observation here is that the optimal relabeling distribution corresponds exactly to MaxEnt inverse RL posterior over tasks (Eq. 3). Thus, we can obtain the optimal relabeling distribution via inverse RL. While the optimal relabeling distribution derived here depends on the entire trajectory, Appendix B shows how to perform relabeling when given a transition rather than an entire trajectory: In the next section we show that prior goal-relabeling methods are a special case of inverse RL.

Special Case: Goal Relabeling
A number of prior works have explicitly [3,20,31] and implicitly [12,26,37] found that hindsight relabeling can accelerate learning for goal-reaching tasks, where tasks ψ correspond to goal states. These prior relabeling methods are a special case of inverse RL. We define a goal-conditioned reward function that penalizes the agent for failing to reaching the goal at the terminal step: We assume that the time step t is included in the observation s t to ensure that this reward function is Markovian. With this reward function, the optimal relabeling distribution q(ψ | τ ) from Eq. 7 is simply q(ψ | τ ) = 1(ψ = s T ), where s T is the final state in trajectory τ . Thus, relabeling with the state actually reached is equivalent inverse RL when using the reward function in Eq. 9. While inverse RL is particularly convenient when using this reward function, it is rarely the metric of success that we actually care about. Viewing goal relabeling as a special case of inverse RL under a special reward function allows us to extend goal relabeling to general task arbitrary reward functions and arbitrary task distributions. In our experiments, we show that inverse RL seamlessly handles task distributions including goal-reaching, discrete sets of tasks, and linear reward functions. (Left) Without normalization, both trajectories are assigned to task ψ1. (Right) After normalizing with the partition function, as is done by inverse RL (our method), trajectory τ1 is assigned task ψ1 and τ2 is assigned to ψ2.

The Importance of the Partition Function
The partition function used by inverse RL will be important for hindsight relabeling, as it will normalize the rewards from tasks with varying difficulty and reward scale. Fig. 2 shows a didactic example with two tasks, where the rewards for one task are larger than the rewards for the other task. Relabeling with the reward under which the agent received the largest reward (akin to Andrychowicz et al. [3]) fails, because all experience will be relabeled with the first (easier) task. Subtracting the partition function from the rewards (as in Eq. 7) results in the desired behavior, trajectory τ 1 is assigned task ψ 1 and τ 2 is assigned to ψ 2 .

How Much Does Relabeling Help?
Up to now, we have shown that the optimal way to relabel data is via inverse RL. How much does relabeling help? We now obtain a lower bound on the improvement from relabeling. Both lemmas in this section will assume that a joint distribution q(τ, ψ) over tasks and trajectories be given (e.g., specified by a policy q(a t | s t , ψ)). We will define q τ (τ ) = q(τ, ψ) as the marginal distribution over trajectories and then construct q τ (τ, ψ) = q τ (ψ | τ )q τ (τ ) using the optimal relabeling distribution q τ (ψ | τ ) (Eq. 7). We first show that relabeling data using inverse RL improves the MaxEnt RL objective: Lemma 1. The relabeled distribution q τ (τ, ψ) is closer to the target distribution than the original distribution, as measured by the KL divergence: Proof. Of the many possible relabeling distributions, one choice is to do no relabeling, assigning to each trajectory τ the task ψ that was commanded when the trajectory was collected. Denote this relabeling distribution q 0 (ψ | τ ), so q 0 (ψ | τ )q τ (τ ) = q(τ, ψ). Because q τ (ψ | τ ) was chosen as that which minimizes the KL among all relabeling distributions (including q 0 (ψ | τ )), the desired inequality holds: Thus, the relabeled data is an improvement over the original data, achieving a larger entropyregularized reward (Eq. 6). As our experiments will confirm, relabeling data will accelerate learning. Our next result will give us a lower bound on this improvement: Lemma 2. The improvement in the MaxEnt RL objective (Eq. 6) gained by relabeling is lower bounded as follows: The proof, a straightforward application of information geometry, is in Appendix A. This result says that the amount that relabeling helps is at least as large as the difference between the task labels q(ψ | τ ) and the task labels inferred by inverse RL, q τ (ψ | τ ). Note that, when we have learned the optimal policy (Eq. 5), our experience is already optimally labeled, so relabeling has no effect.

Using Inverse RL to Accelerate RL
In this section, we outline a general recipe, Hindsight Inference for Policy Improvement (HIPI), for using inverse RL to accelerate the learning of downstream tasks. Given a dataset of trajectories, we use inverse RL to infer for which tasks those trajectories are optimal. We discuss two options for how to use these relabeled trajectories. One option is to apply off-policy RL on top of these relabeled trajectories. This option generalizes previously-introduced hindsight relabeling techniques [3,20],  allowing them to be applied to task distributions beyond goal-reaching. A second option is to apply behavior cloning to the relabeled experience. This option generalizes a number of previous methods, extending variational policy search [6,24,29,30] to the multi-task setting and extending goal-conditioned imitation learning [12,26,37] to arbitrary task distributions.

Using Relabeling Data for Off-Policy RL (HIPI-RL)
Off-policy RL algorithms, such as Q-learning and actor-critic algorithms, represent a broad class of modern RL methods. These algorithms maintain a replay buffer of previously seen experience, and we can relabel this experience using inverse RL when sampling from the replay buffer. As noted in Section 4.1, hindsight experience replay [3] can be viewed as a special case of this idea. Viewing relabeling as inverse RL, we can extend these methods to general classes of reward functions.
There are many algorithms for inverse methods, and we outline one approximate algorithm that can be efficiently integrated into off-policy RL. To relabel entire trajectories, we would start by computing the cumulative reward: R ψ (s, a) = t =t r ψ (s t , a t ). However, most off-policy RL algorithms maintain a replay buffer that stores transitions, rather than entire trajectories. In this case, following Eq. 8, we instead use the soft Q-function: R ψ (s, a) =Q(s t , a t , ψ). We approximate the partition function log Z(ψ) using Monte Carlo samples (s i , a i ) from within a batch of size B: We finally sample tasks ψ (i) following Eq. 7: We summarize the procedure for relabeling with inverse RL procedure in Alg. 1. The application of relabeling with inverse RL to off-policy RL, which we call HIPI-RL, is summarized in Alg. 2. We emphasize that Alg 1 is just one of many methods for performing inverse RL. Alternative methods include gradient-based optimization of the per-sample task, and learning a parametric task-sampler to approximate the optimal relabeling distribution (Eq. 7). We leave this as future work.

Using Relabeled Data for Behavior Cloning
We now introduce a second method to use data relabeled with inverse RL to acquire control policies. The idea is quite simple: given arbitrary data, first relabel that data with inverse RL, and then perform task-conditioned behavior cloning. We call this procedure HIPI-BC and summarize it in Alg. 3. Why should we expect this procedure to work? The intuition is that relabeling with inverse RL makes the joint distribution of tasks and trajectories closer to the target distribution (i.e., it maximizes the multi-task MaxEnt RL objective (Eq. 6)). To convert this joint distribution into an actionable representation, we extract the policy implicitly defined by the relabeled trajectories. Behavioral cloning (i.e., supervised learning) does precisely this.

Relationship to Prior Methods
Prior work on both goal-conditioned supervised learning, self-imitation learning, and reward-weighted regression can all be understood as special cases. Goal-conditioned supervised learning [12,26,37] learns a goal-conditioned policy using a dataset of past experience. For a given state, the action that was actually taken is treated as the correct action (i.e., label) for states reached in the future, and a policy is learned via supervised learning. As discussed in Section 4.1, relabeling with the goal actually achieved is a special case of our framework. We refer the reader to those papers for additional evidence for the value of combining inverse RL (albeit a trivial special case) with behavior cloning can effectively learn complex control policies. Self-imitation learning [27] and iterative maximum likelihood training [25] augment RL with supervised learning on a handful of the best previously-seen trajectories, an approach that can be viewed in the inverse RL followed by supervised learning framework. However, because the connection to inverse RL is not made precise, these methods omit the partition function, which may prove problematic when extending these methods to multi-task settings. Finally, single-task RL methods based on variational policy search [23] and reward-weighted regression [29,30] can also be viewed in this framework. Noting that the optimal relabeling distribution is given as q(ψ | τ ) ∝ exp(R ψ (τ ) − log Z(ψ)), relabeling by sampling from the inverse RL posterior and then performing behavior cloning can be written concisely as the following objective: The key difference between this objective and prior work is the partition function. The observation that these prior methods are special cases of inverse RL allows us to apply similar ideas to arbitrary classes of reward functions, a capability we showcase in our experiments.

Experiments: Relabeling with Inverse RL Accelerates Learning
Our experiments focus on two methods for using relabeled data: off-policy RL (Alg. 2) and behavior cloning (Alg. 3). We evaluate our method on both goal-reaching tasks as well as more general task distributions, including linear combinations of a reward basis and discrete sets of tasks (see Fig. 3).

HIPI-RL: Inverse RL for Off-Policy RL
Our first set of experiments apply Alg. 2 to domains with varying reward structure, demonstrating how relabeling data with inverse RL can accelerate off-policy RL. Didactic Example We start with a didactic example to motivate why relabeling experience with inverse RL would accelerate off-policy RL.
In the gridworld shown in Fig. 4, we construct a dataset with two trajectories: A → B and C → D. From state A, inverse RL identifies both B and D as likely intentions, so we include both A → B and A → D in the relabeled data. Final state relabeling (HER) only uses trajectory A → C. We then apply Q-learning to both datasets. to this dataset. Whereas Qlearning with final state relabeling only succeeds at reaching those goals in the top row, our approach, which corresponds to Q-learning with inverse RL, relabeling succeeds at reaching all goals. The remainder of this section will show the benefits of relabeling using inverse RL in domains of increasing complexity. Goal-Reaching Task Distributions We next apply our method to goal-reaching tasks, where each task ψ corresponds to reaching a different goal state. We used six domains: a quadruped locomotion task, a robotic finger turning a knob, a 2D reacher, a reaching task on the Sawyer robot, a 2D navigation environment with obstacles, and a reaching task on the Jaco robot. Appendix C provides details of all tasks. We compared our method against four alternative relabeling strategies: relabeling with the final state reached (HER [3]), relabeling with a randomly-sampled task, relabeling with a future state in the same trajectory, and doing no relabeling (SAC [15]). For tasks where the goal state only specifies certain dimensions of the state, relabeling with the final state and future state requires privileged information indicating to which state dimensions the goal corresponds.
As shown in Fig. 5, relabeling experience with inverse RL (our method) always learns at least as quickly as the other relabeling strategies, and often achieves larger asymptotic reward. While final state relabeling (HER) performs well on some tasks, it is worse than random relabeling on other tasks. We also observe that random relabeling is a competitive baseline, provided that the number of gradient steps is sufficiently tuned. We conjectured that soft relabeling would be most beneficial in settings with extremely sparse rewards. To test this hypothesis, we modified the reward functions in 2D reacher and Jaco reaching environments to be much sparser. As shown in the far right column on Fig. 5, only soft relabeling is able to make learning progress in this setting.
More General Task Distributions Our next experiment demonstrates that, in addition to relabeling goals, inverse RL can also relabel experience for more general tasks distributions. Our first task distribution is a discrete set of goal states ψ ∈ {1, · · · , 32} for the 2D reacher environment. The  R d . We use the walker environment, with features corresponding to torso height, velocity, relative position of the feet, and a control cost. The third task distribution is again a goal reaching task, but one where the task φ = (s g , m) indicates both the goal state as well as the desired margin from that goal state. As prior relabeling approaches are not applicable to these general task distributions, we only compared our approach to random relabeling and no relabeling (SAC [15]). As shown in Fig. 6, relabeling with inverse RL provides more sample efficient learning in all tasks, and the asymptotic reward is larger than the baselines by a non-trivial amount in two of the three tasks.

HIPI-BC: Behavior Cloning on Experience Relabeled with Inverse RL
In this section, we present experiments that use behavior cloning on top of relabeled experience (Alg. 3). The three domains we use have varying reward structure: (1) half-cheetah with continuous goal velocities; (2) quadruped with linear reward functions; and (3) the manipulation environment with nine discrete tasks. For the half-cheetah and quadruped domains, we collected 1000 demonstrations from a policy trained with off-policy RL. For the manipulation environment, Lynch et al. [26] provided a dataset of 100 demonstrations for each of these tasks, which we aggregate into a dataset of 900 demonstrations. In all settings, we discarded the task labels, simulating the common real-world setting where experience does not come prepared with task labels. As shown in Fig. 7, first inferring the tasks with inverse RL and then performing behavioral cloning results in significantly higher final rewards than task-agnostic behavior cloning on the entire dataset, which is no better than random. Figure 8: Importance of the partition function: On the half-cheetah task, we simulated the effect of unnormalized reward functions by adding a constant bias to the first task. Inverse RL normalizes rewards by the partition function. Without this normalization, experience is disproportionately labeled with the first task label, resulting in poor performance during behavior cloning.
Our final experiment demonstrates the importance of the partition function. On the cheetah domain, we synthetically corrupt the demonstrations by adding a constant bias to the reward for the first task (whichever velocity was sampled first). We then compare the performance of our approach against an ablation that did not normalize by the partition function when relabeling data. As shown in Fig. 8, using task rewards of different scales significantly degrades the performance of the ablation. Our method, which normalizes the task rewards in the inverse RL step, is not affected by reward scaling.

Discussion
In this paper, we introduced the idea that hindsight relabeling is inverse RL. We showed that a number of prior works can be understood as special cases of this general framework. The idea that inverse RL might be used to relabel data is powerful because it enables us to extend relabeling techniques to general classes of reward functions. We explored two particular instantiations of this idea, using experience relabeled with inverse RL for off-policy RL and for supervised learning.
We are only scratching the surface of the many ways relabeled experience might be used to accelerate learning. For example, the problem of task inference is ever-present in meta-learning, and it is intriguing to imagine explicitly incorporating inverse RL into meta RL. Broadly, we hope that the observation that inverse RL can be used to accelerate RL will spur research on better inverse RL algorithms, which in turn will provide better RL algorithms.

A Proof of Lemma 2
This section provides a proof of Lemma 2.
Proof. The optimal relabeling distribution can be viewed as an information projection of the joint distribution q τ (ψ | τ )q τ (τ ) onto the target distribution p(τ, ψ) (Eq. 5): where Q = {q(τ, ψ) s.t. q(τ, ψ)dψ = q τ (τ )} is the set of all joint distributions with marginal q τ (τ ). Note that this set Q is closed and convex. We then apply Theorem 11.6.1 from Cover & Thomas [5]: The second KL divergence on the RHS can be simplified: Substituting this simplification into Eq. 10 and rearranging terms, we obtain the desired result.

B Inverse RL on Transitions
For simplicity, our derivation of relabeling in Section 4 assumed that entire trajectories were provided. This section outlines how to do relabeling with inverse RL when we are only provided with (s, a, s ) transitions, rather than entire trajectories. This derivation will motivate the use of the soft Q-function in Eq. 8.
In this case, policy distribution q in the MaxEnt RL objective (Eq. 6) is conditioned on the current state and action (s t , a t ) in addition to the task ψ: max q(τ,ψ|st,at) Following the derivation in Section 4, we expand this objective, using q(ψ | s t , a t ) as our relabeling distribution: The expected value of the two summations is the soft Q-function for the policy q(a | s, ψ): Substituting Eq. 13 into Eq. 12 and ignoring terms that do not depend on ψ, we can solve the optimal relabeling distribution: C Experimental Details

C.1 Hyperparameters for Off-Policy RL
Except for the didactic experiment, we used SAC [15] as our RL algorithm, taking the implementation from Guadarrama et al. [13]. This implementation scales the critic loss by a factor of 0.5. Following prior work [31], we only relabeled 50% of the samples drawn from the replay buffer, using the originally-commanded task the remaining 50%. The only hyperparameter that differed across relabeling strategies was the number of gradient updates per environment step. For each experiment, we evaluated each method with values in {1, 3, 10, 30} and reported the results of the best hyperparameter in our plots. Perhaps surprisingly, doing random relabeling but simply increasing the number of gradient updates per environment step was a remarkably competitive baseline. To implement final state relabeling, we modified transitions as they were being added to the replay buffer, adding both the original transition and the transition augmented to use the final state as the goal. To implement future state relabeling, we modified transitions as they were being added to the replay buffer, adding both the original transition and a transition augmented to use one of the next 4 states in the same trajectory as the goal.

C.2 Hyperparameters for Behavior Cloning Experiments
To account for randomness in the learning process, we collect at least 200 evaluation episodes per domain; we repeat this experiment for at least 5 random seeds on each domain, and plot the mean and standard deviation over the random seeds. We used a 2-layer neural network with ReLu activations for all experiments. The hidden layers had size (256, 256). We optimized the network to minimize MSE using the Adam optimizer with a learning rate of 3e-4. We used early stopping, halting training when the validation loss increased for 3 consecutive epochs. Typically training converged in 30 -50 epochs. We normalized both the states and actions. For the task-conditioned experiments, we concatenated the task vectors to the state vectors.

Quadruped
The quadruped was a modified version of the environment from Abdolmaleki et al. [2]. We modified the initial state distribution so the agent always started upright, and modified the observation space to include the termination signal as part of the observation. Tasks ψ ∈ R 2 were sampled uniformly from the unit circle. Let s XY vel and s XY pos indicate the XY velocity and position of the agent. For the HIPI-RL experiments, we used the following sparse reward function: r ψ (s, a) = 1( s XY pos − ψ 2 ≤ 0.3) − 1.0, and the episode terminated when s XY pos − ψ 2 ≤ 0.3. We also reset the environment after 300 steps if the agent had failed to reach the goal. For the HIPI-BC experiments, we used the following dense reward function: r ψ (s, a) = s T XY vel ψ + 0.1 a 2

Finger
The finger environment was taken from Tassa et al. [40]. Tasks ψ were sampled using the environment's default goal sampling function. Let s XY denote the XY position of the knob that the agent can manipulate. The reward function was defined as r ψ (s, a) = 1( s XY − ψ 2 ≤ 0.01) − 1.0 and the episode terminated when s XY − ψ 2 ≤ 0.01. We also reset the environment after 1000 steps if the agent had failed to reach the goal.

2D Reacher
The 2D reacher environment was taken from Tassa et al. [40]. Let s XY denote the XY position of the robot end effector. The reward function was defined as r ψ (s, a) = 1( s XY − ψ 2 ≤ m) − 1.0 and the episode terminated when s XY − ψ 2 ≤ m, where m > 0 is a margin around the goal. We used m = 0.01 and m = 0.003 in our experiments. We also reset the environment after 1000 steps if the agent had failed to reach the goal. Tasks were sampled using the environment's default goal sampling function.

Sawyer Reach
The sawyer reach environment was taken from Yu et al. [47]. Let s XYZ denote the XYZ position of the robot end effector. The reward function was defined as We also reset the environment after 150 steps if the agent had failed to reach the goal. Tasks were sampled using the environment's default goal sampling function. For the experiment where the task indicator ψ also specified the margin m, the margin was sampled uniformly from the interval [0, 0.1].

2D Navigation
We used the 2D navigation environment from Eysenbach et al. [9]. The action space is continuous and indicates the desired change of position. The dynamics are stochastic, and the initial state and goal are sampled uniformly at random for each episode. To increase the difficulties of credit assignment and exploration, the agent is always initialized in the lower left corner, and we randomly sampled goal states that are at least 15 steps away. The layout of the obstacles is taken from the classic FourRooms domain, but dilated by a factor of three.

Jaco Reach
We implemented a reaching task using a simulated Jaco robot. Goal states ψ were sampled from uniformly from the interval