The field of Text-to-SQL, which involves converting natural language questions into SQL queries, has progressed remarkably with the emergence of Large Language Models (LLMs). However, while these models are capable of producing valid syntax, they often falter when faced with the subtle intricacies of complex queries. They frequently fail to precisely grasp the user's intent or navigate complex database schemas. Moreover, existing few-shot prompting methods, essential for directing LLMs, typically depend on basic approaches for choosing examples, which don't effectively utilize the full breadth and variety of the available training data. This thesis presents a novel framework for enhancing the accuracy of Text-to-SQL generation through a multi-stage approach incorporating diversity-based clustering few-shot prompting, similarity-driven few-shot prompting, and an iterative feedback-correction loop. Our methodology begins with a Diversity Stage, where various embedding models and clustering strategies were rigorously evaluated. This stage generates a diverse set of validated Chain-of-Thought (CoT) and SQL examples. The subsequent Similarity Stage leverages cosine similarity to select the most relevant correct examples for few-shot prompting, showing robust performance and insensitivity to weight parameter adjustments between question and SQL similarities. Crucially, we introduce static and dynamic Critique/Corrector Loops, featuring a "Critique Agent" that identifies errors and a "Corrector Agent" that refines the CoT and SQL based on expert feedback. This self-correction mechanism significantly improves accuracy. This work also proposes the creation of a unique self-correction dataset derived from this loop, intended for fine-tuning small Language Models to foster autonomous error remediation.
The field of Text-to-SQL, which involves converting natural language questions into SQL queries, has progressed remarkably with the emergence of Large Language Models (LLMs). However, while these models are capable of producing valid syntax, they often falter when faced with the subtle intricacies of complex queries. They frequently fail to precisely grasp the user's intent or navigate complex database schemas. Moreover, existing few-shot prompting methods, essential for directing LLMs, typically depend on basic approaches for choosing examples, which don't effectively utilize the full breadth and variety of the available training data. This thesis presents a novel framework for enhancing the accuracy of Text-to-SQL generation through a multi-stage approach incorporating diversity-based clustering few-shot prompting, similarity-driven few-shot prompting, and an iterative feedback-correction loop. Our methodology begins with a Diversity Stage, where various embedding models and clustering strategies were rigorously evaluated. This stage generates a diverse set of validated Chain-of-Thought (CoT) and SQL examples. The subsequent Similarity Stage leverages cosine similarity to select the most relevant correct examples for few-shot prompting, showing robust performance and insensitivity to weight parameter adjustments between question and SQL similarities. Crucially, we introduce static and dynamic Critique/Corrector Loops, featuring a "Critique Agent" that identifies errors and a "Corrector Agent" that refines the CoT and SQL based on expert feedback. This self-correction mechanism significantly improves accuracy. This work also proposes the creation of a unique self-correction dataset derived from this loop, intended for fine-tuning small Language Models to foster autonomous error remediation.
ENHANCING TEXT-TO-SQL GENERATION THROUGH MULTI-STAGE FEW-SHOT LEARNING AND SELF-CORRECTION
SIGNORILE, MATTIA
2024/2025
Abstract
The field of Text-to-SQL, which involves converting natural language questions into SQL queries, has progressed remarkably with the emergence of Large Language Models (LLMs). However, while these models are capable of producing valid syntax, they often falter when faced with the subtle intricacies of complex queries. They frequently fail to precisely grasp the user's intent or navigate complex database schemas. Moreover, existing few-shot prompting methods, essential for directing LLMs, typically depend on basic approaches for choosing examples, which don't effectively utilize the full breadth and variety of the available training data. This thesis presents a novel framework for enhancing the accuracy of Text-to-SQL generation through a multi-stage approach incorporating diversity-based clustering few-shot prompting, similarity-driven few-shot prompting, and an iterative feedback-correction loop. Our methodology begins with a Diversity Stage, where various embedding models and clustering strategies were rigorously evaluated. This stage generates a diverse set of validated Chain-of-Thought (CoT) and SQL examples. The subsequent Similarity Stage leverages cosine similarity to select the most relevant correct examples for few-shot prompting, showing robust performance and insensitivity to weight parameter adjustments between question and SQL similarities. Crucially, we introduce static and dynamic Critique/Corrector Loops, featuring a "Critique Agent" that identifies errors and a "Corrector Agent" that refines the CoT and SQL based on expert feedback. This self-correction mechanism significantly improves accuracy. This work also proposes the creation of a unique self-correction dataset derived from this loop, intended for fine-tuning small Language Models to foster autonomous error remediation.I documenti in UNITESI sono protetti da copyright e tutti i diritti sono riservati, salvo diversa indicazione.
https://hdl.handle.net/20.500.14253/70643