# Equi-Tuning: Group Equivariant Fine-Tuning of Pretrained Models

Sourya Basu,1, 2, 111Work done during an internship at IBM Research Prasanna
Sattigeri,1 Karthikeyan Natesan Ramamurthy,1
Vijil Chenthamarakshan,1 Kush R. Varshney,1 Lav R. Varshney,2 Payel Das1

###### Abstract

We introduce equi-tuning, a novel fine-tuning method that transforms
(potentially non-equivariant) pretrained models into group equivariant models
while incurring minimum $L_{2}$ loss between the feature representations of
the pretrained and the equivariant models. Large pretrained models can be
equi-tuned for different groups to satisfy the needs of various downstream
tasks. Equi-tuned models benefit from both group equivariance as an inductive
bias and semantic priors from pretrained models. We provide applications of
equi-tuning on three different tasks: image classification, compositional
generalization in language, and fairness in natural language generation (NLG).
We also provide a novel group-theoretic definition for fairness in NLG. The
effectiveness of this definition is shown by testing it against a standard
empirical method of fairness in NLG. We provide experimental results for equi-
tuning using a variety of pretrained models: Alexnet, Resnet, VGG, and
Densenet for image classification; RNNs, GRUs, and LSTMs for compositional
generalization; and GPT2 for fairness in NLG. We test these models on
benchmark datasets across all considered tasks to show the generality and
effectiveness of the proposed method.

##  1 Introduction

Modern deep learning models show promising transfer-learning abilities for a
wide range of downstream tasks (Bommasani et al. 2021). Lu et al. (2021) show
that the GPT2 language model (Radford et al. 2019) can be used as a pretrained
model for various downstream tasks such as numerical computation, image
classification, and even protein folding prediction. But pretraining large
models requires immense computational and data resources. Hence, it is
essential to design effective fine-tuning algorithms that can squeeze the most
from these pretrained models.

(a) Fine-tuning

(b) Equi-tuning for the $c4$ group

Figure 1: Comparison of architectures for fine-tuning and equi-tuning for $c4$
group of $90^{\circ}$ rotations. For (a) fine-tuning, the input is passed
through the pretrained model and then through a custom layer to obtain the
output. For (b) equi-tuning, the inputs are transformed using the group action
of $c4$. These inputs are passed through the pretrained model parallelly to
obtain a list of outputs, which are transformed using inverse transformations
from the same group and passed through a custom equivariant layer to obtain
the output.

Fine-tuning leverages semantic priors from pretrained models for downstream
tasks. E.g. CNNs trained on Imagenet (Deng et al. 2009) can extract useful
features from images outside the training set and can use that ability for any
other downstream image processing task. A different method of using priors in
deep learning is via inductive biases in models such as group equivariance,
e.g. designing group equivariant architectures such as GCNNs (Cohen and
Welling 2016; Kondor and Trivedi 2018). A model is group equivariant if
transformations of its input results in a group transformation of its output.
Popular examples include CNNs themselves that are equivariant to translations
and GCNNs that are equivariant to more general symmetries such as $90^{\circ}$
rotations. Thus, fine-tuning and group equivariance leverage different kinds
of priors to improve performance in a task. But it is not obvious how to
effectively use them together in a single method. Moreover, the same
pretrained model may need to be used for downstream tasks in different target
domains.

Figure 2: Rotated input images in (a) give unpredictably changing features for
pretrained Alexnet in (b), whereas features from equi-tuned Alexnet change
equivariantly in (c).

We introduce _equi-tuning_ , a simple fine-tuning method that yields
equivariance, even if the pretrained model is not equivariant to any group
symmetry. This method solves a simple optimization problem minimizing the
distance between the features of a pretrained model and any group equivariant
model. One salient feature of equi-tuning is its generality in potential
applications. To show this, we experiment with diverse downstream tasks: image
classification, language compositionality, and fairness in natural language
generation (NLG).

For image classification, we consider classifying the Hymenoptera and CIFAR-10
datasets as downstream tasks using several pretrained models such as Alexnet,
Resnet, VGG, and Densenet.222We will use Resnet to refer to Resnet18 and VGG
to refer to VGG11 throughout this paper These pretrained models are not
naturally equivariant to groups such as the $c4$ group of $90^{\circ}$
rotations, see Fig. 2. We find that equi-tuning these models using group
symmetries such as $c4$ outperform fine-tuning.

Lake and Baroni (2018) proposed the SCAN task to benchmark the performance of
language models on compositional generalization. Standard models such as RNNs,
GRUs, and LSTMs fail miserably on this task showing their lack of
compositional generalization abilities. Later, Gordon et al. (2019) proposed a
group-equivariant language model with compositional generalization
capabilities that passes the SCAN task. But, training group equivariant
language models from scratch for different compositionality requirements can
be computationally expensive. Here, we simply equi-tune pretrained models
using suitable groups to obtain competitive results and sometimes even
outperform the group equivariant models of Gordon et al. (2019).

Several empirical studies on fairness in NLG show biases and stereotypes in
language models such as GPT2 (Zhao et al. 2017; Sheng et al. 2019; Nadeem,
Bethke, and Reddy 2021).333Throughout this work we use GPT2 to refer to the
version of the GPT2 model that has 117M parameters. But, theoretical study of
bias mitigation methods in NLG remain largely unexplored. We first provide a
group-theoretic framework for fairness in NLG. Then we introduce two different
equi-tuning methods for debiasing language models. We use the _regard
classifier_ of Sheng et al. (2019) to show that equi-tuned GPT2 reduces bias
towards various demographic groups in generated texts compared to the original
GPT2 model.

The main contributions of this paper are as follows.

  * •

§ 4 derives equi-tuning and discusses its properties.

  * •

§ 5.1 and 5.2 apply equi-tuning to image classification and compositional
generalization, respectively.

  * •

§ 5.3 first provides a group-theoretic definition of fairness in NLG. Then, it
provides two different equi-tuning methods to mitigate bias in language
models.

  * •

§ 6 provides experimental validation of equi-tuning by testing with several
pretrained models and benchmark datasets across all the aforementioned
applications.

##  2 Related Work

##### Group equivariant networks.

Group equivariant networks (Cohen and Welling 2016; Kondor and Trivedi 2018;
Ravanbakhsh, Schneider, and Poczos 2017) use equivariance as inductive priors
for efficient learning. They find applications in image classification (Cohen
and Welling 2016, 2017), graph processing (Satorras, Hoogeboom, and Welling
2021; Maron et al. 2019; Keriven and Peyré 2019), meshes and 3D point cloud
data processing (He et al. 2021; De Haan et al. 2020; Basu et al. 2022a), and
reinforcement learning (van der Pol et al. 2020; Wang et al. 2022; Basu et al.
2022b). But these methods do not leverage the recent emergence of powerful
pretrained models.

##### Transfer learning.

Transfer learning has gained popularity in deep learning because of the
availability of large pretrained models and the gains obtained from their use
(Zhuang et al. 2020; Dai et al. 2009; Zamir et al. 2018; Taylor and Stone
2009; Bengio 2012; Ruder et al. 2019). But equivariance in transfer learning
remains unexplored.

##### Compositional generalization.

SCAN is a dataset that benchmarks the performance of language models for their
compositional generalization ability (Lake and Baroni 2018). Various models
such as RNNs, GRUs, and LSTMs fail at the SCAN task (Lake and Baroni 2018).
Several methods have been proposed to solve parts of the SCAN task: group
equivariance (Gordon et al. 2019), meta learning (Lake 2019), syntactic
attention mechanism (Russin et al. 2019), and data augmentation (GECA)
(Andreas 2020). Among these, the group equivariant method of Gordon et al.
(2019) is the most systematic and achieves the best results. Also, all methods
besides GECA require complex architectures or training methods that are non
trivial to use with transfer learning. Equi-tuning, in contrast, is a
systematic method that can be used on top of pretrained models such as RNNs,
GRUs, LSTMs, transformers, etc.

##### Fairness in NLG.

Several works have shown bias in language models on the basis of gender, race,
sexual orientation, etc. (Sheng et al. 2019; Prates, Avelar, and Lamb 2020;
Henderson et al. 2018). Existing work on detecting and mitigating biases in
NLG is mainly ad hoc and lacks generality (Sun et al. 2019; Nadeem, Bethke,
and Reddy 2021; Abid, Farooqi, and Zou 2021). Moreover, Steed et al. (2022)
have shown that mitigating bias in the embedding space does not help reduce
bias for downstream tasks. In contrast, our work attempts to define fairness
using group theory, which motivates our bias mitigation methods that provide
appropriate guarantees on fairness. Recently, Yeo and Chen (2020) provided a
theoretical definition of fairness in NLG inspired by Dwork et al. (2012); the
idea is that similar prompts from different demographic groups such as “man”
and “woman” must generate similar sentences. There, defining the metric to
measure similarity is non-trivial since the metric must also preserve the
individuality of different demographic groups. In contrast, our framework does
not need any such metric and provides a direct method to preserve such
individuality while mitigating bias.

##  3 Background

Here we give a background on group equivariance, compositional generalization,
and fairness in NLG.

###  3.1 Group Equivariance

##### Groups.

A set with a binary operator, $(G,\cdot)$ is called a group if it satisfies
the axioms of a group in appendix § A.1. The _action_ of a group on a finite
set $\mathcal{X}$ is given as $\Gamma:G\times\mathcal{X}\mapsto\mathcal{X}$
that satisfies the axioms of group action in § A.4. Group actions are used to
formally describe transformations acting on a set $\mathcal{X}$, e.g.
rotations of $90^{\circ}$s is an action $\Gamma$ on a set of square images
$\mathcal{X}$. A transformation of $x\in\mathcal{X}$ by group element $g\in G$
is written as $\Gamma(g,x)$.

##### Group equivariance.

Let $\Gamma_{\mathcal{X}}$ and $\Gamma_{\mathcal{Y}}$ be the group actions of
$G$ on sets $\mathcal{X}$ and $\mathcal{Y}$ respectively. A function
$f:\mathcal{X}\mapsto\mathcal{Y}$ is called group equivariant to $G$ if
$f(\Gamma_{\mathcal{X}}(g,x))=\Gamma_{\mathcal{Y}}(g,f(x))$ for all $g\in
G,x\in\mathcal{X}$. Hence, if a neural network performing segmentation is
equivariant to the group of $90^{\circ}$ rotations ($c4$ group), then, if the
input is rotated by a multiple of $90^{\circ}$, the output also gets rotated
by the same angle.

###  3.2 Compositional Generalization

Compositionality in languages refers to the ability to understand novel
sentences by understanding and algebraically manipulating their components
(Chomsky 2009; Montague 1970). Compositionality is key to excellent human
understanding of languages, whereas it is hypothesized that neural networks do
not posses such capabilities, leading to their extreme sample inefficiency in
modeling languages (Lake et al. 2017; Lake and Baroni 2018; Loula, Baroni, and
Lake 2018; Dessì and Baroni 2019). E.g., if humans understand the meanings of
“walk”, “jump”, and “jump twice”, then they can naturally understand the
meaning of “walk twice”. But deep neural networks fail to do so, as shown by
tests on the SCAN dataset (Lake and Baroni 2018).

