Structure-aware neural generation of text from SQL queries
摘要
This paper introduces a novel approach for generating natural language explanations of SQL queries. To bridge the structural gap between SQL and linear text, we propose injecting the hierarchical information from SQL’s Abstract Syntax Tree (AST) directly into a neural generator. We design structure-encoded trees that decompose a query into its core components (e.g., SELECT clause, conditions). A formal encoding algorithm then assigns each token a structural code representing its precise role and position within the query’s hierarchy. These structural encodings are integrated into a pre-trained Transformer model by replacing BERT’s standard segment embeddings, creating a structure-aware encoder. This modified model is fine-tuned on the WikiSQL dataset to generate fluent descriptions. Experiments demonstrate the effectiveness of our method, achieving a BLEU score of 30.0 and substantially outperforming classical baselines on the SQL-to-text task. The results confirm that explicitly modeling SQL’s inherent hierarchical semantics leads to more accurate and natural-language explanations. Overall, this work presents an effective strategy for incorporating syntactic structural bias into text generation, significantly improving the interpretability and quality of SQL query explanations.