HridaAIofficial commited on
Commit
4847691
·
verified ·
1 Parent(s): cb9983a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +137 -3
README.md CHANGED
@@ -1,3 +1,137 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ library_name: transformers
6
+ pipeline_tag: text2text-generation
7
+ tags:
8
+ - code
9
+ - sql
10
+ - text-to-sql
11
+ - text2sql
12
+ - t2sql
13
+ base_model:
14
+ - microsoft/Phi-3.5-mini-instruct
15
+ ---
16
+
17
+ Introducing Hrida-T2SQL-3B-V0.2, our latest small language model (SLM) tailored for data scientists and industry professionals. This advanced model marks a significant upgrade from our previous release, now equipped with 128k token context window as defaultfor handling even the most intricate data queries with precision. Powered by the Phi 3 architecture, it effortlessly converts natural language queries into precise SQL commands, enhancing data analysis efficiency and decision-making capabilities.
18
+
19
+ Blog & benchmark coming soon!
20
+
21
+
22
+ ## Prompt Template
23
+
24
+ ```txt
25
+ ### Instruction:
26
+ Provide the system prompt.
27
+
28
+ ### Dialect:
29
+ Specify the SQL dialect (e.g., MySQL, PostgreSQL, SQL Server, etc.).
30
+
31
+ ### Context:
32
+ Provide the database schema including table names, column names, and data types.
33
+
34
+ ### Input:
35
+ User's query.
36
+
37
+ ### Response:
38
+ Expected SQL query output based on the input and context.
39
+
40
+ ```
41
+
42
+ - **Instruction (System Prompt)**: This guides the model on processing input to generate the SQL query response effectively.
43
+ - **Dialect (Optional)**: Specify the SQL variant the model should use to ensure the generated query conforms to the correct syntax.
44
+ - **Context**: Provide the database schema to the model for generating accurate SQL queries.
45
+ - **Input**: Provide the user query for the model to comprehend and transform into an SQL query.
46
+ - **Response**: Expected output from the model.
47
+
48
+
49
+ ## Chat Prompt Template
50
+
51
+ ```txt
52
+ <s>
53
+ <|system|>
54
+ { Instruction / System Prompt }
55
+ <|user|>
56
+ { Context / User Query } <|end|>
57
+ <|assistant|>
58
+ ```
59
+
60
+ ## Run the Model
61
+
62
+ ### Using Transformers
63
+
64
+ ```python
65
+ import torch
66
+ from transformers import AutoModelForCausalLM, AutoTokenizer
67
+
68
+ # Define the model and tokenizer
69
+ model_id = "HridaAI/Hrida-T2SQL-3B-V0.2"
70
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
71
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, trust_remote_code=True)
72
+
73
+ # Define the context and prompt
74
+ prompt = """
75
+ Answer to the query will be in the form of an SQL query.
76
+ ### Context: CREATE TABLE Employees (
77
+ EmployeeID INT PRIMARY KEY,
78
+ FirstName VARCHAR(50),
79
+ LastName VARCHAR(50),
80
+ Age INT,
81
+ DepartmentID INT,
82
+ Salary DECIMAL(10, 2),
83
+ DateHired DATE,
84
+ Active BOOLEAN,
85
+ FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
86
+ );
87
+
88
+ CREATE TABLE Departments (
89
+ DepartmentID INT PRIMARY KEY,
90
+ DepartmentName VARCHAR(100),
91
+ Location VARCHAR(100)
92
+ );
93
+ ### Input: if the hiring date of John is 25/12/2024 and he is 48 years old how long it will take him to retire lets say the retirement age is 55?
94
+ ### Response:
95
+ """
96
+ # Prepare the input
97
+ messages = [{"role": "user", "content": prompt}]
98
+ inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
99
+
100
+ # Generate the output
101
+ outputs = model.generate(inputs, max_length=300)
102
+ print(tokenizer.decode(outputs[0]))
103
+
104
+
105
+ ```
106
+
107
+ ### Using MLX
108
+
109
+ ```python
110
+ from mlx_lm import generate, load
111
+
112
+ model,tokenizer = load("HridaAI/Hrida-T2SQL-3B-V0.2")
113
+
114
+ prompt = """
115
+ Answer to the quey will be in the form of SQL query.
116
+ ### Context: CREATE TABLE Employees (
117
+ EmployeeID INT PRIMARY KEY,
118
+ FirstName VARCHAR(50),
119
+ LastName VARCHAR(50),
120
+ Age INT,
121
+ DepartmentID INT,
122
+ Salary DECIMAL(10, 2),
123
+ DateHired DATE,
124
+ Active BOOLEAN,
125
+ FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
126
+ );
127
+
128
+ CREATE TABLE Departments (
129
+ DepartmentID INT PRIMARY KEY,
130
+ DepartmentName VARCHAR(100),
131
+ Location VARCHAR(100)
132
+ ); ### Input: if the hiring date of John is 25/12/2024 and he is 48 years old how long it will take him to retire lets say the retirement age is 55?
133
+ ### Response:"""
134
+
135
+ response = generate(model=model,tokenizer=tokenizer,prompt=prompt, verbose=True)
136
+
137
+ ```