78 lines
2.0 KiB
Markdown
78 lines
2.0 KiB
Markdown
|
|
---
|
||
|
|
license: cc-by-4.0
|
||
|
|
language:
|
||
|
|
- en
|
||
|
|
tags:
|
||
|
|
- Text-to-sql
|
||
|
|
---
|
||
|
|
# OGSQL-7B
|
||
|
|
|
||
|
|

|
||
|
|
|
||
|
|
### Model Description
|
||
|
|
OGSQL-7B was fine-tuned for the task of converting natural language text into SQL queries.
|
||
|
|
|
||
|
|
- **Model type**: Transformer
|
||
|
|
- **Language(s) (NLP)**: SQL (target language for generation)
|
||
|
|
- **Finetuned from model**: codellama 7b
|
||
|
|
|
||
|
|
## Use Case
|
||
|
|
OGSQL-7B is designed to facilitate the conversion of natural language queries into structured SQL commands, aiding in database querying without the need for manual SQL knowledge.
|
||
|
|
|
||
|
|
## How to Get Started with the Model
|
||
|
|
```python
|
||
|
|
# Example code to load and use the model
|
||
|
|
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
||
|
|
|
||
|
|
model_name = "OGSQL-7B"
|
||
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
||
|
|
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
||
|
|
|
||
|
|
def generate_sql(query):
|
||
|
|
inputs = tokenizer.encode(query, return_tensors="pt")
|
||
|
|
outputs = model.generate(inputs)
|
||
|
|
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
||
|
|
|
||
|
|
# Example use
|
||
|
|
query = """
|
||
|
|
using this context:
|
||
|
|
-- Create Customers Table
|
||
|
|
CREATE TABLE Customers (
|
||
|
|
customer_id INTEGER PRIMARY KEY,
|
||
|
|
name TEXT NOT NULL,
|
||
|
|
email TEXT,
|
||
|
|
join_date DATE
|
||
|
|
);
|
||
|
|
|
||
|
|
-- Create Products Table
|
||
|
|
CREATE TABLE Products (
|
||
|
|
product_id INTEGER PRIMARY KEY,
|
||
|
|
name TEXT NOT NULL,
|
||
|
|
price DECIMAL(10, 2)
|
||
|
|
);
|
||
|
|
|
||
|
|
-- Create Orders Table
|
||
|
|
CREATE TABLE Orders (
|
||
|
|
order_id INTEGER PRIMARY KEY,
|
||
|
|
customer_id INTEGER,
|
||
|
|
product_id INTEGER,
|
||
|
|
order_date DATE,
|
||
|
|
quantity INTEGER,
|
||
|
|
total_price DECIMAL(10, 2),
|
||
|
|
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id),
|
||
|
|
FOREIGN KEY (product_id) REFERENCES Products(product_id)
|
||
|
|
);
|
||
|
|
|
||
|
|
show me all the orders from last month , sort by date
|
||
|
|
|
||
|
|
|
||
|
|
"""
|
||
|
|
print(generate_sql(query))
|
||
|
|
|
||
|
|
```
|
||
|
|
|
||
|
|
|
||
|
|
## alternatively you can use this notebook:
|
||
|
|
[](https://colab.research.google.com/drive/1zfuzV3R1GQflHV_va03WArb8vhwPh_2T)
|
||
|
|
|