# Colour versus Shape Goal Misgeneralization in Reinforcement Learning: A Case Study

TL;DR
-----

Different misgeneralized goals can appear based on training random seed alone, including outliers on a scale of 1 in 500.

Abstract
--------

> We explore colour versus shape goal misgeneralization originally demonstrated  
> by [Di Langosco et al. (2022)](https://arxiv.org/abs/2105.14111) in the Procgen Maze environment, where, given  
> an ambiguous choice, the agents seem to prefer generalization based on colour  
> rather than shape. After training over 1,000 agents in a simplified version of the  
> environment and evaluating them on over 10 million episodes, we conclude that the  
> behaviour can be attributed to the agents learning to detect the goal object through  
> a specific colour channel. This choice is arbitrary. Additionally, we show how,  
> due to underspecification, the preferences can change when retraining the agents  
> using exactly the same procedure except for using a different random seed for the  
> training run. Finally, we demonstrate the existence of outliers in out-of-distribution  
> behaviour based on training random seed alone.

For full details see the paper. This post is a version with less text, more visuals and a bit of extra content.

What is goal misgeneralization?
-------------------------------

Let's say you train an agent to reach a yellow line from pixels:

![](https://lh7-us.googleusercontent.com/6yevI5KyS3lo6yqpNPxNxv7dZOcD_rU9gXjYIODACgZq4gi1CK9Go0dYy9gbOV-C9tIeZNQtN2cp8I4bXF8H_UELHDoZhj0Qdhf9XxEuXtDko2v5oEl36zbi61yQajDjSuBmkXZsOU3pYFiYNAm88ydTog=s2048)

After training, you let it choose between a red line and a yellow gem. Which will it pick?

![](https://lh7-us.googleusercontent.com/H_BryQcWJWADtel3uC1l_Wqthuot3vYabroASQb-5lj4FwnYnjZNfoucf1lEQWJjAXOcPiDzYM8ZOq6fSeqUllP294Xip_7fk3R5iLSdN2CCFiiFNVRcFKXHsiUYnYIkVibOe7Oc7YiaCE5_k-0MIDolPQ=s2048)

Spoilers ahead!

![](https://lh7-us.googleusercontent.com/crNVX1Cq52HgEvF8Fr2rLMGgmlfH7iSqp7X6hKsNW0tSEsUBWxrjyIdmijyJUXhkPJ7Xh1xs1FKiAonQHBEmjjA5KPHkreg0AOmLZrzCaN3UOreJnA8mtSWDOdjTZGCFmDQhlCeMcRO1NpeYxTcvU5QExg=s2048)

It capably picks the yellow gem. If the designer intended the goal to be based on shape and not colour, goal misgeneralization occurred.

Measuring preferences and capabilities
--------------------------------------

The above agent reaches the yellow gem first 81% of the time and takes 4 steps on average. We will call these two numbers "preferences" and "capabilities". Goal misgeneralization requires intact capabilities and unintended goal preferences.

Retraining 100 times
--------------------

Let's retrain the agent 100 times with different random seeds[^vcqmhgf7e3m] and test each one in the same red line versus yellow gem experiment.

![](https://lh7-us.googleusercontent.com/CgnKGFtqcFgOAPR-v4FLgwNRxSinPmBqH0R3kuOerMm6T7pCoBVQ97ZfSEyPi9ugABJWCqp2c773PQqqT5NJC71Ejq2TOMyWnbBSrUml_VrYq-iYl-qLPuzPO8Ux7z_Er5DYGR6mjokdSE5v0TeS-AGgEw=s2048)

Each dot is an agent with corresponding preferences and capabilities. Most agents capably reach for the yellow gem. A few don't care and pick 50/50.

Changing objects
----------------

Why test on the red line though? Let's try a green line versus a yellow gem instead.

![](https://lh7-us.googleusercontent.com/9SfMqtxWauMlSH-0owLuYIyAbfCpWj6oW3VVIZcSRISt32ySXOC_iYpT59VB8Gk9vV8SHdHbFUjaiy7cZuBPxUhhmTzB0ZfVe90ptKpNbP8xj01iwlqzFM36yq2Pq3fKlHaSHkete0cQpwhKyNYErL5NIA=s2048)

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/9dbf1ed0f056a11cd641e3fbc096d5e227465dba152d4997.png)

Same 100 agents, but now many prefer the green line, that is, the shape. Also, Agent-3016 (the number is the training random seed) prefers the green line, while Agent-3472 prefers the yellow gem. Both are fully capable. Different goals based on training random seed? Uh-oh...

To illustrate, here's Agent-3016 in action:

![](https://lh7-us.googleusercontent.com/3wBCYKGzJ4kjP5pvnSVf-vj2sOTrvdxVA2_7MhMbpyjoTwtbmtxHuBSX_3EcLJ1MYDWq0MCIt4w7-pD5QzH03IPOkKtQH0ChDKNEs2hRzydDti7BFlEnhdX7ucDLI3pQ_L51EEo3IbR0GCR8CBjeixfrNg=s2048)

And Agent-3472:

![](https://lh7-us.googleusercontent.com/cno8RNWVdpXZK8WAiPVnj6kfgCIZQLOC-KoctVEXoV6uz1kDUsMsFwIC1MJBvO8Eh4-x91gM5TBqm_TkTYS0yMx_Cztvh9K12iyEee6tkzNftzdUcwPppGWt0hmfu2GpcArXv4sySuF0RNGTzhGkP02bWg=s2048)

What would happen if we replaced the green line with a blue line?

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/a0f4eaa244dc7e00627a47592f925fb6058df6a4f91c03f2.png)

All agents prefer the yellow gem and some lose capabilities. Interesting.

What is causing the different behaviour distributions when we change the colour of the line?

Backgrounds
-----------

There are nine background textures and they're not evenly distributed between the red, green and blue channels:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/6ba5e9cab02554ac283212b7e48c65fde14df43fac834b71.png)

Let's try replacing the textures with black colour and train 100 new agents:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/animations/f8cd836a0f990f59888548bd302246c3c29c8e73389e4132.gif)

Evaluate them in the same three settings (red/green/blue line vs yellow gem). The top row is the previous 3 plots, bottom row is the 100 new agents:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/6bc303304ed2e90ccb61a623a0d5ac92cddf36f7bd457840.png)

The asymmetry between the red and green lines disappeared. The blue line plot shows more capability loss.

RGB colour encoding
-------------------

The pixel observations are represented as 64x64x3 matrices, that is three square 2D matrices, one for each of the red, green and blue colours. It's as if the agent has three eyes and observations from a single eye are often enough to solve the task.

Here's what the training observations look like to humans and the three channels seen by the agents:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/animations/ab7419f08e22e02be885c95b5abbbb94bf07e3a15c10deee.gif)

Same thing with black backgrounds:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/animations/eb9a5be8cc61b2a81099e7135e153405a700eef5af8b5a78.gif)

On a black background, yellow = red + green.

Here are all the line object splits into RGB both with and without textures (top line = human view):

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/dcb5a501440ee74c7fcfc6557ea8f1dc08b57ce83f057174.png)

And here are the red line versus yellow gem test environments split into RGB:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/animations/dd5bf1b9a3f23e01f71d0577bf4c75b878514f7c9cf038c7.gif)

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/animations/f7efdf56ccbf0ec0db3fa50651f2a2ae134583d756ac2a88.gif)

During training, the task was [underspecified](https://arxiv.org/abs/2011.03395) and the agents could choose an arbitrary channel through which to learn it. Did the agents that chose the green channel turn out to be the ones that prefer the yellow gem? We ran a simple regression to find out:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/d6a200062b015682241ba639064872a0e9976bcd9bcef512.png)

Agents that prefer the green line over the yellow gem are often the same ones that prefer the green line over the red line. But it's not the whole story, especially when you consider agents like the one closest to the bottom right - its preferences are green line over red line over yellow gem.

Music metaphor
--------------

A nice metaphor to illustrate this is music, where what we call "sound" is waves between 20 and 20,000 Hz, while visible light is waves between 400 and 700 THz. If notes C and E are played on the piano at the same time, a human hears both of them, instead of hearing note D. If note C represents red and note E represents green, D will represent yellow. Humans can't even distinguish monochromatic yellow from yellow produced by mixing red and green light rays, while the agents only see yellow as red and green.

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/49427b3a88a1d3e9e5e100f226b81b07aac7e9b287526612.png)

Uhhh, no [Chatty](https://youtu.be/U9mJuUkhUzk?t=229), don't use DALL-E for that... Just write a Python script to make the image, please.

...

(too many prompts later)

...

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/091b232e3d0ac5b4dc0fbe396bb67be6802a032fdc956945.png)

Outliers
--------

After noticing some outliers in the previous plots we decided to train 500+ agents to reach a white line on a black background. White is red + green + blue, so now there are more arbitrary options to choose from for learning.

![](https://lh7-us.googleusercontent.com/KAPiTpvsIn77MBkW0n6vOn7HKMkjbDVYj-ahO5o2Ulh3FO4fQuaK2OFdKb3K96A0fy89f61RIEYciaa-VSwU1rlI9P8GrCUrVD_y5aHoNz-jne2SHbNMXi0ybteX6X8K83aeIO3uFrkibZrCcf9tZD9HFw=s2048)

We evaluated them in 11 different settings, measuring preferences and capabilities, giving us a dataset of size 512x22:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/698aee3a4a41aa828274677b371e7056a217724779ade28a.png)

Using manual inspection and clustering/outlier detection algorithms helped us find around 10 various outliers in terms of behaviour. Check the paper for the full list. Here's an example:

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/ea8e72e42c3d0fc5d402e6d48772922a4a2275b021e9d168.png)

