Automated Query Reformulation for Efficient Search based on Query Logs From Stack Overflow

Kaibo Cao, Chunyang Chen, Sebastian Baltes, Christoph Treude, Xiang Chen

Abstract

Searching for programming assistance on platforms like Stack Overflow often involves a significant "semantic gap" between a developer's initial query and the platform's content. This paper presents SEQUER, a Transformer-based deep learning model designed to bridge this gap. By training on millions of real-world search logs, SEQUER automatically reformulates software-specific queries to enhance search relevance. Evaluation shows that SEQUER significantly outperforms general-purpose search suggestions, boosting retrieval effectiveness by over 129%.

Developers frequently encounter difficulty finding precise answers on the first attempt due to the discrepancy between their intent and the specific terminology used in technical documentation or community posts. A novice might use generic terms like "list in list" instead of the technical term "nested list," or a developer might include non-searchable local file paths from an error log in their query.

An example of a query reformulation thread where adding the keyword 'loop' significantly improves search relevance.

This gap forces users into a manual cycle of "reformulation"—iteratively tweaking keywords, fixing typos, or adding language constraints (e.g., "in java") until a useful post is found. While general search engines offer auto-complete features, they often lack the domain-specific knowledge required to handle complex programming jargon, API names, or stack traces.

Methodology: SEQUER

The authors frame query reformulation as a machine translation task, where an initial "suboptimal" query is translated into a "successful" reformulated query. The SEQUER model utilizes several key components:

  1. Byte Pair Encoding (BPE): To manage the vast array of out-of-vocabulary (OOV) technical terms (e.g., camelCase variables or specific API calls), BPE breaks rare words into frequent sub-word tokens. This allows the model to process misspelled or compound technical terms effectively.
  2. Transformer Architecture: SEQUER employs an attention-based Transformer model. Its self-attention mechanism is particularly adept at capturing the context of long queries, such as error logs, which traditional RNN-based models often struggle to process.
  3. Beam Search: During inference, the model generates the top-$k$ best candidate reformulations, providing users with multiple high-quality suggestions.

Data Extraction and Processing

The model was trained on a massive proprietary dataset provided by Stack Exchange Inc., consisting of 747 million HTTP requests over one year.

Sample of user navigation logs used to identify successful query reformulation sequences.

By tracking user sessions, the researchers identified "query reformulation threads"—sequences where a user searched, modified their query, and ultimately clicked and stayed on a specific post. This process yielded 1.12 million reformulation pairs, which were filtered down to 651,036 high-quality pairs for training and validation.

Key Insights and Results

An empirical study of the logs revealed that 58% of reformulations involve minor character-level modifications, such as fixing typos or adding a single keyword. Furthermore, the study highlighted that rule-based systems are insufficient because user behavior is highly varied: 40% add information, 33% modify syntax, and 23% delete overly specific details.

SEQUER was evaluated against five baselines, including Google Prediction Service and standard seq2seq models:

  • Accuracy: SEQUER achieved an ExactMatch@10 of 39.37%, meaning the model's top 10 suggestions matched the user's manual fix nearly 40% of the time.
  • Retrieval Effectiveness: Using SEQUER’s reformulations increased the Mean Reciprocal Rank (MRR) of target posts by 129.33% compared to original queries, outperforming the best baseline by 23.7%.

Conclusion and Future Work

SEQUER demonstrates that domain-specific deep learning can significantly mitigate the semantic gap in technical search. While the model currently faces challenges with "context blindness"—where a fix requires information outside the query itself—it represents a major step forward. Future work aims to incorporate broader user context, such as search history and IDE profiles, to further refine predictions and potentially recommend posts directly from initial flawed queries.

Summary updated

BibTeX
@inproceedings{cao2021automated,
  author = {Kaibo Cao and Chunyang Chen and Sebastian Baltes and Christoph Treude and Xiang Chen},
  title = {{Automated Query Reformulation for Efficient Search based on Query Logs From Stack Overflow}},
  booktitle = {ICSE},
  year = {2021},
  doi = {10.1109/icse43902.2021.00116},
}
Figure