{'fraction_non_alphanumeric': 0.027363940407418668, 'fraction_numerical': 0.008563899868247694, 'mean_word_length': 4.725268349289237, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, '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}}
Fast Task-Adaptation for Tasks Labeled Using Natural Language in Reinforcement Learning

Over its lifetime, a reinforcement learning agent is often tasked with different tasks. How to efficiently adapt a previously learned control policy from one task to another, remains an open research question. In this paper, we investigate how instructions formulated in natural language can enable faster and more effective task adaptation. This can serve as the basis for developing language instructed skills, which can be used in a lifelong learning setting. Our method is capable of assessing, given a set of developed base control policies, which policy will adapt best to a new unseen task.


Introduction
Reinforcement Learning (RL) solves sequential decision making problems by utilizing a trial-anderror approach guided by a reward signal. RL has achieved tremendous successes, especially in beating humans in games (Silver et al., 2018;Jaderberg et al., 2019) and robotics (Levine et al., 2016). However, RL also suffers form various open problems, such as its sample inefficiency. This sample inefficiency is often caused by reward function-specification. A sparse and delayed reward signal makes it difficult for the agent to experience, and learn from, meaningful reward signals.
Designing tasks suitable to solve with RL algorithms is often challenging (Ng et al., 1999), and mostly involves designing a task-specific reward function. A recent line of research, surveyed by Luketina et al. (2019), has proposed methods that allow task descriptions to be specified using natural language. However, such methods (Chevalier-Boisvert et al., 2018) have proven to still be very sample inefficient, requiring the usage of up to 50 GPUs during weeks in order to learn relatively simple tasks.
One promising approach includes Jiang et al. (2019), which proposed to tackle this sample inefficiency by decomposing the problem into an hierarchical structure, guided by the compositional nature of natural language.
Humans follow a similar strategy, and when confronted with a new problem, humans are generally capable of forming intuitive theories about how to tackle the problem at hand. These intuitive theories often consist of sequences of high-level actions (e.g. first go to store x, then stop for gas before driving home). An interesting approach to make RL more sample efficient, would be to combine high level human intuitive theories, expressed using natural language, and low-level automated trial and error learning.
An essential part of such a symbiosis is the ability of an agent to quickly adapt from one task to a similar task. A human does not need to learn each individual task from scratch, but has a set of base strategies from which a new strategy can be quickly formed.
Current algorithms capable of quickly adapting their control policies to solve related tasks, mostly rely on intensive training using a diverse set of tasks, often guided by a curriculum of increasingly more difficult and diverse tasks (Bengio et al., 2009).
In this paper, we take a different approach and examine if we can facilitate fast task adaptation by utilizing semantic meaning from task descriptions formulated in natural language. Our method is capable of, given a set of pre-trained control policies, and a new previously unseen task, making a decision about which previously developed control policy will adapt best, in order to solve a new previously unseen task, solely from its instruction.
In the following sections of this paper, we first briefly review key research related to ours (Section 2). Section 3 contains a description of the environment, and tasks we use to demonstrate our method. In Section 4 we describe the proposed method. Section 5 demonstrates experimentally how well our method is capable of performing task-adaptation in a simple environment.

Related work
Our proposed method can be situated on the intersection of transfer learning and natural language usage in RL. In this section, we first briefly review how our method relates to key research in transfer learning in RL, how natural language has been used in RL, and what research has been conducted on this intersection.
Transfer learning in reinforcement learning Utilizing knowledge gained from learning one task to another task has been a widely studied field. The goal of this field is to make RL more sample efficient (Konidaris, 2006;Taylor and Stone, 2009). Common approaches include to train the agent on multiple tasks (Hessel et al., 2019), or to construct parameterized policies (Schaul et al., 2015;Andreas et al., 2017;Oh et al., 2017), which can be configured to perform new tasks. An alternative approach consists of learning inter-task mappings (Taylor, 2007), based on task similarities. Our method similarly is capable of detecting task similarities, using additional information captured in task descriptions.
Language instructions in reinforcement learning Recent advances in RL, surveyed by Luketina et al. (2019), have demonstrated the usage of natural language in order to build models capable of capturing domain knowledge.
A commonly used approach consists of directly embedding both visual observation and language instruction in order to train a control policy (Hermann et al., 2017;Misra et al., 2017;Chevalier-Boisvert et al., 2018). Alternatively, Goyal et al. (2019) uses natural language reward shaping, by predicting if an action in a trajectory matches a task description. Jiang et al. (2019) explores the compositional structure of natural language in order to train a hierarchical algorithm, capable of discovering abstractions that generalize over different sub-tasks using language instructions. However, current approaches commonly heavily depend on large amounts of human labeled data and handdesigned policies. In this context, our method can reduce the dependency on expensive human labeling by providing fast task-adaptation.
Transfer learning guided by language in reinforcement learning Co-Reyes et al. (2019) proposed a meta-learning algorithm capable of utilizing corrective instructions formulated in natural langue in order to facilitate task-adaptation.
Most similar to our research, is the work done by Narasimhan et al. (2018), which includes a way to use entity descriptions in natural language as a layer of abstraction, in order to facilitate transfer of an RL-policy, to a new environment.

BabyAI environment
Environment In order to demonstrate the capabilities of our method, we make use of the BabyAI environment proposed by Chevalier-Boisvert et al. (2018). In this environment, the agent is tasked with completing various tasks in a 2D gridworld. The environment supports multiple rooms, but for our preliminary experiments, we only consider a single room, and use the goto and pickup tasks. The task the agent is charged with, is described using a synthetic baby language. The pixels of the screen, together with this instruction, form the observation of the agent. The environment supports partial observability of the state. However for our experiments we use the fully observable configuration. The action-space we consider for our experiments consists of moving forward, turning left/right, object-pickup/drop, opening doors, and a finish action. Notice that in order to solve the goto and pickup tasks, only a subset of the action-space is required.
In this environment, the reward-signal is only sparsely observed, as the agent only receives a reward upon task completion. A few example tasks are presented in Figure 1.

Goto the yellow key
Pickup the blue box Pickup the green ball Goto the red key Vocabulary The instructions used in the BabyAI environment are all generated using the proposed Baby Language. This language consists of a small vocabulary, but can be used combinatorially to express a relatively rich set of different tasks.
Instructions we use in our transfer experiments follow the same verb, object color, object pattern (e.g. pickup the yellow box). The following words make up the vocabulary used in our experiments: • Verbs: pickup, goto • Objects: box, key, ball • Colors: blue, red, green, yellow In total, this allows us to express 24 different tasks. While the BabyAI platform is a great platform to demonstrate the qualities of our method, our method is not environment-specific, and we plan to extend this research to multiple environments.

Method
The main idea of our approach is to utilize a limited set of pre-trained base control policies. When confronted with a new task, described using natural language (the transfer instruction), the best base policy is selected and the new task is learned based on this base policy.
As such our method consists of two parts: the first part is a pre-training step, while the second part deals with the effective task-adaptation. A pseudo-code summary of our method can be found below in Algorithm 1.
Algorithm 1: Summary of our task-adaptation method 1 α: k instructions sampled from the set of possible instructions Z 2 β: p instructions sampled from the set of possible instructions Z 3 foreach instruction z i ∈ α do 4 Train base policy π i until convergence 5 foreach instruction z j ∈ β do 6 Sample task-adaptation during n training steps, from base policy π i (with instruction z i ) to task z j 7 end 8 end 9 Train the transfer model

Pre-training base control policies
In this pre-training phase, we first train a set of k base control policies {π 0 , ..., π k }. A control policy π i (s t ) determines the action a an agent takes, based on the state s t the agent resides in.
Each base control policy should reliably be able to perform one instruction z i . This task instruction is expressed in natural language (e.g. go to the blue ball or pickup the yellow key). Training base control policies can be done using any RL algorithm. In this preliminary research, the set of possible instructions Z is limited. This is due to the fixed vocabulary described in Section 3. The amount of pre-trained control policies should be sufficiently large, but smaller than the entire set of possible instructions (k |Z|).
For a base control policy to facilitate efficient task-adaptation, it is beneficial to make slight adaptations to the environment. An example of such variations includes spawning the agent in a different position after each iteration.
Our method can be used with a fixed number of base control policies, which are trained during a single pre-training phase. However, our method can also be extended to work in an iterative fashion.
In this iterative approach, the agent starts with a small set of k pre-trained base control policies. When confronted with a new task, our method is used to determine the best base control policy to facilitate task-adaptation (e.g. π i ). After training the new policy π j by adapting the selected base control policy π i , the new policy π j can be added to the set of base control policies. This will allow executing more efficient task-adaptations, as more base control policies become available.
In the proposed method, we select k instructions {z 0 , ..., z k } to train base control policies {π 0 , ..., π k }, from a uniform random distribution. However, an interesting extension to this method might be to select base control policies based on a more advanced selection objective. For example, maximizing distance between the task instructions (in a language-embedding).

Sampling task-adaptations
The second phase of our method consists of utilizing the developed base control policies in order to sample a limited number of task adaptations. A single task adaptation sample π i , z j consists of taking a fully developed base control policy π i , and using it to perform a new instruction z j , different from the one it was trained on. An example of such a sample would include to start from a policy trained on an instruction go to the yellow box, and ask it to perform a different task, such as pickup the yellow box.
A task-adaptation from one policy to a new one is done by loading the parameters of the base policy as the initialization of the new policy we want to develop. Training can be performed using any RL-algorithm. During this sampling phase the policy does not need to converge. Training only needs to happen for a limited number of n steps. This amount of required steps is significantly lower than fully developing the policy. After the sampled task adaptation has been executed for n-steps, we measure the performance. This can be done by, for example, calculating the success rate of the agent satisfying the instruction over the last 100 iterations. Table 1 contains a few examples of this sampling process.

Base control policy instruction Transfer instruction Measured performance
Pickup the red ball Goto the green key 0.91 Pickup the red ball Goto the red ball 0.76 Goto the yellow box Goto the green key 0.86 Goto the yellow box Goto the red ball 0.86 Table 1: Example task-adaptation sampling results (k = 2 base policies, p = 2 transfer instructions). The measured performance is calculated as the success rate of the 100 last episodes, after n training steps. Displayed task performance is exemplary.
For each base control policy, we randomly select p different tasks from Z to sample task adaptation. So in summary, our method requires running k × p task adaptation samples, each consisting of n training steps. Similarly to the selection of the base control policies, we leave a more advanced sampling strategy as future work.
This sampling method allows the generation of a dataset that can be used to generalize expected task adaptation over unseen tasks. Furthermore, the resulting policies, which were partially developed during the sampled task adaptations, could be used by the agent to further develop, when tasked with the linked instruction.

Training the transfer-model
In the next stage of our method, we train a binary classification model f (z x , z i , z j ) → {1, 0} in order to generalize the perceived task adaptation.
The input of the proposed model consists of a concatenation of the sampled transfer instruction z x , combined with the instructions attached to two sampled base policies (z i and z j ). The output of the model consists of a single binary output. This output is trained to be positive, if the first base policy with instruction z i performed better during transfer sampling than the second base policy with instruction z j . An example dataset is presented in Table 2 Instruction z x Transfer instruction z i Transfer instruction z j Class Goto the green key Pickup the red ball Goto the yellow box 1 Goto the red ball Pickup the red ball Goto the yellow box 0 Best adaptation base-policy Figure 2: The high level transfer-model architecture. The input consists of a concatenation of the transfer instruction z x , and instructions z i , z j linked to two base policies. A language-embedding layer is used in order to learn a task specific language-embedding. This layer is followed by a set of fully connected layers which finally output a binary variable.
In order to work directly with instructions in natural language, a language embedding is used. This embedding is trained end-to-end, and thus is specifically trained to encode instructions based on their transfer capabilities.

Transfer-model usage
The resulting transfer-model can be used when the agent is confronted with a new task, it currently has no developed base control policy for. Given a set of labeled base policies, and a task instruction, the various possibilities can be tested in order to make an assessment about which base policy will result in the fastest task-adaptation.

Task-adaptation in the BabyAI environment
In order to find out whether patterns can be discovered in task adaptations using instructions expressed using natural language, we performed a large set of transfer experiments in the BabyAI environment.
In this experiments, we wanted to find out which parts of the instructions (verb, object, color) matter in making efficient task adaptation decisions.
The results of this experiment are summarized in Figure 3, 4 and 5. Each of these plots shows results averaged over 636 task adaptations. The green line represents performance when training a policy from scratch, while the blue line shows transfer performance averaged over all performed transfer experiments.
We see some clear patterns. The verb seems to be the most important part of the task instruction. For example, when confronted with a new task which has a goto verb, base control policies which are also trained on a goto instruction seem to transfer best. This is an expected result, as the verb-part of the instruction, also determines the required set of primitive actions to solve the task.

Transfer model
As experimentally demonstrated in the previous experiment, various parts of task instructions have a different impact on the task adaptation performance.
In this second experiment we trained different amounts k of randomly sampled base control policies. While training can be done using any RL algorithm, we used DQN  in our experiments. Training a base control policy is done using at least 1 million steps, and ends when the policy achieves a success rate of at least 95%, measured on the previous 100 iterations. The full set of used training hyperparameters is described in Appendix A.
After developing k different base control policies, we sampled p task adaptations for each base control policy. The results gathered from these task adaptations were used to train the transfer model.
In table 3, we show performance of our model when using various numbers of base control policies (k), and different numbers of task adaptation samples (p). We measure model accuracy over a holdout-set consisting of all possible expressible task-adaptations not seen during sampling.  Table 3: Accuracy of the binary task adaptation classifier model. The different rows represent the various amount of base control policies used during training, the columns represent the amount of task adaptations sampled for each base control policy. Results are averaged over 5 runs.
Our preliminary results show that even with a limited number of base control policies, and sampled task adaptations, a transfer model can be developed. There is still room for improvement regarding the accuracy of the model, however the stochastic nature of RL makes task transfer inherently noisy.
However the increased sample efficiency, due to efficient task-adaptation provided by our method, is a quintessential building block, in a lifelong learning setting (Silver et al., 2013).     6 Discussion and future work In this paper, we presented a method capable of predicting, given a set of base control policies, which of these base control policies will adapt the fastest to a new previously unseen task. In order to make assessments about task adaptation, our method uses a for this task specifically trained language embedding on the task instructions.
Our preliminary results show that a binary classification approach can make assessments about task-adaptation by utilizing semantic meaning of task instructions formatted in natural language. When confronted with an expanding set of tasks in a lifelong-learning setting, our method has the potential to vastly improve sample efficiency.
However, our method still relies on a set of randomly selected base control policies, and task transfer samples. Future research could optimize our method by introducing an iterative sampling method based on a more advanced selection criterion such as instruction diversity. Another interesting extension to our method includes the usage of an open vocabulary.