[论文解读] Context2Name: A Deep Learning-Based Approach to Infer Natural Variable Names from Usage Contexts
Context2Name 使用基于令牌的静态分析、序列自编码器和 RNN 来从 minified JavaScript 的使用上下文预测自然变量名,取得显著的准确性和速度。它与 JSNice 和 JSNaughty 相比表现更优,并提供独特的预测。
Most of the JavaScript code deployed in the wild has been minified, a process in which identifier names are replaced with short, arbitrary and meaningless names. Minified code occupies less space, but also makes the code extremely difficult to manually inspect and understand. This paper presents Context2Name, a deep learningbased technique that partially reverses the effect of minification by predicting natural identifier names for minified names. The core idea is to predict from the usage context of a variable a name that captures the meaning of the variable. The approach combines a lightweight, token-based static analysis with an auto-encoder neural network that summarizes usage contexts and a recurrent neural network that predict natural names for a given usage context. We evaluate Context2Name with a large corpus of real-world JavaScript code and show that it successfully predicts 47.5% of all minified identifiers while taking only 2.9 milliseconds on average to predict a name. A comparison with the state-of-the-art tools JSNice and JSNaughty shows that our approach performs comparably in terms of accuracy while improving in terms of efficiency. Moreover, Context2Name complements the state-of-the-art by predicting 5.3% additional identifiers that are missed by both existing tools.
研究动机与目标
- 激发并解决对经过压缩的 JavaScript 代码可读性的挑战,通过推断有意义的变量名。
- 开发一个深度学习框架,在不进行大量语言特定的程序分析的情况下,从使用上下文预测自然命名。
- 在大型真实世界的 JavaScript 语料库上展示经验上的有效性和高效性,并与最先进的工具进行比较。
提出的方法
- 将每个最小化名称周围的使用上下文提取为令牌序列。
- 通过对令牌进行独热编码,将使用上下文转换为稀疏向量。
- 使用序列自编码器将上下文压缩成密集嵌入。
- 使用循环神经网络预测名称,输出候选名称的有序列表。
- 贪心地分配预测名称,确保在最终代码中保持语义约束。
实验结果
研究问题
- RQ1RQ1:Context2Name 在现实世界的 JavaScript 中对最小化变量和函数的自然命名预测有多有效?
- RQ2RQ2:Context2Name 在准确性和效率方面与 JSNice 和 JSNaughty 相比如何?
- RQ3RQ3:该方法对于大型程序是否高效且可扩展?
主要发现
| 指标 | Context2Name | JSNice | JSNaughty | JSNaughty ∞ | 基线 |
|---|---|---|---|---|---|
| Local-Once | 47.5% | 48.3% | 39.4% | 55.3% | 0.0% |
| Local-Repeat | 49.8% | 55.3% | 41.3% | 59.2% | 0.0% |
| All-Once | 55.4% | 56.0% | 47.7% | 61.9% | 15.0% |
| All-Repeat | 58.1% | 62.6% | 49.3% | 65.8% | 16.4% |
- Context2Name 能在数据集里精确恢复 47.5% 的本地化最小化名称。
- Context2Name 本地预测每个名称 2.9 ms,平均每个文件 110.7 ms。
- 相较于 JSNice 和 JSNaughty,Context2Name 以相当的准确度获得更高的效率。
- Context2Name 额外恢复了 5.3% 的标识符,这些被 JSNice 和 JSNaughty 都错过。
- 该方法处理文件快速,并且不依赖于繁重的语言特定程序分析。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。