COUNT : CO ntrastive UN likelihood Text Style Transfer for Text Detoxification (2023)

Abstract: Offensive and toxic text on social media platforms can lead to polarization and divisiveness within online communities and hinders constructive dialogue. Text detoxification is a crucial task in natural language processing to ensure the generation of non-toxic and safe text. Text detoxification is a special case of the Text Style Transfer (TST) problem, where an input text is rephrased to an output text that preserves its content while modifying the style (in this case to a more neutral, non-toxic style). State-of-the-art methods for detoxification use supervised training of encoder-decoder models to produce gold-standard outputs with a standard likelihood-based objective. However, it can be hard for these models to deviate from their pretrained auto-encoder identity mapping. While previous methods have used unlikelihood-based losses to penalize input-to-output copying of toxic content, these methods also unfortunately penalize non-toxic content in the input that would be fine to preserve in the output. To address these issues, we introduce a novel contrastive unlikelihood objective (COUNT) that directly contrasts the gold standard rephrasing with the identity input-to-output mapping to effectively isolate and focus learning on non-toxic style transfer. We benchmark COUNT on two parallel datasets, ParaDetox and APPDIA, showing that it achieves significant improvements in jointly combined fluency, content preservation, and detoxification (i.e., the highest “J” score).

## introduction disclaimer. please be aware that as you read this paper, you may come across texts that could be considered toxic due to the nature of this research. exposure to offensive and toxic text on online platforms can have detrimental consequences, causing emotional distress and negative psychological effects on users @xcite . such experiences can deter individuals from actively engaging in online communities and social media. therefore, text detoxification solutions are indispensable for mitigating harmful content on online platforms. text detoxification is a text-style transfer task where the goal is to change the style of an input text from toxic to safe while the content is preserved. most state-of-the-art text detoxification methods use supervised training of encoder-decoder models @xcite . the objective of those methods relies on maximizing the likelihood of generating gold-standard non-toxic outputs, but fails to penalize generation of the toxic inputs. to address this issue, @xcite proposed an "unlikelihood" training methodology that can be used to penalize generation of toxic inputs while encouraging generation of gold standard non-toxic output. while this improves on the simple likelihood objective, we observe experimentally that it often fails to overcome the strong inertia of the pretrained model to produce the identity input-to-output mapping that preserves toxic text. one key reason for this is that unlikelihood cannot be weighted too heavily can penalize both the toxic and non-toxic content in the input. to address this issue, we introduce a novel contrastive unlikelihood text style transfer (count) objective that directly contrasts the likelihood of the gold standard rephrasing with the likelihood of the identity input-to-output mapping to effectively isolate and focus learning on style transfer for text detoxification. our contributions are twofold: (1) we propose the count loss function as a novel training objective for text detoxification. (2) we show that by using the count loss, our method delivers significant improvements on a joint measure ("j" score) of fluency, content preservation, and detoxification on two publicly available parallel datasets, paradetox and appdia, for the text detoxification task. ## methodology the text-detoxification task aims to generate a nontoxic sentence y given a toxic input x while preserving the content of x. state-of-the-art detoxification methods @xcite fine-tune an encoder-decoder model such as bart @xcite for detoxification. bart is a sequence-to-sequence denoising autoencoder that has been trained to reconstruct the input text. the standard approach for fine-tuning encoder-decoder models maximizes the probability of generating target sequence y * by the decoder, given the input x to the encoder. this is done using the standard language modeling (lm) loss: for fine-tuning, eq. ( 1 ) encourages the output to have a non-toxic style by training the model to have a high likelihood for y * (learning from parallel data). however, in the detoxification task, we need to also penalize the toxicity in addition to maximizing the likelihood of target sequence y * . since encoder-decoder models such as bart reconstruct the input, these models need to deviate from the identity mapping to reduce toxicity. unlikelihood training @xcite ) can be used to penalize toxicity by minimizing the likelihood of toxic samples using the following unlikelihood training (ut) loss @xcite : however, minimizing the likelihood of p θ (@xmath0. non-toxic). therefore, we propose the count loss function to discriminatively focus on detoxifying the style of the text. specifically, the count loss function contrasts toxic sentence x and target non-toxic paraphrase y * as they have the same semantics but a different style. hence, contrastively maximizing the likelihood of p θ (@xmath1.e., the toxic component). formally, the count loss function is defined as follows: to minimize the loss in eq. ( 4 ), the model is aiming for a large probability of the non-toxic reference p θ (@xmath2. however, as we show in the next section, this loss aims to avoid penalizing the common (non-toxic) content between y * and y since the probability of this content cancels in the ratio. we combine the count loss with the standard language modeling loss so the total loss would be: ## conclusion in this paper, we observed that existing methodologies for detoxification either fail to penalize inputto-output copying of toxic content (lm loss) or also penalize input-to-output copying of non-toxic content (ut loss). to resolve this, we introduced the novel count loss function to contrastively penalize toxic text style in the detoxification task while effectively normalizing for other style-irrelevant aspects during training. experimental results show the proposed count method achieves significant improvements in the combined j-score metric for text detoxification on paradetox and appdia. in general, the count methodology is not specific to detoxification methods for text style transfer and has potential application to many other style transfer tasks that could be explored in future work.