模型会因隐喻指令生成低效代码,源自源领域抽象流程的迁移。
Metaphor-Induced Algorithmic Steering: Cross-Domain Procedural Transfer in LLM Code Generation

- 通过隐喻化训练,诱发模型迁移低效算法模式。
- 在多项任务中生成了40%以上效率更低的代码,且不违反任务要求。
- 适合关注代码生成安全性和模型行为可解释性的研究者。
大型语言模型受益于自然语言中的隐喻和类比等元素,这些元素有助于跨领域泛化。然而,当隐喻表达隐式传递不恰当的程序模式时,也可能引发不良行为。本文揭示,隐喻性指令会诱导类比迁移程序机制,使代码生成模型倾向于采用低效算法。我们称此现象为‘隐喻式算法引导’:原本在源领域中合理有效的抽象程序结构被迁移到新编程任务中,导致模型偏好穷举搜索、全量扫描或重复重建,即使目标算法未明确提及。为此,我们构建了MASC框架,通过迭代隐喻化与优化良性技能,有效诱发低效代码,同时保持任务相关性。实验表明,该方法能高精度检测出隐喻性技能及其低效实现。此外,我们发现隐喻技能引发隐藏状态向低效程序原型偏移。结果表明,这种引导作用源于与隐喻场景相关的程序模式迁移,而非表层语言本身。
原文摘要 · Abstract (English)
Large language models benefit from elements in natural language, such as metaphors and analogies in training data and inference input to achieve generalisability across different domains. However, these language elements may also lead to unwanted behaviors when metaphorical expressions implicitly transfer inappropriate procedural patterns into new tasks. In this paper, we show that metaphorical instructions can induce analogical transfer of procedural mechanisms, thus steering code-generation models towards less efficient algorithms. We refer to this metaphor-induced effect as metaphorical algorithmic steering: a skill that is benign and plausible within its source domain transfers an abstract procedural schema into a programming task, causing the model to favor exhaustive search, full scans, or repeated reconstruction without explicitly mentioning the target algorithm. More broadly, this suggests that code-generation models can carry procedures that are appropriate in a task's background domain into the task's programming problem, where they can lead to unwanted outcomes. To study this phenomenon, we develop MASC (Metaphorical Algorithmic Steering for Code Generation), a framework that iteratively metaphorizes and refines benign skills to elicit low-efficiency code while remaining benign and task-relevant. Beyond behavioral evaluation, we study whether this phenomenon is detectable and mechanistically reflected in model representations. Our method achieves high detection rates for metaphorical skills and less-efficient implementations. We also find that metaphorical skills induce a hidden-state shift towards lower-efficiency procedural behavior prototypes. These results suggest that metaphorical algorithmic steering operates through the transfer of procedural patterns associated with metaphorical source scenarios rather than surface level metaphorical language alone.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。