ユーザーはSQLクエリを出⼒根拠にされてもわからない。出⼒結果を正しいものとして、 後続の意思決 定をしてしまう。UXや説明性が求められる。 ▍精度向上⼿段が⼀般化されず、個別エンジニアリングが必要なこと l データがあればどのDBでも問題なく利⽤できる汎⽤的なアルゴリズムがあると理想 l 実際は、DBごとにQAぺアの準備やスキーマの説明を充実させるなどが必要
▍実⾏精度(EX) l 実⾏結果が真のSQLクエリの結果と⼀致した割合 l クエリ効率が悪くても評価される l すべての正しいSQLクエリを捕捉することはできない A comprehensive evaluation of ChatGPT’s zero-shot Text-to-SQL capability Evaluating Cross-Domain Text-to-SQL Models and Benchmarks 実⾏精度で本当は正解なのにエラーとされるケース
l https://github.com/chiahsuan156/KaggleDBQA ▍BIRD(2023) l レコード数を増やした33.4GBのデータセットで、最新ベンチマークになっている l https://bird-bench.github.io/ ▍+紹介 MultiSpider(2023) l 7つの⾔語に翻訳した多⾔語 データセット l https://huggingface.co/datasets/dreamerdeo/multispider
理想は質問⽂から⽣成するか、DBの値を事前確保して予測するべき Spider: A large-scale human-labeled dataset for complex and cross-domain semantic parsing and text-to-sql task. Natural Language Interfaces for Tabular Data Querying and Visualization: A Survey
l クエリを⽣成するのにドメイン知識が必要なケース(DBの値の”F”がfemaleを指す、1980sは1980~1989までの期間を指すなど) ▍ データの複雑さ(Data Complexity) l データにノイズが含まれる、単純な集計で処理できないケース(⾦額が数字でなく、⽂字列で記録されているなど) ▍ SQLの複雑さ(SQL Complexity) l JOIN:必要とされるすべてのテーブルや、テーブルを結合するための正しい外部キーを特定することが難しい l GROUP BY :何をグルーピングすべきか不明 l ネストと集合操作を含むクエリ:⼊れ⼦構造を認識しないか、正しい⼊れ⼦または集合操作を検出できない ▍ スキーマリンク(Schema Linking) l 質問の意図と違ったデータベース要素(テーブル、カラム、値)でSQLクエリが⽣成される。 l 「2011年の最優秀⼥優は誰か?」というクエリでは、「⼥優」はデータベースのActor.name 属性に対応させる必要がある。 ▍ その他 l 余分な述語を含むSQLクエリ、述語の⽋落、DISTINCTやDESCキーワードの⽋落や冗⻑など
” Ø クエリの⽂脈による違いでSQLの句が変わる p "Who was the best runner of the marathon? "は、レースを速く完⾛した⼈(min操作)が返されるはず p "Which was the best nation of the 2004 Olympics?" は、最も多くのメダルを獲得した⼈(max操作)が返されるはず Ø ドメインによる違いでカラムリンクが変わる p 映画DBの”Return the top movie” では、”top” はレビュー評価を意味する p サッカーDBの ”Return the top scorer” では、”top” はゴール数を意味する p ビジネスアナリストの“Return the top product”は、 “top” は最も収益性の⾼い製品を意味する
match) で重複を考慮する必要があるのか ▍値の⼀貫性(value consistency ) l 値は⼀貫した形式に従っているか l サッカーの試合であれば「ホームチーム名 – アウェイチーム名」で統⼀。異常値はないなど l マッチ操作に関係する ▍データのカバレッジ(data coverage ) l イベント全体を表しているのか、特定の⽅法(時間/場所など)のサブセットなのか l あるカラムが2009-2013 の範囲のみ保持しているなど l union や deduplication操作に関係する
SELECT句の中での⾮集約列、集約列と⾮集約列の混在 ▍NESTED l ⼊れ⼦になったSQLクエリに⼀意でないカラムを使⽤ ▍WHERE l 列の幻想、必要な条件の省略 ▍LIMIT N l 同順位が複数ある場合 l 同順位を返すこともあれば、1 つだけを返すこともある DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
as a database interface? a big bench for large-scale database grounded text-to-sqls. A Survey on Text-to-SQL Parsing: Concepts, Methods, and Future Directions
外部知識で⾔い換え ・「今」「先⽉」といった時間情報を指定⽅式で置き換える ・スキーマの説明で補完する ・デモデータから補完する ・専⾨⽤語の補完 • 質問から抽出、変換、置換の3つのステップで書き換える • 扱うスキーマが絞られている場合、スキーマに基づいて質問意図を⽣成する Reboost Large Language Model-based Text-to-SQL, Text-to-Python, and Text-to-Function - with Real Applications in Traffic Domain 質問の⾔い換え 質問の分解 スキーマ検索 スキーマ説明 デモ選択 ⾃⼰改善 Fine Tuning
精度 ・LLAMA-13Bと30Bでは、davinci-003 と並ぶがGPT4やgpt-3.5-turboには劣る ・微学習後はFew shot Learningの効果がない Snowflake SQLとGoogleSQL⽂でファインチューニング データセット:GPT4を使⽤しながら、3732件QAを作成し、8:2分割 精度 ・GPT4より精度が向上し、回答までの⽣成時間が短い Text-to-SQL Empowered by Large Language Models: A Benchmark Evaluation FINE-TUNING LANGUAGE MODELS FOR CONTEXT-SPECIFIC SQL QUERY GENERATION デモ選択 ⾃⼰改善 Fine Tuning
question, first create a syntactically correct PostgreSQL query to run, then look at the results of the query and return the answer to the input question. Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per PostgreSQL. You can order the results to return the most informative data in the database. Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers. Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table. Pay attention to use CURRENT_DATE function to get the current date, if the question involves "today". Use the following format: Question: Question here SQLQuery: SQL Query to run SQLResult: Result of the SQLQuery Answer: Final answer here Only use the following tables:{table_info} Question: {input} PostgreSQL⽤のプロンプトを載せます。 他のDBはLnagchainのリポジトリで確認してください。
a SQL database. Given an input question, create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer. Unless the user specifies a specific number of examples they wish to obtain, always limit your query to at most {top_k} results. You can order the results by a relevant column to return the most interesting examples in the database. Never query for all the columns from a specific table, only ask for the relevant columns given the question. You have access to tools for interacting with the database. Only use the below tools. Only use the information returned by the below tools to construct your final answer. You MUST double check your query before executing it. If you get an error while executing a query, rewrite the query and try again. DO NOT make any DML statements (INSERT, UPDATE, DELETE, DROP etc.) to the database. If the question does not seem related to the database, just return "I don't know" as the answer. Begin! Question: {input} Thought: I should look at the tables in the database to see what I can query. Then I should query the schema of the most relevant tables. {agent_scratchpad}
Interfaces for Tabular Data Querying and Visualization: A Survey." arXiv preprint arXiv:2310.17894 (2023). ▍ サーベイ Katsogiannis-Meimarakis, George, and Georgia Koutrika. "A survey on deep learning approaches for text-to-SQL." The VLDB Journal (2023): 1-32. ▍ サーベイ Qin, Bowen, et al. "A survey on text-to-sql parsing: Concepts, methods, and future directions." arXiv preprint arXiv:2208.13629 (2022). ▍ NLQシステム Conversing with databases: Practical Natural Language Querying (Kochedykov et al., EMNLP 2023) ▍ 曖昧さ Huang, Zezhou, Pavan Kalyan Damalapati, and Eugene Wu. "Data Ambiguity Strikes Back: How Documentation Improves GPT's Text-to-SQL." arXiv preprint arXiv:2310.18742 (2023). ▍ ⼤量のスキーマ対策 Guo, Chunxi, et al. "Prompting GPT-3.5 for Text-to-SQL with De-semanticization and Skeleton Retrieval." Pacific Rim International Conference on Artificial Intelligence. Singapore: Springer Nature Singapore, 2023. ▍ ⼤量のスキーマ対策 Kothyari, Mayank, et al. "CRUSH4SQL: Collective Retrieval Using Schema Hallucination For Text2SQL." arXiv preprint arXiv:2311.01173 (2023). ▍ ⼤量のスキーマ対策 Wang, Tianshu, et al. "DBCopilot: Scaling Natural Language Querying to Massive Databases." arXiv preprint arXiv:2312.03463 (2023).
and Prompt: Chain of Thought Prompting for Text-to-SQL." arXiv preprint arXiv:2304.11556 (2023). ▍ CoT Tai, Chang-You, et al. "Exploring Chain-of-Thought Style Prompting for Text-to-SQL." arXiv preprint arXiv:2305.14215 (2023). ▍ CoT Zhang, Hanchong, et al. "ACT-SQL: In-Context Learning for Text-to-SQL with Automatically-Generated Chain-of-Thought." arXiv preprint arXiv:2310.17342 (2023). ▍ ZSL Liu, Aiwei, et al. "A comprehensive evaluation of ChatGPT's zero-shot Text-to-SQL capability." arXiv preprint arXiv:2303.13547 (2023). ▍ スキーマリンク Li, Haoyang, et al. "Resdsql: Decoupling schema linking and skeleton parsing for text-to-sql." Proceedings of the AAAI Conference on Artificial Intelligence. Vol. 37. No. 11. 2023. ▍ デモ選択 Nan, Linyong, et al. "Enhancing Text-to-SQL Capabilities of Large Language Models: A Study on Prompt Design Strategies." Findings of the Association for Computational Linguistics: EMNLP 2023. 2023. ▍ デモ選択 Gao, Dawei, et al. "Text-to-sql empowered by large language models: A benchmark evaluation." arXiv preprint arXiv:2308.15363 (2023). ▍ デモ選択 Chang, Shuaichen, and Eric Fosler-Lussier. "Selective Demonstrations for Cross-domain Text-to-SQL." arXiv preprint arXiv:2310.06302 (2023).