Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
pipeline_tag: text-generation
|
4 |
+
tags:
|
5 |
+
- text-to-sql
|
6 |
+
- t5
|
7 |
+
- natural-language-processing
|
8 |
+
- sql
|
9 |
+
license: apache-2.0
|
10 |
+
datasets:
|
11 |
+
- gretelai/synthetic_text_to_sql
|
12 |
+
base_model:
|
13 |
+
- Salesforce/codet5-base
|
14 |
+
---
|
15 |
+
|
16 |
+
# Text-to-SQL T5 Model (`16pramodh/t2s_model`)
|
17 |
+
|
18 |
+
## Model Description
|
19 |
+
This is a **T5-based text-to-SQL model** trained to convert **natural language questions** into **SQL queries**.
|
20 |
+
It works by taking in:
|
21 |
+
|
22 |
+
natural language query [SEP] table schema
|
23 |
+
|
24 |
+
and producing a SQL statement based on the provided database schema.
|
25 |
+
|
26 |
+
The model is based on `T5ForConditionalGeneration` and supports **text2text-generation** via the Hugging Face Inference API.
|
27 |
+
|
28 |
+
---
|
29 |
+
|
30 |
+
## Intended Use
|
31 |
+
- **Input:** English natural language question **plus** the database schema.
|
32 |
+
- **Output:** SQL query that can be executed on the described database.
|
33 |
+
|
34 |
+
---
|
35 |
+
|
36 |
+
## Example
|
37 |
+
|
38 |
+
**Input:**
|
39 |
+
Get the names and emails of all customers who signed up after January 1, 2024 [SEP] CREATE TABLE customers (customer_id INT PRIMARY KEY, name VARCHAR(50), email VARCHAR(100), signup_date DATE);
|
40 |
+
|
41 |
+
**Output:**
|
42 |
+
SELECT name, email FROM customers WHERE signup_date > '2024-01-01';
|
43 |
+
|
44 |
+
---
|
45 |
+
|
46 |
+
## How to Use
|
47 |
+
|
48 |
+
### Hugging Face Inference API
|
49 |
+
```bash
|
50 |
+
curl -X POST \
|
51 |
+
-H "Authorization: Bearer YOUR_HF_TOKEN" \
|
52 |
+
-H "Content-Type: application/json" \
|
53 |
+
-d '{"inputs": "Get the names and emails of all customers who signed up after January 1, 2024 [SEP] CREATE TABLE customers (customer_id INT PRIMARY KEY, name VARCHAR(50), email VARCHAR(100), signup_date DATE);"}' \
|
54 |
+
https://api-inference.huggingface.co/models/16pramodh/t2s_model
|
55 |
+
```
|
56 |
+
|
57 |
+
### Python (Transformers)
|
58 |
+
```
|
59 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
60 |
+
|
61 |
+
model_name = "16pramodh/t2s_model"
|
62 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
63 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
64 |
+
|
65 |
+
input_text = "Get the names and emails of all customers who signed up after January 1, 2024 [SEP] CREATE TABLE customers (customer_id INT PRIMARY KEY, name VARCHAR(50), email VARCHAR(100), signup_date DATE);"
|
66 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
67 |
+
outputs = model.generate(**inputs)
|
68 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
69 |
+
```
|
70 |
+
|
71 |
+
---
|