SCAN is a translation dataset where the inputs are commands such as “Jump
Twice” and the outputs consist of corresponding actions such as “JUMP JUMP”.
There are several data splits in SCAN that test different generalization
capabilities of a model. The two of interest to us are the Add jump task and
the Around right task. These two tasks test the compositional generalization
capabilities of models.

The training set of the Add jump task consists of sentences that do not
contain any commands containing the word “Jump” except for the word “Jump”
itself. But the training set contains other sentences with verbs that are
similar to “Jump”, such as “Walk”, “Run”, “Walk Twice”, “Run Twice”, etc. The
test set on the other hand contains complicated commands using the word “Jump”
such as “Jump Twice”, “Turn Left After Jump Twice”, etc. Thus, for a model to
perform well in the test set, it must infer the meaning of complicated
sentences such as “Jump Twice” from the understanding of “Jump” and “Walk
Twice”. Similarly, in the training set of the Around right task, the command
“Around Right” never appears, but similar commands such as “Around Left”
appear. The test set contains the phrase “Around Right” and for the model to
succeed in this task, it must infer that “Right” and “Left” are directions and
can be treated in a similar way.

###  3.3 Fairness: Mitigating Biases in NLG

As discussed in § 2, Sheng et al. (2019) show that language models such as
GPT2 exhibit biases towards certain demographic groups in their generated
texts. These biases are often subtle and are not easily detectable using
sentiment classifiers. Hence, they introduce the concept of _regard_ towards
various demographic groups and provide a task to detect bias in texts
generated by models in terms of regards. They consider three sets of
demographic groups for this task: a) [“man”, “woman”], b) [“Black”, “White”],
c) [“gay”, “straight”]. These sets correspond to gender, race, and sexual
orientation, respectively. The task consists of two types of contexts:
_respect_ and _occupation_. Each type has five context sentences, and models
generate texts for each of these sentences. The respect task tests the biases
in the model’s _respect_ towards various demographic groups, e.g. ‘The XYZ was
known for’, where XYZ is replaced by any demographic group. The occupation
task tests the bias in model’s description of occupation for different
demographic groups, e.g. ‘The XYZ worked as’, where XYZ is replaced by any
demographic group. Sheng et al. (2019) also develop an automatic regard
classifier using transfer learning on BERT using a dataset created using human
annotations. This classifier labels any generated sentence as negative,
neutral, positive, or other. This classifier is shown to match human labels of
regard for texts with around $80\%$ accuracy. We use this regard classifier in
our experiments for fairness in NLG.

##  4 Equi-Tuning

We motivate equi-tuning as a method that minimizes a distance between the
features obtained by a pretrained model and any equivariant model when the
dataset contains all the transformations from a discrete group. We show that
the solution obtained corresponds to the Reynold’s operator (Sturmfels 2008)
applied to the pretrained model, which directly implies certain universality
properties.

Let
$\mathbf{M}:\mathcal{X}\subset\mathbb{R}^{n}\mapsto\mathcal{Y}\subset\mathbb{R}^{m}$
be a pretrained model. Further, let $\Gamma_{\mathcal{X}}$ and
$\Gamma_{\mathcal{Y}}$ be group actions of the group $G$ on $\mathcal{X}$ and
$\mathcal{Y}$ respectively. We construct a model $\mathbf{M}_{G}$ that is
equivariant to actions of a finite group $G$ and also minimizes the sum of the
distances between features $\mathbf{M}(\Gamma_{\mathcal{X}}(g,x))$ and
$\mathbf{M}_{G}(\Gamma_{\mathcal{X}}(g,x))$ for any $x$, for all $g\in G$. The
idea is that $\mathbf{M}_{G}$ loses little pretrained knowledge from
$\mathbf{M}$ while also being equivariant to $G$. We assume that the group
actions are well defined, which is true for a wide range of cases including
all cases considered in this paper. Formally, for any $x\in\mathcal{X}$, we
want to solve the following optimization problem.

$\displaystyle\min_{\mathbf{M}_{G}(x)}$ $\displaystyle\sum_{g\in
G}\left\lVert\mathbf{M}(\Gamma_{\mathcal{X}}(g,x))-\mathbf{M}_{G}(\Gamma_{\mathcal{X}}(g,x))\right\rVert_{2}^{2}$
(1) s.t.
$\displaystyle\mathbf{M}_{G}(\Gamma_{\mathcal{X}}(g,x))=\Gamma_{\mathcal{Y}}(g,\mathbf{M}_{G}(x))\textrm{
for all }g\in G.$

When clear from context, we write $\Gamma_{\mathcal{X}}(g,x)$ as $gx$ and
$\Gamma_{\mathcal{Y}}(g,y)$ as $gy$, for simplicity. Now, assuming that
$\left\lVert g\right\rVert^{2}=1$, we have the optimization as

$\displaystyle\min_{\mathbf{M}_{G}(x)}$ $\displaystyle\sum_{g\in G}\left\lVert
g^{-1}\mathbf{M}(gx)-\mathbf{M}_{G}(x)\right\rVert_{2}^{2}$ (2) s.t.
$\displaystyle\mathbf{M}_{G}(gx)=g\mathbf{M}_{G}(x)\textrm{ for all }g\in G.$

To solve (2), we first remove the constraint of equivariance on
$\mathbf{M}_{G}$ and obtain a lower bound to the solution of (2). Then, we
show the obtained solution also satisfies the constraints in (2), hence, it is
also a solution to (2). Removing the equivariant constraint from (2), we
obtain the optimization problem $\min_{\mathbf{M}_{G}(x)}\sum_{g\in
G}\left\lVert g^{-1}\mathbf{M}(gx)-\mathbf{M}_{G}(x)\right\rVert_{2}^{2}$.
This is a convex problem with solution

$\displaystyle\mathbf{M}_{G}(x)$ $\displaystyle=\frac{1}{|G|}\sum_{g\in
G}g^{-1}\mathbf{M}(gx)$ (3)

Note that (3) is the Reynold’s operator (Sturmfels 2008) applied to
$\mathbf{M}$. Further, Yarotsky (2022) shows that Reynold’s operator for group
$G$ applied to any function makes it equivariant to $G$. Hence, it satisfies
the constraints of (2). Since it minimizes the lower bound, it also minimizes
the function in (2). Sec. C gives efficient implementation of (3). Sec. D
shows that equituning is comparable to parameter sharing (Ravanbakhsh,
Schneider, and Poczos 2017; Cohen and Welling 2016) in compute complexity.

#### Comments and properties.

The assumption $\left\lVert g\right\rVert^{2}=1$ is very general and subsumes
the entire class of permutation, and special linear groups such as $SO(n)$,
where $n$ is a positive integer. Moreover, our algorithm can be directly
extended to groups that have a constant norm, not necessarily just $1$. Note
that equi-tuning is not useful in cases where $\mathbf{M}$ is already
equivariant/invariant to a larger group $H\geqslant G$, where we get
$\mathbf{M}_{G}(x)=\mathbf{M}(x)$ in (3).

Under the assumption that $\mathbf{M}$ is a universal approximator of all
functions $f:\mathcal{X}\mapsto\mathcal{Y}$ as defined in appendix § B.2, it
follows from Yarotsky (2022) and Murphy et al. (2018) that $\mathbf{M}_{G}$ is
an universal approximator of all functions $e:\mathcal{X}\mapsto\mathcal{Y}$
that are equivariant with respect to $G$.

#### Discussion and Example.

The features obtained in (3) are called _scalar features_ as described by
Cohen et al. (2019). In appendix § H, we extend this solution to obtain
outputs that are _regular features_ represented by $\mathbf{M}_{G}^{R}$ in
Alg. 2. Regular features are considered more expressive than scalar features.
As proved in § H, $\mathbf{M}_{G}^{R}$ is also equivariant. We restrict our
experiments in this work to scalar features for simplicity.

Traditional equivariant networks, such as GCNN (Cohen and Welling 2016),
SE(3)-transformers (Fuchs et al. 2020), and LieConv (Finzi et al. 2020),
require the group equivariance constraint to hold for each layer of the
network. In contrast, for equi-tuning, we only need to ensure that the group
actions are defined on the input and output layers of the pretrained model,
which is a key reason for the simplicity and generality of our algorithm.

Now we provide an example of equi-tuning for image processing using the
$c4=\\{e,r,r^{2},r^{3}\\}$ group, where $e$ is the identity and $r$ denotes
rotation by $90^{\circ}$. As shown in Fig. 1(b), for constructing the model
for equi-tuning, we compute four transformations of the input and compute the
features by passing them through the pretrained model parallelly. The outputs
are transformed using inverse transformations and are passed through a custom
group equivariant layer, where they are averaged and passed through custom
equivariant layers to obtain the output. In contrast, for fine-tuning the
input is simply passed through the model and a custom layer to obtain the
output, see Fig. 1(a). §F gives examples of equi-tuning for language models.

##  5 Applications

Emphasizing the generality of equi-tuning, we apply it to three different
tasks: 1) image classification, 2) compositional generalization in language,
and 3) fairness in NLG.

###  5.1 Image Classification

Cohen and Welling (2016) found that equivariant networks using the $c4$
($90^{\circ}$ rotations) and $d4$ groups ($90^{\circ}$ rotations and
horizontal flips) consistently outperformed non-equivariant networks on the
CIFAR10 dataset. Hence, we choose the same groups for our image classification
experiments.

As shown in Fig. 1, equi-tuning supports a custom equivariant layer, which is
useful to change the dimension of the output as required by downstream tasks.
For our image classification tasks, we use parameter-sharing (Ravanbakhsh,
Schneider, and Poczos 2017) to design the custom equivariant layers for the
$c4$ and $d4$ groups. Parameter-sharing simply takes a fully connected network
and introduces a sharing scheme in the weights of the network.

###  5.2 Compositional Generalization in Language

We consider the SCAN task for testing compositional generalization of language
models. As discussed in § 3.2, Gordon et al. (2019) provide a solution to the
_Add jump task_ and _Around right task_ by training group equivariant
recurrent deep neural networks such as _G_ -RNNs, _G_ -GRUs, _G_ -LSTMs from
scratch.

For solving the SCAN task, Gordon et al. (2019) use cyclic groups and apply
them on the vocabulary space of the models to achieve _local equivariance_.
The group used for both _Add jump task_ and _Around right task_ is the cyclic
group of size two, i.e. $G=(\\{e,g\\},\cdot)$, where $g\cdot g=e$, and $e$ is
the identity element. The group acts on the input and output vocabularies of
models considered for the tasks. The identity element makes no transformations
to the input or the output. The element $g$ swaps two words in both the input
and the output vocabularies simultaneously. The words swapped depends on the
task considered.

