For tasks like code synthesis from natural language, code retrieval, and code summarization, data-driven models have shown great promise. However, creating these models require parallel data between natural language (NL) and code with fine-grained alignments. Stack Overflow (SO) is a promising source to create such a data set: the questions are diverse and most of them have corresponding answers with high-quality code snippets. However, existing heuristic methods (e.g., pairing the title of a post with the code in the accepted answer) are limited both in their coverage and the correctness of the NL-code pairs obtained. In this paper, we propose a novel method to mine high-quality aligned data from SO using two sets of features: hand-crafted features considering the structure of the extracted snippets, and correspondence features obtained by training a probabilistic model to capture the correlation between NL and code using neural networks. These features are fed into a classifier that determines the quality of mined NL-code pairs. Experiments using Python and Java as test beds show that the proposed method greatly expands coverage and accuracy over existing mining methods, even when using only a small number of labeled examples. Further, we find that reasonable results are achieved even when training the classifier on one language and testing on another, showing promise for scaling NL-code mining to a wide variety of programming languages beyond those for which we are able to annotate data.
StaQC: A Systematically Mined Question-Code Dataset from Stack Overflow
The Ohio State University(俄亥俄州立大学);University of Washington(华盛顿大学);Fujitsu Labs of America(富士通美国实验室)
Stack Overflow(SO)是自然语言问题及其代码解决方案的重要来源(即,问题-代码对),这对于包括代码检索和注释在内的许多任务都是至关重要的。在大多数现有的研究中,问题代码对收集的经验教训,往往有低质量。在本文中,我们研究了一个新的问题,系统地挖掘问题代码对从堆栈溢出(相对于收集他们)。它被公式化为预测代码片段是否是问题的独立解决方案。我们提出了一种新的双视图层次神经网络,它可以捕获代码片段的编程内容和文本上下文(即,两种观点)来进行预测。在Python和SQL领域的两个手动注释数据集上,我们的框架大大优于探试法,F1和准确率至少高出15%。此外,我们还介绍了StaQC(Stack Overflow Question-Code pairs),这是迄今为止最大的数据集,包含约148 K Python和约120 K SQL问题代码对,使用我们的框架自动从SO中挖掘出来。在各种案例研究中,我们证明了StaQC可以极大地帮助开发数据饥饿的模型,将自然语言与程序设计语言相关联。
Diverse Title Generation for Stack Overflow Posts with Multiple Sampling Enhanced Transformer
Wuhan University(武汉大学);Huazhong University of Science and Technology(华中科技大学);Wuhan University of Technology(武汉理工大学);Deakin University(迪肯大学);City University of Hong Kong(香港城市大学)
Improving Stack Overflow question title generation with copying enhanced CodeBERT model and bi-modal information
Wuhan University of Technology(武汉理工大学);Wuhan University(武汉大学);Wuhan University of Technology Chongqing Research Institute(武汉理工大学重庆研究院);Sanya Science and Education Innovation Park of Wuhan University of Technology(武汉理工大学三亚科教创新园);City University of Hong Kong(香港城市大学)