Agent-439 is the only agent out of 512 to prefer a white gem over a yellow line while retaining full capabilities. Goal misgeneralization based on bad luck? Another uh-oh...

Relevance to large models
-------------------------

Is this something that can only happen in toy models though? Perhaps. But here's some evidence that it could also happen in large models. In the [MultiBERTs](https://arxiv.org/abs/2106.16163) paper, Sellam et al. train 25 BERT models where only the random seed differs between the training runs. They then evaluate all of them on the [Winogender](https://arxiv.org/abs/1804.09301) bias correlation test (the doctor = male, nurse = female thing):

![](https://lh7-us.googleusercontent.com/3ZIP4Fr18QWpetQ35wN165A_zjjjoQ6I7KyadYiCIH356Bwh9JEr9I3RG8Z8gW9ualU57GWdPBZNeJCGZWwbEU-8aUmZxXqY9H1QqNwjcJZJJU61mX4HFulzZVdNVk49QNEqK2EuMWTsqKtVjEnGYzldYg=s2048)

source: [Sellam et al. (2021)](https://arxiv.org/abs/2106.16163)

The correlations (black bars) vary between 0.2 and 0.7, with some clear outliers. This phenomenon, called underspecification also happens in [many other domains](https://arxiv.org/abs/2011.03395). That should be enough variation in how the models learn to solve specific tasks for goal misgeneralization to appear, where the goals will vary based on the training random seed alone. So... how do we not get an unlucky roll when training the next largest model?

Conclusion
----------

I loved a review of our paper which said it could be a "microscopic examination of something irrelevant". I completely agree with it. However, I would really like to see more work of this kind. Just take some weird behaviour of some obscure model and dig in. You might just have one of those "[that's funny](https://quoteinvestigator.com/2015/03/02/eureka-funny/)" moments, you never know.

Trained models, experiment data, and code (to do training, evals, plots, videos, gifs and more) are available here: [https://github.com/KarolisRam/colour-shape-goal-misgeneralization](https://github.com/KarolisRam/colour-shape-goal-misgeneralization)

[^vcqmhgf7e3m]: The random seed impacts the neural net weight initialisation and the order of training levels.