pavankumarbalijepalli commited on
Commit
2391b6b
•
1 Parent(s): 26ebc5f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +107 -23
README.md CHANGED
@@ -1,68 +1,143 @@
1
  ---
2
- # For reference on model card metadata, see the spec: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
3
- # Doc / guide: https://huggingface.co/docs/hub/model-cards
4
- {}
 
 
 
 
 
 
 
 
 
 
5
  ---
6
 
7
- # Model Card for Model ID
8
 
9
- Yet to update! Please be patient. I will update the model card very soon.
10
 
11
  <!-- Provide a quick summary of what the model is/does. -->
12
 
13
- This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1).
14
 
15
  ## Model Details
16
 
17
  ### Model Description
18
 
19
  <!-- Provide a longer summary of what this model is. -->
 
20
 
21
-
22
-
23
- - **Developed by:** [More Information Needed]
24
- - **Funded by [optional]:** [More Information Needed]
25
- - **Shared by [optional]:** [More Information Needed]
26
- - **Model type:** [More Information Needed]
27
- - **Language(s) (NLP):** [More Information Needed]
28
- - **License:** [More Information Needed]
29
- - **Finetuned from model [optional]:** [More Information Needed]
30
 
31
  ### Model Sources [optional]
32
 
33
  <!-- Provide the basic links for the model. -->
34
 
35
- - **Repository:** [More Information Needed]
36
- - **Paper [optional]:** [More Information Needed]
37
- - **Demo [optional]:** [More Information Needed]
38
 
39
  ## Uses
40
 
41
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
42
 
 
 
43
  ### Direct Use
44
 
45
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
46
 
47
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
- ### Downstream Use [optional]
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
52
 
53
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  ### Out-of-Scope Use
56
 
57
  <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
58
 
59
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
60
 
61
  ## Bias, Risks, and Limitations
62
 
63
  <!-- This section is meant to convey both technical and sociotechnical limitations. -->
64
 
65
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  ### Recommendations
68
 
@@ -83,6 +158,15 @@ Use the code below to get started with the model.
83
  <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
84
 
85
  [More Information Needed]
 
 
 
 
 
 
 
 
 
86
 
87
  ### Training Procedure
88
 
 
1
  ---
2
+ license: mit
3
+ datasets:
4
+ - b-mc2/sql-create-context
5
+ language:
6
+ - en
7
+ metrics:
8
+ - accuracy
9
+ - code_eval
10
+ library_name: transformers
11
+ pipeline_tag: text-generation
12
+ tags:
13
+ - peft
14
+ - nl2sql
15
  ---
16
 
17
+ # Update: 14-03-2024 - The model card is still updating. Thanks for being patient! 💜💜
18
 
19
+ # Model Card for Model ID
20
 
21
  <!-- Provide a quick summary of what the model is/does. -->
22
 
23
+ A fine-tuned version of Phi-2 for the NL2SQL usecase on `b-mc2/sql-create-context` dataset.
24
 
25
  ## Model Details
26
 
27
  ### Model Description
28
 
29
  <!-- Provide a longer summary of what this model is. -->
30
+ This model has been finetuned with `b-mc2/sql-create-context` on `microsoft/phi-2`. This performed better than `defog/sqlcoder-7b-2` in terms of inference time and accuracy on the holdback dataset. The evaluation is done on `.gguf` models on CPU machine with limited RAM. The average inference times of the Phi-2, and SQLCoder are 24 secs, and 41 secs respectively. That is 41% faster on average. This is due to its smaller size. The Finetuned Phi-2 is 29% better than the SQLCoder based on execution success. The major drawback is its context window of 2048 tokens which requires additional input engineering to get results.
31
 
