CSSG: Measuring Code Similarity with Semantic Graphs
Jingwen Xu, Yiyang Lu, Changze Lv, Zisu Huang, Zhengkang Guo, Zhengyuan Wang, Muzhao Tian, Xuanjing Huang, Xiaoqing Zheng
TL;DR
CSSG addresses the limitation of surface- and syntax-focused code similarity by representing code as integrated program dependence graphs that capture data and control dependencies. It computes semantic similarity via a constrained graph edit distance and normalization, enabling cross-language semantic comparisons. On CodeContests+, CSSG achieves stronger discrimination between correct and incorrect solutions in both monolingual and cross-lingual settings, with stable positive effects across language pairs, highlighting the value of dependency-aware representations. This semantics-grounded approach offers a practical tool for evaluating code similarity and generation quality beyond surface lexical cues.
Abstract
Existing code similarity metrics, such as BLEU, CodeBLEU, and TSED, largely rely on surface-level string overlap or abstract syntax tree structures, and often fail to capture deeper semantic relationships between programs.We propose CSSG (Code Similarity using Semantic Graphs), a novel metric that leverages program dependence graphs to explicitly model control dependencies and variable interactions, providing a semantics-aware representation of code.Experiments on the CodeContests+ dataset show that CSSG consistently outperforms existing metrics in distinguishing more similar code from less similar code under both monolingual and cross-lingual settings, demonstrating that dependency-aware graph representations offer a more effective alternative to surface-level or syntax-based similarity measures.