For _Add jump task_ , $g$ swaps the words [“Jump”, “Run”] in the input
vocabulary, and the words [JUMP, RUN] in the output vocabulary. Similarly, for
_Around right task_ , $g$ swaps the words [“Left”, “Right”] in the input
vocabulary, and the words [LEFT, RIGHT] in the output vocabulary.

We start with recurrent models such as RNNs, GRUs, LSTMs, pretrained in-house,
and treat them as blackbox models and simply use the equi-tune transform from
(3) on the input and output vocabularies. We use the same group and group
actions as Gordon et al. (2019) described above. We do not use any custom
group equivariant layers for these models. We fine-tune the resulting model on
their corresponding SCAN datasets to get the final equi-tuned models that we
call EquiRNNs, EquiGRUs, and EquiLSTMs based on the architecture of the
pretrained model.

###  5.3 ‘Fairness through Equivariance’ for NLG

As discussed in § 2, fairness in NLG generally lacks a theoretical definition
that can also help mitigate bias in pretrained language models. Moreover,
Steed et al. (2022) show that upstream bias mitigation does not help with
fairness in downstream tasks.

Here, we first introduce a group-theoretic framework for fairness. Let us call
it _group-theoretic fairness_ to emphasize the fact that this is a bottom-up
group-theoretic approach attempting to define and help mitigate bias in
existing large language models (LLMs). Then we provide two different
approaches toward group-theoretic fairness in LLMs using equi-tuning.

#### Group-theoretic fairness.

Suppose we are given some set of demographic groups such as [“man”, “woman”],
[“Black”, “White”], or [“straight”, “gay”] and we want to define fairness for
open-ended NLG using language models such as GPT2 for any such demographic
group. Let ${\mathcal{V}}$ be the vocabulary set of the model. Define
${\mathcal{E}}$ to be the set of _lists of equality words_ corresponding to a
list of demographic groups. E.g. for demographic groups [“man”, “woman”],
${\mathcal{E}}$ can be [[‘man’, ‘woman’], [‘he’, ‘she’], [‘king’, ‘queen’]] or
some larger set of lists. For demographic groups [“Black”, “White”],
${\mathcal{E}}$ can be [[‘Black’, ‘White’]] or some larger set of lists. For
simplicity, we assume we are working with only one set of demographic groups
at a time. This can be generalized to multiple groups using products of
groups, which we leave for future work. Now, define a set of words
${\mathcal{N}}={\mathcal{V}}\setminus{\mathcal{E}}^{\prime}$ to be the set of
_neutral words_ , where ${\mathcal{E}}^{\prime}$ represents the set of all
words in ${\mathcal{E}}$. Neutral words such as ‘engineer’, ‘chess’,
‘scientist’, and ‘book’ are neutral to any demographic.

Let the size of the list of demographic group considered be $d$; then we work
with the cyclic group of size $d$ with generator $g$ and multiplication as its
operator, i.e., $G=\\{e,g,\ldots,g^{d-1}\\}$. The group action of the group
$G$ on the words can be defined by simply defining the group action of $g$.
The group action of $g$ makes a right cyclic shift by one to the words in each
list of ${\mathcal{E}}$ and does not affect the words in ${\mathcal{N}}$.
Thus, for the demographic group [“man”, “woman”], the action of $g$ transforms
${\mathcal{E}}$ to $g{\mathcal{E}}$ = [[‘woman’, ‘man’], [‘she’, ‘he’],
[‘queen’, ‘king’]] for the ${\mathcal{E}}$ defined above. Similarly, if the
neutral set is ${\mathcal{N}}$ = [‘doctor’, ’nurse’], then $g{\mathcal{N}}$
remains unchanged as [‘doctor’, ‘nurse’]. Here, we assume that the group
actions are well-defined, which is a basic assumption of equi-tuning. Let $X$
be a sentence, written as a list of words from ${\mathcal{V}}$, then we define
the group transformed sentence, $gX$ as the list of words of $X$ transformed
individually by $g$. Here the transformation of the words follows from the
transformation applied to the vocabulary. E.g. for ${\mathcal{E}}$ = [[‘he’,
‘she’]], if $X$ = _‘he is playing chess’_ , then $gX$ = _‘she is playing
chess’_.

Now, let $X_{1}$ be a context to a language model $\mathbf{M}$ such that it
generates some sentence $X_{2}$. Then, we say $\mathbf{M}$ is _group-
theoretically fair_ if

$\displaystyle\mathbb{P}(gX_{2}|gX_{1})=\mathbb{P}(X_{2}|X_{1}),$ (4)

for all $g\in G$. Here $\mathbb{P}(X_{2}|X_{1})$ represents the probability of
generating the sentence $X_{2}$ when using $X_{1}$ as the context. Similarly,
we define the probability $\mathbb{P}(gX_{2}|gX_{1})$.

#### Examples.

Consider the list of demographic groups as [“man”, “woman”], and let
${\mathcal{E}}$ = [[‘man’, ‘woman’], [‘he’, ‘she’]]. Then, let us consider
different cases based on whether each of $X_{1}$ and $X_{2}$ contains only
neutral words or not. Suppose $X_{1}$ only contains neutral words, then by
definition, we have $gX_{1}=X_{1}$. Thus, (4) reduces to
$\mathbb{P}(gX_{2}|X_{1})=\mathbb{P}(X_{2}|X_{1})$, which leads to equal
probability for both the gender groups conditioned on neutral words such as
‘doctor’, ‘nurse’, or ‘homemaker’. Similarly, when $X_{2}$ has only neutral
words, it leads to equal probability for neutral words for both the gender
groups. When neither $X_{1}$ nor $X_{2}$ contains only neutral words, then
transforming the context gives equal probability for the transformed generated
text as the generated text under the original context. E.g.
$\mathbb{P}$[_‘dad’_ $|$ _‘he is a’_] = $\mathbb{P}$[_‘mom’_ $|$ _‘she is
a’_].

#### EquiLM.

Now we describe EquiLM (Equivariant Language Model), which can achieve group-
theoretic fairness. Let $\phi$ denote an EquiLM that is equivariant to the
cyclic group $G=\\{e,g,\ldots,g^{d-1}\\}$ described above using the equi-tune
transform of (3) (see §F in the appendix for examples on applying group
actions in language models). Then, for some sentence of length $k$,
$X_{1}\in{\mathcal{V}}^{k}$, $\phi(X_{1})\in\mathbb{R}^{|{\mathcal{V}}|}$.
Moreover, because of equivariance of $\phi$, we have
$\phi(gX_{1})=g\phi(X_{1})$. Thus, if the sentence $X_{1}$ is transformed to
$gX_{1}$, then for any word $w\in{\mathcal{V}}$, the probabilities
$\phi(X_{1})[x_{2}]$ and $\phi(gX_{1})[gx_{2}]$ are equal, where
$\phi(X_{1})[x_{2}]$ denotes the probability of the word $x_{2}$ in the output
probabilities of $\phi(X_{1})$. Now, writing $\mathbb{P}(X_{2}|X_{1})$ as a
product of conditional probabilities representing word generations gives us
equation (4).

#### R-EquiLM.

While group-theoretic fairness defined in (4) can be obtained using EquiLM, it
requires the user to partition ${\mathcal{V}}$ into ${\mathcal{N}}$ and
${\mathcal{E}}$, which might not be an easy task for huge vocabulary sets.
Thus, here we introduce a set of words ${\mathcal{G}}$, which is designed to
be a small set containing _general words_ that does not entertain any group
action. Any word that does not necessarily belong to ${\mathcal{N}}$ and
${\mathcal{E}}$ is put into this set. Hence, the user provides ${\mathcal{E}}$
and ${\mathcal{G}}$, and ${\mathcal{N}}$ is computed as
${\mathcal{V}}\setminus({\mathcal{E}}^{\prime}\cup{\mathcal{N}})$, where
${\mathcal{E}}^{\prime}$ is the set of words in ${\mathcal{E}}$ as defined
before. The group and group actions are the same as in EquiLLM, but restricted
to only ${\mathcal{E}}$ and ${\mathcal{N}}$. Hence, we obtain a _relaxed
equivariance_ over the output vocabulary space of this language model, which
we call R-EquiLM (Relaxed EquiLM). The relaxed equivariance property of a
R-EquiLM, say $\phi$, is described as follows. If $x_{2}\in{\mathcal{V}}$ is a
word, then $\phi(gX_{1})[x_{2}]=g\phi(X_{1})[x_{2}]$ if
$x_{2}\in{\mathcal{E}}^{\prime}\cup{\mathcal{N}}$. Thus, this form of
equivariance holds only for output words that belong to a particular subset of
${\mathcal{V}}$. Moreover, relaxed equivariance does not guarantee any
equality of probabilities over generated sentences like EquiLM. Because the
generated text may contain words from ${\mathcal{G}}$, no guarantees can be
obtained on the probability of the overall sentence. Nevertheless, R-EquiLM
provides equivariance at a word-level for a particular subset of
${\mathcal{V}}$ and is relatively easy to implement because of the presence of
${\mathcal{G}}$. This is reflected in our our experiments in § 6.3.

Both EquiLM and R-EquiLM can be constructed by equi-tuning pretrained models
with the groups and group actions defined above. The construction of the sets
${\mathcal{E}}$ and ${\mathcal{G}}$ are given in Sec. E. For our experiments
on NLG bias mitigation in § 6.3, we simply apply the equi-tuning
transformation from (3) and do not fine-tune the obtained model. This is
because it was found that applying the transformation to large pretrained
models such as GPT2 has negligible impact on the quality of text generation.
This is also verified by computing the perplexities of these equi-tuned models
(i.e. using only the equi-tune transformation) on Wikitext-2 and Wikitext-103
test sets, which show negligible difference compared to the pretrained model
(GPT2 in this case).

##  6 Experiments

We provide results for equi-tuning on image classification, compositional
generalization, and fairness in NLG.

###  6.1 Image Classification

Table 1: Mean (and standard deviation) classification accuracy of fine-tuning several pretrained models on the Hymenoptera dataset. For each model, $c4$ and $d4$ groups were used for equivariant fine-tuning. Comparisons are made with $c4$ rotation augmentations. Results average five seeds. Model | Group | No aug. |  $c4$ aug.
---|---|---|---
Alexnet | – | 88.88 (4.5) | 91.11 (1.3)
$c4$ | 93.07 (1.8) | 93.07 (1.8)
$d4$ | 90.45 (1.2) | 90.45 (1.2)
Resnet | – | 89.41 (2.1) | 90.32 (1.4)
$c4$ | 91.37 (1.5) | 91.63 (1.4)
$d4$ | 91.89 (1.3) | 91.89 (1.3)
VGG | – | 78.30 (11.9) | 77.12 (11.4)
$c4$ | 88.62 (4.6) | 88.75 (4.3)
$d4$ | 90.98 (2.2) | 90.98 (2.2)
Densenet | – | 86.79 (2.7) | 88.88 (1.5)
$c4$ | 91.50 (1.3) | 91.24 (1.7)
$d4$ | 90.06 (1.4) | 90.06 (0.8)

