Upload README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,90 @@
|
|
1 |
---
|
2 |
license: gemma
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: gemma
|
3 |
---
|
4 |
+
# Gemma SCAPPY QA adapter
|
5 |
+
|
6 |
+
### Introduction
|
7 |
+
|
8 |
+
This is fine-tuned [QLora](https://github.com/artidoro/qlora) adapter of [Gemma 7B base model](https://huggingface.co/google/gemma-7b) using [Vezora/Tested-22k-Python-Alpaca](https://huggingface.co/datasets/Vezora/Tested-22k-Python-Alpaca).
|
9 |
+
|
10 |
+
This is trained for Python code agent [SCAPPY (Self Critic Agent for Programming in Python)](https://www.kaggle.com/code/kyushikmin/building-self-critic-python-agent-with-gemma) which is submitted for Kaggle Challenge [Google-AI Assistants for Data Tasks with Gemma](https://www.kaggle.com/competitions/data-assistants-with-gemma)
|
11 |
+
|
12 |
+
SCAPPY QA adapter respond answer about Python programming question.
|
13 |
+
|
14 |
+
---
|
15 |
+
|
16 |
+
### Process of SCAPPY
|
17 |
+
|
18 |
+
The process of the SCAPPY is as follows
|
19 |
+
<img src="https://huggingface.co/gcw-ai/gemma-scappy-qatar-adapter/resolve/main/images/img_1_1.png" alt="overview">
|
20 |
+
|
21 |
+
1. First, input the instruction into the QA model and obtain the response from the QA model.
|
22 |
+
2. Extract the code from the QA model's response and use exec to obtain the execution result of the code.
|
23 |
+
3. Input the question, answer, and execution result into the QATAR model and acquire the thought, action, and revised answer information.
|
24 |
+
4. If the action is 'fail', the QATAR model has determined there is an error in the original answer. In this case, set the revised answer as the new answer and execute it to obtain a new execution result. Re-enter the original question along with the newly obtained answer and execution result into the QATAR model. (This process may repeat up to 3 times.)
|
25 |
+
5. If the action is 'pass', use the last obtained answer as the final response. If 'fail' has occurred three or more times, use the last derived revised answer as the final response.
|
26 |
+
|
27 |
+
---
|
28 |
+
|
29 |
+
### Usage
|
30 |
+
|
31 |
+
**Example code** to use SCAPPY QA adapter is as follows:
|
32 |
+
|
33 |
+
`````python
|
34 |
+
import torch
|
35 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
36 |
+
from peft import PeftModel
|
37 |
+
|
38 |
+
base_id = "google/gemma-7b"
|
39 |
+
peft_id_7b_qa = "gcw-ai/gemma-scappy-qa-adapter"
|
40 |
+
|
41 |
+
bnb_config = BitsAndBytesConfig(
|
42 |
+
load_in_4bit=True,
|
43 |
+
bnb_4bit_quant_type="nf4",
|
44 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
45 |
+
)
|
46 |
+
|
47 |
+
base_model = AutoModelForCausalLM.from_pretrained(base_id, quantization_config=bnb_config, device_map={"":0})
|
48 |
+
tokenizer = AutoTokenizer.from_pretrained(base_id)
|
49 |
+
|
50 |
+
model = PeftModel.from_pretrained(base_model, peft_id_7b_qa, adapter_name="qa")
|
51 |
+
|
52 |
+
instruction = f"""Write a function to add the given list to the given tuples.
|
53 |
+
Evaluate the following test cases with print.
|
54 |
+
add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7)
|
55 |
+
add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8)"""
|
56 |
+
|
57 |
+
qa_prompt = f"### Question\n{instruction}\n### Answer\n"
|
58 |
+
inputs = tokenizer(qa_prompt, return_tensors="pt").to("cuda:0")
|
59 |
+
|
60 |
+
outputs = model.generate(**inputs, max_new_tokens=1000)
|
61 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
62 |
+
`````
|
63 |
+
|
64 |
+
The **Result of the example code** is as follows
|
65 |
+
`````
|
66 |
+
### Question
|
67 |
+
Write a function to add the given list to the given tuples.
|
68 |
+
Evaluate the following test cases with print.
|
69 |
+
add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7)
|
70 |
+
add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8)
|
71 |
+
### Answer
|
72 |
+
Here is the function to add the given list to the given tuples:
|
73 |
+
|
74 |
+
```python
|
75 |
+
def add_lists(lst, tuples):
|
76 |
+
return tuples + lst
|
77 |
+
```
|
78 |
+
|
79 |
+
And here are the test cases with print:
|
80 |
+
|
81 |
+
```python
|
82 |
+
print(add_lists([5, 6, 7], (9, 10)))
|
83 |
+
# Output: (9, 10, 5, 6, 7)
|
84 |
+
|
85 |
+
print(add_lists([6, 7, 8], (10, 11)))
|
86 |
+
# Output: (10, 11, 6, 7, 8)
|
87 |
+
```
|
88 |
+
|
89 |
+
The function `add_lists` takes two arguments: `lst` which is a list, and `tuples` which is a tuple. It returns the concatenation of the `tuples` and `lst`.
|
90 |
+
`````
|