thealper2 commited on
Commit
970f3b3
·
verified ·
1 Parent(s): 7359780

Add model card

Browse files
Files changed (1) hide show
  1. README.md +162 -171
README.md CHANGED
@@ -1,199 +1,190 @@
1
  ---
 
 
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
 
 
10
 
 
11
 
12
- ## Model Details
 
 
13
 
14
- ### Model Description
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
 
 
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
 
29
 
30
- <!-- Provide the basic links for the model. -->
 
 
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
 
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
 
 
 
 
43
 
44
- [More Information Needed]
 
 
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
 
50
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- ### Out-of-Scope Use
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
 
103
  ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
  ---
2
+ license: bsd-3-clause
3
+ base_model: Salesforce/codet5p-220m
4
  library_name: transformers
5
+ pipeline_tag: text2text-generation
6
+ language:
7
+ - en
8
+ datasets:
9
+ - gretelai/synthetic_text_to_sql
10
+ tags:
11
+ - sql
12
+ - sql-to-text
13
+ - code
14
+ - codet5p
15
+ - text2text-generation
16
+ model-index:
17
+ - name: codet5p-sql2text
18
+ results:
19
+ - task:
20
+ type: text2text-generation
21
+ name: SQL-to-Text
22
+ dataset:
23
+ name: gretelai/synthetic_text_to_sql
24
+ type: gretelai/synthetic_text_to_sql
25
+ split: test
26
+ metrics:
27
+ - type: bleu
28
+ name: BLEU
29
+ value: 33.1003
30
+ - type: rouge1
31
+ name: ROUGE-1
32
+ value: 66.8589
33
+ - type: rouge2
34
+ name: ROUGE-2
35
+ value: 45.1124
36
+ - type: rougel
37
+ name: ROUGE-L
38
+ value: 57.0609
39
  ---
40
 
41
+ # SQL-to-Text (Salesforce/codet5p-220m)
42
 
43
+ `Salesforce/codet5p-220m` fine-tuned to explain a SQL query in plain English.
44
 
45
+ The direction is **SQL -> natural language**: the model takes a query (and,
46
+ optionally, the DDL of the tables it touches) and returns a sentence describing
47
+ what that query does. It does *not* generate SQL from a question.
48
 
49
+ ## Prompt format
50
 
51
+ Inputs follow one fixed template; training, evaluation and inference all build
52
+ it with the same function, so they cannot drift apart. The schema block is
53
+ dropped when no DDL is supplied, and when it is supplied only `CREATE TABLE ...` statements are kept.
54
 
55
+ ```
56
+ Explain the following SQL query.
57
 
58
+ Schema:
59
+ <CREATE TABLE statements>
60
 
61
+ SQL:
62
+ <the query>
63
+ ```
64
 
65
+ ## Usage
 
 
 
 
 
 
66
 
67
+ ```python
68
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
69
 
70
+ model_id = "thealper2/codet5p-sql2text"
71
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
72
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
73
 
74
+ schema = "CREATE TABLE employees (id INT, name TEXT, salary INT, dept_id INT);"
75
+ sql = "SELECT dept_id, AVG(salary) FROM employees GROUP BY dept_id;"
76
+ prompt = f"Explain the following SQL query.\n\nSchema:\n{schema}\n\nSQL:\n{sql}"
77
 
78
+ inputs = tokenizer(
79
+ prompt,
80
+ return_tensors="pt",
81
+ truncation=True,
82
+ max_length=256,
83
+ )
84
+ outputs = model.generate(
85
+ **inputs,
86
+ num_beams=4,
87
+ max_new_tokens=128,
88
+ min_new_tokens=5,
89
+ early_stopping=True,
90
+ )
91
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
92
+ ```
93
 
94
+ ## Training data
95
 