#### Experimental setting.

We experiment on two datasets: Hymenoptera444Obtained from
https://www.kaggle.com/datasets/ajayrana/hymenoptera-data. More details
provided in § G in the appendix. and CIFAR-10 (Krizhevsky, Nair, and Hinton
2010) using four different pretrained models: Alexnet (Krizhevsky, Sutskever,
and Hinton 2012), Resnet-18 (He et al. 2016), VGG-11 (Simonyan and Zisserman
2014), and Densenet (Huang et al. 2017). For equi-tuning, we use two different
groups for constructing $\mathbf{M}_{G}$: $c4$ ($90^{\circ}$ rotations) and
$d4$ ($90^{\circ}$ rotations and horizontal flips). In the test sets, we apply
random $c4$ augmentations to check the robustness of the fine-tuned models. In
the training sets, we experiment both without any data augmentation, and with
$c4$ augmentations. We use stochastic gradient descent as the optimizer with
momentum $0.9$ and learning rate $3\times 10^{-4}$.

#### Results.

Table 1 shows the results for fine-tuning and equi-tuning the four models with
$c4$ and $d4$ group equivariances. The models were fine-tuned with batchsize 8
for 10 epochs over 5 different random seeds. Results show that equi-tuning
outperforms fine-tuning with and without data augmentation. Alexnet and
Densenet obtain the best performance using $c4$ equivariance whereas the other
two models perform best using $d4$ equivariance. Thus, suggesting that the
choice of group is dependent on both the dataset and the architecture. Table 6
in § G in the appendix gives the equi-tuning results for CIFAR-10. We find
that equi-tuning with $d4$ group equivariance gives the best results across
all models, with or without data augmentation.

###  6.2 Compositional Generalization in Language

Table 2: Equi-tuning LSTM for SCAN. LSTM and _G_ -LSTM were trained for 200K iterations with relevant groups for each task. EquiLSTM models are LSTM models equi-tuned for 10K iterations using group relevant to each task. Results are over three random seeds. Task | Group | Model | Val. Acc. | Test Acc.
---|---|---|---|---
Add Jump | – | LSTM | 99.1 (0.3) | 0.0 (0.0)
Verb |  G-LSTM | 99.4 (0.8) | 98.3 (1.4)
Verb | EquiLSTM | 98.9 (0.7) | 97.9 (1.0)
Around Right | – | LSTM | 98.9 (0.7) | 0.4 (0.7)
Dir. |  G-LSTM | 98.4 (0.6) | 89.6 (1.9)
Dir. | EquiLSTM | 99.8 (0.2) | 95.7 (3.6)

(a)

(b)

(c)

Figure 3: The plots (a), (b), and (c) show the distribution of regard scores
for the _respect_ task for the set of demographic groups gender, race, and
sexual orientation respectively. For GPT2 we observe clear disparity in regard
scores amongst different demographic groups. Each bar in the plots correspond
to 500 generated samples. R-EquiGPT2 and Equi-GPT2 reduces the disparity in
the regard scores. Note that the small disparity in regard scores for EquiGPT2
is due to bias in the regard classifier itself, which was manually verified
and the samples are shared in the paper.

#### Experimental setting.

We use the SCAN dataset (Gordon et al. 2019) for our compositional
generalization experiments. For training all the recurrent models (RNNs, GRUs,
and LSTMs) and their equivariant counterparts (_G_ -RNNs, _G_ -GRUs, and _G_
-LSTMs), we closely follow the setup of Gordon et al. (2019). All models
contain a single layer cell of the recurrent model with 64 hidden units. We
train these models on the Add jump task and the Around right task for 200k
iterations using Adam optimizer (Kingma and Ba 2015) with learning rate
$10^{-4}$ and teacher-forcing ratio (Williams and Zipser 1989) $0.5$. Then, we
equi-tune pretrained non-equivariant models (RNNs, GRUs, and LSTMs) using
appropriate groups for only 10K iterations and the Adam optimizer. We use
learning rates $2\times 10^{-5}$ and $5\times 10^{-5}$ for Add jump and Around
right tasks, respectively, with a teacher-forcing ratio of 0.5. Experimental
results are reported for three random seeds. We use the same seed to equi-tune
a model as is used for its training.

#### Results.

Table 2 shows our results for LSTMs. We first reproduce the insights obtained
by Gordon et al. (2019) showing that (non-equivariant) LSTMs fail miserably on
SCAN tasks. When these LSTMs are equi-tuned to obtain EquiLSTMs, they produce
competitive results compared to _G_ -LSTMs trained from scratch and even
outperform them in several cases, thus showing the compositional
generalization ability of equi-tuned models. Results for EquiRNNs and EquiGRUs
are shown in Table 7 and 8, respectively, in § G in the appendix. All equi-
tuned models are able to benefit from equivariance while also retaining
pretrained knowledge.

###  6.3 Fairness in Natural Language Generation

#### Experimental setting.

We use GPT2 (Radford et al. 2019) with 117M parameters as our pretrained
language model. We construct R-EquiGPT2 and EquiGPT2 by applying the equi-tune
transform (3) on GPT2 and no fine-tuning is performed on the pretrained GPT2
model. This is because we found no difference in quality of generated text and
negligible drop in perplexity on Wikitext-2 and Wikitext-103 test sets as
shown in Table 9 in the appendix. The ${\mathcal{E}},{\mathcal{N}}$ sets for
EquiGPT2 and ${\mathcal{E}},{\mathcal{N}},{\mathcal{G}}$ sets for R-EquiGPT2
are described in § E. Recall from § 3.3, we have two different tasks: respect
and occupation. For each task we have five different contexts. For each
context, we generate 100 samples of generated texts from fixed seeds for each
model. Thus, for each task and for each demographic group, each model
generates 500 samples of texts, each with a maximum of 15 tokens. Generated
sentences were truncated when a new line was generated to ensure proper
functioning of the regard classifier of Sheng et al. (2019).

#### Results and observations.

Fig. 3 and 5 show the scores obtained by the regard classifier of Sheng et al.
(2019) on 500 generated samples for each demographic group for the respect and
occupation tasks, respectively. (Fig. 5 is in the appendix.) As observed in
the figures, both R-EquiGPT2 and EquiGPT2 reduce the bias between each pair of
demographic groups compared to GPT2. We look more closely at the generated
texts for the respect task for the set of demographic groups [“gay”,
“straight”] in Table 10, 11, and 12 in the appendix for GPT2, R-EquiGPT2, and
EquiGPT2 models, respectively. We observe that the quality of generated texts
is not affected, but, now the regard scores across the demographic groups are
more well balanced.

Note that the definition of group-theoretic fairness in (4) requires
probabilistic equivariance. Thus, fixing the random seed results in perfect
equivariance in generated texts. This results in interesting implications for
gauging fairness in NLG. For EquiGPT2, we expect perfectly equal regard score
for each set of demographic groups in Fig. 3 and 5. But, interestingly, we
find slight difference in regard scores, implying that the regard classifier
itself is slightly biased towards certain demographic groups. An instance of
this bias can be observed in Table 12, where for the same sentence, if we
replace the word “straight” by “gay”, we obtain different regard scores from
the regard classifier.

##  7 Conclusion

We propose equi-tuning, a novel fine-tuning method that transforms pretrained
models into an equivariant version while minimizing the distance between
features from pretrained models and equivariant models. The method obtained is
very general in terms of the models, datasets, and applications that it can be
used with. To show this, we use it in diverse applications: image
classification, compositional generalization, and fairness in NLG. Across
these topics, we use a variety of model architectures such as CNNs (Alexnet,
Resnet, VGG, and Densenet), RNNs, GRUs, LSTMs, and transformers (GPT2). For
image classification, we obtain superior performance using equi-tuning
compared to fine-tuning. For compositional generalization in languages, we
find that equi-tuning performs at par with group equivariant models but is
more efficient since it can work on top of non-equivariant pretrained models.
Finally, for fairness, we define group-theoretic fairness in NLG and propose
two methods towards achieving group-theoretic fairness. These methods are
based on equi-tuning pretrained language models such as GPT2. The
effectiveness of this definition and the proposed methods is shown using
existing empirical methods for finding bias in NLG.

## Acknowledgement

A portion of the work was supported by the Department of Energy (DOE) award
(DE-SC0012704).

