thanhdath commited on
Commit
defcc2e
·
verified ·
1 Parent(s): df4e627

chore: remove stale scripts/build_validator_2agents_v3.py

Browse files
Files changed (1) hide show
  1. scripts/build_validator_2agents_v3.py +0 -109
scripts/build_validator_2agents_v3.py DELETED
@@ -1,109 +0,0 @@
1
- """Split v3 unified validator data into 2 specialized SFT datasets:
2
- - Validator Selection (v_s): critique only the SELECT clause
3
- - Validator Condition (v_c): critique only the WHERE/HAVING/CASE conditions
4
-
5
- Per the paper (approach.tex §Combined Validator), the multi-agent design has
6
- 2 specialized validators, not one unified validator. This script extracts the
7
- <select>...</select> and <condition>...</condition> sections from v3 unified
8
- completions and emits 2 SFT datasets with section-specific prompts.
9
-
10
- Outputs:
11
- - data/multi-agents/fixed/sft-validator-selection-v3
12
- - data/multi-agents/fixed/sft-validator-condition-v3
13
- """
14
- import re
15
- from datasets import load_from_disk, Dataset, DatasetDict
16
-
17
-
18
- SEL_INSTR = "You are a SQL SELECT-clause critique agent. Output ONE critique section <select>...</select> analysing the SELECT clause of the SQL query below; do NOT output any SQL. Use 'None' if the SELECT clause looks correct."
19
- COND_INSTR = "You are a SQL CONDITION critique agent. Output ONE critique section <condition>...</condition> analysing the WHERE/HAVING/CASE-WHEN conditions of the SQL query below; do NOT output any SQL. Use 'None' if the conditions look correct."
20
-
21
-
22
- SEC_RE = {
23
- "select": re.compile(r"<select>(.*?)</select>", re.DOTALL),
24
- "condition": re.compile(r"<condition>(.*?)</condition>", re.DOTALL),
25
- }
26
-
27
-
28
- def replace_header_block(prompt_unified, new_header_line):
29
- """Replace the leading 'You are a SQL critique agent...' line with a section-specific one."""
30
- # The unified prompts begin with: "You are a SQL critique agent. Output FOUR critique sections (...). do NOT output any SQL.\n\n..."
31
- # Strip everything before the first blank line; keep the rest (schema + question + sql).
32
- # Use a safe split on the first \n\n.
33
- parts = prompt_unified.split("\n\n", 1)
34
- rest = parts[1] if len(parts) > 1 else parts[0]
35
- return new_header_line + "\n\n" + rest
36
-
37
-
38
- def main():
39
- v3 = load_from_disk("/home/datht/mats-sql-tist/data/multi-agents/fixed/sft-validator-diverse-v3")
40
- sel_train, sel_test = [], []
41
- cond_train, cond_test = [], []
42
-
43
- for split, train_list, test_list in [("train", sel_train, cond_train), ("test", sel_test, cond_test)]:
44
- target_sel = train_list
45
- target_cond = test_list # placeholder; will reassign below
46
- # redo:
47
- sel_train, sel_test = [], []
48
- cond_train, cond_test = [], []
49
-
50
- for split_name, sel_out, cond_out in [("train", sel_train, cond_train), ("test", sel_test, cond_test)]:
51
- ds = v3[split_name]
52
- for ex in ds:
53
- prompt = ex["prompt"]
54
- completion = ex["completion"]
55
- sel_match = SEC_RE["select"].search(completion)
56
- cond_match = SEC_RE["condition"].search(completion)
57
- if not sel_match or not cond_match:
58
- continue
59
- sel_body = sel_match.group(0).strip() # full <select>...</select>
60
- cond_body = cond_match.group(0).strip()
61
-
62
- # Build section-specific prompt
63
- sel_prompt = replace_header_block(prompt, SEL_INSTR)
64
- cond_prompt = replace_header_block(prompt, COND_INSTR)
65
-
66
- # NOTE: SFT trainer in alignment-handbook reads `messages` column via dict access
67
- # (chat_template uses messages['prompt'] / messages['completion']), so store as dict.
68
- sel_out.append({
69
- "prompt": sel_prompt,
70
- "completion": sel_body,
71
- "messages": {"prompt": sel_prompt, "completion": sel_body},
72
- })
73
- cond_out.append({
74
- "prompt": cond_prompt,
75
- "completion": cond_body,
76
- "messages": {"prompt": cond_prompt, "completion": cond_body},
77
- })
78
-
79
- sel_dd = DatasetDict({
80
- "train": Dataset.from_list(sel_train),
81
- "test": Dataset.from_list(sel_test),
82
- })
83
- cond_dd = DatasetDict({
84
- "train": Dataset.from_list(cond_train),
85
- "test": Dataset.from_list(cond_test),
86
- })
87
-
88
- sel_dir = "/home/datht/mats-sql-tist/data/multi-agents/fixed/sft-validator-selection-v3"
89
- cond_dir = "/home/datht/mats-sql-tist/data/multi-agents/fixed/sft-validator-condition-v3"
90
- sel_dd.save_to_disk(sel_dir)
91
- cond_dd.save_to_disk(cond_dir)
92
-
93
- # Distribution
94
- def stats(rows, key):
95
- n_none = sum(1 for r in rows if r["completion"].strip().lower().endswith("none") or "None\n</" in r["completion"] or "No issues" in r["completion"])
96
- return f"{len(rows)} total, {n_none} all-OK ({100*n_none/max(len(rows),1):.1f}%)"
97
-
98
- print(f"=== Validator Selection (v_s) ===")
99
- print(f" train: {stats(sel_train, 'sel')}")
100
- print(f" test: {stats(sel_test, 'sel')}")
101
- print(f" Saved to {sel_dir}")
102
- print(f"\n=== Validator Condition (v_c) ===")
103
- print(f" train: {stats(cond_train, 'cond')}")
104
- print(f" test: {stats(cond_test, 'cond')}")
105
- print(f" Saved to {cond_dir}")
106
-
107
-
108
- if __name__ == "__main__":
109
- main()