96
+ [`gretelai/synthetic_text_to_sql`](https://huggingface.co/datasets/gretelai/synthetic_text_to_sql), mapping
97
+ `sql` + `sql_context`
98
+ to `sql_explanation`.
99
 
100
+ Preprocessing drops rows that are too short to be a real explanation, removes
101
+ exact duplicates and duplicate *inputs*, and removes any training row whose
102
+ input also appears in the official test split, so the reported test scores are
103
+ not inflated by leakage. The validation split is
104
+ 3% of the cleaned train
105
+ split (seed 42).
106
 
107
+ Sequence lengths were chosen from the measured token-length distribution:
108
+ source 256 tokens, target
109
+ 128 tokens.
110
 
 
111
 
112
+ ## Training procedure
113
 
114
+ | Hyper-parameter | Value |
115
+ | --- | --- |
116
+ | Epochs | 3.00 |
117
+ | Learning rate | 0.0001 |
118
+ | LR schedule | linear |
119
+ | Warmup ratio | 0.0500 |
120
+ | Weight decay | 0.0100 |
121
+ | Optimiser | adamw_torch |
122
+ | Per-device train batch size | 16 |
123
+ | Gradient accumulation | 4 |
124
+ | Max gradient norm | 1.00 |
125
+ | Model selection | eval_rougeL |
126
+ | Seed | 42 |
127
+ | Effective batch size | 64 |
128
 
129
+ Trained on a single NVIDIA GeForce RTX 5060 Ti (15.9 GB) with torch 2.11.0+cu128, bf16 mixed precision.
130
 
131
+ Wall-clock training time: 84 minutes.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  ## Evaluation
134
 
135
+ Scored by `evaluate.py` on the full splits with beam search (num_beams=4).
136
+
137
+ ### Generation quality
138
+
139
+ | Metric | Validation | Test | _meta |
140
+ | --- | --- | --- | --- |
141
+ | Examples | 2989 | 5850 | - |
142
+ | BLEU | 33.65 | 33.10 | - |
143
+ | ROUGE-1 | 67.15 | 66.86 | - |
144
+ | ROUGE-2 | 45.76 | 45.11 | - |
145
+ | ROUGE-L | 57.58 | 57.06 | - |
146
+ | Mean generated length | 36.37 | 35.69 | - |
147
+ | Loss | 0.5829 | 0.5923 | - |
148
+
149
+ ### SQL-aware faithfulness
150
+
151
+ Recall metrics ask whether the explanation mentions what the query actually does; the *rate* metrics are error rates, where lower is better -- they measure claims the query does not support.
152
+
153
+ | Metric | Validation | Test |
154
+ | --- | --- | --- |
155
+ | Examples | 2989 | 5850 |
156
+ | Operation recall | 98.53 | 98.40 |
157
+ | Aggregation recall | 98.72 | 98.57 |
158
+ | Join mention recall | 98.21 | 98.74 |
159
+ | Join table coverage | 98.34 | 98.56 |
160
+ | Condition column coverage | 82.98 | 81.99 |
161
+ | Condition value coverage | 86.18 | 87.24 |
162
+ | Operation over-claim rate | 5.47 | 5.29 |
163
+ | Unsupported number rate | 3.98 | 3.18 |
164
+ | Unsupported quoted-string rate | 3.20 | 3.18 |
165
+ | Unsupported entity rate | 1.38 | 1.72 |
166
+
167
+ ## Limitations
168
+
169
+ * Trained on synthetic queries and synthetic explanations, so the phrasing
170
+ reflects that generator's style rather than how a particular team documents
171
+ its own queries.
172
+ * Explanations are grounded in the query text, not in the data: the model
173
+ cannot know what a column means beyond its name.
174
+ * Condition coverage is the weakest area -- long `WHERE` clauses lose some
175
+ columns and literals -- so an explanation may describe a filter less
176
+ precisely than the query applies it. Do not rely on it as an audit of what a
177
+ query returns.
178
+ * Inputs are truncated past the configured source length, so very large schemas
179
+ are only partially visible to the model.
180
+ * English only.
181
+
182
+ ## Reproduction
183
+
184
+ ```bash
185
+ make preprocess
186
+ make train
187
+ make evaluate
188
+ ```
189
+
190
+ Base model: [`Salesforce/codet5p-220m`](https://huggingface.co/Salesforce/codet5p-220m).