Introduction
Multilingual Large Language Models (LLMs) have achieved remarkable proficiency across dozens of languages. However, they frequently encounter a phenomenon known as "unexpected code-switching," where the model abruptly transitions into an incorrect language mid-response. For instance, a user might query the model in English, only to receive a response that starts in English but suddenly incorporates Chinese, Russian, or Korean characters. This "language leakage" significantly undermines user trust and the practical utility of these models.
While previous mitigation strategies often relied on "black-box" reinforcement learning or vocabulary penalties, they lacked a fundamental understanding of the underlying cause. This research investigates the internal mechanics of code-switching and proposes a novel finetuning method, Sparse Autoencoder-guided Supervised Finetuning (SASFT), to address the issue at its source.
Mechanistic Analysis of Code-Switching
To understand why models switch languages unexpectedly, the researchers employed Sparse Autoencoders (SAEs). SAEs allow for the decomposition of a model's high-dimensional hidden states into sparse, interpretable "features." By analyzing these features, the team identified specific neural activation directions corresponding to individual languages—for example, a distinct "Chinese feature."
A critical discovery was the "smoking gun" of code-switching: right before a model transitions to an unintended language, the internal activation of that language's specific feature spikes abnormally. The researchers validated this causal link by manually intervening during inference—artificially increasing the activation of a "Chinese feature" forced the model to switch its output to Chinese.
The SASFT Method
The core contribution of this work is Sparse Autoencoder-guided Supervised Finetuning (SASFT). Unlike standard Supervised Finetuning (SFT), which focuses solely on next-token prediction, SASFT introduces an auxiliary loss function. This loss acts as a "guardrail," penalizing the model if irrelevant language features exceed a specific activation threshold during training.
By incorporating this internal constraint, the model learns to suppress the "noise" of competing language features. This approach is more robust than external inference-time interventions because it internalizes language control within the model's weights. Furthermore, the researchers found that applying this penalty across multiple layers is essential, as language identity is a deep property processed throughout the network.
Experimental Results
The effectiveness of SASFT was evaluated across five model families, including Gemma-2, Llama-3.1, and Qwen-3, using datasets specifically curated for Chinese, Russian, and Korean.
The results demonstrate a significant reduction in language leakage:
- Substantial Mitigation: SASFT reduced unexpected code-switching by over 50% in 23 out of 30 tested scenarios compared to standard finetuning.
- Total Elimination: In specific cases, such as Korean language tasks on Qwen-3 models, the method completely eliminated unexpected code-switching.
- Performance Maintenance: Crucially, the models did not suffer from an "alignment tax." In fact, performance on benchmarks like MMLU (general knowledge) and HumanEval (coding) often improved, suggesting that better internal language regulation may enhance overall reasoning clarity.
Conclusion and Future Directions
SASFT represents a significant step toward more reliable multilingual LLMs by leveraging mechanistic interpretability to guide the finetuning process. While currently focused on three major languages and models under 9B parameters, future work will explore scaling this method to support dozens of languages simultaneously and testing its efficacy on frontier-scale models (70B+). The integration of SASFT with other alignment techniques like Direct Preference Optimization (DPO) also remains a promising avenue for creating even more robust and controllable AI systems.
Summary updated