Abstract
Large language models (LLMs) often experience language confusion, which is the unintended mixing of languages during text generation. Current solutions to this problem either necessitate model retraining or cannot differentiate between harmful confusion and acceptable code-switching. This paper introduces the Language Confusion Gate (LCG), a lightweight, plug-in solution that filters tokens during decoding without altering the base LLM. The LCG is trained using norm-adjusted self-distillation to predict appropriate language families and apply masking only when needed. Our method is based on the findings that language confusion is infrequent, correct-language tokens are usually among the top predictions, and output token embedding norms are larger for high-resource languages, which biases sampling. When evaluated across various models, including Qwen3, GPT-OSS, Gemma3, Llama3.1, LCG decreases language confusion significantly, often by an order of magnitude, without negatively impacting task performance. Code is available at this https URL.
Abstract (translated)
大型语言模型(LLMs)常常会遇到语言混淆的问题,即在文本生成过程中意外地混杂使用不同语言。目前解决这个问题的方法要么需要重新训练模型,要么无法区分有害的混淆和可接受的语言转换(code-switching)。本文介绍了一种名为“语言混淆门”(Language Confusion Gate, LCG)的技术,这是一种轻量级、插件式的解决方案,在解码过程中过滤掉不需要的标记,而无需修改基础LLM。LCG通过调整范数的自我蒸馏训练方法来预测合适的语言家族,并仅在必要时应用屏蔽操作。 本文的方法基于以下发现:语言混淆是相对罕见的现象;正确语言中的词汇通常出现在模型输出的最前面位置;资源丰富的语言(如英语)的输出标记嵌入规范较大,这会偏向于采样这些语言。通过跨多个模型进行评估,包括Qwen3、GPT-OSS、Gemma3和Llama3.1等,LCG显著减少了语言混淆现象,有时甚至可以减少一个数量级,并且不会对任务性能产生负面影响。 代码可以在提供的链接地址获取。
URL
https://arxiv.org/abs/2510.17555