Style-Specific Neurons for Steering LLM s in Text Style Transfer (2024)

Abstract: Text style transfer (TST) aims to modify the style of a text without altering its original meaning. Large language models (LLMs) demonstrate superior performance across multiple tasks, including TST. However, in zero-shot setups, they tend to directly copy a significant portion of the input text to the output without effectively changing its style. To enhance the stylistic variety and fluency of the text, we present sNeuron-TST, a novel approach for steering LLMs using style-specific neurons in TST. Specifically, we identify neurons associated with the source and target styles and deactivate source-style-only neurons to give target-style words a higher probability, aiming to enhance the stylistic diversity of the generated text. However, we find that this deactivation negatively impacts the fluency of the generated text, which we address by proposing an improved contrastive decoding method that accounts for rapid token probability shifts across layers caused by deactivated source-style neurons. Empirical experiments demonstrate the effectiveness of the proposed method on six benchmarks, encompassing formality, toxicity, politics, politeness, authorship, and sentiment.

## introduction text style transfer (tst; @xcite aims to transform text from a source style to a target style while maintaining the original content and ensuring the fluency of the generated text. given any text x in an original style s 1 , the objective of tst is to transform x into a new text x in a different style s 2 (s 2 ̸ = s 1 ), ensuring that the content remains unchanged despite the shift in style. large language models (llms; @xcite exhibit exceptional performance across various nlp tasks @xcite , including tst @xcite . however, existing llms (e.g., llama-3 meta, 2024) 1 https://github.com/wenlai-lavine/sneuron-tst tend to prioritize preserving the original meaning over enhancing stylistic differences in tst. our analysis reveals that 34% of the outputs generated by llama-3 are identical to the input text when tasked with transferring polite text to impolite text (section 6.2). enhancing the generation of words that align with the target style during the decoding process remains a significant challenge in tst. recent llms have been successfully applied to tst, broadly categorized into two approaches: (i) employing single-style or parallel-style text data for either full-parameter or parameter-efficient finetuning @xcite , and (ii) leveraging the robust in-context learning capabilities of llms to create specialized prompts for zeroshot or few-shot learning @xcite . however, (i) typically requires substantial data and computational resources to achieve good results, while (ii) is highly sensitive to prompts, where even minor changes can significantly impact the outcomes @xcite . neuron analysis @xcite , which aims to identify and understand the roles of individual neurons within a neural network, is a crucial method for enhancing the interpretability of neural networks and has garnered increasing attention in recent years. by identifying neurons associated with specific attributes such as language @xcite , knowledge @xcite , and skill @xcite , neuron analysis can boost performance on targeted tasks. recent research has demonstrated that focusing on language-specific neurons can markedly enhance the multilingual capabilities of llms during the decoding stage @xcite . however, the exploration of style-specific neurons remains relatively underexplored until now. thus motivated, we raise the following two research questions: q1: do llms possess neurons that specialize in processing style-specific text? q2: if such neurons exist, how can we optimize their utilization during the decoding process to steer llms in generating text that faithfully adheres to the target style? to address these research questions, we introduce sneuron-tst, a novel framework designed to steer llms in performing tst by leveraging stylespecific neurons. initially, we feed both sourceand target-style texts into the llm to identify neurons that exclusively activate in each style based on their activation values. we distinguish neurons active in both styles as overlapping neurons. notably, eliminating these overlapping neurons during stylespecific neuron selection is crucial as their presence can hinder the generation of text in the target style. our experiments highlight that deactivating neurons specific solely to the source style (excluding those active in both source and target styles) improves style transfer accuracy while impacting sentence fluency. furthermore, to improve the fluency of generated text, we adapt the state-of-the-art contrastive decoding algorithm (dola; @xcite for optimal performance in tst tasks. our empirical findings (detailed in section 3.3.2) reveal that layers primarily responsible for style-related outputs are concentrated in the model's latter layers, termed as style layers. this indicates that the determination of style-specific words predominantly occurs in these style layers. more precisely, we refine the probability distribution of generated words by comparing logits from these style layers with the final layers, which exert significant influence on style-related outputs. we conduct a comprehensive evaluation to verify the efficacy of our approach across six benchmarks: formality @xcite , toxicity @xcite , politics @xcite , politeness @xcite , authorship @xcite and sentiment @xcite . each benchmark contains two distinct styles, resulting in a total of 12 tst directions. experimental results demonstrate that our method generates a higher proportion of words in the target style compared to baseline systems, achieving superior style transfer accuracy and fluency, while preserving the original meaning of the text. in summary, we make the following contributions: (i) to the best of our knowledge, this is the first work on using style-specific neurons to steer llms in performing text style transfer tasks. ## method our goal is to identify style-specific neurons to steer llms towards generating vocabulary tailored exclusively to a target style, while maintaining fluent text generation in a zero-shot setting. to accomplish this, we first identify style-specific neurons based on their activation values and demonstrate the necessity of eliminating source-and targetstyle neurons to avoid overlap (section 3.1). then, we deactivate neurons associated solely with the instruction: please transfer the following positive style sentence into a negative style sentence and maintain the meaning of the sentence. input: both dishes were prepared with quality veggies. output: neither dishes were prepared with poor veggies. ## results overall performance. while the ape, avf, and pnma demonstrate strong performance in enhancing multilingual capabilities, they do not outperform the original llama-3 model in the tst task, with the exception of the content preservation metric. this disparity arises primarily because language-specific properties can be identified using straightforward features, such as script differences. consequently, the neuron selection methods of these baselines, despite their partial overlaps, have minimal impact on multilingual performance. however, text style represents a more complex attribute, requiring models to learn extensive knowledge and execute nuanced judgments at both the word and semantic levels. the overlap of neurons in baseline systems across source and target styles adversely affects the results, particularly in style accuracy. furthermore, the baseline methods lack a contrastive decoding strategy, which compromises their fluency. our method outperforms the baseline methods in terms of both accuracy and fluency, highliting the importance of eliminating overlapping style neurons and employing contrastive decoding. content preservation. interestingly, we observe that the original llama-3 and other baseline systems exhibit strong performance in content preservation, which appears inconsistent with conclusions drawn from the other two metrics. upon closer examination, we find that this content preser- ## analysis in this section, we conduct an ablation study to verify the criticality of eliminating overlap between source-and target-side style neurons, alongside the importance of neuron deactivation and contrastive decofing (section 6.1). subsequently, we conduct a detailed analysis of the copy problem in the tst task (section 6.2). finally, we delve into several other significant factors inherent to our approach (section 6.4). ## conclusion we revisit the tst task in llms through a neuronal analysis perspective. our study focuses on identifying style-specific neurons within llms, highlighting the critical importance of removing overlap between source-and target-side stylistic neurons. we find that deactivating source-specific neurons enhances the probability of generating target-style words but may compromise the fluency of generated sentences. to mitigate this issue, we adapt the state-of-the-art contrastive decoding method (dola) for tst, ensuring both the fluency and effective style transformation of generated sentences. experimental results across six benchmarks demonstrate the efficacy of our approach.