Abstract
We introduce CosmoCore, a neuroscience-inspired reinforcement learning (RL) architecture that integrates affective signals to enhance code generation in large language models (LLMs). Motivated by human and animal learning where embarrassment from mistakes drives rapid correction, as observed in training a puppy to avoid repeating errors after a single scolding CosmoCore tags code generation trajectories with valence and surprise using a lightweight multi-layer perceptron (MLP). High-negative valence (cringe) episodes, such as buggy code outputs, are prioritized in a Dream Queue for five-fold replay during off-policy updates, while low-surprise successes are pruned to prevent overconfidence and buffer bloat. Evaluated on code generation benchmarks like HumanEval and BigCodeBench, alongside simulations with a custom data pipeline environment, CosmoCore reduces hallucinated code (e.g., syntax errors or logical bugs) by 48\% and accelerates self-correction by 45\%. Local experiments using Hugging Face models in a PySpark environment validate these gains, with code snippets provided for replication. Ablations confirm valence tagging boosts curiosity in exploration, and pruning mitigates inefficiency. This framework extends RL from human feedback (RLHF) for more emotionally aware code assistants, with applications in IDEs and data pipelines. Code and the custom mini-world simulation are released.
Abstract (translated)
我们介绍了一种受神经科学启发的强化学习(RL)架构CosmoCore,它将情感信号融入大型语言模型(LLMs)中的代码生成过程,以增强其性能。这种设计灵感来源于人类和动物的学习方式,在这种模式下,从错误中感到尴尬会迅速促使修正行为,例如训练一只小狗在被责备一次后避免重复犯错。CosmoCore使用轻量级多层感知器(MLP)为代码生成轨迹标记正负情感价值和惊讶度。 高负面情感值(如因出现缺陷代码而产生的不适感)的片段会被优先放入一个名为Dream Queue的队列中,在离线更新时进行五倍重播,以促进快速修正。而对于低惊讶度的成功结果则被修剪掉,以防过早自信或数据缓冲区膨胀。 在诸如HumanEval和BigCodeBench等代码生成基准测试以及使用自定义数据管道环境的模拟实验中,CosmoCore将幻觉性代码(例如语法错误或逻辑缺陷)减少了48%,同时使自我纠正的速度提高了45%。通过Hugging Face模型在PySpark环境中进行的本地实验验证了这些改进的有效性,并提供了可供复制的代码片段。 消融研究确认情感标记能够增加探索过程中的好奇心,而修剪则有助于减少低效现象的发生。这一框架将强化学习从人类反馈(RLHF)扩展到了对情绪更为敏感的代码助手系统中,在集成开发环境和数据管道等领域有着广泛的应用前景。相关的代码以及定制的小世界模拟程序已对外发布。
URL
https://arxiv.org/abs/2510.18895