Introduction
Current text-to-code models often struggle with under-specified natural language descriptions (NLDs). When a user provides a vague prompt like "Do a logistic regression," a model must guess whether to include grid searches, model serialization, or specific hyperparameters. This ambiguity often results in code that is syntactically valid but fails to meet the user's actual intent. To address this, we introduce a framework that enables models to behave like human pair-programmers by identifying missing information and asking clarification questions (CQs).
Methodology: Identifying Missing Operations
The core of our approach is a pipeline designed to detect "key operations"—API calls essential to the code's logic—that are absent from the initial user prompt.
- Key Operation Identification: We represent code as a data flow graph using the
GraphGen4Codetoolkit to isolate core API calls. - Schema Alignment: We extract "schemas" (comprising verbs, key-phrases, and relations) from both the code documentation and the user's NLD. Using Sentence-BERT, we calculate similarity scores between these schemas. If the similarity falls below a threshold, the operation is flagged as missing.
- Synthetic CQ Generation: For each missing operation, the system generates a question using predefined templates, offering either multiple-choice or yes/no options.
The CodeClarQA Dataset
To train and evaluate this framework, we developed CodeClarQA, a dataset derived from the notebookCDG collection of Jupyter notebooks. It consists of approximately 19,368 NLD-code samples focused on data science libraries such as pandas and scikit-learn. The dataset includes synthetic clarification questions and answers, validated through human annotation to ensure the accuracy of "missingness" labels.
Experimental Results
Our evaluation demonstrates that interactivity significantly boosts model performance. When provided with "oracle" (perfect) clarifications, models like CodeT5 saw their BLEU scores increase from 27.03 to 39.13. Similarly, PLBART achieved a notable jump in Exact Match (EM) rates.
In an end-to-end setting, the system employs a three-stage pipeline:
- Clarification Need Predictor: Decides if a prompt requires clarification.
- CQ Ranker: Selects the most relevant questions from a candidate pool.
- Code Generator: Produces the final code based on the prompt and the resulting Q&A.
Conclusion and Future Work
While the current framework effectively handles missing API calls, challenges remain in addressing missing arguments and complex logic. Future work will focus on expanding the system to handle multi-turn conversations and broader programming domains beyond data science. By moving from static generation to interactive dialogue, we can create more robust and reliable AI coding assistants.
Summary updated