support-pvelocity
commited on
Commit
•
fa60e04
1
Parent(s):
49b9ed4
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: llama2
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: text-generation
|
6 |
+
|
7 |
+
widget:
|
8 |
+
- text: "[INST] Write SQLite query to answer the following question given the database schema. Please wrap your code answer using ```: Schema: CREATE TABLE head (age INTEGER) Question: How many heads of the departments are older than 56 ? [/INST] Here is the SQLite query to answer to the question: How many heads of the departments are older than 56 ?: ```"
|
9 |
+
example_title: "Example 1"
|
10 |
+
- text: "[INST] Write SQLite query to answer the following question given the database schema. Please wrap your code answer using ```: Schema: CREATE TABLE people (first_name VARCHAR) Question: List the first names of people in alphabetical order? [/INST] Here is the SQLite query to answer to the question: List the first names of people in alphabetical order?: ```"
|
11 |
+
example_title: "Example 2"
|
12 |
+
- text: "[INST] Write SQLite query to answer the following question given the database schema. Please wrap your code answer using ```: Schema: CREATE TABLE weather (zip_code VARCHAR, mean_sea_level_pressure_inches INTEGER) Question: What is the zip code in which the average mean sea level pressure is the lowest? [/INST] Here is the SQLite query to answer to the question: What is the zip code in which the average mean sea level pressure is the lowest?: ```"
|
13 |
+
example_title: "Example 3"
|
14 |
+
- text: "[INST] Write SQLite query to answer the following question given the database schema. Please wrap your code answer using ```: Schema: CREATE TABLE weather (date VARCHAR, mean_temperature_f VARCHAR, mean_humidity VARCHAR, max_gust_speed_mph VARCHAR) Question: What are the date, mean temperature and mean humidity for the top 3 days with the largest max gust speeds? [/INST] Here is the SQLite query to answer to the question: What are the date, mean temperature and mean humidity for the top 3 days with the largest max gust speeds?: ```"
|
15 |
+
example_title: "Example 4"
|
16 |
+
- text: "[INST] Write SQLite query to answer the following question given the database schema. Please wrap your code answer using ```: Schema: CREATE TABLE trip (end_station_id VARCHAR); CREATE TABLE station (id VARCHAR, city VARCHAR) Question: Count the number of trips that did not end in San Francisco city. [/INST] Here is the SQLite query to answer to the question: Count the number of trips that did not end in San Francisco city.: ```"
|
17 |
+
example_title: "Example 5"
|
18 |
+
|
19 |
+
---
|
20 |
+
# **Llama-2-7B-instruct-text2sql-GPTQ Model Card**
|
21 |
+
|
22 |
+
**Model Name**: Llama-2-7B-instruct-text2sql-GPTQ
|
23 |
+
|
24 |
+
**Description**: This model is a GPTQ quantisation of a fine-tuned version of the Llama 2 with 7 billion parameters, specifically tailored for text-to-SQL tasks. It has been trained to generate SQL queries given a database schema and a natural language question. The GPTQ quantisation was performed with AutoGPTQ.
|
25 |
+
|
26 |
+
## Model Information
|
27 |
+
|
28 |
+
- **Base Model**: [support-pvelocity/Llama-2-7B-instruct-text2sql](https://huggingface.co/support-pvelocity/Llama-2-7B-instruct-text2sql)
|
29 |
+
|
30 |
+
## GPTQ Parameters
|
31 |
+
|
32 |
+
- **bits**: 4
|
33 |
+
- **group_size**: 128
|
34 |
+
- **desc_act**: False
|
35 |
+
- **damp_percent**: 0.01
|
36 |
+
|
37 |
+
## GPTQ dataset
|
38 |
+
|
39 |
+
- **Dataset**: [bugdaryan/sql-create-context-instruction](https://huggingface.co/datasets/bugdaryan/sql-create-context-instruction)
|
40 |
+
- **Randomized Rows**: 1024
|
41 |
+
|
42 |
+
## License
|
43 |
+
|
44 |
+
This model is governed by a custom commercial license from Code Llama. For details, please visit: [Custom Commercial License](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)
|
45 |
+
|
46 |
+
## Intended Use
|
47 |
+
|
48 |
+
**Intended Use Cases**: This model is intended for commercial and research use in English. It is designed for text-to-SQL tasks, enabling users to generate SQL queries from natural language questions.
|
49 |
+
|
50 |
+
**Out-of-Scope Uses**: Any use that violates applicable laws or regulations, use in languages other than English, or any other use prohibited by the Acceptable Use Policy and Licensing Agreement for Code Llama and its variants.
|
51 |
+
|
52 |
+
## Example Code
|
53 |
+
|
54 |
+
You can use the Llama-2-7B-instruct-text2sql-GPTQ model to generate SQL queries from natural language questions, as demonstrated in the following code snippet:
|
55 |
+
```cmd
|
56 |
+
pip install -q transformers==4.35.0 torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 optimum==1.13.2 auto-gptq==0.4.2
|
57 |
+
```
|
58 |
+
|
59 |
+
```python
|
60 |
+
from transformers import AutoTokenizer
|
61 |
+
from auto_gptq import AutoGPTQForCausalLM
|
62 |
+
|
63 |
+
model_name = 'support-pvelocity/Llama-2-7B-instruct-text2sql-GPTQ'
|
64 |
+
|
65 |
+
model = AutoGPTQForCausalLM.from_quantized(model_name, use_safetensors=True, device_map='auto')
|
66 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
67 |
+
|
68 |
+
table = "CREATE TABLE sales ( sale_id number PRIMARY KEY, product_id number, customer_id number, salesperson_id number, sale_date DATE, quantity number, FOREIGN KEY (product_id) REFERENCES products(product_id), FOREIGN KEY (customer_id) REFERENCES customers(customer_id), FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id)); CREATE TABLE product_suppliers ( supplier_id number PRIMARY KEY, product_id number, supply_price number, FOREIGN KEY (product_id) REFERENCES products(product_id)); CREATE TABLE customers ( customer_id number PRIMARY KEY, name text, address text ); CREATE TABLE salespeople ( salesperson_id number PRIMARY KEY, name text, region text ); CREATE TABLE product_suppliers ( supplier_id number PRIMARY KEY, product_id number, supply_price number );"
|
69 |
+
|
70 |
+
question = 'Find the salesperson who made the most sales.'
|
71 |
+
|
72 |
+
prompt = f"[INST] Write SQLite query to answer the following question given the database schema. Please wrap your code answer using ```: Schema: {table} Question: {question} [/INST] Here is the SQLite query to answer to the question: {question}: ``` "
|
73 |
+
|
74 |
+
tokens = tokenizer(prompt, return_tensors="pt").to('cuda:0')
|
75 |
+
input_ids = tokens.input_ids
|
76 |
+
|
77 |
+
generated_ids = model.generate(input_ids=input_ids, max_length=4048, pad_token_id=tokenizer.eos_token_id)
|
78 |
+
output = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
79 |
+
output = output.split('```')[2]
|
80 |
+
print(output)
|
81 |
+
```
|
82 |
+
|
83 |
+
This code demonstrates how to utilize the model for generating SQL queries based on a provided database schema and a natural language question. It showcases the model's capability to assist in SQL query generation for text-to-SQL tasks.
|