Introduction: The Fine-Tuning Dilemma
Supervised Fine-Tuning (SFT) is the standard approach for adapting Large Language Models (LLMs) to specialized tasks like Natural Language to SQL (NL2SQL). However, SFT is often a "black box" process where practitioners invest significant compute resources without knowing if the resulting model will actually perform better on their target task. In many cases, fine-tuning on a misaligned dataset can lead to performance degradation or overfitting to irrelevant patterns.
This paper introduces a predictive framework based on structural alignment to determine the likelihood of SFT success before training begins. By measuring how closely the "skeletons" of training queries match the target task, researchers can make informed decisions about dataset selection.
Methodology: Measuring Structural Alignment
The core of the proposed framework is the KL-alignment metric, which quantifies the similarity between datasets based on their logical structure rather than raw text.
- Structural Templates: SQL queries are stripped of specific identifiers (table and column names) to create "skeletons" (e.g.,
SELECT / FROM WHERE = ORDER BY). - N-gram Distributions: The frequency of structural token sequences (n-grams) is calculated for these templates to capture the "shape" of the logic.
- KL-Divergence: Kullback-Leibler divergence measures the distance between the n-gram distributions of the training and target sets.
- Alignment Ratio (AR): This metric compares the training data's similarity to the target set against the model's own prior predictions. An $AR > 1$ indicates that the training data is a better structural match for the target than the model's current output, signaling a high probability of SFT success.
Experimental Results and the Overfitting Trap
The researchers evaluated several LLMs, including Qwen2 and CodeLlama, across benchmarks like BIRD (complex, real-world), Spider (cross-domain), and Gretel (synthetic).
The results demonstrate that alignment is a critical predictor of performance. For base models, the correlation between KL-alignment and execution accuracy was remarkably high ($r \approx 0.92$ to $0.94$). However, the study also revealed an "overfitting trap." When models like CodeLlama were fine-tuned on the highly complex BIRD dataset, they often lost accuracy on simpler datasets like Gretel because they were forced to align with overly complex structures.
As shown in the data, smaller or older models are particularly sensitive to alignment. While they show massive gains when properly aligned, they can suffer significant performance drops when misaligned. In contrast, modern models like Qwen 2.5 Coder appear "pre-aligned," showing high base performance and greater resistance to negative SFT effects, though their relative gains from fine-tuning are more modest.
Conclusion
The structural alignment framework provides a robust, efficient "go/no-go" signal for NL2SQL fine-tuning. By calculating the Alignment Ratio using even a small sample (1%) of target data, engineers can predict whether SFT will yield substantial gains or lead to performance regression. Future work aims to incorporate semantic dimensions, such as schema grounding and query correctness, to further refine these predictive capabilities.
Summary updated