[论文解读] On Distribution Shift in Learning-based Bug Detectors
本文識別出分佈偏移——具體而言,是訓練時使用的合成錯誤與實際生產環境中的真實錯誤之間的不匹配——是基於學習的錯誤檢測器性能不佳的根本原因。作者提出一種兩階段訓練方法:首先在合成錯誤上進行預訓練以學習通用特徵,然後在一個小規模、具有資料不平衡的真實錯誤數據集上進行微調,結合聚焦損失(focal loss)、對比學習與多任務層次結構。該方法在真實世界測試集上實現了高精確度(最高達51%),顯著優於先前的方法。
Deep learning has recently achieved initial success in program analysis tasks such as bug detection. Lacking real bugs, most existing works construct training and test data by injecting synthetic bugs into correct programs. Despite achieving high test accuracy (e.g., 90%), the resulting bug detectors are found to be surprisingly unusable in practice, i.e., <10% precision when used to scan real software repositories. In this work, we argue that this massive performance difference is caused by a distribution shift, i.e., a fundamental mismatch between the real bug distribution and the synthetic bug distribution used to train and evaluate the detectors. To address this key challenge, we propose to train a bug detector in two phases, first on a synthetic bug distribution to adapt the model to the bug detection domain, and then on a real bug distribution to drive the model towards the real distribution. During these two phases, we leverage a multi-task hierarchy, focal loss, and contrastive learning to further boost performance. We evaluate our approach extensively on three widely studied bug types, for which we construct new datasets carefully designed to capture the real bug distribution. The results demonstrate that our approach is practically effective and successfully mitigates the distribution shift: our learned detectors are highly performant on both our test set and the latest version of open source repositories. Our code, datasets, and models are publicly available at https://github.com/eth-sri/learning-real-bug-detector.
研究动机与目标
- 識別基於合成錯誤訓練的錯誤檢測器與其在真實世界部署之間性能差距的根本原因。
- 解決訓練時使用的合成錯誤與生產環境中發現的真實錯誤之間的根本性分佈偏移問題。
- 開發一種實用的兩階段訓練架構,以提升檢測器在真實世界程式碼倉儲中的表現。
- 建立能反映真實錯誤分佈的現實數據集,包括極端的類別不平衡。
- 證明結合在合成錯誤上預訓練與在真實錯誤上微調的策略,可產生更有效且更精確的檢測器。
提出的方法
- 提出兩階段訓練流程:首先在平衡的合成錯誤數據集上進行預訓練,然後在具有現實性、類別不平衡的真實錯誤數據集上進行微調。
- 整合多任務層次結構,以提升跨相關錯誤類型的泛化能力與特徵學習。
- 在微調階段應用聚焦損失以緩解類別不平衡問題,專注於難檢測的真實錯誤。
- 使用對比學習來區分有錯誤與無錯誤的程式碼對,增強表示學習。
- 利用預訓練的程式碼模型(例如,CuBERT)作為程式碼表徵的主幹網絡。
- 建立新的數據集,從GitHub提交記錄中提取真實錯誤,並搭配非錯誤程式碼,以反映真實世界的資料分佈。
实验结果
研究问题
- RQ1當基於學習的錯誤檢測器部署於真實世界程式碼倉儲時,其精確度急劇下降的根本原因是什麼?
- RQ2合成錯誤與真實錯誤之間的分佈偏移在多大程度上會損害現有錯誤檢測器的性能?
- RQ3結合合成錯誤與真實錯誤資料的兩階段訓練策略,能否有效緩解錯誤檢測中的分佈偏移?
- RQ4如聚焦損失、對比學習與任務層次結構等輔助組件,如何提升檢測器在真實世界資料上的表現?
- RQ5在少量真實錯誤上訓練的檢測器,能否有效泛化至大規模、不平衡的生產環境程式碼?
主要发现
- 現有錯誤檢測器在合成測試集上的精確度超過90%,但在真實世界測試集上則低於10%,顯示出嚴重的分佈偏移。
- 在包含0.5%真實錯誤與99.5%非錯誤程式碼的真實世界測試集中,最佳基線模型僅達3%的精確度,突顯當前方法在實際應用中的無效性。
- 所提出的兩階段訓練方法在相同真實世界測試集中達到了最高51%的精確度,顯著優於基線模型,顯示出對分佈偏移的有效緩解。
- 結合在合成錯誤上預訓練與在真實錯誤上使用聚焦損失與對比學習進行微調的策略,達到了最佳性能,顯示出兩個階段的必要性。
- 該方法在多種錯誤類型上均具備良好泛化能力,包括變數濫用與錯誤的二元運算子,且在最新版本的開源倉儲中表現良好。
- 作者公開發布了數據集、模型與程式碼,支援可重現性,並促進真實錯誤檢測領域的進一步研究。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。