Downloads · 30 days
17
5% of all-time downloads
jonathanjordan21/flan-alpaca-base-finetuned-lora-knowSQL
flan-alpaca-base-finetuned-lora-knowSQL is a text generation model from jonathanjordan21. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as mit.
This model is based on the declare-lab/flan-alpaca-base model finetuned with knowrohit07/knowsql dataset.
Downloads · 30 days
17
5% of all-time downloads
All-time downloads
310
Public
Repo size
14.2 MB
Likes
1
Public
Click a slice to open those files.
.safetensors7.1 MB · 74%
From the Hugging Face model README
This model is based on the declare-lab/flan-alpaca-base model finetuned with knowrohit07/know_sql dataset.
The model generates a string of SQL query based on a question and MySQL table schema. You can modify the table schema to match MySQL table schema if you are using different type of SQL database (e.g. PostgreSQL, Oracle, etc). The generated SQL query can be run perfectly on the python SQL connection (e.g. psycopg2, mysql_connector, etc).
"""Question: what is What was the result of the election in the Florida 18 district?\nTable: table_1341598_10 (result VARCHAR, district VARCHAR)\nSQL: """
"""SELECT * FROM table_1341598_10 WHERE district = "Florida 18""""
Load model
from peft import get_peft_config, get_peft_model, TaskType
from peft import PeftConfig, PeftModel
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
model_id = "jonathanjordan21/flan-alpaca-base-finetuned-lora-knowSQL"
config = PeftConfig.from_pretrained(model_id)
model_ = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path, return_dict=True)
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
model = PeftModel.from_pretrained(model_, model_id)
Model inference
question = "server of user id 11 with status active and server id 10"
table = "table_name_77 ( user id INTEGER, status VARCHAR, server id INTEGER )"
test = f"""Question: {question}\nTable: {table}\nSQL: """
p = tokenizer(test, return_tensors='pt')
device = "cuda" if torch.cuda.is_available() else "cpu"
out = model.to(device).generate(**p.to(device),max_new_tokens=50)
print("SQL Query :", tokenizer.batch_decode(out,skip_special_tokens=True)[0])
The model inference takes about 2-3 seconds to run in Google Colab Free Tier CPU