text2sql-eval-toolkit 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- text2sql_eval_toolkit-1.0.0/LICENSE +201 -0
- text2sql_eval_toolkit-1.0.0/PKG-INFO +382 -0
- text2sql_eval_toolkit-1.0.0/README.md +334 -0
- text2sql_eval_toolkit-1.0.0/pyproject.toml +73 -0
- text2sql_eval_toolkit-1.0.0/setup.cfg +4 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/__init__.py +107 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/analysis/__init__.py +5 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/analysis/error_analysis.py +335 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/analysis/report_tools.py +719 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/config_args.py +65 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/data/__init__.py +4 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/data/benchmarks.json +69 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/data/test-benchmarks.json +69 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/env_loader.py +55 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/evaluation/__init__.py +26 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/evaluation/evaluation_tools.py +759 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/evaluation/llm_as_judge.py +90 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/execution/__init__.py +5 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/execution/execution_tools.py +1448 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/execution/replace_select_tool.py +114 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/inference/__init__.py +5 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/inference/agentic_pipeline.py +2335 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/inference/base_pipeline.py +11 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/inference/baseline_llm_pipeline.py +372 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/inference/inference_tools.py +769 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/logging.py +54 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/profiling/profiling_tools.py +185 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit/utils.py +302 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit.egg-info/PKG-INFO +382 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit.egg-info/SOURCES.txt +36 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit.egg-info/dependency_links.txt +1 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit.egg-info/requires.txt +37 -0
- text2sql_eval_toolkit-1.0.0/src/text2sql_eval_toolkit.egg-info/top_level.txt +1 -0
- text2sql_eval_toolkit-1.0.0/tests/test_inference_tools.py +99 -0
- text2sql_eval_toolkit-1.0.0/tests/test_public_api.py +40 -0
- text2sql_eval_toolkit-1.0.0/tests/test_run_experiment_behavior.py +55 -0
- text2sql_eval_toolkit-1.0.0/tests/test_run_experiment_integration.py +72 -0
- text2sql_eval_toolkit-1.0.0/tests/test_sql_analysis.py +160 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 IBM Corporation
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: text2sql-eval-toolkit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A toolkit for evaluating text-to-SQL pipelines
|
|
5
|
+
Author-email: Oktie Hassanzadeh <lastname@us.ibm.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/IBM/text2sql-eval-toolkit
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: ibm_watsonx_ai>=1.3.30
|
|
15
|
+
Requires-Dist: pandas>=2.2.3
|
|
16
|
+
Requires-Dist: requests>=2.32.4
|
|
17
|
+
Requires-Dist: sqlalchemy>=2.0.41
|
|
18
|
+
Requires-Dist: sqlparse>=0.5.3
|
|
19
|
+
Requires-Dist: unitxt>=1.26.1
|
|
20
|
+
Requires-Dist: psycopg2-binary>=2.9.10
|
|
21
|
+
Requires-Dist: sqlglot>=27.0.0
|
|
22
|
+
Requires-Dist: asyncpg>=0.30.0
|
|
23
|
+
Requires-Dist: setuptools>=77.0.3
|
|
24
|
+
Requires-Dist: loguru>=0.7.3
|
|
25
|
+
Requires-Dist: func-timeout>=4.3.5
|
|
26
|
+
Requires-Dist: tqdm>=4.67.1
|
|
27
|
+
Requires-Dist: matplotlib>=3.10.5
|
|
28
|
+
Requires-Dist: python-dotenv>=1.1.1
|
|
29
|
+
Requires-Dist: langgraph>=0.2.0
|
|
30
|
+
Requires-Dist: langchain-core>=0.3.0
|
|
31
|
+
Requires-Dist: openai>=1.0.0
|
|
32
|
+
Provides-Extra: db2
|
|
33
|
+
Requires-Dist: ibm-db>=3.2.6; extra == "db2"
|
|
34
|
+
Requires-Dist: ibm-db-sa>=0.4.0; extra == "db2"
|
|
35
|
+
Requires-Dist: sqlalchemy>=2.0; extra == "db2"
|
|
36
|
+
Provides-Extra: mysql
|
|
37
|
+
Requires-Dist: pymysql>=1.1.1; extra == "mysql"
|
|
38
|
+
Requires-Dist: aiomysql>=0.2.0; extra == "mysql"
|
|
39
|
+
Requires-Dist: greenlet>=3.0.0; extra == "mysql"
|
|
40
|
+
Requires-Dist: cryptography>=45.0.6; extra == "mysql"
|
|
41
|
+
Provides-Extra: presto
|
|
42
|
+
Requires-Dist: pyhive>=0.7.0; extra == "presto"
|
|
43
|
+
Requires-Dist: presto-python-client>=0.8.4; extra == "presto"
|
|
44
|
+
Provides-Extra: notebook
|
|
45
|
+
Requires-Dist: jupyter>=1.0.0; extra == "notebook"
|
|
46
|
+
Requires-Dist: nbconvert>=7.0.0; extra == "notebook"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# Text-to-SQL Evaluation Toolkit
|
|
50
|
+
|
|
51
|
+
> **A modular framework for evaluating natural language to SQL systems**
|
|
52
|
+
> Supports execution-based metrics, multiple ground truths, LLM-as-judge, and rich error analysis.
|
|
53
|
+
|
|
54
|
+
Text-to-SQL systems aim to translate natural language questions into executable SQL queries, enabling intuitive access to structured data. While recent advances in large language models have significantly improved generation quality, evaluating these systems remains a complex and critical challenge.
|
|
55
|
+
|
|
56
|
+
*Why an Evaluation Toolkit?*
|
|
57
|
+
|
|
58
|
+
Assessing the correctness and utility of generated SQL queries requires more than simple string matching—it demands a flexible, rigorous framework that accounts for semantic equivalence, execution behavior, and real-world variability in query formulation. This toolkit was designed to address key limitations in existing approaches and provide a comprehensive solution for researchers and developers.
|
|
59
|
+
|
|
60
|
+
### Key Challenges in Evaluation
|
|
61
|
+
|
|
62
|
+
- **SQL Semantics Are Subtle**: Minor syntactic differences can lead to major semantic changes—or none at all. Traditional string-based metrics often fail to capture this nuance.
|
|
63
|
+
- **Execution-Based Validation Is Inconsistent**: Existing implementations often expect exact column sets, even when the question allows flexibility. For example, a query asking for a list of customers might return IDs, names, or both—all valid answers, yet not always recognized as such.
|
|
64
|
+
- **Lack of Unified Standards**: There is no widely adopted, unified implementation for execution-based evaluation, leading to fragmented and sometimes misleading results.
|
|
65
|
+
- **Multiple Valid SQLs**: Many questions have more than one correct SQL formulation. This toolkit supports multiple ground truth queries to reflect that reality.
|
|
66
|
+
- **LLM-as-Judge Support**: In cases where ground truth is unavailable or traditional metrics fall short, the toolkit enables using LLMs as judges—a surprisingly reliable method for assessing query correctness and relevance.
|
|
67
|
+
- **Error Analysis and Visualization**: Understanding *why* a model fails is just as important as knowing *that* it fails. The toolkit includes scripts and notebooks for summarizing results, visualizing performance, and performing detailed error analysis.
|
|
68
|
+
|
|
69
|
+
### What This Toolkit Offers
|
|
70
|
+
|
|
71
|
+
- Modular components for inference, execution, evaluation, profiling, and analysis
|
|
72
|
+
- Support for multiple benchmarks and flexible configurations
|
|
73
|
+
- Extensible metrics and evaluation strategies
|
|
74
|
+
- Tools for debugging and improving model performance
|
|
75
|
+
- A practical framework for both academic research and production-level benchmarking
|
|
76
|
+
|
|
77
|
+
Whether you're building new models, comparing existing ones, or diagnosing performance bottlenecks, this toolkit provides the resources needed to evaluate text-to-SQL systems with rigor and clarity.
|
|
78
|
+
|
|
79
|
+
## Components
|
|
80
|
+
|
|
81
|
+
<p align="center">
|
|
82
|
+
<img src="toolkit.png" alt="Text-to-SQL Toolkit Components" width="500"/>
|
|
83
|
+
</p>
|
|
84
|
+
|
|
85
|
+
- **Evaluation** ([`scripts/evaluation`](scripts/evaluation)/`src/evaluation.py`): Includes a script and library for evaluating text-to-SQL model outputs using various metrics. See [`scripts/evaluation/README.md`](scripts/evaluation/README.md) for details.
|
|
86
|
+
- **Text-to-SQL Inference** ([`scripts/inference`](scripts/inference)): Provides a simple LLM inference pipeline for generating SQL queries from natural language inputs. Run `python scripts/inference/run_inference.py -h` for more information.
|
|
87
|
+
- **SQL Execution** ([`scripts/execution`](scripts/execution)): Runs the ground truth and predicted SQLs for a given benchmark and saves the dataframes for evaluation and error analysis. Run `python scripts/execution/run_execution.py -h` for more information.
|
|
88
|
+
- **Results and Error Analysis** ([`scripts/analysis`](`scripts/analysis`)): Contains scripts and utilities for analyzing evaluation results, identifying common error patterns, and generating summary statistics and visualizations. Useful for debugging and improving model performance.
|
|
89
|
+
- **SQL Profiling** ([`scripts/profiling`](`scripts/profiling`)) tools to profile SQL queries to gather query characteristics to facilitate better analysis of results and errors.
|
|
90
|
+
|
|
91
|
+
## Setup
|
|
92
|
+
|
|
93
|
+
### Prerequisites
|
|
94
|
+
|
|
95
|
+
- Python 3.11 or higher
|
|
96
|
+
- [UV](https://github.com/astral-sh/uv) package manager (recommended) or pip/conda
|
|
97
|
+
|
|
98
|
+
### Installing UV (Recommended)
|
|
99
|
+
|
|
100
|
+
UV is a fast Python package manager that makes setup much quicker:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# macOS/Linux
|
|
104
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
105
|
+
|
|
106
|
+
# Or using pip
|
|
107
|
+
pip install uv
|
|
108
|
+
|
|
109
|
+
# Or using Homebrew (macOS)
|
|
110
|
+
brew install uv
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Installation
|
|
114
|
+
|
|
115
|
+
### From PyPI
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
pip install text2sql-eval-toolkit
|
|
119
|
+
|
|
120
|
+
# Optional: install database-specific extras
|
|
121
|
+
pip install "text2sql-eval-toolkit[mysql,presto,db2]"
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### From source (recommended for development)
|
|
125
|
+
|
|
126
|
+
Using UV:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Clone the repository
|
|
130
|
+
git clone https://github.com/IBM/text2sql-eval-toolkit.git
|
|
131
|
+
cd text2sql-eval-toolkit
|
|
132
|
+
|
|
133
|
+
# Create virtual environment and install dependencies
|
|
134
|
+
uv venv
|
|
135
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
136
|
+
|
|
137
|
+
# Install the package in editable mode
|
|
138
|
+
uv pip install -e .
|
|
139
|
+
|
|
140
|
+
# Optional: Install with database-specific dependencies
|
|
141
|
+
uv pip install -e ".[mysql,presto,db2]"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Using pip/conda:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Create conda environment (or use venv)
|
|
148
|
+
conda create -n evaltoolkit python=3.12
|
|
149
|
+
conda activate evaltoolkit
|
|
150
|
+
|
|
151
|
+
# Clone and install
|
|
152
|
+
git clone https://github.com/IBM/text2sql-eval-toolkit.git
|
|
153
|
+
cd text2sql-eval-toolkit
|
|
154
|
+
pip install -e .
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Additional Requirements
|
|
158
|
+
|
|
159
|
+
To use features that rely on LLM inference, you need to set the required environment variables for the relevant services. For watsonx.ai, this includes setting the following environment variables: `WATSONX_APIKEY`, `WATSONX_API_BASE`, and `WATSONX_PROJECTID`. See [env.example](env.example) for all available configuration options.
|
|
160
|
+
|
|
161
|
+
### Benchmarks
|
|
162
|
+
|
|
163
|
+
The toolkit comes with pre-defined public benchmarks including BIRD-SQL, Spider, Beaver, and Archer. These benchmarks require initial setup such as downloading databases or configuring connection strings. The toolkit also includes smaller test benchmarks (subsets of the full benchmarks) for quick validation and CI/CD pipelines.
|
|
164
|
+
|
|
165
|
+
**📚 See [data/benchmarks/README.md](data/benchmarks/README.md) for complete benchmark details, setup instructions, and configuration.**
|
|
166
|
+
|
|
167
|
+
## Usage
|
|
168
|
+
|
|
169
|
+
### Using the library API
|
|
170
|
+
|
|
171
|
+
After installation you can import the toolkit and use both low-level and high-level evaluation APIs:
|
|
172
|
+
|
|
173
|
+
**Evaluate a single prediction record in memory**
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from text2sql_eval_toolkit import evaluate_prediction, parse_dataframe, get_gt_sqls
|
|
177
|
+
|
|
178
|
+
# record comes from a benchmark JSON entry, prediction from your model
|
|
179
|
+
record = {
|
|
180
|
+
"id": "q1",
|
|
181
|
+
"sql": "SELECT * FROM customers",
|
|
182
|
+
"gt_df": some_serialized_dataframe, # JSON in pandas orient='split' format
|
|
183
|
+
}
|
|
184
|
+
prediction = {
|
|
185
|
+
"predicted_sql": "SELECT * FROM customers",
|
|
186
|
+
"predicted_df": some_serialized_dataframe, # same format
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
result = evaluate_prediction(record, prediction)
|
|
190
|
+
print(result["subset_non_empty_execution_accuracy"])
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**Evaluate a predictions JSON file**
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from text2sql_eval_toolkit import evaluate_predictions
|
|
197
|
+
|
|
198
|
+
data, summary_df = evaluate_predictions(
|
|
199
|
+
input_file="data/results/my-benchmark-predictions.json",
|
|
200
|
+
)
|
|
201
|
+
print(summary_df.head())
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Run evaluation for a known benchmark ID**
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from text2sql_eval_toolkit import get_available_benchmarks, run_evaluation
|
|
208
|
+
|
|
209
|
+
print(get_available_benchmarks()) # uses packaged benchmark metadata
|
|
210
|
+
data, summary_df = run_evaluation("bird_mini_dev_sqlite")
|
|
211
|
+
print(summary_df[["subset_non_empty_execution_accuracy_avg"]])
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Run SQL execution for a benchmark before evaluation**
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
from text2sql_eval_toolkit import run_execution
|
|
218
|
+
|
|
219
|
+
# Requires appropriate DB connection env vars (e.g., POSTGRES_CONNECTION_STRING)
|
|
220
|
+
run_execution("bird_mini_dev_postgres")
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Use the inference pipelines**
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
from text2sql_eval_toolkit import LLMSQLGenerationPipeline, AgenticSQLGenerationPipeline
|
|
227
|
+
|
|
228
|
+
pipeline = LLMSQLGenerationPipeline()
|
|
229
|
+
pipeline.run_pipeline(
|
|
230
|
+
benchmark_id="bird_mini_dev_sqlite",
|
|
231
|
+
model_name="wxai:ibm/granite-34b-code-instruct",
|
|
232
|
+
model_parameters={"max_new_tokens": 512},
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
agentic = AgenticSQLGenerationPipeline()
|
|
236
|
+
agentic.run_pipeline(
|
|
237
|
+
benchmark_id="bird_mini_dev_sqlite",
|
|
238
|
+
model_name="wxai:ibm/granite-34b-code-instruct",
|
|
239
|
+
model_parameters={"max_new_tokens": 512},
|
|
240
|
+
max_attempts=3,
|
|
241
|
+
)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
See the docstrings of the exported functions/classes in `text2sql_eval_toolkit.__init__` for the full list of public APIs.
|
|
245
|
+
|
|
246
|
+
### Running Experiments
|
|
247
|
+
|
|
248
|
+
**Single Benchmark:**
|
|
249
|
+
```bash
|
|
250
|
+
python scripts/run_experiment.py [benchmark_name]
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
This will initialize a pipeline, perform inference to generate SQLs and output dataframes, and run the evaluation script to gather accuracy metrics. Benchmark names and configurations are defined in [`data/benchmarks.json`](data/benchmarks.json) (for full benchmarks) or [`data/test-benchmarks.json`](data/test-benchmarks.json) (for test benchmarks). See [data/benchmarks/README.md](data/benchmarks/README.md) for more details. Run `python scripts/run_experiment.py -h` for details on how to set different input arguments for the script.
|
|
254
|
+
|
|
255
|
+
**Multiple Benchmarks:**
|
|
256
|
+
```bash
|
|
257
|
+
# Run all test benchmarks (recommended for quick validation)
|
|
258
|
+
python scripts/run_all_benchmarks.py --test
|
|
259
|
+
|
|
260
|
+
# Run all full benchmarks
|
|
261
|
+
python scripts/run_all_benchmarks.py
|
|
262
|
+
|
|
263
|
+
# Run with all baselines (standard + 6 agentic variants)
|
|
264
|
+
python scripts/run_all_benchmarks.py --test --run_all_baselines
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
The `run_all_benchmarks.py` script supports separate model configurations for standard and agentic baselines to optimize runtime. See [data/benchmarks/README.md](data/benchmarks/README.md#model-configuration) for detailed configuration options.
|
|
268
|
+
|
|
269
|
+
### Running Individual Components
|
|
270
|
+
|
|
271
|
+
To run evaluation only:
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
python scripts/evaluation/run_evaluation.py [-h] [--output_file OUTPUT_FILE] [--summary_file SUMMARY_FILE] [--csv_summary_file CSV_SUMMARY_FILE] [--use_llm_judge] input_file
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
See [`scripts/evaluation/README.md`](scripts/evaluation/README.md) for details.
|
|
278
|
+
|
|
279
|
+
To run inference only:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# Standard baseline inference
|
|
283
|
+
python scripts/inference/run_inference.py benchmark_id [--model_names MODEL1 MODEL2 ...]
|
|
284
|
+
|
|
285
|
+
# Agentic pipeline inference with default models
|
|
286
|
+
python scripts/inference/run_inference.py benchmark_id --pipeline_type agentic
|
|
287
|
+
|
|
288
|
+
# Agentic pipeline with custom models
|
|
289
|
+
python scripts/inference/run_inference.py benchmark_id --pipeline_type agentic \
|
|
290
|
+
--agentic_models "wxai:openai/gpt-oss-120b" "wxai:meta-llama/llama-3-3-70b-instruct"
|
|
291
|
+
|
|
292
|
+
# Additional options
|
|
293
|
+
python scripts/inference/run_inference.py benchmark_id \
|
|
294
|
+
--pipeline_type agentic \
|
|
295
|
+
--agentic_version v2 \
|
|
296
|
+
--max_attempts 5 \
|
|
297
|
+
--max_new_tokens 1024
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Like `run_experiment.py` and `run_all_benchmarks.py`, the inference script supports separate model configurations via `--model_names` (for standard baseline) and `--agentic_models` (for agentic pipeline). Run `python scripts/inference/run_inference.py -h` for all options.
|
|
301
|
+
|
|
302
|
+
To run execution only:
|
|
303
|
+
|
|
304
|
+
```
|
|
305
|
+
python scripts/execution/run_execution.py [-h] benchmark_id
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
To produce the results dashboard along with results summary and error analysis Markdown files for all the benchmarks defined in the `data/benchmarks.json` file, run:
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
python scripts/analysis/make_summary_report.py
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
The output will be written to [data/results/README.md](data/results/README.md).
|
|
315
|
+
|
|
316
|
+
## Project Structure
|
|
317
|
+
|
|
318
|
+
```
|
|
319
|
+
text2sql-eval-toolkit
|
|
320
|
+
├── notebooks/ # Jupyter notebooks showcasing the use of the toolkit functions
|
|
321
|
+
├── data/ # Benchmark datasets and evaluation results
|
|
322
|
+
│ ├── benchmarks/ # Benchmark data and schema files
|
|
323
|
+
│ │ ├── README.md # Detailed benchmark documentation
|
|
324
|
+
│ │ ├── test_benchmarks/ # Test benchmark data files
|
|
325
|
+
│ │ └── dbs/ # Database files and setup instructions
|
|
326
|
+
│ ├── benchmarks.json # Full benchmarks configuration
|
|
327
|
+
│ ├── test-benchmarks.json # Test benchmarks configuration (smaller datasets)
|
|
328
|
+
│ └── results/ # Evaluation outputs
|
|
329
|
+
│ └── README.md # Summary of results
|
|
330
|
+
├── scripts/ # Scripts for running experiments
|
|
331
|
+
│ ├── analysis/ # Results and error analysis scripts and utilities
|
|
332
|
+
│ ├── curation/ # Benchmark data curation and preprocessing scripts
|
|
333
|
+
│ ├── evaluation/ # Evaluation pipeline script
|
|
334
|
+
│ ├── execution/ # Scripts for SQL execution
|
|
335
|
+
│ ├── inference/ # Inference pipeline (baseline) script
|
|
336
|
+
│ ├── profiling/ # SQL query profiling script
|
|
337
|
+
├── src/ # Source code for the toolkit
|
|
338
|
+
│ └── text2sql_eval_toolkit/ # Core modules
|
|
339
|
+
│ ├── analysis/ # Results and error analysis module
|
|
340
|
+
│ ├── evaluation/ # Evaluation module
|
|
341
|
+
│ ├── execution/ # SQL execution module
|
|
342
|
+
│ ├── inference/ # LLM inference (baseline) module
|
|
343
|
+
│ └── profiling/ # SQL profiling module
|
|
344
|
+
├── pyproject.toml # Build system and project metadata
|
|
345
|
+
├── README.md # Project documentation
|
|
346
|
+
├── requirements.txt # Python dependencies
|
|
347
|
+
└── LICENSE # License file
|
|
348
|
+
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Contributing
|
|
352
|
+
|
|
353
|
+
We welcome external contributions! If you have an itch, please feel free to scratch it.
|
|
354
|
+
|
|
355
|
+
To contribute code or documentation, please submit a [pull request](https://github.com/IBM/text2sql-eval-toolkit/pulls).
|
|
356
|
+
|
|
357
|
+
A good way to familiarize yourself with the codebase and contribution process is to look for and tackle low-hanging fruit in the [issue tracker](https://github.com/IBM/text2sql-eval-toolkit/issues).
|
|
358
|
+
|
|
359
|
+
**Note: We appreciate your effort, and want to avoid a situation where a contribution requires extensive rework (by you or by us), sits in backlog for a long time, or cannot be accepted at all!**
|
|
360
|
+
|
|
361
|
+
For detailed contribution guidelines, please see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
362
|
+
|
|
363
|
+
### Pull Request Process
|
|
364
|
+
|
|
365
|
+
1. Fork the repo
|
|
366
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
367
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
368
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
369
|
+
5. Create new Pull Request
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for more details.
|
|
374
|
+
|
|
375
|
+
## Additional Resources
|
|
376
|
+
|
|
377
|
+
- [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) - Community guidelines
|
|
378
|
+
- [SECURITY.md](SECURITY.md) - Security policy and vulnerability reporting
|
|
379
|
+
- [MAINTAINERS.md](MAINTAINERS.md) - Project maintainers
|
|
380
|
+
- [CHANGELOG.md](CHANGELOG.md) - Project changelog
|
|
381
|
+
|
|
382
|
+
[issues]: https://github.com/IBM/text2sql-eval-toolkit/issues/new
|