Update README.md
Browse files
README.md
CHANGED
@@ -35,17 +35,6 @@ The goal of this model is to improve the quality and efficiency of code generati
|
|
35 |
- **Repository:** [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1}{mistralai/Mistral-7B-v0.1)
|
36 |
- **Paper:** [Mistral-7B](https://arxiv.org/abs/2310.06825)
|
37 |
|
38 |
-
## How to Get Started with the Model
|
39 |
-
|
40 |
-
Use the code below to get started with the model.
|
41 |
-
|
42 |
-
```python
|
43 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
44 |
-
|
45 |
-
tokenizer = AutoTokenizer.from_pretrained('mistralai/Mistral-7B-v0.1')
|
46 |
-
model = AutoModelForCausalLM.from_pretrained('aswain4/custom_coding_LLM', device_map='auto', torch_dtype=torch.bfloat16)
|
47 |
-
```
|
48 |
-
|
49 |
## Uses
|
50 |
|
51 |
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
@@ -74,6 +63,131 @@ The model was trained on a dataset that is predominantly Python code; therefore,
|
|
74 |
|
75 |
Users (both direct and downstream) should be made aware of the risks and limitations of the model. Please read the above section before using this model.
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
## Training Details
|
78 |
|
79 |
### Training Data
|
|
|
35 |
- **Repository:** [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1}{mistralai/Mistral-7B-v0.1)
|
36 |
- **Paper:** [Mistral-7B](https://arxiv.org/abs/2310.06825)
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
## Uses
|
39 |
|
40 |
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
|
|
63 |
|
64 |
Users (both direct and downstream) should be made aware of the risks and limitations of the model. Please read the above section before using this model.
|
65 |
|
66 |
+
## How to Get Started with the Model
|
67 |
+
|
68 |
+
Use the code below to get started with the model.
|
69 |
+
|
70 |
+
```python
|
71 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
72 |
+
|
73 |
+
tokenizer = AutoTokenizer.from_pretrained('mistralai/Mistral-7B-v0.1')
|
74 |
+
model = AutoModelForCausalLM.from_pretrained('aswain4/custom_coding_LLM', device_map='auto', torch_dtype=torch.bfloat16)
|
75 |
+
```
|
76 |
+
|
77 |
+
### Input Formats
|
78 |
+
|
79 |
+
Formatting the prompt similarly to the training data will yield the best results. This means creating the prompt in a Program of Thought (PoT) technique. However, simply asking the question will yield quality output.
|
80 |
+
|
81 |
+
PoT prompt:
|
82 |
+
```python
|
83 |
+
prompt = (
|
84 |
+
"Instruct: Plan:\n"
|
85 |
+
"1. Analyze the following question: \"Write a Python function to check if a number is a palindrome.\"\n"
|
86 |
+
"2. Think step by step and plan a clear, efficient solution before writing code.\n"
|
87 |
+
"3. Consider any necessary programming constructs or tools.\n"
|
88 |
+
"4. Explain your approach, then write well-organized and well-documented code with in-line comments.\n\n"
|
89 |
+
"Response:"
|
90 |
+
)
|
91 |
+
|
92 |
+
input_ids = tokenizer(prompt, return_tensors="pt").to(model.device)
|
93 |
+
|
94 |
+
#generate text
|
95 |
+
outputs = model.generate(
|
96 |
+
**input_ids,
|
97 |
+
max_new_tokens=300,
|
98 |
+
temperature=0.7,
|
99 |
+
top_p=0.95,
|
100 |
+
do_sample=True,
|
101 |
+
pad_token_id=tokenizer.pad_token_id
|
102 |
+
)
|
103 |
+
|
104 |
+
#decode and print
|
105 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
106 |
+
print(generated_text)
|
107 |
+
```
|
108 |
+
|
109 |
+
Question only prompt:
|
110 |
+
```python
|
111 |
+
prompt = "Write a Python function to check if a number is a palindrome."
|
112 |
+
|
113 |
+
input_ids = tokenizer(prompt, return_tensors="pt").to(model.device)
|
114 |
+
|
115 |
+
#generate text
|
116 |
+
outputs = model.generate(
|
117 |
+
**input_ids,
|
118 |
+
max_new_tokens=300,
|
119 |
+
temperature=0.7,
|
120 |
+
top_p=0.95,
|
121 |
+
do_sample=True,
|
122 |
+
pad_token_id=tokenizer.pad_token_id
|
123 |
+
)
|
124 |
+
|
125 |
+
#decode and print
|
126 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
127 |
+
print(generated_text)
|
128 |
+
```
|
129 |
+
|
130 |
+
### Expected Outputs
|
131 |
+
|
132 |
+
If the PoT prompting approach is used, users should expect the output to yield a response stating it can perform the task, followed by the generated code, and then an explanation of what is happening in the code. If the question-only prompting approach is used, the output is expected to yield the generated code followed by an explanation of what is happening in the code.
|
133 |
+
|
134 |
+
PoT output:
|
135 |
+
```text
|
136 |
+
Sure! Here's an example of a Python function that checks if a number is a palindrome:
|
137 |
+
|
138 |
+
def is_palindrome(num):
|
139 |
+
str_num = str(num)
|
140 |
+
if str_num == str_num[::-1]:
|
141 |
+
return True
|
142 |
+
else:
|
143 |
+
return False
|
144 |
+
|
145 |
+
num = 12321
|
146 |
+
result = is_palindrome(num)
|
147 |
+
print(result)
|
148 |
+
|
149 |
+
The function `is_palindrome` takes a number as input and converts it into a string using the `str()` function. It then checks if the string is equal to its reversed version (`str_num[::-1]`). If they are equal, it means the number is a palindrome and the function returns `True`. Otherwise, it returns `False`.
|
150 |
+
|
151 |
+
In the example code, we test the function with the number `12321`. The function call `is_palindrome(num)` returns `True` because `12321` is a palindrome. Finally, the result is printed to the console.
|
152 |
+
|
153 |
+
I hope this helps! Let me know if you have any further questions.
|
154 |
+
```
|
155 |
+
|
156 |
+
Question only output:
|
157 |
+
```text
|
158 |
+
def is_palindrome(n):
|
159 |
+
# convert the number to string
|
160 |
+
n = str(n)
|
161 |
+
|
162 |
+
# check if the string is equal to its reverse
|
163 |
+
if n == n[::-1]:
|
164 |
+
return True
|
165 |
+
else:
|
166 |
+
return False
|
167 |
+
|
168 |
+
|
169 |
+
print(is_palindrome(12321))
|
170 |
+
|
171 |
+
|
172 |
+
# Output:
|
173 |
+
# True
|
174 |
+
|
175 |
+
|
176 |
+
# Explanation:
|
177 |
+
# The function is_palindrome takes a number as input and converts it to a string.
|
178 |
+
# It then checks if the string is equal to its reverse.
|
179 |
+
# If the string is equal to its reverse, the function returns True, indicating that the number is a palindrome.
|
180 |
+
# Otherwise, it returns False.
|
181 |
+
# In the given example, the number 12321 is a palindrome, so the function returns True.
|
182 |
+
```
|
183 |
+
|
184 |
+
The function `is_palindrome` takes a number as input and converts it into a string using the `str()` function. It then checks if the string is equal to its reversed version (`str_num[::-1]`). If they are equal, it means the number is a palindrome and the function returns `True`. Otherwise, it returns `False`.
|
185 |
+
|
186 |
+
In the example code, we test the function with the number `12321`. The function call `is_palindrome(num)` returns `True` because `12321` is a palindrome. Finally, the result is printed to the console.
|
187 |
+
|
188 |
+
I hope this helps! Let me know if you have any further questions.
|
189 |
+
```
|
190 |
+
|
191 |
## Training Details
|
192 |
|
193 |
### Training Data
|