support-pvelocity commited on
Commit
1dbba77
1 Parent(s): da1e7d1

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +141 -0
README.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: llama2
3
+ datasets:
4
+ - bugdaryan/sql-create-context-instruction
5
+ language:
6
+ - en
7
+ pipeline_tag: text-generation
8
+
9
+ widget:
10
+ - 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 ?: ```"
11
+ example_title: "Example 1"
12
+ - 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?: ```"
13
+ example_title: "Example 2"
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 (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?: ```"
15
+ example_title: "Example 3"
16
+ - 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?: ```"
17
+ example_title: "Example 4"
18
+ - 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.: ```"
19
+ example_title: "Example 5"
20
+
21
+ ---
22
+ # **Code-Llama-2-7B-instruct-text2sql Model Card**
23
+
24
+ **Model Name**: Code-Llama-2-7B-instruct-text2sql
25
+
26
+ **Description**: This model is a fine-tuned version of the Code 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.
27
+
28
+ ## Model Information
29
+
30
+ - **Base Model**: [codellama/CodeLlama-13b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-13b-Instruct-hf)
31
+ - **Reference Model**: [bugdaryan/Code-Llama-2-13B-instruct-text2sql](https://huggingface.co/bugdaryan/Code-Llama-2-13B-instruct-text2sql)
32
+ - **Finetuning Dataset**: [bugdaryan/sql-create-context-instruction](https://huggingface.co/datasets/bugdaryan/sql-create-context-instruction)
33
+ - **Training Time**: Approximately 8 hours on 1 A100 40GB GPU
34
+
35
+ ## LoRA Parameters
36
+
37
+ - **lora_r**: 64
38
+ - **lora_alpha**: 16
39
+ - **lora_dropout**: 0.1
40
+
41
+ ## bitsandbytes Parameters
42
+
43
+ - **use_4bit**: True
44
+ - **bnb_4bit_compute_dtype**: float16
45
+ - **bnb_4bit_quant_type**: nf4
46
+ - **use_nested_quant**: False
47
+
48
+ ## Training Parameters
49
+
50
+ - **Number of Training Epochs**: 1
51
+ - **Mixed-Precision Training (fp16/bf16)**: False
52
+ - **Batch Size per GPU for Training**: 32
53
+ - **Batch Size per GPU for Evaluation**: 4
54
+ - **Gradient Accumulation Steps**: 1
55
+ - **Gradient Checkpointing**: True
56
+ - **Maximum Gradient Norm (Gradient Clipping)**: 0.3
57
+ - **Initial Learning Rate**: 2e-4
58
+ - **Weight Decay**: 0.001
59
+ - **Optimizer**: paged_adamw_32bit
60
+ - **Learning Rate Scheduler Type**: cosine
61
+ - **Max Steps**: -1
62
+ - **Warmup Ratio**: 0.03
63
+ - **Group Sequences by Length**: True
64
+ - **Save Checkpoint Every X Update Steps**: 0
65
+ - **Log Every X Update Steps**: 25
66
+
67
+ ## License
68
+
69
+ 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/)
70
+
71
+ ## Intended Use
72
+
73
+ **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.
74
+
75
+ **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.
76
+
77
+ ## Model Capabilities
78
+
79
+ - Code completion.
80
+ - Infilling.
81
+ - Instructions / chat.
82
+
83
+ ## Model Architecture
84
+
85
+ Code-Llama-2-7B-instruct-text2sql is an auto-regressive language model that uses an optimized transformer architecture.
86
+
87
+ ## Model Dates
88
+
89
+ This model was trained between January 2023 and July 2023.
90
+
91
+ ## Ethical Considerations and Limitations
92
+
93
+ Code-Llama-2-7B-instruct-text2sql is a powerful language model, but it may produce inaccurate or objectionable responses in some instances. Safety testing and tuning are recommended before deploying this model in specific applications.
94
+
95
+ ## Hardware and Software
96
+
97
+ - **Training Libraries**: Custom training libraries
98
+ - **Training Hardware**: 1 A100 40GB GPU provided by Google Colab Pro+
99
+ - **Carbon Footprint**: Training all Code Llama models required 400K GPU hours on A100-80GB hardware with emissions offset by Meta's sustainability program.
100
+
101
+ ## Training Data
102
+
103
+ This model was trained and fine-tuned on the same data as Llama 2 with different weights.
104
+
105
+ ## Evaluation Results
106
+
107
+ For evaluation results, please refer to Section 3 and safety evaluations in Section 4 of the research paper.
108
+
109
+ ## Example Code
110
+
111
+ You can use the Code-Llama-2-7B-instruct-text2sql model to generate SQL queries from natural language questions, as demonstrated in the following code snippet:
112
+
113
+ ```python
114
+ from transformers import (
115
+ AutoModelForCausalLM,
116
+ AutoTokenizer,
117
+ pipeline
118
+ )
119
+ import torch
120
+
121
+ model_name = 'support-pvelocity/Code-Llama-2-7B-instruct-text2sql'
122
+
123
+ model = AutoModelForCausalLM.from_pretrained(model_name, device_map='auto', torch_dtype=torch.float16)
124
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
125
+
126
+ 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 );"
127
+
128
+ question = 'Find the salesperson who made the most sales.'
129
+
130
+ 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}: ``` "
131
+
132
+ tokens = tokenizer(prompt, return_tensors="pt").to('cuda:0')
133
+ input_ids = tokens.input_ids
134
+
135
+ generated_ids = model.generate(input_ids=input_ids, max_length=4048, pad_token_id=tokenizer.eos_token_id)
136
+ output = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
137
+ output = output.split('```')[2]
138
+ print(output)
139
+ ```
140
+
141
+ 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.