SASFT: Sparse Autoencoder-guided Supervised Finetuning to Mitigate Unexpected Code-Switching in LLMs

Boyi Deng, Yu Wan, Baosong Yang, Fei Huang, Wenjie Wang, Fuli Feng

TL;DR

Multilingual Large Language Models (LLMs) frequently suffer from "unexpected code-switching," where they randomly inject words or characters from an incorrect language mid-response. By using Sparse Autoencoders (SAEs) to uncover the internal mechanistic cause—abnormally high pre-activation spikes in irrelevant language features—the authors introduce SASFT, a finetuning method that penalizes these spikes. SASFT slashes unexpected code-switching by over 50% across multiple model families while fully preserving or even boosting their core multilingual capabilities.

What Problem Does This Paper Address?

While modern LLMs boast impressive multilingual capabilities, they suffer from a frustrating failure mode known as unexpected code-switching or language mixing. A model prompted entirely in English might suddenly output a sentence containing random Chinese, Russian, or Korean phrases. This behavior severely degrades readability and compromises the reliability of the model for end-users.

Figure 1: Examples of unexpected code-switching to Chinese, Russian, and Korean.

Previous attempts to mitigate this issue treat the LLM as a black box, using reinforcement learning methods like GRPO with language consistency rewards. However, these approaches lack a fundamental understanding of why the model switches languages internally and often show limited or unstable effectiveness. This paper bridges that gap by providing the first mechanistic analysis of code-switching and offering a targeted training solution.

Methods

The authors leverage Sparse Autoencoders (SAEs) to inspect the internal hidden states (specifically the residual streams) of LLMs. SAEs allow researchers to decompose complex, dense activations into interpretable, sparse features. Through this lens, they discover that specific directions in the residual stream act as "language-specific features."

Building on this insight, they propose Sparse Autoencoder-guided Supervised Finetuning (SASFT). Instead of manually steering features during inference (which adds computational overhead), SASFT introduces an auxiliary loss term ($L_{reduce}$) during standard Supervised Finetuning (SFT). This loss applies a ReLU-based penalty whenever the pre-activation values of irrelevant language features exceed a pre-estimated baseline threshold. Essentially, it teaches the model to actively suppress the internal triggers of unwanted languages while it is trained to speak a target language.

Datasets

The authors constructed six distinct SFT training datasets using a mix of open-source repositories:

  • Single-language sources: KULLM (Korean), Tulu3 (English), WildChat (Russian), and BelleGroup (Chinese).
  • Multilingual sources: Multialpaca, Flores, and GSM8KInstruct.

They evaluated their approach across two dataset sizes (210k and 110k samples) on five base models: Gemma-2-2B, Gemma-2-9B, Llama-3.1-8B, Qwen3-1.7B-Base, and Qwen3-8B-Base. Evaluation prompts were drawn from multilingual versions of standard benchmarks including MMLU, MGSM, HellaSwag, LogiQA, IFEval, and Flores-200.

Key Insights and Ideas

  • The Smoking Gun: Unexpected code-switching isn't random noise. SAE analysis revealed that immediately before a model switches languages, the pre-activation values of the intruder language's features gradually and abnormally ramp up.
  • Bidirectional Causal Proof: The authors proved a direct causal link between these internal features and text generation. Mechanistically ablating (subtracting) the feature during inference suppressed the code-switching behavior, while artificially enhancing (adding) the feature forced the model to code-switch.
  • Multi-Layer Distribution: Language features are not localized to a single layer; they are distributed across the network. The authors found that applying the SASFT penalty across multiple consecutive layers provides significantly more stable and robust reduction than targeting a single layer.

Key Results

  • Substantial Code-Switching Reduction: SASFT consistently outperformed standard SFT and GRPO baselines, reducing unexpected code-switching by more than 50% in 23 out of 30 tested scenarios. In several cases, such as Qwen3-1.7B-Base responding to Korean prompts, the unwanted code-switching was completely eliminated (a 100% reduction).
  • Preserved Multilingual Performance: A common pitfall of vocabulary or token-level penalties is that they degrade the model's general intelligence. Because SASFT operates on internal semantic features rather than raw tokens, it maintained or even improved performance on standard benchmarks. For example, Llama-3.1-8B trained with SASFT saw an improvement of +3.13 on MMLU and +4.14 on HumanEval compared to the standard SFT baseline.

Limitations and Future Work

While highly effective, the authors note a few limitations:

  1. Language Scope: The study only evaluated code-switching into three target languages (Chinese, Russian, and Korean).
  2. Model Scale: The experiments were restricted to models under 9B parameters. Testing on larger models (e.g., 70B+) is necessary to confirm scalability.
  3. Coarse Thresholds: The auxiliary loss relies on static, pre-estimated average pre-activation values as thresholds. The authors suggest that developing dynamic, token-level thresholds could further optimize performance.

Summary updated

BibTeX
@inproceedings{deng2026sasft,
  author = {Boyi Deng and Yu Wan and Baosong Yang and Fei Huang and Wenjie Wang and Fuli Feng},
  title = {{SASFT: Sparse Autoencoder-guided Supervised Finetuning to Mitigate Unexpected Code-Switching in LLMs}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=BQOFU9qO5j},
}
Figure