文本到 SQL 数据生成器

文本到 SQL 数据生成器可生成合成 SQL 数据,其中包含描述数据库操作的自然语言语句和执行数据库操作的等效 SQL 语句。

注: 目前,自然语言声明必须以英文书写。

种子数据格式

创建一个包含纯文本语句示例的输入 YAML 文件。 向该文件添加以下信息:

  • 对关系数据库中存储的数据执行的操作
  • 执行每个操作的相应 SQL 查询
  • 定义数据组织和存储方式的数据库模式

YAML 文件使用以下结构:

task_description: <Description of this task>
seed_examples:
   - utterance: <input question 1>
     query: <sample SQL 1>
   - utterance: <input question 2>
     query: <sample SQL 2>
database:
   schema: "<Data Definition Language (DDL) statement of one or more tables. Separate each DDL by a semi-colon>"

种子数据样本

要下载文本到 SQL 数据生成器的样本种子数据,请参阅 watsonx -ai-samples。

JSON 文件请求正文示例

以下请求体包含使用文本到 SQL 数据生成器的非结构化合成数据生成任务的配置。 它还有生成令牌的高级设置。

{
    "project_id": "<ID of the project to create the job in>",
    "name": "<Name of the job that you want to create>",
    "description": "<Description for the job>",
    "configuration": {
        "pipeline": "nl2sql",
        "num_outputs_to_generate": <A value between 1 to 1000>,
        "overwrite_output_file": false,
        "generator": {
            "model_id": "<LLM. For example ibm/granite-3-8b. For models deployed on demand, this is the deployment_id>",
            "temperature": 0.5,
            "max_new_tokens": 1024,
            "min_new_tokens": 100,
            "decoding_method": "sample",
            "top_p": 0.9,
            "top_k": 50
        },
        "validators": [            
            {
                "type": "rouge_scorer",
                "filter": true,
                "threshold": 0.9
            },
            {
                "type": "lm_judge",
                "lm_config": {
                    "model_id": "<LLM. For example ibm/granite-3-8b."
                }
            }
        ],
        "seed_data_reference": {
            "type": "container",
            "location": {
                "path": "<YAML file name in project assets. For example qna_know_seed.yaml>"
            }
        },
        "results_reference": {
            "type": "container",
            "location": {
                "path": "<File name for the generated data output. For example sdg-output-know.jsonl>"
            }
        }
    },
    "job": {
        "schedule": "0 0 1 * *",
        "schedule_info": {
            "repeat": true,
            "startOn": 1547578689512,
            "endOn": 1547578689512
        }
    }
}