Formalizing preference utilitarianism in physical world models

Introduction Usually, ethical imperatives are not formulated with sufficient precision to study them and their realization mathematically.  (McLaren 2011, p. 297; Gips 2011, p. 251)  In particular, it is impossible to implement them on an intelligent machine to make it behave benevolently in our universe, which is the subject of a field known as Friendly AI (e.g. see  Yudkowsky 2001, p. 2)  or machine ethics (e.g. see  Anderson and Anderson 2011, p. 1) . Whereas existing formalizations of utilitarian ethics have been successfully applied to economics, they are incomplete due to the nature of their dualistic world model in which agents are assumed to be ontologically fundamental. In this paper however, we take the following steps towards a workable and simple formalization of preference utilitarianism 1 in physical world models: -We describe the problem of informality in ethics and the shortcomings of previous dualist approaches to formalizing utilitarian ethics (Sect. 2). -We justify cellular automata as a world model, use Bayes' theorem to extract utility functions from a given space-time embedded agent and introduce a formalization of preference utilitarianism (Sect. 3). -We compare our approach with existing work in ethics, game theory and artificial intelligence (Sect. 4). Our formalization is novel but nevertheless relates to a growing movement to treat agents as embedded into the environment.
 The problem of formalizing ethics in physical systems Discussion on informally specified moral imperatives can be difficult due to different interpretations of the texts describing the imperative. Thus, formalizing moral imperatives could augment informal ethical discussion.  (Gips 2011, p. 251; Anderson 2011; Dennett 2006; Moor 2011, p. 19 ) Furthermore, science and engineering answer formally described questions and solve well-specified tasks, but are not immediately applicable to the informal question of how to make the world "better". This problem has been identified in economics and game theory, which has led to some very useful formalizations of utilitarianism (e.g.  Harsanyi 1982 ). However, their formalization relies on consciousness-matter dualism: The agents are not part of the physical world or embedded into it, so that their thoughts or computations can not be influenced by physical laws. Also, agents' utility functions are assumed to not depend on the agents (or their physical configurations) themselves. These are typical assumptions in game theory. After all, game theory is about games, in which players are not actually inside the game, nor can they decide themselves what goals to pursue. This classic (multi-)agent-environment model is depicted in Fig.  1 . Our world, however, is (usually presumed to be) a purely physical system: ethically relevant entities (animals etc.) are embedded in the environment. For example, our brains behave according to the same laws of physics as the rest of the world. Also, happiness and preferences are not given by predetermined utility functions or rewards from the environment, but are the result of physical processes in our bodies. Therefore, dualist descriptions and formalizations leave questions unanswered: (compare Orseau and Ring 2012) -What objects are ethically relevant? (What are the agents of our non-dualist world?) -What is a space-time embedded agent's or, more generally, an object's utility function? Thus, even though classic formalizations of (preferentist) utilitarianism in the agentenvironment-model can formalize the vague notions of goals and preferences with
 A Bayesian approach to formalizing preference utilitarianism in physical systems
 Cellular automata as non-dualist world models To overcome the described problems of dualist approaches to utilitarianism, we first have to choose a new, physical setting for our ethical imperative. Instead of employing string theory and other contemporary theoretical frameworks, we choose a model that is much more simple to handle formally: cellular automata. These have sometimes even been pointed out to be candidates for modeling our own universe,  (Wolfram 2002, ch. 9; Schmidhuber 1999; Zuse 1967 Zuse , 1969  but even if physics will prove cellular automata to be a wrong model, they may still be of instrumental value for the purpose of this paper.  (compare Downey 2012, pp. 70f., 77-79; Hawking and Mlodinow 2010, ch. 8)  For detailed introductions to classic cellular automata with neighbor-based rules, see  Wolfram (2002)  or  Shiffman (2012, ch. 7 ) for a purely informal and  Wolfram (1983)  for a slightly more technical treatment that focuses on one-dimensional cellular automata. In Sect. 3.1.1, we will consider a generalized and relatively simple formalism, which is not limited to rules that only depend on neighbors of a cell. In CA, it is immediately clear that for a (preference) utilitarian morality we have to answer the questions that are avoided by assuming a set of agents and their utility functions to be known from the beginning. It also frees us from many ethical intuitions that we build up specifically for our own living situations and reduces moral intuition to its very fundamentals. Figure  2  shows a state of a cellular automaton illustrating the problem of defining utilitarianism or any other ethical imperative in physical models. Clearly, many intuitions are very difficult (if not impossible) to formulate universally and precisely in CA. Thereby, the required formality helps in choosing and defining an ethical imperative.
 A formal introduction to cellular systems We now introduce some very basic notation and terminology of cellular systems, a generalization of classic cellular automata, thus setting the scene for our ethical imperative. For given sets A and B, let A B denote the set of functions from B to A. A cellular system is a triple (C, S, d) of a countable set of cells C, a finite set of cell states S and a function d : S C → S C that maps a world state s : C → S onto its successor. So basically a world consists of a set of cells that can have different values and a function that models deterministic state-transitions.  2  Cells of cellular systems do not necessarily have to be on a regular grid and computing new states does not have to be done via neighbor-based lookup tables. This makes formalization much easier. But before anything else, we have to define structures which represent objects in our cellular systems. A space Spc ⊆ C in a cellular system (C, S, d) is a finite subset of the set of cells C. A structure str on a space Spc is a function str : Spc → S that maps the cells of the space onto cell values. A history is a function h : N → S C that maps natural numbers as time steps onto states of the system. For example, the history h s of an initial state s can then be defined recursively by h s (n) = d(h s (n − 1)) for n ≥ 1 with the base case h s (0) = s.
 Posterior probabilities and the priority of a (given) goal to a given agent Before extracting preferences from a given structure, we have to decide on a model of preferences. Preferences themselves are mere orderings of alternative outcomes or lotteries over these outcomes with the outcomes being entire histories h ∈ (S C ) N in our case. The problem is that this makes it difficult to compare two outcomes when the preferences of multiple individuals are involved. To be able to make such comparisons, we move from orderings to utility functions u : (S C ) N → R that map histories of the world onto their (cardinal) utilities.  3  This will make it possible to just add up the utilities of different individuals and then compare the sum among outcomes. This by no means "solves" the problem of interpersonal comparison. Rather, it makes it more explicit. For example, a given set of preferences is represented equally well by u and 2 • u, but ceteris paribus 2 • u will make the preferences more significant in summation. Different approaches to the problem have been proposed.  (Hammond 1989)  In this paper we will ignore the problem (or hope that the fair treatment in determining all individuals' utility functions induces moral permissibility). Now we ask the question: Does a particular structure str want to maximize some utility function u? It is fruitful to think about how one would approach such questions in our world, when encountering some very odd organism. At least one possible approach would be to put it into different situations or environments and see what it does to them. If the structure increases some potential utility function in different environments, it seems as if this utility function represents an aspect of the structure's preferences.  4  However, for some utility functions it is not very special that their values are increased and then it might just be coincidence that the structure in question also does so. For example, it is usually not considered a structure's preference to increase entropy even if entropy increases in environments including this structure, because an increase in entropy is extremely common with or without the structure. Also, we feel that some utility functions are less likely than others by themselves, e.g. because they are very complex or specific. But how can we formally capture these notions? Since uncertainty is involved, we interpret the degree to which a utility function u is important to some structure str that exists at time step i as the posterior probability of that utility function given the structure, a probability we denote by P(u|str@i), where str@i denotes the event that str exists in time step i.  5  Here, the utility function is interpreted as a hypothesis about the structure's "true intentions" 6 . In a purely physical, non-dualist world there is nothing but the structure itself, of course. Therefore, the "true intentions" do not really exist, which makes it still hard to know what P(u|str@i) is supposed to mean. To finally overcome this problem, we will equate intention and purpose, i.e. we equate the following interpretations of u as a hypothesis explaining the data str@i:  (compare Dennett 1989, pp. 289ff., 299f., 318, 320f.)  -The utility function u is the goal of structure str. -Maximizing u was the goal of an entity that chose str. The second interpretation is more useful, because it describes a data-generating process and thus comes closer to typical statistical models. Thus, we have to find the posterior probability of some model (a utility function) given some data (a structure). For this problem Bayes' theorem suggests itself, because it provides an equation for posterior probabilities. In our case, Bayes' theorem can be used to infer the likelihood that some utility function was a goal when a structure was chosen from some priors and the likelihood of choosing the structure given that the goal is to maximize the utility function. Specifically, Bayes' theorem gives us P(u|str@i) = P(str@i|u) • P(u) P(str@i) , ( 1 ) where P(u) and P(str@i) are prior probability distributions of utility functions and structures, respectively, and P(str@i|u) is the probability of (some hypothetical entity choosing) str at time step i when u is to be maximized. Whereas P(u|str@i) is very hard to grasp intuitively, it is more clear what the probability distributions on the right hand side of the equation mean. Nevertheless, they do not correspond to measurable probability distributions like the results from rolling a dice. Indeed, P(u) and P(str@i) are ultimately subjective (e.g. see  Olshausen 2004, pp. 1f .; Robert 1994, p. 9) and P(str@i|u) depends on what exactly the hypothesis u is supposed to express, thus leaving our ethical imperative parametrized by these distributions. Footnote 5 continued history, because then structures cannot have preferences about themselves ("personal happiness") without also having preferences about all other identical structures (at the same place). An alternative would be to apply utility functions only to the part of the history from the point of the existence of the structure onwards, so that identical structures at different points in time have equal utility functions that are applied differently. However, it seems like this neglects that the past can depend on the action of an agent in the present, as illustrated in Newcomb's paradox by  Nozick (1969) .  6  Intuitively, some structures can have more than one utility function, while others have no utility function at all. One way to model this would be to understand different utility functions as events in separate sample spaces. So, the sum u P(u|str) could vary among different structures str. A similar scenario is the inference of multiple diseases from a set of symptoms.  (Charniak 1983)  While some individuals may have no diseases or preferences at all, others may be thought of as having more than one disease or utility function. In more technical terms, for each utility function there would be a sample space of having that utility function and not having that utility function. In this paper however, we will assume mutual exclusivity and collective exhaustiveness of utility functions. All utility functions live in the same sample space and thus u P(u|str) = 1 for all structures str. This does not mean that all structures have equal moral standing: The idea is that "meaningless" structures str have high P(u|str) only for constant utility functions u, i.e. for "don't care"-utility functions, which are irrelevant for decision making. Nonetheless, there seem to be canonical approaches. P(str@i|u) should be understood as the probability that str is chosen at time step i by an approximately rational agent that wants to maximize u. So, structures that are better at maximizing or more suitable for u should receive higher P(str@i|u) values. This corresponds to the assumption of (approximate) rationality in Dennett's intentional stance.  (Dennett 1989, pp. 21, 49f.)  Unfortunately, the debate about causal and evidential decision theory (e.g.  Peterson 2009, ch. 9)  shows that formalizing the notion of rational choice is difficult. The prior of utility functions P(u) on the other hand should denote the "intrinsic plausibility" of a goal u. That does not have to mean defining and excluding "evil" or "banal" utility functions. In the preference extraction context, utility functions are models or hypotheses that explain the behavior of a structure. And Solomonoff's formalization of Occam's razor is often cited as a universal prior distribution of hypotheses.  (Legg 1997 ) It assumes complicated hypotheses (utility functions), i.e. ones that require more symbols to be described in some programming language, to be less likely than simpler ones. If utility functions are conceived of as competing hypotheses (see footnote 6), then P(str@i) = u P(str@i|u) • P(u). Otherwise, P(str@i) could potentially be chosen more freely. Finally, note how Bayes' theorem catches our intuitions from above, especially when assuming probability distributions similar to the suggested ones: When some structure str maximizes some utility function u very well, then P(str@i|u) and thereby the relevance of the utility function to the object would increase. On the other hand, if many other structures are comparably good, then the probability for each one to be chosen when given the utility function is smaller (due to the sum of the probabilities of all possible structures on a given space and time step being 1) and the probability of the utility function being a real preference would decrease with it. Finally, multiplying by P(u) catches abstruse utility functions, e.g. utility functions that are specifically suited to be fulfilled by the structure in question.
 An individual structure's welfare function Having introduced a way of determining how likely it is that some utility function is the utility function of some object, we define the welfare U str@i of a structure str that exists at some step i of a history h, as the weighted sum over all utility functions U str@i = u P(u|str@i)u(h), ( 2 ) where h is the history and the sum is over all theoretically possible utility functions u : (S C ) N → R. We call this term expected utility, because this expression is generally used for adding utilities based on their likelihood, which is a common concept. However, the term usually suggests that there is also an actual utility. In our case of ascribing preferences to physical objects however, no such thing exists. We only imagine there to be some real utility or welfare functions and that we use Bayesian inference to find them. But in fact, the structure itself is all there exists and thus the expected utility is as actual as possible. The sum in the term for expected utility is over an uncountably infinite set, which can only converge when only countably many summands are non-zero. 7 Some other concerns are described in footnote 9 and addressed in footnote 10.
 Summing over all agents The utilitarian imperative is to maximize a global welfare function that is the sum of all individuals' welfare functions. We already defined the welfare function of single structures. So next we have to define what the set of all agents is and how to sum over it. As foreshadowed before, we will consider all possible structures of a cellular automaton using Eq. 2 and rely on (intuitively) irrelevant ones to receive high P(u|str@i) values only for constant and therefore irrelevant utility functions u (see footnote 6). To sum the utility over all agents, we not only have to sum over all structures in a particular state, but first over all (discrete) time steps of the history of the cellular automaton world and only then over all structures in every state. This way, we sum the welfare of all agents ever coming into existence. For the summands, we can insert the term obtained in Eq. 2 i str@i U str@i = i str@i u P(u|str@i)u(h), ( where U str@i denotes the welfare or utility of the structure str that exists at time step i, the first sum is over all integers functioning as time steps, the second is over all structures in h(i) and the third over all possible utility functions. 8 So, our formalization of the main imperative of preference utilitarianism turns out to be nothing more than maximizing global, all-time expected utility (of every space-time embedded agent that ever comes into existence). In general, the value of the series depends on the order of these infinite sums. 9 Also, the series can diverge. Nonetheless it may still be usable for comparing histories in many cases. 10
 Related work Preferentist utilitarianism has become a common form of utilitarianism in the second half of the 20th century, with the best known proponents being Hare and Singer. However, the intuitions underlying the presented formalization are different from the most common ethical intuitions in preference utilitarianism. Since our formal preference utilitarianism is not meant to describe a decision procedure for humans (or, more generally and in  Hare's (1981, pp. 44f.)  terminology, non-"archangels"), we do not consider an application-oriented utilitarianism like Hare's two-level consequentialism.  (Hare 1981, p. 25ff .) Also, most preference utilitarians ascribe preferences only to humans (or abstract agents) and do not contain prioritization among individuals,  (Harsanyi 1982, p. 46)  or they use a low number of classes of moral standing.  (Singer 1993, pp. 101ff., 283f.)  Whereas some have pointed out that a variety of behavior and even trivial systems can be viewed from an "intentional stance",  (Dennett 1971 (Dennett , 1989 compare Hofstadter 2007, pp. 52ff.)  only relatively recent articles in preference utilitarianism have discussed the connection between goal-directed behavior and ethically relevant preferences and with the universality of the former pointed out the potential universality of the latter.  (Tomasik 2015b, ch. 7; Tomasik 2015a, ch. 4, 6; Tomasik 2015c)  This idea is an important step when formalizing preference utilitarianism because otherwise one would have to define moral standing depending on other, usually binary, notions: being alive, the ability to suffer (Bentham 1823, ch. 17 note 122) personhood  (Gruen 2014, ch. 1) , free will, sentience and (self-)consciousness  (Singer 1993, pp. 101ff.)  or the ability of moral judgment. However, all of them seem to be very difficult to define (universally) in physical systems in the intended binary sense. 11 Also, continuous definitions of these terms are often connected with goal-directed behavior.  (Tomasik 2015a, ch. 4; Wolfram 2002 Wolfram , p. 1136  9 Specifically, the Riemann series theorem states that any conditionally convergent series can be reordered to have arbitrary values.  10  It is very important to differentiate the series from its value. Otherwise, one may identify the series with positive or negative infinity or as being undefined. Two infinite values of the series would then not be comparable anymore, which  Bostrom (2011)  identified as a problem for (consequentialist) ethics. But this problem can sometimes be eliminated by comparing the series itself to another. In this particular case, a history h is better than another history h , if i Spc u u(h)P(u|(h(i)| Spc )@i) − u(h )P(u|(h (i)| Spc )@i) > 0, where h(i)| Spc : Spc → S : c → h(i)(c) denotes the restriction of h(i) to Spc, i.e. the structure on Spc in the state h(i). If no such relation can be established then the two histories are arguably incomparable or may be called approximately equally good. Again, the ordering could be important in some cases, see footnote 9.
 Fig. 3 Comparison between formalizations of utilitarianism. The first row shows the formalization of this paper, the second row is adapted from  Harsanyi (1982, p. 46) , and the third row from  Gips (2011, p. 245) . The utility of an agent n is denoted by U n and its weight by w n sum over all agents utility of an agent i str @i u P (u|str @i)u(h) agent n∈N U n agent n∈N w n • U n Whereas most ethical work is conducted informally,  (McLaren 2011, p. 297; Gips 2011, p. 251)  there has been some formal work at the intersection of (utilitarian) ethics, game theory and economics, most notably by  Harsanyi (1982) . Some formalization has also been conducted in the realm of machine ethics.  (Anderson et al. 2004; Gips 2011, pp. 245ff .) However, influenced by game theory and dualist traditions in philosophy, they are based on the classic agent-environment-model as displayed in Fig.  1  and assume utility functions (or even the utilities in different trajectories themselves) as given by the world model. Nonetheless, there is at least one parallel: all models of utilitarianism contain the notion of summing the utility over all agents. As shown in Fig.  3 , both the definition of all agents and how to obtain the utility or welfare of an agent differ among formalizations. In Artificial Intelligence, the idea of learning preferences has become more popular, e.g. see Fürnkranz and Hüllermeier (2010) and  Nielsen and Jensen (2004)  for technical treatments or  Bostrom (2014, pp. 192ff.)  for an introduction in the context of making an AI do what the engineers value. However, most of the time, the agent is still presumed to be separated from the environment. Nonetheless, the idea of evaluating space-time-embedded intelligence is beginning to be established in artificial (general) intelligence,  (Orseau and Ring 2012)  which is closely related to the probability distribution P(str@i|u).
 Conclusion By reversing Dennett's intentional stance with Bayes' theorem, we were able to ascribe preferences to physical objects and thus formalize preference utilitarianism in cellular automata. Theoretically, such formalizations can function as a specification for an artificial intelligence or more generally as a basis for "paradise engineering" (e.g. see  Ettinger 2009, p. 124) . However, there are several potential problems that require further work before such practical applications of our formalization or improved variations of it can be approached: -Through sums over all structures, possible utility functions and states and the application of incomputable concepts like Solomonoff's prior in P(u), our formalization is incomputable in theory and practice. So even in simulations of cellular automata our formalization is not immediately applicable. -Computing our global welfare function in the real world is even more difficult, because it requires full information about the world on particle level. Also, the formalization must first be translated into the physical laws of our universe. -The difficulty to apply our formalization is by no means only relevant to actually using it as a moral imperative. Instead, it is also relevant to discussing our formalization from a normative standpoint: Even though the derivation of our formalization is plausible, it may still differ significantly from intuition. There could be some kind of trivial agents with trivial preferences that dominate comparison of different histories. Because the formalization's incomputability makes it difficult to assess whether such problems are present, further work on its potential flaws is necessary. Based on such discussion, our formalization may be revised or even discarded. In any case, we could learn a lot from its shortcomings especially due to the formalization's simplicity and plausible derivation. -We outlined how P(str@i|u) and P(u) could be determined in principle. However, they need to be specified more formally, which in the case of P(str@i|u) seems to require a solution to the problem of normative decision theory. Some problems of our formalization could inspire additional refinements of these distributions. Fig. 1 1 Fig. 1 The classic agent-environment-model
 Fig. 2 2 Fig. 2 A state of a two-dimensional cellular automaton. It is very unclear, what agents are and which preferences they have. Adapted from http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#mediaviewer/ File:Conways_game_of_life_breeder
			 For introductions to and ethical discussions of the underlying notion of preference utilitarianism see Tomasik (2015a, b) .
			 The choice of deterministic systems was made primarily to simplify the formalization. It appears to be unproblematic to transfer formal preference utilitarianism to non-deterministic systems, but defining non-deterministic cellular automata themselves is a little more difficult.
			 Other codomains of utility functions seem possible as long as they are subsets of a totally ordered vector space over R. Intervals like [0, 1] seem specifically suitable, because they avoid problems of infinite utility and allow for normalization. (Isbell 1959 )4  Alternatively, one can try to avoid this hypothetical experiment by predicting the organism's behavior. For example, one could try to ask the organism what it would do or infer its typical behavior from its internals.5  Including i into the data is important, because otherwise identical structures at different points in time would have identical utility functions. This is a problem, when the utility function u is applied to the whole
			 If Solomonoff's prior is chosen for P(u), all incomputable utility functions have zero probability. Since the set of computable functions is countable, only countably many summands could possibly be non-zero. 8 More precisely, but less elegantly, one could write∞ i=0 Spc∈Fin(C) u:(S C ) N →R u(h)P(u|(h(i)| Spc )@i),where Fin(C) := {A ⊆ C||A| ∈ N} is the set of finite subsets of C and h(i)| Spc : Spc → S : c → h(i)(c) is the restriction of the state h(i) to the space Spc and therefore the structure on that space.
			 For example, Wolfram (2002 Wolfram ( , pp. 823-825, 1178Wolfram ( -1180 and Emmeche (1997)  discuss the property of life,Hofstadter (2007, pp. 9-24, 51-54)  discusses consciousness andArneson (1998, p. 5) discusses personhood.

Abstract: Most ethical work is done at a low level of formality. This makes practical moral questions inaccessible to formal and natural sciences and can lead to misunderstandings in ethical discussion. In this paper, we use Bayesian inference to introduce a formalization of preference utilitarianism in physical world models, specifically cellular automata. Even though our formalization is not immediately applicable, it is a first step in providing ethics and ultimately the question of how to "make the world better" with a formal basis.


Kelvin Xu
Ellis Ratner
Anca Dragan
Sergey Levine
Chelsea Finn

Learning a Prior over Intent via Meta-Inverse Reinforcement Learning

Introduction Reinforcement learning (RL) algorithms have the potential to automate a wide range of decision-making and control tasks across a variety of different domains, as demonstrated by successful recent applications ranging from robotic control  (Kober & Peters, 2012; Levine et al., 2016)  to game playing  (Mnih et al., 2015; Silver et al., 2016) . A key assumption of the RL problem statement is the availability of a reward function that accurately describes the desired task. For many real world tasks, reward functions can be chal-Figure  1 . A diagram of our meta-inverse RL approach. Our approach attempts to remedy over-fitting in few-shot IRL by learning a "prior" that constraints the set of possible reward functions to lie within a few steps of gradient descent. Standard IRL attempts to recover the reward function directly from the available demonstrations. The shortcoming of this approach is that there is little reason to expect generalization as it is analogous to training a density model with only a few examples. lenging to manually specify, while being crucial for good performance  (Amodei et al., 2016) . Most real world tasks are multifaceted and require reasoning over multiple factors in a task (e.g. a robot cleaning in a house with children), while simultaneously providing appropriate reward shaping to make the task feasible with tractable exploration  (Ng et al., 1999) . These challenges are compounded by the inherent difficulty of specifying rewards for tasks with highdimensional observation spaces such as images. Inverse reinforcement learning (IRL) is an approach that aims to address this problem by instead inferring the reward function from demonstrations of the task  (Ng & Russell, 2000) . This has the appealing benefit of taking a datadriven approach to reward specification in place of hand engineering. In practice however, rewards functions are rarely learned as it can be prohibitively expensive to provide demonstrations that cover the variability common in real world tasks (e.g., collecting demonstrations of opening every type of door knob). In addition, while learning a complex function from high dimensional observations might make an expressive function approximator seem like a reasonable modelling assumption, in the "few-shot" domain it is notoriously difficult to unambiguously recover a good reward function with expressive function approximators. Many prior approaches have thus relied on low-dimensional linear models with handcrafted features that effectively encode a strong prior on the relevant features of a task. This requires engineering a set of features by hand that work well for a specific problem. In this work, we propose an approach that instead explicitly learns expressive features that are robust even when learning with limited demonstrations. Our approach relies on the key observation that related tasks share a common structure that we can leverage when learning new tasks. To illustrate, considering a robot navigating through a home. While the exact reward function we provide to the robot may differ depending on the task, there is a structure amid the space of useful behaviours, such as navigating to a series of landmarks, and there are certain behaviors we always want to encourage or discourage, such as avoiding obstacles or staying a reasonable distance from humans. This notion agrees with our understanding of why humans can easily infer the intents and goals (i.e., reward functions) of even abstract agents from just one or a few demonstrations  (Baker et al., 2007) , as humans have access to strong priors about how other humans accomplish similar tasks accrued over many years. Similarly, our objective is to discover the common structure among different tasks, and encode that structure in a way that can be used to infer reward functions from a few demonstrations. More specifically, in this work we assume access to a set of tasks, along with demonstrations of the desired behaviors for those tasks, which we refer to as the meta-training set. From these tasks, we then learn a reward function parameterization that enables effective few-shot learning when used to initialize IRL in a novel task. Our method is summarized in Fig.  1 . Our key contribution is an algorithm that enables efficient learning of new reward functions by using metatraining to build a rich "prior" for goal inference. Using our proposed approach, we show that we can learn deep neural network reward functions from raw pixel observations on two distinct domains with substantially better data efficiency than existing methods and standard baselines.
 Related Work Inverse reinforcement learning (IRL)  (Ng & Russell, 2000)  is the problem of inferring an expert's reward function directly from demonstrations. Prior methods for performing IRL range from margin based approaches  (Abbeel & Ng, 2004; Ratliff et al., 2006)  to probabilistic approaches  (Ramachandran & Amir, 2007; Ziebart et al., 2008) . Although it is possible to extend our approach to any other IRL method, in this work we base on work on the maximum entropy (MaxEnt) framework  (Ziebart et al., 2008) . In addition to allowing for sub-optimality in the expert demonstrations, MaxEnt-IRL can be re-framed as a maximum likelihood estimation problem. (Sec. 3). In part to combat the under-specified nature of IRL, prior work has often used low-dimensional linear parameterizations with handcrafted features  (Abbeel & Ng, 2004; Ziebart et al., 2008) . In order to learn from high dimensional input,  Wulfmeier et al. (2015)  proposed applying fully convolutional networks  (Shelhamer et al., 2017)  to the MaxEnt IRL framework  (Ziebart et al., 2008)  for several navigation tasks  (Wulfmeier et al., 2016b; a) . Other methods that have incorporated neural network rewards include guided cost learning (GCL)  (Finn et al., 2017a) , which uses importance sampling and regularization for scalability to highdimensional spaces, and adversarial IRL  (Fu et al., 2018) . Several other methods have also proposed imitation learning approaches based on adversarial frameworks that resemble IRL, but do not aim to directly recover a reward function  (Ho & Ermon, 2016; Hausman et al., 2017; Kuefler & Kochenderfer, 2018) . In this work, instead of improving the ability to learn reward functions on a single task, we focus on the problem of effectively learning to use prior demonstration data from other IRL tasks, allowing us to learn new tasks from a limited number demonstrations even with expressive non-linear reward functions. Prior work has explored the problem of multi-task IRL, where the demonstrated behavior is assumed to have originated from multiple experts achieving different goals. Some of these approaches include those that aim to incorporate a shared prior over reward functions through extending the Bayesian IRL  (Ramachandran & Amir, 2007)  framework to the multi-task setting  (Dimitrakakis & Rothkopf, 2012; Choi & Kim, 2012) . Other approaches have clustered demonstrations while simultaneously inferring reward functions for each cluster  (Babes ¸-Vroman et al., 2011)  or introduced regularization between rewards to a common "shared reward"  (Li & Burdick, 2017) . Our work is similar in that we also seek to encode prior information common to the tasks. However, a critical difference is that our method specifically aims to distill the meta-training tasks into a prior that can then be used to learn rewards for new tasks efficiently. The goal therefore is not to acquire good reward functions that explain the meta-training tasks, but rather to use them to learn efficiently on new tasks. Our approach builds on work on the broader problem of meta-learning  (Schmidhuber, 1987; Bengio et al.; Naik & Mammone, 1992; Thrun & Pratt, 2012)  and generative modelling  (Rezende et al., 2016; Reed et al., 2018; Mordatch, 2018) . Prior work has proposed a variety of solutions for learning to learn including memory based methods  (Duan et al., 2016; Santoro et al., 2016; Mishra et al., 2017) , methods that learn an optimizer and/or initialization  (Andrychowicz et al., 2016; Ravi & Larochelle, 2016; Finn et al., 2017a; Li & Malik, 2017) , and methods that compare new datapoints in a learned metric space  (Koch, 2015; Wang & Hebert, 2016; Vinyals et al., 2016; Shyam et al., 2017; Snell et al., 2017) . Our work is motivated by the goal of broadening the applicability of IRL, but in principle it is possible to adapt many of these metalearning approaches for our problem statement. We build upon  Finn et al. (2017a) , which has also been previously applied to the related problems of imitation learning and human motion prediction  Finn et al., 2017b; Alet et al., 2018) . We leave it to future work to do a comprehensive investigation of different meta-learning approaches which could broaden the applicability of IRL.
 Preliminaries and Overview In this section, we introduce our notation and describe the IRL and meta-learning problems.
 Learning Rewards via Maximum Entropy Inverse Reinforcement Learning The standard Markov decision process (MDP) is defined by the tuple (S, A, p s , r, ) where S and A denote the set of possible states and actions respectively, r : S ⇥ A ! R is the reward function, 2 [0, 1] is the discount factor and p s : S ⇥ S ⇥ A ! [0, 1] denotes the transition distribution over the next state s t+1 , given the current state s t and current action a t . Typically, the goal of "forward" RL is to maximize the expected discounted return R(⌧ ) = P T t=1 t 1 r(s t , a t ). In IRL, we instead assume that the reward function is unknown but that we instead have access to a set of expert demonstrations D = {⌧ 1 , . . . , ⌧ K }, where ⌧ k = {s 1 , a 1 , . . . , s T , a T }. The goal of IRL is to recover the unknown reward function r from the set of demonstrations. We build on the maximum entropy (MaxEnt) IRL framework by  Ziebart et al. (2008) , which models trajectories as being distributed proportional to their exponentiated return p(⌧ ) = 1 Z exp (R(⌧ )) , (1) where Z is the partition function, Z = R ⌧ exp(R(⌧ ))d⌧ . This distribution can be shown to be induced by the optimal policy in entropy regularized forward RL problem: ⇡ ⇤ = arg max ⇡ E ⌧ ⇠⇡ [R(⌧ ) log ⇡(⌧ )] . (2) This formulation allows us to pose the reward learning problem as a maximum likelihood estimation (MLE) problem in an energy-based model r by defining the following loss: min E ⌧ ⇠D [L IRL (⌧ )] := min E ⌧ ⇠D [ log p (⌧ )] . (3) Learning in general energy-based models of this form is common in many applications such as structured prediction. However, in contrast to applications where learning can be supervised by millions of labels (e.g. semantic segmentation), the learning problem in Eq. 3 must typically be performed with a relatively small number of example demonstrations. In this work, we seek to address this issue in IRL by providing a way to integrate information from prior tasks to constrain the optimization in Eq. 3 in the regime of limited demonstrations.
 Meta-Learning The goal of meta-learning algorithms is to optimize for the ability to learn efficiently on new tasks. Rather than attempting to generalize to new datapoints, meta-learning can be understood as attempting to generalize to new tasks. It is assumed in the meta-learning setting that there are two disjoint sets of tasks that we refer to as the meta-training set {T i ; i = 1..N } and meta-test set {T j ; j = 1..M }, which are both drawn from a distribution p(T ). During meta-training time, the meta-learner attempts to learn the structure of the tasks in the meta-training set, such that when it is presented with a test task, it can leverage this structure to learn efficiently from a limited number of examples. To illustrate this distinction, consider the case of fewshot learning setting. Let f ✓ denote the learner, and let a task be defined by learning from K training examples X tr T = {x 1 . . . , x K }, Y tr T = {y 1 . . . , y K }, and evaluat- ing on K 0 test examples X test T = {x 1 . . . , x K 0 }, Y test T = {y 1 . . . , y K 0 }. One approach to meta-learning is to directly parameterize the meta-learner with an expressive model such as a recurrent or recursive neural network  (Duan et al., 2016; Mishra et al., 2017)  conditioned on the task training data and the inputs for the test task: f ✓ (Y |X test T , X tr T , Y tr T ) . Such a model is optimized using log-likelihood across all tasks. In this approach to meta-learning, since neural networks are known to be universal function approximators  (Siegelmann & Sontag, 1995) , any desired structure between tasks can be implicitly encoded. Rather than learn a single black-box function, another approach to meta-learning is to learn components of the learning procedure such as the initialization  (Finn et al., 2017a)  or the optimization algorithm  (Ravi & Larochelle, 2016; Andrychowicz et al., 2016) . In this work we extend the approach of model agnostic meta-learning (MAML) introduced by  Finn et al. (2017a) , which learns an initialization that is adapted by gradient descent. Concretely, in the supervised learning case, given a loss function L(✓, X T , Y T ) (e.g. cross-entropy), MAML performs the following optimization min ✓ X T L( T , X test T , Y test T ) = min ✓ X T L ✓ ↵r ✓ L(✓, X tr T , Y tr T ), X test T , Y test T , (4) where the optimization is over an initial set of parameters ✓ and the loss on the held out tasks X test T becomes the signal for learning the initial parameters for gradient descent (with step size ↵) on X tr T . This optimization is analogous to adding a constraint in a multi-task setting, which we show in later sections is analogous in our setting to learning a prior over reward functions.
 Learning to Learn Rewards Our goal in meta-IRL is to learn how to learn reward functions across many tasks such that the model can infer the reward function for a new task using only one or a few expert demonstrations. Intuitively, we can view this problem as aiming to learn a prior over the rewards of expert demonstrators, such that when given just one or a few demonstrations of a new task, we can combine the learned prior with the new data to effectively determine the expert's intent. Such a prior is helpful in inverse reinforcement learning settings, since the space of reward functions with are relevant to particular task is much smaller than the space of all possible rewards definable on the raw observations. During meta-training, we have a set of tasks {T i ; i = 1..N }. Each task T i has a set of demonstrations D T = {⌧ 1 , . . . , ⌧ K } from an expert policy which we partition into disjoint D tr T and D test T sets. The demonstrations for each meta-training task are assumed to be produced by the expert according to the maximum entropy model in Section 3.1. During meta-training, these tasks will be used to encodes common structure so that our model can quickly acquire rewards for new tasks from just a few demonstrations. After meta-training, our method is presented with a new task. During this meta-test phase, the algorithm must infer the parameters of the reward function r (s t , a t ) for the new task from a few demonstrations. As is standard in meta-learning, we assume that the test task is from the same distribution of tasks seen during meta-training, a distribution that we denote as p(T ).
 Meta Reward and Intention Learning (MandRIL) In order to meta-learn a reward function that can act as a prior for new tasks and new environments, we first formalize the notion of a good reward by defining a loss L T (✓) on the reward function r ✓ for a particular task T . We use the MaxEnt IRL loss L IRL discussed in Section 3, which, for a given D T , leads to the following gradient  (Ziebart et al., 2008) : r ✓ L T (✓) = @r ✓ @✓ ⇥ E ⌧ [µ ⌧ ] µ D T ⇤ . ( 5 ) where µ ⌧ are the state-action visitations under the optimal maximum entropy policy under r ✓ , and µ D are the mean state visitations under the demonstrated trajectories. If our end goal were to achieve a single reward function that # Compute Max-Ent state visitations 7: E ⌧ [µ ⌧ ] = STATE-VISITATIONS-POLICY(r ✓ , T ) 8: # MaxEntIRL gradient  (Ziebart et al., 2008)  9: @L @r ✓ = E ⌧ [µ ⌧ ] µ D 10: Return @L @r ✓ 11: 12: Randomly initialize ✓ 13: while not done do 14: Sample batch of tasks T i ⇠ {T } meta-train 15: for all T i do 16: Sample demos D tr = {⌧ 1 , . . . , ⌧ K } ⇠ T i 17: # Inner loss computation 18: @L tr T i (✓) @r ✓ = MAXENTIRL-GRAD(r ✓ , T i , D tr ) 19: Compute r ✓ L tr Ti (✓) from @L tr T i (✓) @r ✓ 20: Compute Ti = ✓ ↵r ✓ L tr Ti (✓) 21: Sample demos D test = {⌧ 0 1 , . . . , ⌧ 0 K 0 } ⇠ T i 22: # Outer loss computation 23: @L test T i @r ✓ = MAXENTIRL-GRAD(r T i , T i , D test )) 24: # Compute meta-gradient 25: Compute r ✓ L test Ti from @L test T i @r ✓ via chain rule 26: Compute update to ✓ ✓ P i r ✓ L test Ti works as well as possible across all tasks in {T i ; i = 1..N }, then we could simply follow the mean gradient across all tasks. However, our objective is different: instead of optimizing performance on the meta-training tasks, we aim to learn a reward function that can be quickly and efficiently adapted to new tasks at meta-test time. In doing so, we aim to encode prior information over the task distribution in this learned reward prior. We propose to implement such a learning algorithm by finding the parameters ✓, such that starting from ✓ and taking a small number of gradient steps on a few demonstrations from given task leads to a reward function for which a set of test demonstrations have high likelihood, with respect to the MaxEnt IRL model. In particular, we would like to find a ✓ such that the parameters T = ✓ ↵r ✓ L tr T (✓) (6) lead to a reward function r T for task T , such that the IRL loss (corresponding to negative log-likelihood) for a disjoint set of test demonstrations, given by L T ,test IRL , is minimized. The corresponding optimization problem for ✓ can therefore be written as follows: min ✓ N X i=1 L test Ti ( Ti ) = N X i=1 L test Ti ✓ ↵r ✓ L tr Ti (✓) . (7) Our method acquires this prior ✓ over rewards in the task distribution p(T ) by optimizing this loss. This amounts to an extension of the MAML algorithm in Section 3.2 to the inverse reinforcement learning setting. This extension is quite challenging, because computing the MaxEnt IRL gradient requires repeatedly solving for the current maximum entropy policy and visitation frequencies, and the MAML objective requires computing derivatives through this gradient step. Next, we describe in detail how this is done. An overview of our method is also outlined in Alg. 1.
 Meta-training. The computation of the meta-gradient for the objective in Eq. 7 can be conceptually separated into two parts. First, we perform the update in Eq. 6 by computing the expected state visitations µ, which is the expected number of times an agent will visit each state. We denote this overall procedure as STATE-VISITATIONS-POLICY, and follow  Ziebart et al. (2008)  by first computing the maximum entropy optimal policy in Eq. 2 under the current r ✓ , and then approximating µ using dynamic programming. Next, we compute the state visitation distribution of the expert using a procedure which we denote as STATE-VISITATIONS-TRAJ. This can be done either empirically, by averaging the state visitation of the experts demonstrations, or by using STATE-VISITATIONS-POLICY if the true reward is available at meta-training time. This allows us to recover the IRL gradient according to Eq. 5, which we can then apply to compute T according to Eq. 6. Second, we need to differentiate through this update to compute the gradient of the meta-loss in Eq. 7. Note that the meta-loss itself is the IRL loss evaluated with a different set of test demonstrations. We follow the same procedure as above to evaluate the gradient of L T ,test IRL with respect to the post-update parameters T , and then apply the chain rule to compute the meta-gradient: r ✓ L test T (✓) = @ @✓ (✓ ↵r ✓ L tr T (✓)) @r T @ T @L test T @r T = I ↵ @ 2 L tr T (✓) @✓ 2 ↵ @ r ✓ @ ✓ D @ r ✓ @ ✓ > ! @r T @ T @L test T @r T (8) where on the second line we differentiate through the MaxEnt-IRL update, and we define the |S||A|-dimensional diagonal matrix D as  D := diag ⇢ @ @ r ✓,i (E ⌧ [µ ⌧ ]) i |S||A| i=1 ! . a 1 a 2 s 1 s 2 . . . . . . (⌧ ) = 1 Z Q T t=1 r( T , st, at) dyn(st+1, st, at) (above) where we learn a prior over T , which during meta-test is used for MAP inference over new expert demonstrations. A detailed derivation of this expression is provided in the supplementary Appendix E. Meta-testing. Once we have acquired the meta-trained parameters ✓ that encode a prior over p(T ), we can leverage this prior to enable fast, few-shot IRL of novel tasks in {T j ; j = 1..M }. For each task, we first compute the state visitations from the available set of demonstrations for that task. Next, we use these state visitations to compute the gradient, which is the same as the inner loss gradient computation of the meta-training loop in Alg. 1. We apply this gradient to adapt the parameters ✓ to the new task. Even if the model was trained with only one inner gradient steps, we found in practice that it was beneficial to take substantially more gradient steps during meta-testing; performance continued to improve with up to 20 steps.
 Connection to Learning a Prior over Intent The objective in Eq. 6 optimizes for parameters that enable the reward function to generalize efficiently on a wide range of tasks. Intuitively, constraining the space of reward functions to lie within a few steps of gradient descent can be interpreted as expressing a "locality" prior over reward function parameters. This intuition can be made more concrete by the following analysis. By viewing IRL as maximum likelihood estimation in a particular graphical model (Fig.  2 ), we can take the perspective of  Grant et al. (2018)  who showed that for a linear model, fast adaptation via a few steps of gradient descent in MAML is performing MAP inference over , under a Gaussian prior with the mean ✓ and a covariance that depends on the step size, number of steps and hessian of the loss. This is based on the connection between early stopping and regularization previously discussed in  Santos (1996) , which we refer the readers to for a more detailed discussion. The interpretation of MAML as imposing a Gaussian prior on the parameters is exact in the case of a likelihood that is quadratic in the parameters (such as the log-likelihood of a Gaussian in terms of its mean). For any non-quadratic likelihood, this is an approximation in a local neighborhood around ✓ (i.e. up to convex quadratic approximation). In the case of complex parameterizations, such as deep function approximators, this is a coarse approximation and unlikely to be the mode of a posterior. However, we can still frame the effect of early stopping and initialization as serving as a prior in a similar way as prior work  (Sjöberg & Ljung, 1995; Duvenaud et al., 2016; Grant et al., 2018) . More importantly, this interpretation hints at future extensions to our approach that could benefit from employing more fully Bayesian approaches to reward and goal inference.
 Experiments Our evaluation seeks to answer two questions. First, we aim to test our core hypothesis that using prior task experience enables reward learning for new tasks with just a few demonstrations. Second, we compare our method with alternative approaches that make use of multi-task experience. We test our core hypothesis by comparing learning performance on a new tasks starting from the initialization produced by MandRIL with learning a separate model for every task starting either from a random initialization or from an initialization obtained by supervised pre-training. We refer to these approaches as learning "FROM SCRATCH" and "AVERAGE GRADIENT" pretraining respectively. Our supervised pre-training baseline follows the average gradient during meta-training tasks and finetunes at meta-test time (as discussed in Section 4). Unlike our method, supervised pre-training does not optimize for a model that performs well under fine tuning, but does use the same prior data to pre-train. We additionally compare to pre-training on a single task as well as all the meta-training tasks. To our knowledge, there is no prior work that addresses the specific meta-inverse reinforcement learning problem introduced in this paper. Thus, to provide a point of comparison and calibrate the difficulty of the tasks, we adapt two alternative black-box meta-learning methods to the IRL setting. The comparisons to both of the black-box methods described below evaluate the importance of incorporating the IRL gradient into the meta-learning process, rather than learning the adaptation process entirely from scratch. Demo conditional model: Our method implicitly conditions on the demonstrations through the gradient update. In principle, a conditional deep model with sufficient capacity could implicitly implement a similar learning rule. Thus, we consider a conditional model (often referred to as a "contextual model"  (Finn et al., 2017b) ), which receives the demonstration as an additional input. Recurrent meta-learner: We additionally compare to an RNN-based meta-learner  (Santoro et al., 2016; Duan et al., 2017) . Specifically, we implement a conditional model by feeding both images and sequences of states visited by the demonstrations to an LSTM. When learning a task, the agent has access to the image (left) and demonstrations (red arrows). To evaluate learning (right), the agent is tested for its ability to recover the reward for the task when the objects have been rearranged. The reward structure we wish to capture can be illustrated by considering the initial state in blue. An policy acting optimally under a correctly inferred reward should interpret the other objects as obstacles, and prefer a path on dirt. We consider two environments: (1) an image-based navigation task with an aerial viewpoint, (2) a first-person navigation task in a simulated home environment with object interaction. We describe here the environments and evaluation protocol and provide detailed experimental settings and hyperparameters for both domains in Appendices A and B. (1) SpriteWorld navigation domain. Since most prior IRL work (and multi-task IRL work) studied settings where linear reward function approximators suffice (i.e., lowdimensional state spaces and hand-designed features), we design an experiment that is significantly more challengingthat requires learning rewards on raw pixels. We consider a navigation problem where we must learn a convolutional neural network that directly maps image pixels to rewards. We introduce a family of tasks called "SpriteWorld." Some example tasks are shown in Fig.  3 . Tasks involve navigating to goal objects while exhibiting preference over terrain types (e.g., the agent prefers to traverse dirt tiles over traversing grass tiles). At meta-test time, we provide one or a few demonstrations in a single training environment and evaluate the reward learned using these demonstrations in a new, test environment that contains the same objects as the training environment, but arranged differently. Evaluating in a new test environment is critical to measure that, after adapting to the training environment from a few demonstrations, the reward learned the correct visual cues, rather than simply memorizing the demonstration trajectory. We generate unique tasks in this domain as follows. First, we randomly choose a set of three sprites from one hundred sprites from the original game (creating a total of 161,700 unique tasks). We randomly place these three sprites within a randomly generated terrain tiling; we designate one of the sprites to be the goal landmark of the navigation task. The other two objects are treated as obstacles for which the agent incurs a large negative reward for not avoiding. In each task, we optimize our model on a training world and generalization in a test world, as described below. The agent must complete either a "NAV" task (blue line) where the goal is to navigate from the start to the cup or a "PICK" task (blue + green line) where the agent must also bring the cup to the bed. The agent's observation is a panoramic first-person viewpoint (see bottom left for RGB). Following the convention in prior work  (Fu et al., 2019) , we provide to the reward function the corresponding semantic images (bottom right). These images are 32 ⇥ 24 containing 61 channels corresponding to each object class. (2) SUNCG navigation domain: In addition to the SpriteWorld domain, we evaluate our approach on a first person image-based navigation task in an indoor house environment where the agent must interact with objects. We use an environment built on top of the SUNCG dataset  (Song et al., 2017)  which has previously been used in the context of IRL  (Fu et al., 2019)  with language instructions. We follow a similar task setup as  Fu et al. (2019) , although we omit the language instructions. In this domain, we consider tasks that can be categorized into two types.
 Navigation (NAV): In this task, the agent must navigate to a location in the house that corresponds either to a target object or location. For example, in the blue line of Fig.  4 , the agent must navigate to the "cup" object. Pick-and-place (PICK): In this more difficult task, the agent moves an object between two locations. For example, in Fig  4 , the agent must navigate to the "cup", perform a pick action and then navigate to the "bedroom". Evaluation protocol: We evaluate on held-out tasks that were unseen during meta-training. In the SpriteWorld domain, we consider two settings: (1) tasks involving new combinations and placements of sprites, with sprites that were present during meta-training, and (2) tasks with combinations of unseen sprites which we refer to as "out of domain objects." For each task, we generate one environment (a set of sprite positions) along with demonstrations for adapting the reward, and generate a second environment (with new sprite positions) for evaluating the adapted reward. In the SUNCG domain, we similarly evaluate on both novel combinations of objects and locations. We follow the evaluation protocol of  Fu et al. (2019)  and evaluate on "TEST" tasks which consist of tasks within the same houses as training, but with novel combinations of objects and locations. In addition, we evaluate on environments which consists of new houses not in the training set. We refer to these as "UNSEEN-HOUSES." This evaluation adds complexity by testing the models ability to successfully infer rewards in an entirely new scene. In total, the dataset consists of 1413 tasks (716 PICK, 697 NAV). The meta-train set is composed of 1004 tasks, the "TEST" set contains 236 tasks, and the "UNSEEN-HOUSES" set contains 173 tasks. Evaluation Metrics. We measure performance using the expected value difference, which measures the suboptimality of a policy learned under the learned reward; this is a performance metric used in prior IRL work  (Levine et al., 2011; Wulfmeier et al., 2015) . The metric is computed by taking the difference between the value of the optimal policy under the learned reward and the value of the optimal policy under the true reward. On the SUNCG domain, we follow  Fu et al. (2019)  and report the success rate of the optimal policy under the learned reward function. . We find that pre-training on the full set of tasks leads to negative transfer, while pre-training on a single task is comparable to random initialization. ManDRIL outperforms both alternative initialization approaches, which shows that optimizing for initial weights for fine-tuning robustly improves performance. Shaded regions show 95% confidence intervals. Results. The results for SpriteWorld are shown in Fig.  6 , which illustrate test performance with in-distribution and out-of-distribution sprites. Our approach, MandRIL, achieves consistently better performance in both settings. Most significantly, our approach performs well even with single-digit numbers of demonstrations. By comparison, alternative meta-learning methods generally overfit considerably, attaining good training performance (see Appendix. C for curves) but poor test performance. Learning the reward function from scratch is in fact the most competitive baseline -as the number of demonstrations increases, simply training the reward function from scratch on the new task is the only method that matches the performance of MandRIL when provided 20 or more demonstrations. With only a few demonstrations however, MandRIL has substantially lower value difference. It is worth noting the performance of MandRIL on the out of distribution test setting (Fig.  6 , bottom): although the evaluation is on new sprites, Man-dRIL is still able to adapt via gradient descent and exceed the performance all other methods. In both domains, we perform a comparison to representations finetuned from a supervised pre-training phase in Fig.  6  and Table  5 . We compare against an approach that follows the mean gradient across the tasks at meta-training time and is fine-tuned at meta-test time which we find consistently leads to negative transfer. We conclude that fine tuning reward functions learned in this manner is not an effective way of using prior task information. In contrast, we find that our approach, which explicitly optimizes for initial weights for fine-tuning, robustly improves performance on all task types and test settings. By visualizing the value under the learned reward function (see Fig.  5 ), we see that even with a small number of gradient steps, the reward function can be effectively adapted to an unseen home layout. Note that the SUNCG task is substantially more challenging, requiring the reward function to interpret first-person images. Indeed, the pretrained MaxEntIRL algorithm that does not use meta-learning exhibits negative transfer, as illustrated by the lower performance of this method on all tasks as compared to the learning "FROM SCRATCH" version, which learns each task entirely from random initialization. Training from scratch is a strong baseline here, because the method still sees every single first-person image in the house -2257.7 images on average. This provides sufficient variety to learn effective visual features in many cases. Nonetheless, our method (last row in Table  1 ) produces a substantial improvement, especially on the much harder "PICK" task, demonstrating that meta-learning can produce positive transfer even when pre-training does not.
 Conclusion In this work, we present an approach that enables few-shot learning of reward functions. We achieve this through a novel formulation of IRL that learns to encode common structure across tasks. Using our meta-IRL approach, we show that we can leverage data from previous tasks to effectively learn reward functions from raw pixel observations for new tasks, from only a handful of demonstrations. Our work paves the way for future work that considers unknown dynamics, or work that employs more fully probabilistic approaches to reward and goal inference. Algorithm 1 1 Meta Reward and Intention Learning (Man- dRIL)    1: Input: Set of meta-training tasks {T } meta-train 2: Input: hyperparameters ↵, 3: function MAXENTIRL-GRAD(r ✓ , T , D)
 Figure 2 . 2 Figure2. Our approach can be understood as approximately learning a distribution over the demonstrations ⌧ , in the factor graph p(⌧ ) = 1
 Figure 3 . 3 Figure 3. An example task on the SpriteWorld domain. When learning a task, the agent has access to the image (left) and demonstrations (red arrows).To evaluate learning (right), the agent is tested for its ability to recover the reward for the task when the objects have been rearranged. The reward structure we wish to capture can be illustrated by considering the initial state in blue. An policy acting optimally under a correctly inferred reward should interpret the other objects as obstacles, and prefer a path on dirt.
 Figure 4 . 4 Figure 4. An example task in the SUNCG environment (top).The agent must complete either a "NAV" task (blue line) where the goal is to navigate from the start to the cup or a "PICK" task (blue + green line) where the agent must also bring the cup to the bed. The agent's observation is a panoramic first-person viewpoint (see bottom left for RGB). Following the convention in prior work (Fu et al., 2019) , we provide to the reward function the corresponding semantic images (bottom right). These images are 32 ⇥ 24 containing 61 channels corresponding to each object class.
 Figure 5 . 5 Figure 5. An example adaptation in an UNSEEN-HOUSE (best viewed in color). The agent starts in one room (blue square) and is required to pick up the vase (green square) and take it to the living room (red square). The value function (blue is high, red is low) under the learned reward (bottom) exhibits no "PICK" task structure pre-adaptation (bottom left-column). Post-adaptation (bottom right-column), the reward function successfully leads the agent to the vase (bottom figure, top-right plot) and after the pick action (bottom figure, bottom-right plot) is performed, navigates the agent to the goal location.
 Figure 6 . 6 Figure6. Meta-test performance on the SpriteWorld domain (lower is better): held-out tasks performance (top) and held-out tasks with novel sprites (bottom). The recurrent meta-learner has a value difference > 60 in both test settings. In both test settings, Man-dRIL achieves comparable performance to the training environment, while the other methods overfit until they receive at least 10 demonstrations (see Appendix C for training environment performance). We find that pre-training on the full set of tasks leads to negative transfer, while pre-training on a single task is comparable to random initialization. ManDRIL outperforms both alternative initialization approaches, which shows that optimizing for initial weights for fine-tuning robustly improves performance. Shaded regions show 95% confidence intervals.
 Table 1 . 1 Success rate (%) on heldout tasks with 5 demonstrations. ManDRIL achieves consistently better performance on all task/environment types. Results are averaged over 3 random seeds. METHOD TEST PICK NAV TOTAL PICK NAV TOTAL UNSEEN HOUSES BEHAVIORAL CLONING 0.4 8.2 4.3 3.7 12.0 9.4 MAXENT IRL (AVG GRADIENT) 37.3 83.7 60.8 38.3 89.7 73.3 MAXENT IRL (FROM SCRATCH) 42.4 87.9 65.4 48.1 89.9 76.5 MANDRIL(OURS) 52.3 90.7 77.3 56.3 91.0 82.6 MANDRIL (PRE-ADAPTATION) 6.0 35.3 20.7 4.3 34.6 25.3
			 Department of Electrical Engineering and Computer Science, University of California, Berkeley, USA. Correspondence to: Kelvin Xu <kelvinxu@berkeley.edu>.

Abstract: A significant challenge for the practical application of reinforcement learning to real world problems is the need to specify an oracle reward function that correctly defines a task. Inverse reinforcement learning (IRL) seeks to avoid this challenge by instead inferring a reward function from expert demonstrations. While appealing, it can be impractically expensive to collect datasets of demonstrations that cover the variation common in the real world (e.g. opening any type of door). Thus in practice, IRL must commonly be performed with only a limited set of demonstrations where it can be exceedingly difficult to unambiguously recover a reward function. In this work, we exploit the insight that demonstrations from other tasks can be used to constrain the set of possible reward functions by learning a "prior" that is specifically optimized for the ability to infer expressive reward functions from limited numbers of demonstrations. We demonstrate that our method can efficiently recover rewards from images for novel tasks and provide intuition as to how our approach is analogous to learning a prior.