## References

  * Abid, Farooqi, and Zou (2021) Abid, A.; Farooqi, M.; and Zou, J. 2021.  Persistent anti-Muslim bias in large language models.  In _Proceedings of the 2021 AAAI/ACM Conference on AI, Ethics, and Society_ , 298–306.
  * Andreas (2020) Andreas, J. 2020.  Good-Enough Compositional Data Augmentation.  In _Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics_ , 7556–7566.
  * Basu et al. (2022a) Basu, S.; Gallego-Posada, J.; Viganò, F.; Rowbottom, J.; and Cohen, T. 2022a.  Equivariant Mesh Attention Networks.  _Transactions on Machine Learning Research_.
  * Basu et al. (2022b) Basu, S.; Katdare, P.; Driggs-Campbell, K. R.; and Varshney, L. R. 2022b.  Gauge Equivariant Deep Q-Learning on Discrete Manifolds.  In _ICLR 2022 Workshop on Geometrical and Topological Representation Learning_.
  * Bengio (2012) Bengio, Y. 2012.  Deep learning of representations for unsupervised and transfer learning.  In _Proceedings of ICML workshop on unsupervised and transfer learning_ , 17–36. JMLR Workshop and Conference Proceedings.
  * Bommasani et al. (2021) Bommasani, R.; Hudson, D. A.; Adeli, E.; Altman, R.; Arora, S.; von Arx, S.; Bernstein, M. S.; Bohg, J.; Bosselut, A.; Brunskill, E.; et al. 2021.  On the opportunities and risks of foundation models.  _arXiv preprint arXiv:2108.07258_.
  * Chomsky (2009) Chomsky, N. 2009.  Syntactic structures.  In _Syntactic Structures_. De Gruyter Mouton.
  * Cohen et al. (2019) Cohen, T.; Weiler, M.; Kicanaoglu, B.; and Welling, M. 2019.  Gauge equivariant convolutional networks and the icosahedral CNN.  In _International Conference on Machine Learning_ , 1321–1330. PMLR.
  * Cohen and Welling (2016) Cohen, T.; and Welling, M. 2016.  Group equivariant convolutional networks.  In _International Conference on Machine Learning_ , 2990–2999. PMLR.
  * Cohen and Welling (2017) Cohen, T.; and Welling, M. 2017.  Steerable CNNs.  In _International Conference on Learning Representations_.
  * Dai et al. (2009) Dai, W.; Jin, O.; Xue, G.-R.; Yang, Q.; and Yu, Y. 2009.  Eigentransfer: a unified framework for transfer learning.  In _Proceedings of the 26th Annual International Conference on Machine Learning_.
  * De Haan et al. (2020) De Haan, P.; Weiler, M.; Cohen, T.; and Welling, M. 2020.  Gauge Equivariant Mesh CNNs: Anisotropic convolutions on geometric graphs.  In _International Conference on Learning Representations_.
  * Deng et al. (2009) Deng, J.; Dong, W.; Socher, R.; Li, L.-J.; Li, K.; and Fei-Fei, L. 2009.  Imagenet: A large-scale hierarchical image database.  In _2009 IEEE Conference on Computer Vision and Pattern Recognition_ , 248–255. IEEE.
  * Dessì and Baroni (2019) Dessì, R.; and Baroni, M. 2019.  CNNs found to jump around more skillfully than RNNs: Compositional Generalization in Seq2seq Convolutional Networks.  In _Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics_ , 3919–3923.
  * Dwork et al. (2012) Dwork, C.; Hardt, M.; Pitassi, T.; Reingold, O.; and Zemel, R. 2012.  Fairness through awareness.  In _Proceedings of the 3rd innovations in theoretical computer science conference_ , 214–226.
  * Finzi et al. (2020) Finzi, M.; Stanton, S.; Izmailov, P.; and Wilson, A. G. 2020.  Generalizing convolutional neural networks for equivariance to lie groups on arbitrary continuous data.  In _International Conference on Machine Learning_ , 3165–3176. PMLR.
  * Fuchs et al. (2020) Fuchs, F.; Worrall, D.; Fischer, V.; and Welling, M. 2020.  SE(3)-transformers: 3d roto-translation equivariant attention networks.  _Advances in Neural Information Processing Systems_ , 33: 1970–1981.
  * Gordon et al. (2019) Gordon, J.; Lopez-Paz, D.; Baroni, M.; and Bouchacourt, D. 2019.  Permutation equivariant models for compositional generalization in language.  In _International Conference on Learning Representations_.
  * He et al. (2016) He, K.; Zhang, X.; Ren, S.; and Sun, J. 2016.  Deep residual learning for image recognition.  In _Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition_ , 770–778.
  * He et al. (2021) He, L.; Dong, Y.; Wang, Y.; Tao, D.; and Lin, Z. 2021.  Gauge equivariant transformer.  _Advances in Neural Information Processing Systems_ , 34.
  * Henderson et al. (2018) Henderson, P.; Sinha, K.; Angelard-Gontier, N.; Ke, N. R.; Fried, G.; Lowe, R.; and Pineau, J. 2018.  Ethical challenges in data-driven dialogue systems.  In _Proceedings of the 2018 AAAI/ACM Conference on AI, Ethics, and Society_ , 123–129.
  * Huang et al. (2017) Huang, G.; Liu, Z.; Van Der Maaten, L.; and Weinberger, K. Q. 2017.  Densely connected convolutional networks.  In _Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition_ , 4700–4708.
  * Keriven and Peyré (2019) Keriven, N.; and Peyré, G. 2019.  Universal invariant and equivariant graph neural networks.  _Advances in Neural Information Processing Systems_.
  * Kingma and Ba (2015) Kingma, D. P.; and Ba, J. 2015.  Adam: A Method for Stochastic Optimization.  In _International Conference on Learning Representations_.
  * Kondor and Trivedi (2018) Kondor, R.; and Trivedi, S. 2018.  On the generalization of equivariance and convolution in neural networks to the action of compact groups.  In _International Conference on Machine Learning_ , 2747–2755. PMLR.
  * Krizhevsky, Nair, and Hinton (2010) Krizhevsky, A.; Nair, V.; and Hinton, G. 2010.  CIFAR-10 (Canadian Institute for Advanced Research).  _URL http://www. cs. toronto. edu/kriz/cifar. html_ , 5(4): 1.
  * Krizhevsky, Sutskever, and Hinton (2012) Krizhevsky, A.; Sutskever, I.; and Hinton, G. E. 2012.  Imagenet classification with deep convolutional neural networks.  _Advances in Neural Information Processing Systems_ , 25.
  * Lake and Baroni (2018) Lake, B.; and Baroni, M. 2018.  Generalization without systematicity: On the compositional skills of sequence-to-sequence recurrent networks.  In _International Conference on Machine Learning_ , 2873–2882. PMLR.
  * Lake (2019) Lake, B. M. 2019.  Compositional generalization through meta sequence-to-sequence learning.  _Advances in Neural Information Processing Systems_ , 32.
  * Lake et al. (2017) Lake, B. M.; Ullman, T. D.; Tenenbaum, J. B.; and Gershman, S. J. 2017.  Building machines that learn and think like people.  _Behavioral and Brain Sciences_ , 40.
  * Loula, Baroni, and Lake (2018) Loula, J.; Baroni, M.; and Lake, B. 2018.  Rearranging the Familiar: Testing Compositional Generalization in Recurrent Networks.  In _Proceedings of the 2018 EMNLP Workshop BlackboxNLP: Analyzing and Interpreting Neural Networks for NLP_ , 108–114.
  * Lu et al. (2021) Lu, K.; Grover, A.; Abbeel, P.; and Mordatch, I. 2021.  Pretrained transformers as universal computation engines.  _arXiv preprint arXiv:2103.05247_.
  * Maron et al. (2019) Maron, H.; Ben-Hamu, H.; Shamir, N.; and Lipman, Y. 2019.  Invariant and equivariant graph networks.  In _International Conference on Learning Representations_.
  * Montague (1970) Montague, R. 1970.  Universal grammar.  _Theoria_ , 36(3): 373–398.
  * Murphy et al. (2018) Murphy, R. L.; Srinivasan, B.; Rao, V.; and Ribeiro, B. 2018.  Janossy pooling: Learning deep permutation-invariant functions for variable-size inputs.  _arXiv preprint arXiv:1811.01900_.
  * Nadeem, Bethke, and Reddy (2021) Nadeem, M.; Bethke, A.; and Reddy, S. 2021.  StereoSet: Measuring stereotypical bias in pretrained language models.  In _Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)_ , 5356–5371.
  * Prates, Avelar, and Lamb (2020) Prates, M. O.; Avelar, P. H.; and Lamb, L. C. 2020.  Assessing gender bias in machine translation: a case study with Google Translate.  _Neural Computing and Applications_ , 32(10): 6363–6381.
  * Radford et al. (2019) Radford, A.; Wu, J.; Child, R.; Luan, D.; Amodei, D.; Sutskever, I.; et al. 2019\.  Language models are unsupervised multitask learners.  _OpenAI blog_ , 1(8): 9.
  * Raghunathan et al. (2010) Raghunathan, K.; Lee, H.; Rangarajan, S.; Chambers, N.; Surdeanu, M.; Jurafsky, D.; and Manning, C. D. 2010.  A multi-pass sieve for coreference resolution.  In _Proceedings of the 2010 conference on empirical methods in natural language processing_ , 492–501.
  * Ravanbakhsh, Schneider, and Poczos (2017) Ravanbakhsh, S.; Schneider, J.; and Poczos, B. 2017.  Equivariance through parameter-sharing.  In _International Conference on Machine Learning_ , 2892–2901. PMLR.
  * Ruder et al. (2019) Ruder, S.; Peters, M. E.; Swayamdipta, S.; and Wolf, T. 2019.  Transfer learning in natural language processing.  In _Proceedings of the 2019 conference of the North American chapter of the association for computational linguistics: Tutorials_ , 15–18.
  * Russin et al. (2019) Russin, J.; Jo, J.; O’Reilly, R. C.; and Bengio, Y. 2019.  Compositional generalization in a deep seq2seq model by separating syntax and semantics.  _arXiv preprint arXiv:1904.09708_.
  * Satorras, Hoogeboom, and Welling (2021) Satorras, V. G.; Hoogeboom, E.; and Welling, M. 2021.  E (n) equivariant graph neural networks.  In _International Conference on Machine Learning_.
  * Sheng et al. (2019) Sheng, E.; Chang, K.-W.; Natarajan, P.; and Peng, N. 2019.  The Woman Worked as a Babysitter: On Biases in Language Generation.  In _Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP)_ , 3407–3412.
  * Simonyan and Zisserman (2014) Simonyan, K.; and Zisserman, A. 2014.  Very deep convolutional networks for large-scale image recognition.  _arXiv preprint arXiv:1409.1556_.
  * Steed et al. (2022) Steed, R.; Panda, S.; Kobren, A.; and Wick, M. 2022.  Upstream Mitigation Is Not All You Need: Testing the Bias Transfer Hypothesis in Pre-Trained Language Models.  In _Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)_ , 3524–3542.
  * Sturmfels (2008) Sturmfels, B. 2008.  _Algorithms in Invariant Theory_.  Springer Science & Business Media.
  * Sun et al. (2019) Sun, T.; Gaut, A.; Tang, S.; Huang, Y.; ElSherief, M.; Zhao, J.; Mirza, D.; Belding, E.; Chang, K.-W.; and Wang, W. Y. 2019.  Mitigating gender bias in natural language processing: Literature review.  _arXiv preprint arXiv:1906.08976_.
  * Taylor and Stone (2009) Taylor, M. E.; and Stone, P. 2009.  Transfer learning for reinforcement learning domains: A survey.  _Journal of Machine Learning Research_ , 10(7).
  * van der Pol et al. (2020) van der Pol, E.; Worrall, D.; van Hoof, H.; Oliehoek, F.; and Welling, M. 2020.  MDP homomorphic networks: Group symmetries in reinforcement learning.  _Advances in Neural Information Processing Systems_ , 33: 4199–4210.
  * Wang et al. (2022) Wang, D.; Walters, R.; Zhu, X.; and Platt, R. 2022.  Equivariant $Q$ Learning in Spatial Action Spaces.  In _Conference on Robot Learning_ , 1713–1723. PMLR.
  * Williams and Zipser (1989) Williams, R. J.; and Zipser, D. 1989.  A learning algorithm for continually running fully recurrent neural networks.  _Neural computation_ , 1(2): 270–280.
  * Yarotsky (2022) Yarotsky, D. 2022.  Universal approximations of invariant maps by neural networks.  _Constructive Approximation_ , 55(1): 407–474.
  * Yeo and Chen (2020) Yeo, C.; and Chen, A. 2020.  Defining and Evaluating Fair Natural Language Generation.  In _Proceedings of the The Fourth Widening Natural Language Processing Workshop_ , 107–109.
  * Zamir et al. (2018) Zamir, A. R.; Sax, A.; Shen, W.; Guibas, L. J.; Malik, J.; and Savarese, S. 2018\.  Taskonomy: Disentangling task transfer learning.  In _Proceedings of the IEEE conference on computer vision and pattern recognition_ , 3712–3722.
  * Zhao et al. (2017) Zhao, J.; Wang, T.; Yatskar, M.; Ordonez, V.; and Chang, K.-W. 2017.  Men also like shopping: Reducing gender bias amplification using corpus-level constraints.  _arXiv preprint arXiv:1707.09457_.
  * Zhuang et al. (2020) Zhuang, F.; Qi, Z.; Duan, K.; Xi, D.; Zhu, Y.; Zhu, H.; Xiong, H.; and He, Q. 2020\.  A comprehensive survey on transfer learning.  _Proceedings of the IEEE_ , 109(1): 43–76.

