Update README.md
Browse files
README.md
CHANGED
|
@@ -1,11 +1,23 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
# Model Card for
|
| 7 |
|
| 8 |
-
<!--
|
| 9 |
|
| 10 |
|
| 11 |
|
|
@@ -13,65 +25,136 @@ tags: []
|
|
| 13 |
|
| 14 |
### Model Description
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- **
|
| 21 |
-
- **
|
| 22 |
-
- **
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
|
| 28 |
### Model Sources [optional]
|
| 29 |
|
| 30 |
<!-- Provide the basic links for the model. -->
|
| 31 |
|
| 32 |
-
- **Repository:**
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
|
| 36 |
## Uses
|
| 37 |
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
### Direct Use
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
|
| 46 |
### Downstream Use [optional]
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
|
| 52 |
### Out-of-Scope Use
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
|
| 64 |
### Recommendations
|
| 65 |
|
| 66 |
-
|
| 67 |
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
|
| 70 |
## How to Get Started with the Model
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
## Training Details
|
| 77 |
|
|
@@ -79,7 +162,7 @@ Use the code below to get started with the model.
|
|
| 79 |
|
| 80 |
<!-- 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. -->
|
| 81 |
|
| 82 |
-
|
| 83 |
|
| 84 |
### Training Procedure
|
| 85 |
|
|
@@ -87,113 +170,12 @@ Use the code below to get started with the model.
|
|
| 87 |
|
| 88 |
#### Preprocessing [optional]
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
|
| 93 |
#### Training Hyperparameters
|
| 94 |
|
| 95 |
-
- **Training regime:**
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
|
| 197 |
-
|
| 198 |
|
| 199 |
-
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- Phi-3-mini-4k-instruct
|
| 5 |
+
- NLP
|
| 6 |
+
- Chatbot
|
| 7 |
+
- Instruction Tuning
|
| 8 |
+
- SQL
|
| 9 |
+
- SQL-Generation
|
| 10 |
+
license: mit
|
| 11 |
+
datasets:
|
| 12 |
+
- gretelai/synthetic_text_to_sql
|
| 13 |
+
language:
|
| 14 |
+
- en
|
| 15 |
+
pipeline_tag: text-generation
|
| 16 |
---
|
| 17 |
|
| 18 |
+
# Model Card for sql-xp-phi-3-mini
|
| 19 |
|
| 20 |
+
<!-- Phi-3 Mini is a transformer-based language model optimized for understanding and generating responses based on instructional input. -->
|
| 21 |
|
| 22 |
|
| 23 |
|
|
|
|
| 25 |
|
| 26 |
### Model Description
|
| 27 |
|
| 28 |
+
This model card describes Phi-3 Mini, a smaller variant of the Phi-3 series, designed to handle instructions with a 4k token context length. It is specifically fine-tuned to follow instructional prompts effectively, making it suitable for applications requiring interactive and responsive dialogue systems.
|
| 29 |
|
| 30 |
+
- **Developed by:** [spectrewolf8]
|
| 31 |
+
- **Model type:** Transformer-based Language Model
|
| 32 |
+
- **Language(s) (NLP):** English (and SQL)
|
| 33 |
+
- **License:** MIT
|
| 34 |
+
- **Finetuned from model [optional]:** Phi-3-mini-instruct-4k base model
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
### Model Sources [optional]
|
| 37 |
|
| 38 |
<!-- Provide the basic links for the model. -->
|
| 39 |
|
| 40 |
+
- **Repository:** https://github.com/Spectrewolf8/kaggle-sql-xp-phi-3-mini-4k-instruct
|
|
|
|
|
|
|
| 41 |
|
| 42 |
## Uses
|
| 43 |
|
|
|
|
|
|
|
| 44 |
### Direct Use
|
| 45 |
|
| 46 |
+
Phi-3 Mini can be used to translate natural language instructions into SQL queries, making it a powerful tool for database querying and management. Users can input descriptive text, and the model will generate the corresponding SQL commands.
|
|
|
|
|
|
|
| 47 |
|
| 48 |
### Downstream Use [optional]
|
| 49 |
|
| 50 |
+
This model can be integrated into applications such as chatbots or virtual assistants that interact with databases. It can also be used in tools designed for automatic query generation based on user-friendly descriptions.
|
|
|
|
|
|
|
| 51 |
|
| 52 |
### Out-of-Scope Use
|
| 53 |
|
| 54 |
+
Phi-3 Mini is not suitable for tasks requiring non-SQL-related language understanding or generation. It should not be used for generating queries in languages other than SQL or for other domains outside database querying.
|
| 55 |
|
| 56 |
+
### Bias, Risks, and Limitations
|
| 57 |
|
| 58 |
+
Phi-3 Mini, like other language models, may have limitations in understanding complex or ambiguous instructions. The SQL queries generated might need manual review to ensure accuracy and appropriateness.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
### Recommendations
|
| 61 |
|
| 62 |
+
Users should verify the generated SQL queries for correctness and security, especially when using them in production environments. Implementing additional layers of validation and testing can help mitigate risks associated with incorrect SQL generation.
|
| 63 |
|
|
|
|
| 64 |
|
| 65 |
## How to Get Started with the Model
|
| 66 |
|
| 67 |
+
To get started with Phi-3 Mini for SQL generation, follow the code snippet below:
|
| 68 |
+
|
| 69 |
+
```
|
| 70 |
+
# Import necessary libraries
|
| 71 |
+
import torch
|
| 72 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed
|
| 73 |
+
|
| 74 |
+
# Set the seed for the random number generator to ensure reproducibility
|
| 75 |
+
set_seed(1234)
|
| 76 |
+
|
| 77 |
+
# Define the repository name for the Hugging Face model
|
| 78 |
+
# 'hf_model_repo' is a variable that holds the repository name for the Hugging Face model
|
| 79 |
+
# 'username/modelname' is the repository name, where 'username' is the username of the repository owner
|
| 80 |
+
# and 'modelname' is the name of the model
|
| 81 |
+
hf_model_repo = "spectrewolf8/sql-xp-phi-3-mini-4k"
|
| 82 |
+
|
| 83 |
+
# Retrieve the device mapping and computation data type
|
| 84 |
+
# 'device_map' is a variable that holds the mapping of the devices that are used for computation
|
| 85 |
+
# 'compute_dtype' is a variable that holds the data type that is used for computation
|
| 86 |
+
|
| 87 |
+
# device_map = {"": 0}
|
| 88 |
+
# compute_dtype = torch.bfloat16 or torch.float16
|
| 89 |
+
device_map, compute_dtype
|
| 90 |
+
|
| 91 |
+
# Load a pre-trained tokenizer from the Hugging Face Model Hub
|
| 92 |
+
# 'tokenizer' is the variable that holds the tokenizer
|
| 93 |
+
# 'trust_remote_code=True' allows the execution of code from the model file
|
| 94 |
+
tokenizer = AutoTokenizer.from_pretrained(hf_model_repo, trust_remote_code=True)
|
| 95 |
+
|
| 96 |
+
# Load a pre-trained model for causal language modeling from the Hugging Face Model Hub
|
| 97 |
+
# 'model' is the variable that holds the model
|
| 98 |
+
# 'trust_remote_code=True' allows the execution of code from the model file
|
| 99 |
+
# 'torch_dtype=compute_dtype' sets the data type for the PyTorch tensors
|
| 100 |
+
# 'device_map=device_map' sets the device mapping
|
| 101 |
+
model = AutoModelForCausalLM.from_pretrained(hf_model_repo, trust_remote_code=True, torch_dtype=compute_dtype, device_map=device_map)
|
| 102 |
+
|
| 103 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 104 |
+
|
| 105 |
+
# Define the input phrase which represents the user's request or query.
|
| 106 |
+
input_phrase = """
|
| 107 |
+
insert 5 values
|
| 108 |
+
"""
|
| 109 |
+
|
| 110 |
+
# Define the context phrase which provides the SQL table schema relevant to the input phrase.
|
| 111 |
+
context_phrase = """
|
| 112 |
+
CREATE TABLE tasks (
|
| 113 |
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
| 114 |
+
name VARCHAR(100) NOT NULL,
|
| 115 |
+
task_name VARCHAR(100) NOT NULL,
|
| 116 |
+
userid INT NOT NULL,
|
| 117 |
+
date DATE NOT NULL,
|
| 118 |
+
FOREIGN KEY (userid) REFERENCES users(id)
|
| 119 |
+
);
|
| 120 |
+
"""
|
| 121 |
+
|
| 122 |
+
# Create a prompt by applying a chat template to the input and context phrases using the tokenizer.
|
| 123 |
+
# The 'apply_chat_template' method formats the input as a chat message, making it suitable for text generation.
|
| 124 |
+
# 'tokenize=False' indicates that the input should not be tokenized yet.
|
| 125 |
+
# 'add_generation_prompt=True' adds a prompt for text generation.
|
| 126 |
+
prompt = pipe.tokenizer.apply_chat_template(
|
| 127 |
+
[{"role": "user", "content": f"\n #prompt: {input_phrase}\n #context: {context_phrase}"}],
|
| 128 |
+
tokenize=False,
|
| 129 |
+
add_generation_prompt=True
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
# Create a text generation pipeline using the specified model and tokenizer.
|
| 133 |
+
# The 'pipeline' function sets up a ready-to-use text generation pipeline, combining the model and tokenizer.
|
| 134 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 135 |
+
|
| 136 |
+
# Generate text using the pipeline with the specified parameters.
|
| 137 |
+
# 'max_new_tokens=256' sets the maximum number of new tokens to generate.
|
| 138 |
+
# 'do_sample=True' enables sampling for text generation.
|
| 139 |
+
# 'num_beams=1' specifies the number of beams for beam search (1 means no beam search).
|
| 140 |
+
# 'temperature=0.3' controls the randomness of predictions by scaling the logits before applying softmax.
|
| 141 |
+
# 'top_k=50' considers only the top 50 token predictions for sampling.
|
| 142 |
+
# 'top_p=0.95' enables nucleus sampling, considering tokens that have a cumulative probability of 0.95.
|
| 143 |
+
# 'max_time=180' sets the maximum generation time to 180 seconds.
|
| 144 |
+
outputs = pipe(
|
| 145 |
+
prompt,
|
| 146 |
+
max_new_tokens=256,
|
| 147 |
+
do_sample=True,
|
| 148 |
+
num_beams=1,
|
| 149 |
+
temperature=0.3,
|
| 150 |
+
top_k=50,
|
| 151 |
+
top_p=0.95,
|
| 152 |
+
max_time=180
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
# Print the generated text by stripping out the prompt portion and displaying only the new generated content.
|
| 156 |
+
print(outputs[0]['generated_text'][len(prompt):].strip())
|
| 157 |
+
```
|
| 158 |
|
| 159 |
## Training Details
|
| 160 |
|
|
|
|
| 162 |
|
| 163 |
<!-- 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. -->
|
| 164 |
|
| 165 |
+
- **Data set used was:** https://huggingface.co/datasets/gretelai/synthetic_text_to_sql
|
| 166 |
|
| 167 |
### Training Procedure
|
| 168 |
|
|
|
|
| 170 |
|
| 171 |
#### Preprocessing [optional]
|
| 172 |
|
| 173 |
+
Ignore columns other than "sql_prompt", "sql_context", "sql" from the dataset.
|
|
|
|
| 174 |
|
| 175 |
#### Training Hyperparameters
|
| 176 |
|
| 177 |
+
- **Training regime:** Mixed precision (fp16) for efficiency. <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
+
### Training aftermath
|
| 180 |
|
| 181 |
+
The model was trained on the RTX 3060 OC 12 GB variant. It took 5 hours to train the model with 10,000 values for training and 3,300 values for testing with 2 Epochs.
|