nl2jq-bench
收藏资源简介:
nl2jq-bench 是一个用于评估模型将自然语言转换为 jq(一种 JSON 查询和处理语言)程序能力的执行评分基准数据集。它包含 400 个经过冻结的测试项目(版本 1.0.0),每个项目代表一个现实世界的查询任务,包括一个简短的自然语言请求、一个小型的 JSON 输入数据、一个经过执行验证的参考 jq 程序以及该程序在 jq 1.7.1 下运行得到的预期输出。模型性能通过其生成的 jq 程序执行输出是否与参考输出匹配来评分,而非基于程序文本相似性。数据集项目根据 jq 语言特性的复杂度分为五个难度层级(Tier 1 到 Tier 5),分别涵盖基础操作、核心功能、聚合与重塑、字符串与格式处理以及泛化构造。设计上严格防止了与训练集(nl2jq)的数据污染,确保了字段名称零重叠、T5层级使用训练数据语法未覆盖的结构,并引入了训练集未出现的新领域(如临床、交通、体育等)。每个数据条目采用 JSON 格式,包含唯一标识符、难度等级、领域、请求文本、输入 JSON、参考程序、预期输出等关键字段,部分条目还包含可接受的替代输出列表。数据集旨在用于模型的一次性评估,以公正衡量其泛化能力,并附带了独立的评分工具(harness.py)。
nl2jq-bench is an execution-based evaluation benchmark dataset for assessing the ability of models to convert natural language into jq (a JSON query and processing language) programs. It contains 400 frozen test items (version 1.0.0), each representing a real-world query task, including a short natural language request, a small JSON input data, an execution-verified reference jq program, and the expected output from running the program under jq 1.7.1. Model performance is scored based on whether the execution output of the generated jq program matches the reference output, rather than program text similarity. The dataset items are divided into five difficulty tiers (Tier 1 to Tier 5) based on the complexity of jq language features, covering basic operations, core functions, aggregation and reshaping, string and format processing, and generalization constructs. The design strictly prevents data contamination with the training set (nl2jq), ensuring zero overlap in field names, the use of structures not covered by training data syntax in Tier 5, and the introduction of new domains not present in the training set (e.g., clinical, transportation, sports). Each data entry is in JSON format, containing key fields such as a unique identifier, difficulty level, domain, request text, input JSON, reference program, expected output, with some entries also including a list of acceptable alternative outputs. The dataset is intended for one-time evaluation of models to fairly measure their generalization capabilities and comes with an independent scoring tool (harness.py).
数据集概述:nl2jq-bench
nl2jq-bench 是一个用于评估自然语言到 jq 程序生成能力的执行评分冻结基准(Execution-scored, Frozen Benchmark)。它属于 nl2jq 项目的一部分。
核心特点
- 基于执行结果评分:模型得分基于其生成的 jq 程序在 jq 1.7.1 环境下的实际输出是否与参考输出一致,而非基于字符串相似度。
- 冻结基准:数据集版本 v1.0.0 已冻结,内容永不改变。
- 抗污染设计:通过多种机制确保与训练集无重叠,防止数据泄露。
数据规模与配置
- 数据集大小:< 1K 条样本。
- 配置文件:
default:包含test分片,数据文件为nl2jq-bench-1.0.0.jsonl(基准集,400 条已冻结样本)。devset-v0:包含dev分片,数据文件为devset-v0.jsonl(已停用的 100 条开发集,不用于基准评估)。
- 许可证:CC-BY-4.0。
任务与标签
- 任务类别:文本生成(text-generation)。
- 标签:
jq、code-generation、json、execution-benchmark。
数据集设计
基准集包含 400 条样本,划分为五个难度层级(tier),覆盖不同复杂度的 jq 操作:
| 层级 | 样本数 | 内容描述 |
|---|---|---|
| T1 Elementary 基础 | 60 | 单操作:路径/索引/切片/length/keys/has/type/// |
| T2 Core 核心 | 100 | select/map、比较、算术、unique/sort/min/max/add、contains |
| T3 Aggregation & reshape 聚合与重塑 | 100 | group_by/sort_by/*_by、to_entries 家族、map_values、flatten、any/all、对象构造 |
| T4 Strings, formats & composition 字符串、格式与组合 | 80 | split/join/test/capture/sub/gsub、类型转换、插值、@csv/@tsv/@json/@base64、3 阶段以上管道 |
| T5 Generalization 泛化 | 60 | reduce、foreach、walk/..、paths/getpath、try/catch、if/then/elif、对象合并 add、计算键 group_by、INDEX |
抗污染机制
- 字段名无重叠:所有输入字段名与完整训练词汇表(687 个名称)无任何共享 ≥4 字符前缀、小编辑变体或常见缩写,且无训练集枚举值出现在输入值或程序字面量中。
- T5 超语法:60 个 T5 样本仅使用训练数据语法保证不会生成的结构,需单独报告 T5 得分。
- 新领域:12 个与训练集不相交的领域(如临床、成绩单、交通、体育等)。
- 密封金丝雀:100 条密封样本已冻结,从未发布,用于检测未来模型是否在测试集上训练。
样本格式示例
json { "id": "v1-042", "tier": 3, "difficulty": 3, "domain": "transit", "request": "total ridership per garage", "input": [ {"route_no": "41B", "garage": "Elmside", "ridership": 10432}, ... ], "reference_program": "group_by(.garage) | map({garage: .[0].garage, ridership: (map(.ridership) | add)})", "expected_output": [ ... ], "order_insensitive": false, "abstract": false, "novel_fields": ["route_no", "garage", "ridership"], "grammar_covered": true, "provenance": "hand", "source": "original", "jq_version": "1.7.1", "frozen_in": "1.0.0", "canary_id": "…", "license": "CC-BY-4.0" }
评分方法
预测正确的条件:其 jq 输出在以下标准化规则下等于可接受的输出(acceptable_outputs)之一:
- 数组/流等价:
map(.x)和.[].x评分相同。 - 数组顺序不敏感:针对标记为
order_insensitive的样本。 - 浮点数容差:针对数值输出。
评分工具为独立的 harness.py,需 Python 3.10+ 和 jq 二进制文件。
结果示例 (v1.0.0)
| 系统 | pass@1 | valid@1 | T1 | T2 | T3 | T4 | T5-gen |
|---|---|---|---|---|---|---|---|
| nl2jq-40m (v7 weights) | 0.04 | 0.56 | 0.08 | 0.08 | 0.02 | 0.01 | 0.02 |
| nl2jq-qwen3-0.6b (v6 weights) | 0.40 | 0.73 | 0.65 | 0.52 | 0.36 | 0.28 | 0.20 |
| nl2jq-qwen3.5-2b (v7 LoRA) | 0.46 | 0.75 | 0.67 | 0.61 | 0.47 | 0.33 | 0.13 |
| Claude Opus 4.8 (zero-shot) | 0.96 | 0.98 | 1.00 | 0.96 | 0.96 | 0.96 | 0.90 |
项目资源
- 完整项目集合:nl2jq 项目合集
- 代码与 CLI:GitHub 仓库
- 在线演示:Hugging Face Space
- 配套训练集:gauthierpiarrette/nl2jq




