Skip to main content
QUICK REVIEW

[Paper Review] Predicting the Programming Language of Questions and Snippets of StackOverflow Using Natural Language Processing

Kamel Alreshedy, Dhanush Dharmaretnam|arXiv (Cornell University)|Sep 21, 2018
Topic ModelingComputer Science13 references3 citations
TL;DR

This paper proposes a machine learning classifier that predicts the programming language of Stack Overflow questions using natural language processing and code snippets, achieving 91.1% accuracy by combining textual and code features. It also introduces models using only text (81.1% accuracy) or only code (77.7% accuracy), demonstrating effective language detection for automated tagging and code analysis tools.

ABSTRACT

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.

Motivation & Objective

  • Address the problem of incorrect or missing programming language tags in Stack Overflow questions, which hinders effective question routing and code rendering.
  • Improve the accuracy of automatic tag suggestion systems by leveraging both natural language text and code snippets in questions.
  • Develop a reliable method to identify the programming language of short code snippets independently, applicable beyond Stack Overflow.
  • Evaluate the relative contribution of textual content versus code structure in programming language prediction.
  • Enable better support for code search engines, documentation tools, and snippet managers by automating language detection.

Proposed method

  • Trained a hybrid classifier using Multinomial Naive Bayes, Random Forest, and XGBoost on features extracted from question titles, bodies, and code snippets.
  • Extracted linguistic and syntactic features from text (title and body) using NLP techniques including dependency parsing and vocabulary analysis.
  • Preprocessed code snippets by removing comments and whitespace, then extracted syntactic and structural features such as keywords, operators, and syntax patterns.
  • Combined textual and code-based features into a unified feature vector for training the primary classifier.
  • Used a hybrid auto-tagging system that suggests tags based on predicted language from code and text, improving user tagging accuracy.
  • Visualized feature spaces of Java and SQL to identify language-specific lexical and syntactic patterns in developer questions.

Experimental results

Research questions

  • RQ1Can we predict the programming language of a Stack Overflow question using both textual content and code snippets?
  • RQ2Can we predict the programming language of a question using only textual information (title and body), without relying on code snippets?
  • RQ3Can we predict the programming language of a code snippet in isolation using machine learning?
  • RQ4How does the performance of language prediction vary when using only text, only code, or a combination of both?

Key findings

  • The combined classifier using both text and code features achieved 91.1% accuracy, with precision and recall both at 0.91.
  • The text-only classifier achieved 81.1% accuracy, outperforming prior state-of-the-art models (e.g., Baquero et al. [13]) with higher precision (0.83) and recall (0.81).
  • The code-only classifier achieved 77.7% accuracy, demonstrating that even short code snippets can be reliably classified using ML.
  • Textual features contributed more predictively than code features, suggesting that natural language cues in questions are more discriminative for language identification.
  • Feature space visualization revealed distinct lexical and syntactic patterns in questions about Java and SQL, indicating language-specific vocabulary and phrasing in developer discourse.
  • The model generalizes beyond Stack Overflow and could be applied to blog posts, documentation, and code repositories for automated language tagging.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.