How Do Language Models Speak Languages? A Case Study on Unintended Code-Switching
Abstract
Lay Summary
Large language models can answer questions and write text in many languages, but they sometimes unexpectedly switch to another language in the middle of a response. This behavior, called unintended code-switching, can make multilingual systems less reliable and harder to trust, especially for users who expect answers in a specific language. We study why this happens inside language models. Instead of treating the model as a black box, we identify small groups of internal neurons that help the model keep track of the intended language. We find that multilingual generation depends on two interacting processes: one that maintains the target language, and another that represents the meaning of the response across languages. Code-switching tends to occur when the meaning-related process becomes too influential and weakens language-specific control. This understanding also suggests a practical fix. By fine-tuning only a very small set of language-related neurons, we can reduce unintended code-switching while leaving most of the model unchanged. Our work helps explain a common failure in multilingual language models and points toward more targeted ways to make them safer and more consistent for users across languages.