Machine learning models are widely used but can also often be wrong. Users would benefit from a reliable indication of whether a given output from a given model should be trusted, so a rational decision can be made whether to use the output or not. For example, outputs can be associated with a confidence measure; if this confidence measure is strongly associated with likelihood of correctness, then the model is said to be well-calibrated. In this case, for example, high-confidence outputs could be safely accepted, and low-confidence outputs rejected. Calibration has so far been studied in non-generative (e.g., classification) settings, especially in Software Engineering. However, generated code can quite often be wrong: Developers need to know when they should e.g., directly use, use after careful review, or discard model-generated code; thus Calibration is vital in generative settings. However, the notion of correctness of generated code is non-trivial, and thus so is Calibration. In this paper we make several contributions. We develop a framework for evaluating the Calibration of code-generating models. We consider several tasks, correctness criteria, datasets, and approaches, and find that by and large generative code models are not well-calibrated out of the box. We then show how Calibration can be improved, using standard methods such as Platt scaling. Our contributions will lead to better-calibrated decision-making in the current use of code generated by language models, and offers a framework for future research to further improve calibration methods for generative models in Software Engineering.
翻译:机器学习模型被广泛应用,但常常会产生错误。用户需要一个可靠的指标来判断是否应当信任某个模型的特定输出,从而能够理性决定是否使用该输出。例如,可以为输出关联一个置信度度量;如果该置信度度量与正确可能性高度相关,则称该模型具有良好校准性。在此情况下,高置信度输出可被安全接受,而低置信度输出则被拒绝。目前,校准性研究主要集中于非生成式场景(如分类),尤其在软件工程领域。然而,生成的代码往往存在错误:开发者需要明确何时应直接使用、经仔细审查后使用或弃用模型生成的代码,因此校准性在生成式场景中至关重要。但生成代码的正确性概念本身具有复杂性,导致校准性研究同样复杂。本文提出多项贡献:我们构建了评估代码生成模型校准性的框架,考虑了多种任务、正确性标准、数据集及方法,发现当前生成式代码模型普遍未达到开箱即用的良好校准性。随后,我们展示了如何通过普拉特缩放等标准方法改进校准性。我们的研究成果将推动当前语言模型生成代码使用中更优校准决策,并为软件工程领域生成式模型校准方法的未来研究提供了框架基础。