[论文解读] Predicting the Programming Language of Questions and Snippets of StackOverflow Using Natural Language Processing
本文提出了一种机器学习分类器,通过自然语言处理和代码片段预测 Stack Overflow 问题的编程语言,结合文本和代码特征后准确率达到 91.1%。同时,该研究还提出了仅使用文本(准确率 81.1%)或仅使用代码(准确率 77.7%)的模型,证明了在自动化标签分配和代码分析工具中实现有效编程语言检测的可行性。
Stack Overflow is the most popular Q&A website among software developers. As a platform for knowledge sharing and acquisition, the questions posted in Stack Overflow usually contain a code snippet. Stack Overflow relies on users to properly tag the programming language of a question and it simply assumes that the programming language of the snippets inside a question is the same as the tag of the question itself. In this paper, we propose a classifier to predict the programming language of questions posted in Stack Overflow using Natural Language Processing (NLP) and Machine Learning (ML). The classifier achieves an accuracy of 91.1% in predicting the 24 most popular programming languages by combining features from the title, body and the code snippets of the question. We also propose a classifier that only uses the title and body of the question and has an accuracy of 81.1%. Finally, we propose a classifier of code snippets only that achieves an accuracy of 77.7%. These results show that deploying Machine Learning techniques on the combination of text and the code snippets of a question provides the best performance. These results demonstrate also that it is possible to identify the programming language of a snippet of few lines of source code. We visualize the feature space of two programming languages Java and SQL in order to identify some special properties of information inside the questions in Stack Overflow corresponding to these languages.
研究动机与目标
- 解决 Stack Overflow 问题中编程语言标签错误或缺失的问题,该问题会妨碍问题的有效路由和代码渲染。
- 通过在问题中同时利用自然语言文本和代码片段,提升自动标签建议系统的准确性。
- 开发一种可靠的方法,独立识别简短代码片段的编程语言,该方法可广泛应用于 Stack Overflow 之外的场景。
- 评估文本内容与代码结构在编程语言预测中的相对贡献。
- 通过自动化语言检测,为代码搜索引擎、文档工具和代码片段管理器提供更好的支持。
提出的方法
- 使用从问题标题、正文和代码片段中提取的特征,对多项式朴素贝叶斯、随机森林和 XGBoost 模型进行混合分类器训练。
- 利用自然语言处理技术(包括依存句法分析和词汇分析)从文本(标题和正文)中提取语言学和句法特征。
- 通过去除注释和空白字符对代码片段进行预处理,然后提取句法和结构特征,如关键字、运算符和语法模式。
- 将文本特征与基于代码的特征组合成统一的特征向量,用于主分类器的训练。
- 采用混合自动标签系统,基于从代码和文本中预测出的语言建议标签,从而提高用户标签建议的准确性。
- 对 Java 和 SQL 的特征空间进行可视化,以识别开发者问题中特有的词汇和句法模式。
实验结果
研究问题
- RQ1我们能否同时使用文本内容和代码片段来预测 Stack Overflow 问题的编程语言?
- RQ2我们能否仅使用文本信息(标题和正文)来预测问题的编程语言,而无需依赖代码片段?
- RQ3我们能否使用机器学习对孤立的代码片段独立预测其编程语言?
- RQ4当仅使用文本、仅使用代码或两者结合时,语言预测的性能如何变化?
主要发现
- 结合文本和代码特征的混合分类器准确率达到 91.1%,精确率和召回率均为 0.91。
- 仅使用文本的分类器准确率达到 81.1%,优于先前的最先进模型(例如 Baquero 等 [13]),精确率(0.83)和召回率(0.81)更高。
- 仅使用代码的分类器准确率达到 77.7%,表明即使短代码片段也能通过机器学习被可靠分类。
- 文本特征的预测贡献高于代码特征,表明问题中的自然语言线索对编程语言识别更具区分性。
- 特征空间可视化揭示了关于 Java 和 SQL 的问题中存在显著的词汇和句法模式,表明开发者话语中存在语言特异性词汇和表达方式。
- 该模型具有良好的泛化能力,可应用于博客文章、文档和代码仓库等场景,实现自动化语言标签分配。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。