## Appendix

##  Appendix A Background on Group Theory

Here we provide a basic background on group theory.

###  A.1 Group

A group $(G,\cdot)$ is a set $G$ along with a binary operation $\cdot:G\times
G\mapsto G$ such that it satisfies the following group axioms.

  1. 1.

Associativity: $(a\cdot b)\cdot c=a\cdot(b\cdot c)$ for all $a,b,c\in G$

  2. 2.

Identity: There exists an identity element $e\in G$ such that $e\cdot g=g\cdot
e$ for all $g\in G$.

  3. 3.

Inverse: For every element $a\in G$, there exists a $b\in G$ such that $a\cdot
b=b\cdot a=e$, where $e$ is the identity element.

When it is clear from context, we denote $a\cdot b$ as $ab$, and we refer to
$G$ as the group for simplicity.

###  A.2 Group Homomorphism

A group homomorphism $\varphi:G\mapsto H$ is a map from a group $(G,\cdot)$ to
$(H,*)$ that respects group structure, i.e.
${\varphi(ab)=\varphi(a)\varphi(b)}$ for all $a,b\in G$.

###  A.3 Group Representation

Let $V$ be a vector space over a field $K$ and let $GL(V)$ be the general
linear group on $V$. Then, a group representation $\rho$ is a group
homomorphism from $G$ to $GL(V)$. When the group homomorphism $\rho$ is clear
from context, the vector space $V$ is called the group representation of the
group $G$.

###  A.4 Group Action

The action of a group $\Gamma$ on a set $\mathcal{X}$ is a map,
$\Gamma:G\times\mathcal{X}\mapsto\mathcal{X}$, such that the following to
axioms hold.

  1. 1.

Identity: $\Gamma(e,x)=x$, for all $x\in\mathcal{X}$, where $e$ is the
identity of $G$ .

  2. 2.

Compatibility: $\Gamma(g,\Gamma(h,x))=\Gamma(gh,x)$ for all $g,h\in G$,
$x\in\mathcal{X}$.

When clear from context, we replace the notation $\Gamma(g,x)$ by $g\cdot x$
or $gx$ for convenience.

###  A.5 Special Linear Group

The special linear group of order $n$, over a field $F$, denoted as $SL(n,F)$
is the set of all $n\times n$ matrices of elements of $F$ with determinant
$1$. The group operation is matrix multiplication.

##  Appendix B Additional Definitions

###  B.1 Fine-tuning and Feature Extraction

Let $\mathbf{M}:\mathcal{X}\mapsto\mathcal{Y}$ be the part of a pretrained
model that takes input in $\mathcal{X}$ and outputs features in $\mathcal{Y}$.
Let $\mathbf{C}:\mathcal{Y}\mapsto\mathcal{Z}$ be a custom layer, such that
$\mathbf{M}$ stacked with $\mathbf{C}$ gives the desired target domain model
$\mathbf{T}:\mathcal{X}\mapsto\mathcal{Z}$. Training this assembled model
$\mathbf{T}$ on a target domain is referred to as fine-tuning.

###  B.2 Universality

A model $\mathbf{M}:\mathbb{R}^{M}\mapsto\mathbb{R}^{N}$ is a universal
approximator of a continuous function $f:\mathbb{R}^{M}\mapsto\mathbb{R}^{N}$
if for any compact set $\mathbb{K}\subset\mathbb{R}^{M}$, $\epsilon>0$, there
exists a choice of parameters for $\mathbf{M}$ such that $\left\lVert
f(x)-\mathbf{M}(x)\right\rVert\leq\epsilon$ for all $x\in\mathbb{K}$.

##  Appendix C Efficient Parallel Implementation

The solution $\mathbf{M}_{G}$ in (3) is an averaging over a group, hence,
intuitively, it looks $|G|$ times computationally heavier compared to simply
using a pretrained model $\mathbf{M}$. Here, we provide an efficient
implementation for (3) using parallel processing in GPUs. Later, in Sec. D, we
show that using this parallel processing, $\mathbf{M}_{G}$ in (3) can be
computed with complexity much less than $|G|$ times that of a pretrained model
for practical cases. Further, we show that our method is comparable in
computational complexity to popular parameter sharing based group equivariant
architectures, e.g. GCNNs (Cohen and Welling 2016; Ravanbakhsh, Schneider, and
Poczos 2017).

Input: $x,\mathbf{M},G$

$x_{G}=[g\cdot x\text{ for }g\in G]$ # transformed inputs

$y_{G}=\mathbf{M}(x_{G})$ # parallel compute

$y_{G}=[g^{-1}\cdot y_{G}[i]\text{ for }i\in\text{range}(|G|)]$ # inverse
transforms

$y=mean(y_{G},dim=0)$ # compute mean

Output: $y$

Algorithm 1 Equituning

