This paper presents SEER, an upgraded version of our prior method Context Is All You Need for detecting Gang of Four (GoF) design patterns from source code. The earlier approach modeled code as attention-ready sequences that blended lightweight structure with behavioral context; however, it lacked explicit role disambiguation within classes and treated call edges uniformly. SEER addresses these limitations with two principled additions: (i) a spectral-entropy role encoder that derives per-member role embeddings from the Laplacian spectrum of each class's interaction graph, and (ii) a time-weighted calling context that assigns empirically calibrated duration priors to method categories (e.g., constructors, getters/setters, static calls, virtual dispatch, cloning). Together, these components sharpen the model's notion of "who does what" and "how much it matters," while remaining portable across languages with minimal adaptation and fully compatible with Transformer-based sequence encoders. Importantly, SEER does not "force" a win by capacity or data; it nudges the classifier, steering attention toward role-consistent and temporally calibrated signals that matter most. We evaluate SEER on PyDesignNet (1,832 files, 35,000 sequences, 23 GoF patterns) and observe consistent gains over our previous system: macro-F1 increases from 92.47% to 93.20% and accuracy from 92.52% to 93.98%, with macro-precision 93.98% and macro-recall 92.52%. Beyond aggregate metrics, SEER reduces false positives by nearly 20%, a decisive improvement that strengthens its robustness and practical reliability. Moreover, SEER yields interpretable, symbol-level attributions aligned with canonical roles, exhibits robustness under small graph perturbations, and shows stable calibration.
翻译:本文提出SEER,这是我们先前方法"Context Is All You Need"的升级版本,用于从源代码中检测GoF设计模式。早期方法将代码建模为注意力就绪序列,融合了轻量级结构与行为上下文,但缺乏对类内角色的显式消歧,并统一处理调用边。SEER通过两个原则性改进解决这些局限:(i)谱熵角色编码器,从每个类的交互图谱的拉普拉斯谱中推导每个成员的角色嵌入;(ii)时间加权调用上下文,为方法类别(如构造函数、getter/setter、静态调用、虚函数分发、克隆操作)分配经验校准的时长先验。这些组件共同增强了模型对"谁执行什么操作"及"其重要性程度"的认知,同时保持跨语言移植的便捷性(仅需最小适配),并与基于Transformer的序列编码器完全兼容。重要的是,SEER并非通过扩大容量或数据量"强制"提升性能,而是通过引导分类器将注意力聚焦于最具相关性的角色一致性与时间校准信号。我们在PyDesignNet数据集(1,832个文件,35,000个序列,23种GoF模式)上评估SEER,观察到相较于先前系统的持续提升:宏平均F1分数从92.47%增至93.20%,准确率从92.52%提升至93.98%,宏平均精确率达93.98%,宏平均召回率为92.52%。除总体指标外,SEER将误报率降低近20%,这一决定性改进增强了其鲁棒性与实际可靠性。此外,SEER能生成与规范角色对齐的可解释符号级归因,在小规模图扰动下保持鲁棒性,并展现出稳定的校准特性。