RichardErkhov commited on
Commit
9a67abb
·
verified ·
1 Parent(s): 1b64a3f

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +149 -0
README.md ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Quantization made by Richard Erkhov.
2
+
3
+ [Github](https://github.com/RichardErkhov)
4
+
5
+ [Discord](https://discord.gg/pvy7H8DZMG)
6
+
7
+ [Request more models](https://github.com/RichardErkhov/quant_request)
8
+
9
+
10
+ Hrida-T2SQL-3B-V0.1 - bnb 8bits
11
+ - Model creator: https://huggingface.co/HridaAI/
12
+ - Original model: https://huggingface.co/HridaAI/Hrida-T2SQL-3B-V0.1/
13
+
14
+
15
+
16
+
17
+ Original model description:
18
+ ---
19
+ license: apache-2.0
20
+ language:
21
+ - en
22
+ library_name: transformers
23
+ pipeline_tag: text2text-generation
24
+ tags:
25
+ - sql
26
+ - t2sql
27
+ - text2sql
28
+ ---
29
+
30
+ The **Hrida-T2SQL-3B-V0.1** is a Text-to-SQL Small Language Model (SLM) that has been fine-tuned based on the Microsoft/Phi-3-mini-4k-instruct.
31
+
32
+ For full details of this model please read our [blog post](https://www.hridaai.com/blog/t2sql).
33
+
34
+ ## Prompt Template
35
+
36
+ ```txt
37
+ ### Instruction:
38
+ Provide the system prompt.
39
+
40
+ ### Dialect:
41
+ Specify the SQL dialect (e.g., MySQL, PostgreSQL, SQL Server, etc.).
42
+
43
+ ### Context:
44
+ Provide the database schema including table names, column names, and data types.
45
+
46
+ ### Input:
47
+ User's query.
48
+
49
+ ### Response:
50
+ Expected SQL query output based on the input and context.
51
+
52
+ ```
53
+
54
+ - **Instruction (System Prompt)**: This guides the model on processing input to generate the SQL query response effectively.
55
+ - **Dialect (Optional)**: Specify the SQL variant the model should use to ensure the generated query conforms to the correct syntax.
56
+ - **Context**: Provide the database schema to the model for generating accurate SQL queries.
57
+ - **Input**: Provide the user query for the model to comprehend and transform into an SQL query.
58
+ - **Response**: Expected output from the model.
59
+
60
+
61
+ ## Chat Prompt Template
62
+
63
+ ```txt
64
+ <s>
65
+ <|system|>
66
+ { Instruction / System Prompt }
67
+ <|user|>
68
+ { Context / User Query } <|end|>
69
+ <|assistant|>
70
+ ```
71
+
72
+ ## Run the Model
73
+
74
+ ### Using Transformers
75
+
76
+ ```python
77
+ import torch
78
+ from transformers import AutoModelForCausalLM, AutoTokenizer
79
+
80
+ # Define the model and tokenizer
81
+ model_id = "HridaAI/Hrida-T2SQL-3B-V0.1"
82
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
83
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, trust_remote_code=True)
84
+
85
+ # Define the context and prompt
86
+ prompt = """
87
+ Answer to the query will be in the form of an SQL query.
88
+ ### Context: CREATE TABLE Employees (
89
+ EmployeeID INT PRIMARY KEY,
90
+ FirstName VARCHAR(50),
91
+ LastName VARCHAR(50),
92
+ Age INT,
93
+ DepartmentID INT,
94
+ Salary DECIMAL(10, 2),
95
+ DateHired DATE,
96
+ Active BOOLEAN,
97
+ FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
98
+ );
99
+
100
+ CREATE TABLE Departments (
101
+ DepartmentID INT PRIMARY KEY,
102
+ DepartmentName VARCHAR(100),
103
+ Location VARCHAR(100)
104
+ );
105
+ ### Input: Write a SQL query to select all the employees who are active.
106
+ ### Response:
107
+ """
108
+ # Prepare the input
109
+ messages = [{"role": "user", "content": prompt}]
110
+ inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
111
+
112
+ # Generate the output
113
+ outputs = model.generate(inputs, max_length=300)
114
+ print(tokenizer.decode(outputs[0]))
115
+
116
+
117
+ ```
118
+
119
+ ### Using MLX
120
+
121
+ ```python
122
+ from mlx_lm import generate, load
123
+
124
+ model,tokenizer = load("HridaAI/Hrida-T2SQL-3B-V0.1")
125
+
126
+ prompt = """
127
+ Answer to the quey will be in the form of SQL query.
128
+ ### Context: CREATE TABLE Employees (
129
+ EmployeeID INT PRIMARY KEY,
130
+ FirstName VARCHAR(50),
131
+ LastName VARCHAR(50),
132
+ Age INT,
133
+ DepartmentID INT,
134
+ Salary DECIMAL(10, 2),
135
+ DateHired DATE,
136
+ Active BOOLEAN,
137
+ FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
138
+ );
139
+
140
+ CREATE TABLE Departments (
141
+ DepartmentID INT PRIMARY KEY,
142
+ DepartmentName VARCHAR(100),
143
+ Location VARCHAR(100)
144
+ ); ### Input: Write a SQL query to select all the employees who are active. ### Response:"""
145
+
146
+ response = generate(model=model,tokenizer=tokenizer,prompt=prompt, verbose=True)
147
+
148
+ ```
149
+