thanhdath's picture
v3: exact-SQL keyed gating, upstream bug in add_correct_sqls_from_eval.py named and fixed
67568ff verified
|
Raw History Blame Contribute Delete
6.64 kB
---
license: cc-by-4.0
task_categories:
- text2sql
language:
- en
tags:
- text-to-sql
- bird
- spider
- finer-sql
- reinforcement-learning
size_categories:
- 10K<n<100K
extra_gated_prompt: "Manual approval. Please say who you are and what you will use this for."
---
# finer-sql-train-joint-fixed — the FINER-SQL joint BIRD+Spider training corpus with its reference SQLs re-attached to the right sample
18,087 training rows (9,428 BIRD train + 8,659 Spider train) over 215 training databases.
Same rows, same order, same prompts as
`data/train/grpo_sql_writer_origdata_joint_oldprompt_full` — **only the reference SQLs in
`groundtruth_sqls[1:]` differ**.
## Trainer exposure
`grpo_writer.py:1264` binds the list. The **binary execution match uses entry 0 only**
(`grpo_writer.py:1346`), but the **atomic-ops shaping bonus takes the maximum over the
whole list** (`grpo_writer.py:1410` and `:1448` → `atomic_ops/reward.py:40
score_against_list`, "max Jaccard similarity between pred_sql and any SQL in gt_sqls").
So a reference that answers a different question paid a shaping bonus to a prediction
that answered that other question.
## The upstream bug, fixed
`/home/datht/finer-sql/evaluation/add_correct_sqls_from_eval.py` wrote an evaluation's
correct SQLs onto the sample document addressed by `{"db_id": db_id, "_id": sample_id}`
(old lines 144 and 210), assuming the collection's primary key `_id` is the same number
as the evaluation's `sample_id`. Where the two id spaces disagree, that selects a
**different sample of the same database** and the correct SQLs of sample N land on
sample N−k. The corpus shows exactly that signature: of the 34,205 references that are
textually closer to one other sample of their own database, 90.1% name a LATER sample and
**73.9% sit at their own database's single dominant offset** (bird/airline +5 throughout,
works_cycles +5, public_review_platform +3, chicago_crime +9). The script now resolves
the document by its own `sample_id` and refuses the write unless the document's own gold
is the gold those SQLs were judged against.
## Why this exists
A row's `groundtruth_sqls` is `[gold] + references`. Entry 0 is the benchmark gold;
entries 1.. are FINER-SQL's own training-SQL enrichment. The trainer reads the whole
list: the binary execution match uses entry 0 only, but the atomic-ops shaping bonus
(`atomic_ops/reward.py: score_against_list`) takes the **maximum similarity over every
entry**.
In the original corpus a block of references belongs to a **different sample of the same
database** — a positive shift of one to ten sample ids, a later sample's references
sitting at the head of an earlier sample's list. So the shaping bonus paid a prediction
that answered a different question.
The example, verbatim from the original corpus (`bird / airline`,
`sample_id` 5849, *"Tell the number of flights that landed at Lake Charles Regional
Airport on 2018/8/15"*): references 1..11 were
```sql
SELECT SUM(CASE WHEN dep_delay <= 0 THEN 1 ELSE 0 END)
FROM airlines WHERE fl_date = '2018/8/1';
```
— eleven counts of *on-time departures on 2018/8/1*, which are `sample_id` **5854**'s,
*"How many flights departed on time on 8/1/2018?"*. In this corpus sample 5849 carries
only Lake Charles counts and sample 5854 has its own references back.
## How it was repaired
Every reference passes four gates against the gold it is attached to, or it leaves the
list:
| gate | question |
|---|---|
| i | it parses (sqlglot, SQLite dialect) |
| ii | it returns the gold's answer on the **original** training database — executed through the db_execution HTTP API at the trainer's own 60 s ceiling, compared with the campaign's canonical comparator |
| iii | no other gold of the same database is a better owner for it |
| iv | it is not the same statement as the gold, or as a reference the sample already keeps |
Every execution record is fetched by the **exact SQL** (`sha1(dataset\0db_id\0sql)`), so a
reference is only ever judged on its own result; the tables a reference reads are **not** a
gate (the reward asks for the gold's answer, not its tables) and survive as the
informational `reads_extra_tables` field in `reference_audit.jsonl`.
A removed reference is then offered back to the samples of its own database and
re-attached to the one whose gold it passes every gate against — which is how the shifted
blocks reach their real owner. Nothing is invented.
| | references |
|---|---:|
| before | 239,338 |
| after | **200,137** |
| of those, re-attached to a different sample | 34,334 |
| dataset | before | after |
|---|---:|---:|
| bird | 132541 | 109429 |
| spider | 106797 | 90708 |
Why each of the 73,535 removed reference occurrences left its sample: answer differs from
the gold on the original database 41,985; mis-attached, no sample accepts it 14,840; the
same statement as the gold 7,584; the same statement as another reference of this sample
7,160; mis-attached, re-attached elsewhere 1,159; the reference does not execute 372; the
gold does not execute 290; the gold timed out at 60 s 74; does not parse 64; the reference
timed out at 60 s 7. The per-dataset table is in `FIX_REPORT.md`.
## Files
| file | what it is |
|---|---|
| `data-00000-of-00001.arrow`, `dataset_info.json`, `state.json` | the corpus, an HF `datasets` directory — load with `datasets.load_from_disk` |
| `FIX_REPORT.md` | root cause, mechanism, every count, the gates, and the sha256 of both arrow files |
| `removed_references.jsonl` | one line per removed reference: dataset, db_id, sample_id, its index in `groundtruth_sqls`, the SQL, the reason, and the samples it was re-attached to |
| `reference_audit.jsonl` | one line per reference occurrence of the input corpus, kept or not, with `reads_extra_tables`, `same_answer_as_gold` and `l1_shape` |
| `fix_summary.json` | the same counts, machine-readable |
```python
from huggingface_hub import snapshot_download
from datasets import load_from_disk
d = snapshot_download("thanhdath/finer-sql-train-joint-fixed", repo_type="dataset")
ds = load_from_disk(d) # 18,087 rows
```
sha256 of `data-00000-of-00001.arrow`:
`807b9e2660f29353bd1cf22aa6e8ecb13abeca3fcac2a443a0ef00e9f7e51961`
(the corpus it was built from:
`4475ac267d80b881d80ee3a65f44008ddbbd2df8606ab355ef099d0f53b6dfd3`).
The (gold, neighbour) pair set built over the same corpus, with a `provenance_check`
column marking every mis-attached reference, is at
[thanhdath/finer-sql-gold-neighbour-pairs](https://huggingface.co/datasets/thanhdath/finer-sql-gold-neighbour-pairs).
Built by `campaigns/chained_05b_tkde/pairset/fix_corpus.py`.