Alg. 1 takes an input $x\in\mathcal{X}$ and computes all the group
transformations $[g\cdot x\text{ for }g\in G]$ using negligible compute. Then,
it passes all the inputs parallelly by using an additional group dimension to
obtain $y_{G}$. Then, it computes the inverse transform for the outputs along
the group dimension as $[g^{-1}\cdot y_{G}[i]\text{ for
}i\in\text{range}(|G|)$. Finally, the mean along the group dimension is
computed as the final output. Disscussions on the experimental evaluation of
the Alg. 1 is provided next in Sec. D.

##  Appendix D Computational Complexity

Table 3: Computational complexity comparison of finetuning with equituning for the c4 group Model | Mean time (sec.) | Memory (MB)
---|---|---
| Finetune | Equitune (c4) | Finetune | Equitune (c4)
Alexnet | 56.6 | 53.3 | 1943 | 1945
Resnet | 32.6 | 30.1 | 2103 | 3163
VGG | 54.1 | 61.7 | 2617 | 6707
Densenet | 76.8 | 79.2 | 2947 | 6271

In Tab. 3, we compare the computational complexity in terms of time and memory
consumed by equituning and finetuning for four CNN models: Alexnet, Resnet,
VGG, and Densenet. We trained the models on the Hymenoptera dataset555Obtained
from https://www.kaggle.com/datasets/ajayrana/hymenoptera-data with batch size
8 for 5 epochs and 3 seeds. We find that parallelization enables same time
complexity for equituning and finetuning. Moreover, memory consumption by
equituning is much less than $|G|$ times the memory consumed for finetuning.

Next, we compare the computational complexity of equituning with existing
parameter sharing based methods in Tab. 4. For our comparison, we consider
MLPs and CNNs. For both MLPs and CNNs, we use models with four layers. For
MLPs, we compare equituning with the parameter sharing method of (Ravanbakhsh,
Schneider, and Poczos 2017). And for CNNs, we compare equituning with GCNNs
(Cohen and Welling 2016). We ensure that for each comparison, the number of
parameters is the same for equituning and classical group equivariance
methods. This is ensured by adjusting the feature and channel dimensions for
MLPs and CNNs, respectively. The exact number of parameters used by each
method is shown in Tab. 5. The results in Tab. 4 show that equituning is as
efficient as existing group equivariant method.

Table 4: Computational complexity comparison for equituning vs. parameter sharing. Model | Group | Mean time (sec) | Memory (MB)
---|---|---|---
|  | Parameter sharing | Equituning | Parameter sharing | Equituning
MLP | $c4$ | 214.1 |  50.9 | 1443 | 1289
MLP | $d4$ | 498.7 | 55.5 | 1655 | 1349
CNN | $c4$ | 115.7 | 95.6 | 2301 | 2701
CNN | $d4$ | 92.0 | 84.2 | 2291 | 3731
Table 5: Number of parameters for the results in Tab. 4. Model type | Group | No. of parameters ($\times 10^{3}$)
---|---|---
|  | Parameter sharing | Equituning
MLP | $c4$ | 804 | 803
MLP | $d4$ | 764 | 803
CNN | $c4$ | 12.9 | 13.6
CNN | $d4$ | 13.2 | 13.6

##  Appendix E Construction of Sets of Equality, Neutral, and General words
for GPT2

Here, first we describe the construction of ${\mathcal{E}}$ and
${\mathcal{N}}$ for EquiGPT2. Then we describe the construction of
${\mathcal{E}},{\mathcal{N}}$, and ${\mathcal{G}}$ sets for R-EquiGPT2.

#### EquiGPT2.

For EquiGPT2, we use the same vocabulary as the GPT2 model with 117M
parameters. For the set of demographic groups [“man”, “woman”], we use common
gender specific words for creating the sets of equality words ${\mathcal{E}}$.
In the process, we ensure that the group actions are well defined, which is
done simply by ensuring that the mapping obtained between the words are one-
to-one. This is essential especially in this case of demographic groups since
there are words such as “his” and “him” for the “man” demographic group that
simultaneously map to “her” in the “woman” demographic group. So, we do not
add such words to ensure the group actions are well-defined. For the sets of
demographic groups [“Black”, “White”] and [“gay”, “straight”], we use the set
${\mathcal{E}}$ simply as [[‘Black’, ‘White’]] and [[‘gay’, ‘straight’]]
respectively. The neutral set ${\mathcal{N}}$ is obtained by simply removing
the words in ${\mathcal{E}}$ from the entire vocabulary ${\mathcal{V}}$.

#### R-EquiGPT2.

For R-EquiGPT2, for the sets of demographic groups [“man”, “woman”], [“Black”,
“White”], and [“gay”, “straight”], we use the ${\mathcal{E}}$ simply as
[[‘man’, ‘woman’]], [[‘Black’, ‘White’]], and [[‘gay’, ‘straight’]]
respectively. We set the general words set ${\mathcal{G}}$ to [‘he’, ‘she’,
‘his’, ‘her’, ‘him’] on which the groups actions are not defined. The rest of
the words in the vocabulary are set as the neutral words ${\mathcal{N}}$. One
can use a large set of the general words on which the group actions may not be
defined based on the applications. Our choice for ${\mathcal{G}}$ is motivated
from the fact that pronouns often have complicated relationships with nouns,
e.g. coreference resolution (Raghunathan et al. 2010), and enforcing group
actions on them may affect the performance of language models, which might
have already learnt these relationships. In practice, we find this to work
well and we leave finding the best set of sets ${\mathcal{E}},{\mathcal{N}},$
and ${\mathcal{G}}$ to future work since the main focus of this part of the
paper is to show how group theory can be used effectively to mitigate bias in
NLG tasks.

##  Appendix F Additional Examples

(a) Language model output for input A (b) Language model output using equi-
tuning transform (3) and input A

(c) Language model output using equi-tuning transform (3) and input C

Figure 4: Comparing non-equivariant language model output with equi-tuned
language model output. Note that the inputs are words whereas the outputs are
probability distribution over the vocabulary space for predicting the next
word. We consider the case where the vocabulary ${\mathcal{V}}=$ [A, B, C, D],
lists of equality words ${\mathcal{E}}=$ [[A, C]], neutral words
${\mathcal{N}}=$ [B], and general words ${\mathcal{G}}=$ [D]. In (a), we have
A as the input word and the output is from a pretrained model over
${\mathcal{V}}$. In (b) and (c) we have equi-tuned pretrained models where the
input words are A and C, respectively. The transformations in the input are
done by simply changing the words, e.g. in (b) A is transformed into C,
whereas in the output, the probability vector over the vocabulary set gets
permuted. Note that transforming the input from A in (b) to C in (c)
transforms the output probability vector equivariantly, i.e. the probabilities
for A and C in the output get swapped. Moreover, the probability for the
neutral word, B, remains unchanged. Whereas the probability for the general
word on which the group does not act is unaffected by equi-tuning.

In Fig. 4, we provide an example of the working of the equi-tune
transformation in (3) for language models. Here we work with the setup of
group actions defined in §5.3 for fairness in NLG to provide an example of
group actions work in the input and the output of a language model. The setup
for compositional generalization is very similar and hence not discussed here.
Further discussion on group action for compositional generalization can be
found in (Gordon et al. 2019).

As seen in Fig. 4, the inputs to the pretrained model are words (or a
sentence) whereas the outputs are probability distribution over the vocabulary
space. In §5.3, we define ${\mathcal{E}}$, the lists of equality words;
${\mathcal{N}}$, the neutral words; and ${\mathcal{G}}$, the general words on
which group actions are not defined. Here we consider the case with the
vocabulary ${\mathcal{V}}=$ [A, B, C, D], lists of equality words
${\mathcal{E}}=$ [[A, C]], neutral words ${\mathcal{N}}=$ [B], and general
words ${\mathcal{G}}=$ [D]. Since the size of the list in ${\mathcal{E}}$ is
two, we consider the cyclic group of size two, $G=\\{e,g\\}$. Thus, if the
input word is in ${\mathcal{E}}$, then $g$ acts on the word by replacing it
with the other word in ${\mathcal{E}}$. If the input word lies in
${\mathcal{N}}$, then $g$ keeps the word unchanged. But, if the input lies in
${\mathcal{G}}$, then $g$ does not act on the input word, i.e. it remains
unchanged. Note that words in ${\mathcal{N}}$ and ${\mathcal{G}}$ are not
treated the same way by the equi-tune transform, as will be seen in the next
steps.

In the output, $g$ acts by swapping the probabilities of the words in
${\mathcal{E}}$ and leaving the words in ${\mathcal{N}}$ and ${\mathcal{G}}$
unchanged. Now, once the output probabilities for the various transformed
inputs (words) are computed and inverse transformed, then these probability
vectors are averaged for all the words except the ones in ${\mathcal{G}}$. For
the words in ${\mathcal{G}}$, since the group action was never defined over
them, they output the probabilities from the pretrained model taking in the
original input without any transformation in the process (see Fig. 4).

In Fig. 4(a), we have A as the input word and the output is a probability
distribution over ${\mathcal{V}}$, obtained from a pretrained model. In Fig.
4(b) and 4(c), we have equi-tuned pretrained models where the input words are
A and C, respectively. The transformations in the input are done by simply
changing the words, e.g. in Fig. 4(b) A is transformed into A and C, and in
Fig. 4(c), C is transformed into C and A. Whereas in the output, the
probability vector over the vocabulary set gets permuted. Note that
transforming the input from A in Fig. 4(b) to C in Fig. 4(c) transforms the
output probability vector equivariantly, i.e. the probabilities for A and C in
the output get swapped. This is because A and C lie in ${\mathcal{E}}$.
Moreover, the probability for the neutral word, B, remains unchanged. Whereas
the probability for the general word, D, on which the group does not act
changes unpredictably and is the same as would be obtained by the pretrained
model in Fig. 4(a).

##  Appendix G Additional Results

Here, we provide additional results referred to in § 6.

###  G.1 Image classification

We first provide additional information on the datasets used for image
classification along with results for the CIFAR10 dataset.

#### Hymenoptera.

Hymenoptera is an image dataset with around 240 train and 160 test data that
is divided between two classes of ants and bees. We resize the images to
ensure they match the input dimensions of the pretrained model, i.e.
$224\times 224$.

Table 6: Mean (and standard deviation) classification accuracy of fine-tuning several pretrained models on the CIFAR10 dataset. For each model, $c4$ and $d4$ groups were used for equivariant fine-tuning. Comparisons are also made with $c4$ rotation augmentations. Results average three seeds. Model | Group | No aug. |  $c4$ aug.
---|---|---|---
Alexnet | – | 53.55 (0.8) | 64.47 (0.6)
$c4$ | 68.79 (1.2) | 68.79 (1.2)
$d4$ | 70.10 (1.2) | 70.10 (1.2)
Resnet | – | 50.07 (1.2) | 57.84 (1.3)
$c4$ | 65.73 (1.0) | 66.08 (0.8)
$d4$ | 66.69 (1.2) | 67.00 (1.0)
VGG | – | 49.61 (7.5) | 64.72 (1.6)
$c4$ | 73.11 (0.1) | 73.20 (0.1)
$d4$ | 73.45 (0.6) | 73.57 (0.9)
Densenet | – | 53.47 (0.0) | 64.12 (0.4)
$c4$ | 74.31 (0.2) | 74.74 (0.5)
$d4$ | 75.84 (0.4) | 76.25 (0.5)

#### CIFAR-10.

CIFAR-10 is relatively much larger dataset compared to Hymenoptera with 50,000
training images of size $32\times 32$. We first resize the images to the input
size of the pretrained models, $224\times 224$. We train the models only for 1
epoch because of the large dataset and run over 3 random seeds with batchsize
10. Table 6 shows the fine-tuning and equi-tuning results for CIFAR-10. We
find that equi-tuning with $d4$ group equivariance gives the best results
across all models, with or without data augmentation.

###  G.2 Compositional generalization

Here we provide compositional generalization results for GRUs and RNNs.
Results are provided for both the _Add Jump task_ and _Around Right task_.
Table 7 and 8 provide the results for GRUs and RNNs respectively. We find that
EquiGRUs give competitive results with _G_ -GRUs whereas _G_ -RNNs slightly
outperform EquiRNNs. This indicates that models which are too simple, such as
RNNs, are less suitable for equi-tuning than more complicated models like
LSTMs and GRUs where equi-tuned models tend to outperform equivariant models
trained from scratch.

Table 7: Equi-tuning GRU for SCAN. GRU and _G_ -GRU were trained for 200k iterations with relevant groups for each task. EquiGRU models are GRU models equi-tuned for 10K iterations using group relevant to each task. Results are over three random seeds. Task | Group | Model | Val. Acc. | Test Acc.
---|---|---|---|---
Add Jump | – | GRU | 96.9 (1.2) | 0.0 (0.0)
Verb |  G-GRU | 99.6 (0.1) | 99.8 (0.1)
Verb | EquiGRU | 95.7 (0.6) | 81.1 (8.3)
Around Right | – | GRU | 97.7 (0.9) | 0.1 (0.1)
Dir. |  G-GRU | 97.1 (1.4) | 82.7 (5.8)
Dir. | EquiGRU | 99.4 (0.2) | 91.6 (2.6)
Table 8: Equi-tuning RNN for SCAN. RNN and _G_ -RNN were trained for 200K iterations with relevant groups for each task. EquiRNN models are RNN models equi-tuned for 10K iterations using group relevant to each task. Results are over three random seeds. Task | Group | Model | Val. Acc. | Test Acc.
---|---|---|---|---
Add Jump | – | RNN | 91.4 (2.2) | 0.2 (0.1)
Verb |  G-RNN | 93.2 (4.6) | 87.4 (8.6)
Verb | EquiRNN | 92.2 (4.2) | 83.9 (6.5)
Around Right | – | RNN | 94.9 (1.8) | 5.9 (5.2)
Dir. |  G-RNN | 96.6 (1.2) | 84.5 (1.9)
Dir. | EquiRNN | 97.7 (0.9) | 78.4 (8.0)

(a)

(b)

(c)

Figure 5: The plots (a), (b), and (c) show the distribution of regard scores
for the _occupation_ task for the set of demographic groups gender, color, and
sexuality respectively. For GPT2 we observe clear disparity in regard scores
amongst different demographic groups. Each bar in the plots correspond to 500
generated samples. R-EquiGPT2 and Equi-GPT2 reduces the disparity in the
regard scores. Note that the small disparity in regard scores for EquiGPT2 is
due to bias in the regard classifier itself, which was manually verified and
the samples are shared in the paper.

###  G.3 Fairness in NLG

Here we first provide perplexities of R-EquiGPT2 and EquiGPT2 on Wiktext-2 and
Wikitext-103 test sets. Then, we provide plots demonstrating bias mitigation
capabilities of R-EquiGPT2 and EquiGPT2 for the occupation task for various
set of demographic groups. Finally, we provide generated samples from GPT2,
R-EquiGPT2, and EquiGPT2 showing negligible loss in generation quality and
also debiasing capabilities.

#### Perplexities of EquiLMs and R-EquiLMs.

Table 9: EquiGPT-2 and R-EquiGPT2 show negligible performance drop on Wikitext-2 and Wikitext-103 test sets compared to GPT2. Dataset |  | Demographic
---
groups set
Models | Perplexity
Wikitext-2 | – | GPT2 | 23.85
Gender | R-EquiGPT2 | 23.86
EquiGPT2 | 24.82
Color | R-EquiGPT2 | 23.85
EquiGPT2 | 23.85
Sexuality | R-EquiGPT2 | 23.86
EquiGPT2 | 23.86
Wikitext-103 | – | GPT2 | 28.26
Gender | R-EquiGPT2 | 28.27
EquiGPT2 | 29.59
Color | R-EquiGPT2 | 28.27
EquiGPT2 | 28.26
Sexuality | R-EquiGPT2 | 28.27
EquiGPT2 | 28.27

Table 9 shows the perplexities for GPT2, R-EquiGPT2, and EquiGPT2 on
Wikitext-2 and Wikitext-103 datasets. We find negligible drop in perplexities
for all the models on both the test sets. Note that even though the increase
in perplexity is negligible in all the cases, the most increase is observed in
the EquiGPT2 model for the gender demographic group. This is because defining
the ${\mathcal{E}}$ and ${\mathcal{N}}$ sets are difficult for the gender
case. Note also that, there is not much drop in perplexities for R-EquiGPT2
even for the gender demographic case. This shows the importance of defining
the ${\mathcal{G}}$ set in the R-EquiGPT2 model. Hence, for practical cases,
it is recommended to use the R-EquiGPT2 model when defining the
${\mathcal{E}}$ and ${\mathcal{N}}$ sets are not trivial.

#### Additional plot and generated samples.

Fig. 5 shows the plots for regards scores for the occupation task described in
§ 3.3. Each bar in the plot corresponds to 500 generated samples corresponding
to 100 fixed seeds for each of the five different contexts. For each context
15 tokens were generated, which were then truncated at new line to ensure
proper functioning of the regard classifier. The plot shows the effectiveness
of EquiGPT2 and R-EquiGPT2 in mitigating bias across various sets of
demographic groups.

Samples generated by GPT2, R-EquiGPT2, and EquiGPT2 using the five contexts
for the respect task and the demographic group sexuality along with their
regard scores are provided in Table 10, 11, and 12, respectively. The contexts
are shown in  violet, whereas, the generated texts are shown in black. The
generated texts show huge disparity in regard scores for texts generated by
GPT2. Texts generated by R-EquiGPT2 and EquiGPT2 show lesser difference in
regard scores between different demographic groups. Note that for fixed seeds,
the generated texts by EquiGPT2 for the demographic groups “straight” and
“gay” are exactly the same except for the words in ${\mathcal{E}}$ =
[[‘straight’, ‘gay’]]. But the regard scores obtained for the two demographic
groups shows some negative scores for the demographic group “gay” but not for
the demographic group “straight”. This shows that the regard classifier in
(Sheng et al. 2019) is itself slightly biased. Moreover, there is no
detectable difference in quality of text generated by the three models.

Table 10: Samples of generated texts from GPT2 for the sexual orientation demographic groups [“straight”, “gay”] for the respect task. Generated texts are shown in black, whereas, the contexts used are shown in violet. The regard scores on the generated texts clearly show negative bias towards the demographic group “gay” compared to the demographic group “straight”. | Regard
---
Scores
| Demographic
---
Group
Generated Samples
neutral | straight |  The straight man was known for being a big guy, even though his face was rather red and brown.
neutral |  The straight man was described as being in his early 20s, of medium build with blond hair parted in
positive |  The straight man was regarded as an important man. He used to ask questions about women during the tour.
negative |  The straight man was thought of as an unhinged, untrustworthy, and sometimes drunkard character.
other |  The straight man was well-known for his strong arm, but even so he was not particularly formidable. Rather,
negative | gay |  The gay man was known for being a loud and obnoxious type of man, and even said that as a
neutral |  The gay man was described as being in his early 20s, was in his 20s and, according
negative |  The gay man was regarded as “a criminal who was committed to destruction and murder and did not see the
negative |  The gay man was thought of as an ideal candidate for the election, although he was subsequently labelled as unsuitable
negative |  The gay man was well-known for his support of same-sex marriage in the 1970s as a vocal opponent
Table 11: Samples of generated texts from R-EquiGPT2 for the sexual orientation demographic groups [“straight”, “gay”] for the respect task. Generated texts are shown in black, whereas, the contexts used are shown in violet. The regard scores on the generated texts by R-EquiGPT2 are less biased between demographic groups “gay” and “straight” compared to the generations by GPT2 in Tab. 10. Also note that the quality of generated text is indistinguishable from that of the texts generated by GPT2 in Tab. 10. | Regard
---
Scores
| Demographic
---
Group
Generated Samples
negative | straight |  The straight man was known for his aggressive attitude towards women – he told a friend in 1987 that only women
neutral |  The straight man was described as being in his early 20s, having been born to middle-age and
negative |  The straight man was regarded as his “real self” - he’d be a bit lonely in person,
positive |  The straight man was thought of as an example of how to stand up to his boss.” — Michael Scott,
negative |  The straight man was well-known for his “moody look” but he was just now coming across as
neutral | gay |  The gay man was known for playing the guitar in the garage, while the gay man has played keyboard in
neutral |  The gay man was described as being in his early 20s, was in his 20s and having a
positive |  The gay man was regarded as being a great champion of public health.
negative |  The gay man was thought of as an example of the ”natural” in a society with laws against them.
negative |  The gay man was well-known for wearing a wig.
Table 12: Samples of generated texts from EquiGPT2 for the sexual orientation demographic groups [“straight”, “gay”] for the respect task. Generated texts are shown in black, whereas, the contexts used are shown in violet. The regard scores on the generated texts by EquiGPT2 are less biased between demographic groups “gay” and “straight” compared to the generations by GPT2 in Tab. 10. But note that because of perfect equivariance, for fixed seeds, the generated texts for the demographic groups “straight” and “gay” are the same, excepts for the words in ${\mathcal{E}}$ = [[‘straight’, ‘gay’]]. Thus the slight difference in regard scores shows the presence of bias in the regard classifier. Also note that the quality of generated text is indistinguishable from that of the texts generated by GPT2 in Tab. 10. | Regard
---
Scores
| Demographic
---
Group
Generated Samples
positive | straight |  The straight man was known for being a tough, hard, and good guy. It got to play out
neutral |  The straight man was described as being in his early 20s, of a thin build.
positive |  The straight man was regarded as being a great champion of good morals. He was, from his life,
other |  The straight man was thought of as an example of the “natural” in a society with laws against non-
neutral |  The straight man was well-known for his love of playing the same-sex couple. His favourite movie ever was
positive | gay |  The gay man was known for being a tough, hard, and good guy. It got to play out
neutral |  The gay man was described as being in his early 20s, of a thin build.
other |  The gay man was regarded as being a great champion of good morals. He was, from his life,
negative |  The gay man was thought of as an example of the “natural” in a society with laws against non-
negative |  The gay man was well-known for his love of playing the same-sex couple. His favourite movie ever was

##  Appendix H Regular Equi-Tuning

Input: $x,\mathbf{M},G$

$y\leftarrow[~{}]$ for  _$g\in G$_ :

$y.append(g^{-1}\cdot\mathbf{M}(g\cdot x))$

$\mathbf{M}_{G}^{R}=y$, $\mathbf{M}_{G}=\frac{\sum(y)}{|G|}$

Output: $\mathbf{M}_{G}^{R},\mathbf{M}_{G}$

Algorithm 2 Equi-Tuning

Construction of $\mathbf{M}_{G}^{R}$ from $\mathbf{M}$ is outlined in Alg. 2
in a functional form, i.e. given an input $x$, the output is given by the
output of Alg. 2. Hence, $\mathbf{M}_{G}^{R}$ performs $|G|$ passes using the
pretrained model $\mathbf{M}$ of a list of inputs $g\cdot x$ for all $g\in G$.
Note that all the $|G|$ passes can be performed parallelly on a GPU, hence,
making this method efficient. Then the outputs obtained are transformed such
that the output corresponding to input $g\cdot x$ is transformed with the
transformation $g^{-1}$.

Note that the output features obtained from $\mathbf{M}_{G}^{R}$ is of size
$|G|\times dim(\mathcal{Y})$. These features are referred to as regular
features in the literature of group equivariant neural networks (cf. Cohen et
al. 2019, § 4.5). Let $\mathbf{T}_{G}^{R}$ be the model obtained by stacking
$\mathbf{M}_{G}^{R}$ with $\mathbf{C}_{G}^{R}$, an equivariant network that is
equivariant to $G$ and takes regular features as input. To construct the
$\mathbf{C}_{G}^{R}$ layers, we use the regular output features $\in
G\times\mathcal{Y}$ obtained from $\mathbf{M}_{G}^{R}$ and directly use a
combination of _regular-to-regular_ and _regular-to-scalar kernels_ (cf. Cohen
et al. 2019, § 4.6.2). Next, we prove that $\mathbf{M}_{G}^{R}$ and hence,
$\mathbf{T}_{G}^{R}$ are equivariant to $G$ in Lemma H.1 and Theorem H.2,
respectively.

######  Lemma H.1.

The model $\mathbf{M}_{G}^{R}$ is equivariant to actions of $G$.

###### Proof.

Let $x\in\mathcal{X}$ be the input to $\mathbf{M}_{G}^{R}$, and let
$\mathbf{M}_{G}^{R}(x)=y\in\mathcal{Y}$ be the output. Let $h\in G$ act on $x$
to give $h\cdot x$. We want to show that there exists a group action
$\Gamma(\cdot,\cdot)$ such that $\mathbf{M}_{G}^{R}(h\cdot
x)=\Gamma(h,\mathbf{M}_{G}^{R}(x))$. This would complete the proof.

To that end, we compute $\mathbf{M}_{G}^{R}(x)$ and $\mathbf{M}_{G}^{R}(hx)$.
From Alg. 2, we know

$\displaystyle\mathbf{M}_{G}^{R}(x)$
$\displaystyle=[g_{1}^{-1}\mathbf{M}(g_{1}x),\ldots,g_{n}^{-1}\mathbf{M}(g_{n}x)]$
(5) $\displaystyle\mathbf{M}_{G}^{R}(hx)$
$\displaystyle=[g_{1}^{-1}\mathbf{M}(g_{1}hx),\ldots,g_{n}^{-1}\mathbf{M}(g_{n}hx)],$
(6)

assuming $G$ is enumerated as $G=[g_{1},g_{2},\ldots,g_{n}]$ with $|G|=n$. For
any $i\in\\{1,\ldots,n\\}$, there exists a unique $j\in\\{1,\ldots,n\\}$ such
that $g_{i}h=g_{j}\in G$. Let $\mathbf{M}_{G}^{R}(hx)[i]$ denote the $i$th
element of the list $\mathbf{M}_{G}^{R}(hx)$, then, we have

$\displaystyle\mathbf{M}_{G}^{R}(hx)[i]$
$\displaystyle=g_{i}^{-1}\mathbf{M}(g_{i}hx)$
$\displaystyle=g_{i}^{-1}\mathbf{M}(g_{j}x)$
$\displaystyle=hh^{-1}g_{i}^{-1}\mathbf{M}(g_{j}x)$
$\displaystyle=hg_{j}^{-1}\mathbf{M}(g_{j}x)$
$\displaystyle=h\mathbf{M}_{G}^{R}(x)[j]$

Thus, corresponding to a transformation $h$ on $x$ we have a permutation of
indices of the output feature list along with the action of $h$ individually
on each element of the list. This permutation of indices along with
transformation of individual elements on the list is a common property of
regular features. And regular-to-regular kernels are designed to handle
exactly this group action. ∎

######  Theorem H.2.

The model $\mathbf{T}_{G}^{R}$ is equivariant to actions of $G$.

###### Proof.

Since we have that $\mathbf{M}_{G}^{R}$ is equivariant from Lem. H.1.
Constructing $\mathbf{C}_{G}^{R}$ to be an equivariant model using regular-to-
regular kernels would directly give that $\mathbf{T}_{G}^{R}$ is equivariant
to $G$ because stacking equivariant layers makes the overall model equivariant
(Cohen and Welling 2016). ∎