Dependency-Aware Code Naturalness
摘要
Code naturalness, which captures repetitiveness and predictability in programming languages, has proven valuable for various code-related tasks in software engineering. However, precisely measuring code naturalness remains a fundamental challenge. Existing methods measure code naturalness over individual lines of code while ignoring the deep semantic relations among different lines, e.g., program dependency, which may negatively affect the precision of the measure. Despite the intuitive appeal of extending the code naturalness measure to the code dependency domain (as there are some work that have initiated the utilization of code dependency for diverse code-related tasks), this assumption remains unexplored and warrants direct investigation. In this study, we aim to perform the first empirical study to investigate whether incorporating code dependency, instead of analyzing individual lines, can enhance the precision of measuring code naturalness.
To achieve that, we first propose a new method named DAN for measuring code naturalness by incorporating the rich dependency information in the code. Specifically, DAN extracts multiple sequences of code lines by traversing the program dependency graph, where different code lines are connected by dependencies in each sequence, and then the code naturalness will be measured by taking each sequence as a whole. In this way, the dependency information can be well captured. Finally, we have conducted an extensive study to evaluate the influence of code dependency for measuring code naturalness with DAN, and compared it with the state-of-the-art methods under three emerging application scenarios of code naturalness. The results demonstrate that DAN can not only better distinguish natural and unnatural code, but also substantially boost two important downstream applications of code naturalness, i.e., distinguishing buggy and non-buggy code lines and data cleansing for training better code models, reflecting the significance of code dependency in measuring code naturalness.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 4 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning 引用了 CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
- CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesis 引用了 CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
- CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesis 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models 引用了 Clarifying Semantics of In-Context Examples for Unit Test Generation
- Clarifying Semantics of In-Context Examples for Unit Test Generation 引用了 Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models
- Uncovering Business Logic Bugs via Semantics-Driven Unit Test Generation (Experience Paper) 引用了 Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models
- Uncovering Business Logic Bugs via Semantics-Driven Unit Test Generation (Experience Paper) 引用了 Clarifying Semantics of In-Context Examples for Unit Test Generation
引用它的顶会 Paper4
- Fuzzing MLIR Compiler Infrastructure via Operation Dependency AnalysisChenyao Suo, Junjie Chen, Shuang Liu, Jiajun Jiang 等ISSTA 2024 · 12 次引用
- Reflective Unit Test Generation for Precise Type Error Detection with Large Language ModelsChen Yang, Ziqi Wang, Yanjie Jiang, Lin Yang 等ASE 2025 · 1 次引用
- Clarifying Semantics of In-Context Examples for Unit Test GenerationChen Yang, Lin Yang, Ziqi Wang, Dong Wang 等ASE 2025 · 1 次引用
- Uncovering Business Logic Bugs via Semantics-Driven Unit Test Generation (Experience Paper)Chen Yang, Junjie ChenISSTA 2026
它引用的 Paper16
- CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan 等EMNLP Findings 2020 · 2,828 次引用
- GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng 等ICLR 2021 · 1,644 次引用
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 次引用
- CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement LearningHung Le, Yue Wang, Akhilesh Deepak Gotmare, Silvio Savarese 等NeurIPS 2022 · 571 次引用
- CodeGen: An Open Large Language Model for Code with Multi-Turn Program SynthesisErik Nijkamp, Bo Pang, Hiroaki Hayashi, Lifu Tu 等ICLR 2023 · 234 次引用
相关 Paper
- Do bugs lead to unnaturalness of source code?Yanjie Jiang, Hui Liu, Yuxia Zhang, Weixing Ji 等FSE 2022 · 8 次引用
- Has My Code Been Stolen for Model Training? A Naturalness Based Approach to Code Contamination DetectionHaris Ali Khan, Yanjie Jiang, Qasim Umer, Yuxia Zhang 等FSE 2025 · 1 次引用
- Beyond Sequences: Two-dimensional Representation and Dependency Encoding for Code GenerationXiangyu Zhang, Yu Zhou, Guang Yang, Wei Cheng 等ACL 2025
- CrystalBLEU: Precisely and Efficiently Measuring the Similarity of CodeAryaz Eghbali, Michael PradelASE 2022 · 33 次引用
- Contextuality of Code Representation LearningYi Li, Shaohua Wang, Tien N. NguyenASE 2023 · 2 次引用