32
+ - **Developed by:** pavankumarbalijepalli
33
+ - **Model type:** CASUAL_LM
34
+ - **Language(s) (NLP):** English, SQL
35
+ - **License:** MIT
36
+ - **Finetuned from model [optional]:** [microsoft/phi-2](https://huggingface.co/microsoft/phi-2)
 
 
 
 
37
 
38
  ### Model Sources [optional]
39
 
40
  <!-- Provide the basic links for the model. -->
41
 
42
+ - **Repository:** [pavankumarbalijepalli/pr-phi2-vs-defog](https://github.com/pavankumarbalijepalli/pr-phi2-vs-defog/)
43
+ - **Paper [optional]:** [BITS Project Paper](https://github.com/pavankumarbalijepalli/pr-phi2-vs-defog/blob/main/2021SC04115%20-%20Final.pdf)
 
44
 
45
  ## Uses
46
 
47
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
48
 
49
+ Model is supposed to be used for the cases where you have a natural language question, database schema which is relevant the question to retrieve a SQL query which answers the question. The context should be below 2048 tokens. The output will be generated in postgresql.
50
+
51
  ### Direct Use
52
 
53
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
54
 
55
+ ```python
56
+ # SAME TEMPLATE AS DEFOG MODEL
57
+ prompt = f"""### Task
58
+ Generate a SQL query to answer the following question:
59
+ `{data_point['question']}`
60
+
61
+ ### Database Schema
62
+ The query will run on a database with the following schema:
63
+ {data_point['context']}
64
+
65
+ ### Answer
66
+ Given the database schema, here is the SQL query that answers `{data_point['question']}`:
67
+ ```sql"""
68
+ ```
69
 
70
+ ```python
71
+ # USING ON CPU MACHINE
72
+ from llama_cpp import Llama
73
+
74
+ phi2 = Llama(model_path=f"{path_to_model}/phi2_sqlcoder_f16.gguf")
75
+
76
+ response = phi2(prompt=prompt, max_tokens = 200, temperature = 0.2, stop = ['```'])
77
+
78
+ print(response['choices'][0]['text'].strip())
79
+ ```
80
+
81
+ ### Downstream Use
82
 
83
  <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
84
 
85
+ ```python
86
+ import torch
87
+ from transformers import AutoModelForCausalLM, AutoTokenizer
88
+ from peft import PeftModel, PeftConfig
89
+
90
+ model_name = "microsoft/phi-2"
91
+
92
+ model = AutoModelForCausalLM.from_pretrained(
93
+ model_name,
94
+ trust_remote_code=True,
95
+ device_map="auto"
96
+ )
97
+
98
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
99
+ inputs = tokenizer(new_prompt, return_tensors="pt", padding=True, truncation=True)
100
+ inputs.to('cuda')
101
+
102
+ model_id = "pavankumarbalijepalli/phi2-sqlcoder"
103
+ trained_model = PeftModel.from_pretrained(model, model_id)
104
+ outputs = trained_model.generate(**inputs, max_length=1000)
105
+ text = tokenizer.batch_decode(outputs,skip_special_tokens=True)[0]
106
+ print(text)
107
+ ```
108
 
109
  ### Out-of-Scope Use
110
 
111
  <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
112
 
113
+ __Generating Unintended Code:__
114
+
115
+ While the model can translate natural language into SQL queries, it may not be robust enough to handle complex logic or edge cases. Using it to generate critical production code could lead to errors or unexpected behavior in databases.
116
+
117
+ __Security Risks:__
118
+
119
+ NL2SQL models can be susceptible to adversarial attacks where malicious users input natural language designed to trick the model into generating SQL code with security vulnerabilities, like SQL injection attacks.
120
+
121
+ __Beyond its Training Scope:__
122
+
123
+ The model is trained on a specific SQL Language (e.g., PostgreSQL). Using it for a different SQL Syntax (e.g., MS SQL Server) could lead to inaccurate or nonsensical SQL queries.
124
 
125
  ## Bias, Risks, and Limitations
126
 
127
  <!-- This section is meant to convey both technical and sociotechnical limitations. -->
128
 
129
+ __Bias and Fairness:__
130
+
131
+ The model's training data may contain biases that are reflected in the generated SQL queries. This could lead to unfair or discriminatory outcomes, especially if the data is not carefully curated.
132
+
133
+ __Interpretability and Explainability:__
134
+
135
+ NL2SQL models are often "black boxes" where it's difficult to understand how they translate natural language to SQL. This lack of interpretability makes it challenging to debug errors or ensure the generated queries are safe and efficient.
136
+
137
+ __Replacing Human Expertise:__
138
+
139
+ While the model can automate some SQL query generation tasks, it shouldn't be a complete replacement for human database administrators or analysts. Understanding the data schema and database design is crucial for writing efficient and secure SQL queries.
140
+
141
 
142
  ### Recommendations
143
 
 
158
  <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
159
 
160
  [More Information Needed]
161
+ ```
162
+ @misc{b-mc2_2023_sql-create-context,
163
+ title = {sql-create-context Dataset},
164
+ author = {b-mc2},
165
+ year = {2023},
166
+ url = {https://huggingface.co/datasets/b-mc2/sql-create-context},
167
+ note = {This dataset was created by modifying data from the following sources: \cite{zhongSeq2SQL2017, yu2018spider}.},
168
+ }
169
+ ```
170
 
171
  ### Training Procedure
172