Text Generation
Transformers
Safetensors
English
t5
text2text-generation
sql
sql-to-text
code
codet5p
Eval Results (legacy)
text-generation-inference
Instructions to use thealper2/codet5p-sql2text with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thealper2/codet5p-sql2text with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="thealper2/codet5p-sql2text")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("thealper2/codet5p-sql2text") model = AutoModelForSeq2SeqLM.from_pretrained("thealper2/codet5p-sql2text", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use thealper2/codet5p-sql2text with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "thealper2/codet5p-sql2text" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thealper2/codet5p-sql2text", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/thealper2/codet5p-sql2text
- SGLang
How to use thealper2/codet5p-sql2text with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "thealper2/codet5p-sql2text" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thealper2/codet5p-sql2text", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "thealper2/codet5p-sql2text" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thealper2/codet5p-sql2text", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use thealper2/codet5p-sql2text with Docker Model Runner:
docker model run hf.co/thealper2/codet5p-sql2text
Add model card
Browse files
README.md
CHANGED
|
@@ -1,199 +1,190 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
library_name: transformers
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 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 |
-
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
| 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 |
-
|
| 106 |
-
|
| 107 |
-
###
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 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).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|