Skip to main content
QUICK REVIEW

[论文解读] Unveiling Memorization in Code Models

Zhou Yang, Zhipeng Zhao|arXiv (Cornell University)|Aug 19, 2023
Software Engineering Research参考文献 64被引用 7
一句话总结

本文首次对大规模预训练代码模型中的记忆化现象进行了系统的实证研究,发现仅生成20,000个输出即可产生超过40,125个逐字记忆的代码片段。研究识别出模型规模、输出长度和训练数据频率为关键影响因素,提出了一个包含3个大类、14个子类别的记忆内容分类体系,并证明通过移除重复的训练数据可降低记忆化现象,同时提出了有效的检测指标以识别记忆内容。

ABSTRACT

The availability of large-scale datasets, advanced architectures, and powerful computational resources have led to effective code models that automate diverse software engineering activities. The datasets usually consist of billions of lines of code from both open-source and private repositories. A code model memorizes and produces source code verbatim, which potentially contains vulnerabilities, sensitive information, or code with strict licenses, leading to potential security and privacy issues. This paper investigates an important problem: to what extent do code models memorize their training data? We conduct an empirical study to explore memorization in large pre-trained code models. Our study highlights that simply extracting 20,000 outputs (each having 512 tokens) from a code model can produce over 40,125 code snippets that are memorized from the training data. To provide a better understanding, we build a taxonomy of memorized contents with 3 categories and 14 subcategories. The results show that the prompts sent to the code models affect the distribution of memorized contents. We identify several key factors of memorization. Specifically, given the same architecture, larger models suffer more from memorization problems. A code model produces more memorization when it is allowed to generate longer outputs. We also find a strong positive correlation between the number of an output's occurrences in the training data and that in the generated outputs, which indicates that a potential way to reduce memorization is to remove duplicates in the training data. We then identify effective metrics that infer whether an output contains memorization accurately. We also make suggestions to deal with memorization.

研究动机与目标

  • 调查大规模预训练代码模型中记忆化现象的程度与性质,特别是考虑到其在来自开源和私有代码库的海量代码库上进行训练的背景。
  • 识别并分类记忆内容的类型,包括敏感代码、受版权保护的代码或存在漏洞的代码,以评估隐私与安全风险。
  • 分析影响记忆化的关键因素,如模型规模、输出长度和训练数据频率。
  • 开发有效的指标以检测模型输出中的记忆内容。
  • 为训练和部署阶段减轻代码模型中的记忆化现象提供可操作的建议。

提出的方法

  • 使用起始标记提示从CodeParrot和CodeParrot-small中实证提取20,000个代码输出(每个512个token)。
  • 通过在生成输出与训练数据之间进行精确字符串匹配,识别逐字记忆现象。
  • 基于内容类型和敏感性,构建一个包含3个主要类别和14个子类别的记忆内容分类体系。
  • 分析训练数据频率与模型输出中记忆频率之间的相关性。
  • 评估多种指标(如n-gram重叠、嵌入相似度)在检测记忆化输出方面的有效性。
  • 对GitHub Copilot等已部署模型进行案例研究,以评估现实世界中的记忆化风险。

实验结果

研究问题

  • RQ1大规模预训练代码模型在多大程度上会记忆训练数据的原文?从少量模型输出中能提取出多少记忆化的代码片段?
  • RQ2哪些类型的内容最常被记忆?如何从敏感性和风险角度对它们进行系统性分类?
  • RQ3模型规模、输出长度和训练数据频率如何影响记忆化的可能性与数量?
  • RQ4能否识别出有效的指标,以准确检测模型输出是否包含记忆内容?
  • RQ5在训练和部署阶段,可采取哪些实际策略来减少代码模型中的记忆化现象?

主要发现

  • 仅从代码模型中提取20,000个输出(每个512个token)即可从训练数据中产生超过40,125个逐字记忆的代码片段。
  • 训练数据中某段代码片段的频率与模型生成输出中该片段的频率之间存在强烈正相关关系,表明在训练数据中移除重复内容可降低记忆化现象。
  • 在模型架构保持不变的情况下,更大的模型比更小的模型更容易出现记忆化现象,表明模型规模是关键影响因素。
  • 输出长度越长,记忆内容的可能性和数量越高,凸显输出长度是可控制的风险因素。
  • 本研究在3个主要类别下识别出14种子类别的记忆内容——敏感信息、受版权保护的代码和存在漏洞的代码,揭示了多样化的隐私与安全风险。
  • 特定指标如n-gram重叠和基于嵌入的相似度在检测记忆化输出方面表现出高准确性,使实际系统中实现有效检测成为可能。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。