CFL : Causally Fair Language Models Through Token-level Attribute Controlled Generation (2023)

Abstract: We propose a method to control the attributes of Language Models (LMs) for the text generation task using Causal Average Treatment Effect (ATE) scores and counterfactual augmentation. We explore this method, in the context of LM detoxification, and propose the Causally Fair Language (CFL) architecture for detoxifying pre-trained LMs in a plug-and-play manner. Our architecture is based on a Structural Causal Model (SCM) that is mathematically transparent and computationally efficient as compared with many existing detoxification techniques. We also propose several new metrics that aim to better understand the behaviour of LMs in the context of toxic text generation. Further, we achieve state of the art performance for toxic degeneration, which are computed using Real Toxicity Prompts. Our experiments show that CFL achieves such a detoxification without much impact on the model perplexity. We also show that CFL mitigates the unintended bias problem through experiments on the BOLD dataset.

## introduction as language models (lms) get deployed into more and more real world applications, safe deployment is a pressing concern @xcite @xcite . the twin issues of toxicity and bias in text generation are important challenges to such deployment @xcite @xcite @xcite . often, the toxicity and bias goals are opposed to each other, as toxicity mitigation techniques may increase the bias of a language model towards certain protected groups such as gender, race or religion @xcite . from an initial focus towards toxicity detection @xcite , recent works on hate speech in lms have focused directly on toxicity mitigation @xcite . such detoxification methods may use data-based approaches @xcite @xcite , fine-tuning methods @xcite , decodingtime strategies @xcite or reward modelling @xcite . we summarize a few such methods in while these approaches optimize for toxicity metrics, they are prone to over-filtering texts related to marginalized groups @xcite . this in this work, we employ the causal formalisms of average treatment effect (ate) with counterfactual augmentation to identify spurious correlations. we then propose a structural causal model (scm) for identifying causal attribute scores, say for the toxicity attribute, using a general l p norm metric. such an scm allows fine-grained control over losses passed to the lm during training. we use such scm losses for controlled text generation in a more robust, efficient and interpretable manner. figure 1 illustrates our mechanism with examples. ## related work in this section we will look at five related lines of work: (a) controlled generation (b) toxicity detection (c) language detoxification (d) unintended bias due to detoxification (e) causal fairness. (a) controlled generation: our task is to control the toxicity in lm generation. towards controlling language attributes, several methods have been studied. current methods for controlling the text attributes could be categorised into either using posthoc decoding time control using attribute classifiers @xcite , finetuning the base model using reinforcement learning @xcite , generative adversarial models @xcite , training conditional generative models @xcite , or conditioning on control codes to govern style and content @xcite . a survey of these techniques is discussed in @xcite . of these, decoding time methods are quite slow (for example see in the next section we will outline our approach to the problem of simultaneously mitigating toxicity and unintended bias in lms. ## our approach the broad goal of this paper is to use a causal model to fine-tune a pretrained lm used for the text generation task, towards having certain attributes. to this end, we detect the presence of the attributes in text generated by the pretrained lm using a structural causal model (scm), and penalize the model for undesirable text. our pipeline consists of two main parts, the scm used for fine-tuning, and a pretrained lm that will be fine-tuned. the data that will be used for prompting the text-generation is also an important component of this fine-tuning step. ## notations and theory let us consider a sentence s, having certain attributes, and made up of tokens from some universe of words w . for simplicity, we consider each sentence to be of the same length n (if not, we add dummy tokens). for each attribute a on this sentence, we may have access to classifiers that provide us with estimates of the probability of attribute a, given the sentence s, i.e. p{a | s}. for the purpose of the toxicity attribute, we may use classifiers like hatebert or hatecheck @xcite , which provide us with estimates of p{hate | sentence}. more generally, we can denote f a (s) as the estimate of p{a | s} obtained from some model. if sentence s is made up of tokens {t 1 , . . . , t i , . . . , t n }. we may consider a counter-factual sentence s ′ where (only) the ith token is changed: {t 1 , . . . , , t ′ i , . . . , t n }. such a token t ′ i may be the most probable token to replace t i , given the rest of the sentence. note that we have good models to give us such tokens t ′ i . (in fact masked language modeling (mlm) tasks train language models like bert for precisely this objective). we now define a certain value that may be called the treatment effect (te), which computes the effect of replacement of t i with t ′ i in sentence s, on the attribute probability. ## experimental results we highlight the efficacy of our approach through various experiments. first we define several new toxicity measures and measure our performance over these metrics. then we compare with several competing detoxification techniques. we then highlight the trade-off between toxicity mitigation and language fluency measured using perplexity scores over a 10k subset of open web text corpus (owtc). finally we measure the unintended bias due to detoxification. we detail these as below: ## conclusion and future directions in this paper, we outlined a method for causal attribute control of the text generated by lms. we utilized our methods in the specific context of toxicity mitigation. we proposed novel methods using counterfactual generation and ate scores to obtain token level contribution towards an attribute. we then proposed a causal graph, and thereby an scm, that outputs causal attribute loss for any given sentence. we utilized such an scm to fine-tune pretrained lms to mitigate toxicity and reduce bias. the scm framework we proposed is mathematically transparent as well as computationally efficient, and shows promise towards being useful for various goals in text generation. an interesting future direction of work would be to consider the theoretical implications of our causal ate framework to supplement probabilistic reasoning across various natural language tasks.