Update README.md
Browse files
README.md
CHANGED
@@ -1,202 +1,91 @@
|
|
1 |
---
|
2 |
library_name: peft
|
3 |
base_model: google/gemma-7b-it
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
# Model Card for Model ID
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
-
|
12 |
-
## Model Details
|
13 |
-
|
14 |
-
### Model Description
|
15 |
-
|
16 |
-
<!-- Provide a longer summary of what this model is. -->
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
- **Developed by:** [More Information Needed]
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
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:** [More Information Needed]
|
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 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
-
|
44 |
-
[More Information Needed]
|
45 |
-
|
46 |
-
### Downstream Use [optional]
|
47 |
-
|
48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
-
|
50 |
-
[More Information Needed]
|
51 |
-
|
52 |
-
### Out-of-Scope Use
|
53 |
-
|
54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
-
|
58 |
-
## Bias, Risks, and Limitations
|
59 |
-
|
60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
-
|
64 |
-
### Recommendations
|
65 |
-
|
66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
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 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
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 |
-
## Model Card Contact
|
198 |
-
|
199 |
-
[More Information Needed]
|
200 |
|
201 |
|
202 |
### Framework versions
|
|
|
1 |
---
|
2 |
library_name: peft
|
3 |
base_model: google/gemma-7b-it
|
4 |
+
datasets:
|
5 |
+
- nmarafo/truthful_qa_TrueFalse-Feedback
|
6 |
+
language:
|
7 |
+
- en
|
8 |
+
- es
|
9 |
+
license: other
|
10 |
+
license_name: gemma-terms-of-use
|
11 |
+
license_link: https://ai.google.dev/gemma/terms
|
12 |
---
|
13 |
|
14 |
# Model Card for Model ID
|
15 |
|
16 |
+
This is an adapter prepared to return True or False depending on whether the student's answer ("student_answer") is correct based on the question ("question") and comparing it with a given answer ("best_answer").
|
17 |
+
The prompt has the following structure:
|
18 |
+
```
|
19 |
+
<s>[INST]Analyze the question, the expected answer, and the student's response.
|
20 |
+
Determine if the student's answer is correct or not. It only returns True if the student's answer is correct with respect to the expected answer or False otherwise.
|
21 |
+
Add a brief comment explaining why the answer is correct or incorrect.\n\n
|
22 |
+
Question: {question}\n
|
23 |
+
Expected Answer: {best_answer}\n
|
24 |
+
Student Answer: {student_answer}[/INST]"
|
25 |
+
```
|
26 |
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
## How to Get Started with the Model
|
29 |
+
In Google Colab:
|
30 |
+
```
|
31 |
+
|
32 |
+
!pip install -q -U transformers peft accelerate optimum
|
33 |
+
!pip install datasets==2.15.0
|
34 |
+
!pip install auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu117/
|
35 |
+
|
36 |
+
from peft import AutoPeftModelForCausalLM
|
37 |
+
from rich import print
|
38 |
+
from transformers import GenerationConfig, AutoTokenizer
|
39 |
+
|
40 |
+
import torch
|
41 |
+
|
42 |
+
model_id = "TheBloke/Mistral-7B-Instruct-v0.2-GPTQ"
|
43 |
+
adapter = "nmarafo/Mistral-7B-Instruct-v0.2-TrueFalse-Feedback-GPTQ"
|
44 |
+
|
45 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, return_token_type_ids=False)
|
46 |
+
tokenizer.pad_token = tokenizer.eos_token
|
47 |
+
|
48 |
+
model = AutoPeftModelForCausalLM.from_pretrained(adapter, low_cpu_mem_usage=True, return_dict=True, torch_dtype=torch.float16, device_map="cuda")
|
49 |
+
|
50 |
+
def predict(question, best_answer, student_answer):
|
51 |
+
system_message = "Analyze the question, the expected answer, and the student's response. Determine if the student's answer is conceptually correct in relation to the expected answer, regardless of the exact wording. Return True if the student's answer is correct or False otherwise. Add a brief comment explaining the rationale behind the answer being correct or incorrect."
|
52 |
+
prompt = f"{system_message}\n\nQuestion: {question}\nBest Answer: {best_answer}\nStudent Answer: {student_answer}"
|
53 |
+
prompt_template=f"<s>[INST]{prompt}[/INST]"
|
54 |
+
|
55 |
+
encoding = tokenizer(prompt_template, return_tensors='pt', padding=True, truncation=True, max_length=512)
|
56 |
+
input_ids = encoding['input_ids'].cuda()
|
57 |
+
attention_mask = encoding['attention_mask'].cuda()
|
58 |
+
|
59 |
+
output = model.generate(input_ids, attention_mask=attention_mask,
|
60 |
+
temperature=0.7, do_sample=True, top_p=0.95,
|
61 |
+
top_k=40, max_new_tokens=512, pad_token_id=tokenizer.eos_token_id)
|
62 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
63 |
+
return response
|
64 |
+
|
65 |
+
question="Mention all the Canary Island"
|
66 |
+
best_answer="Tenerife, Fuerteventura, Gran Canaria, Lanzarote, La Palma, La Gomera, El Hierro, La Graciosa"
|
67 |
+
student_answer="Tenerife"
|
68 |
+
|
69 |
+
print(predict(question, best_answer, student_answer))
|
70 |
+
|
71 |
+
```
|
72 |
+
|
73 |
+
# To perform inference on the test dataset example load the model from the checkpoint
|
74 |
+
persisted_model = AutoPeftModelForCausalLM.from_pretrained(
|
75 |
+
adapter,
|
76 |
+
low_cpu_mem_usage=True,
|
77 |
+
return_dict=True,
|
78 |
+
torch_dtype=torch.float16,
|
79 |
+
device_map="cuda")
|
80 |
+
# Some gen config knobs
|
81 |
+
generation_config = GenerationConfig(
|
82 |
+
penalty_alpha=0.6,
|
83 |
+
do_sample = True,
|
84 |
+
top_k=5,
|
85 |
+
temperature=0.5,
|
86 |
+
repetition_penalty=1.2,
|
87 |
+
max_new_tokens=512
|
88 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
|
91 |
### Framework versions
|