Update README.md
Browse filesadd description of model
README.md
CHANGED
@@ -17,7 +17,9 @@ tags:
|
|
17 |
# 100suping/Qwen2.5-Coder-34B-Instruct-kosql-adapter
|
18 |
|
19 |
<!-- Provide a quick summary of what the model is/does. -->
|
20 |
-
This Repo contains **LoRA (Low-Rank Adaptation) Adapter** for [unsloth/qwen2.5-coder-32b-instruct]
|
|
|
|
|
21 |
|
22 |
This adapter was created through **instruction tuning**.
|
23 |
|
@@ -29,7 +31,6 @@ This adapter was created through **instruction tuning**.
|
|
29 |
<!-- Provide a longer summary of what this model is. -->
|
30 |
|
31 |
|
32 |
-
|
33 |
- **Base Model:** unsloth/Qwen2.5-Coder-32B-Instruct
|
34 |
- **Task:** Instruction Following(Korean)
|
35 |
- **Language:** English (or relevant language)
|
@@ -47,13 +48,92 @@ To use this LoRA adapter, refer to the following code:
|
|
47 |
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
48 |
|
49 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
```
|
51 |
|
|
|
52 |
### Inference
|
53 |
|
54 |
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
55 |
|
56 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
```
|
58 |
|
59 |
## Bias, Risks, and Limitations
|
|
|
17 |
# 100suping/Qwen2.5-Coder-34B-Instruct-kosql-adapter
|
18 |
|
19 |
<!-- Provide a quick summary of what the model is/does. -->
|
20 |
+
This Repo contains **LoRA (Low-Rank Adaptation) Adapter** for [unsloth/qwen2.5-coder-32b-instruct-bnb-4bit]
|
21 |
+
|
22 |
+
The Adapter was trained for improving model's SQL generation capability in Korean question & multi-db context.
|
23 |
|
24 |
This adapter was created through **instruction tuning**.
|
25 |
|
|
|
31 |
<!-- Provide a longer summary of what this model is. -->
|
32 |
|
33 |
|
|
|
34 |
- **Base Model:** unsloth/Qwen2.5-Coder-32B-Instruct
|
35 |
- **Task:** Instruction Following(Korean)
|
36 |
- **Language:** English (or relevant language)
|
|
|
48 |
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
49 |
|
50 |
```
|
51 |
+
GENERAL_QUERY_PREFIX = """๋น์ ์ ์ฌ์ฉ์์ ์
๋ ฅ์ MySQL ์ฟผ๋ฆฌ๋ฌธ์ผ๋ก ๋ฐ๊พธ์ด์ฃผ๋ ์กฐ์ง์ ํ์์
๋๋ค.
|
52 |
+
๋น์ ์ ์๋ฌด๋ DB ์ด๋ฆ ๊ทธ๋ฆฌ๊ณ DB๋ด ํ
์ด๋ธ์ ๋ฉํ ์ ๋ณด๊ฐ ๋ด๊ธด ์๋์ (context)๋ฅผ ์ด์ฉํด์ ์ฃผ์ด์ง ์ง๋ฌธ(user_question)์ ๊ฑธ๋ง๋ MySQL ์ฟผ๋ฆฌ๋ฌธ์ ์์ฑํ๋ ๊ฒ์
๋๋ค.
|
53 |
+
|
54 |
+
(context)
|
55 |
+
{context}
|
56 |
+
"""
|
57 |
+
|
58 |
+
GENERATE_QUERY_INSTRUCTIONS = """
|
59 |
+
์ฃผ์ด์ง ์ง๋ฌธ(user_question)์ ๋ํด์ ๋ฌธ๋ฒ์ ์ผ๋ก ์ฌ๋ฐ๋ฅธ MySQL ์ฟผ๋ฆฌ๋ฌธ์ ์์ฑํด ์ฃผ์ธ์.
|
60 |
+
"""
|
61 |
+
```
|
62 |
+
|
63 |
+
### Preprocess Functions
|
64 |
+
|
65 |
+
```
|
66 |
+
def get_conversation_data(examples):
|
67 |
+
questions = examples['question']
|
68 |
+
schemas =examples['schema']
|
69 |
+
sql_queries =examples['SQL']
|
70 |
+
convos = []
|
71 |
+
for question, schema, sql in zip(questions, schemas, sql_queries):
|
72 |
+
conv = [
|
73 |
+
{"role": "system", "content": GENERAL_QUERY_PREFIX.format(context=schema) + GENERATE_QUERY_INSTRUCTIONS},
|
74 |
+
{"role": "user", "content": question},
|
75 |
+
{"role": "assistant", "content": "```sql\n"+sql+";\n```"}
|
76 |
+
]
|
77 |
+
convos.append(conv)
|
78 |
+
return {"conversation":convos,}
|
79 |
+
|
80 |
+
def formatting_prompts_func(examples):
|
81 |
+
convos = examples["conversation"]
|
82 |
+
texts = [tokenizer.apply_chat_template(convo, tokenize = False, add_generation_prompt = False) for convo in convos]
|
83 |
+
return { "text" : texts, }
|
84 |
+
```
|
85 |
+
|
86 |
+
### Example input
|
87 |
+
|
88 |
+
```
|
89 |
+
<|im_start|>system
|
90 |
+
๋น์ ์ ์ฌ์ฉ์์ ์
๋ ฅ์ MySQL ์ฟผ๋ฆฌ๋ฌธ์ผ๋ก ๋ฐ๊พธ์ด์ฃผ๋ ์กฐ์ง์ ํ์์
๋๋ค.
|
91 |
+
๋น์ ์ ์๋ฌด๋ DB ์ด๋ฆ ๊ทธ๋ฆฌ๊ณ DB๋ด ํ
์ด๋ธ์ ๋ฉํ ์ ๋ณด๊ฐ ๋ด๊ธด ์๋์ (context)๋ฅผ ์ด์ฉํด์ ์ฃผ์ด์ง ์ง๋ฌธ(user_question)์ ๊ฑธ๋ง๋ MySQL ์ฟผ๋ฆฌ๋ฌธ์ ์์ฑํ๋ ๊ฒ์
๋๋ค.
|
92 |
+
|
93 |
+
(context)
|
94 |
+
DB: movie_platform
|
95 |
+
table DDL: CREATE TABLE `movies` ( `movie_id` INTEGER `movie_title` TEXT `movie_release_year` INTEGER `movie_url` TEXT `movie_title_language` TEXT `movie_popularity` INTEGER `movie_image_url` TEXT `director_id` TEXT `director_name` TEXT `director_url` TEXT PRIMARY KEY (movie_id) FOREIGN KEY (user_id) REFERENCES `lists_users`(user_id) FOREIGN KEY (user_id) REFERENCES `lists_users`(user_id) FOREIGN KEY (user_id) REFERENCES `lists`(user_id) FOREIGN KEY (list_id) REFERENCES `lists`(list_id) FOREIGN KEY (user_id) REFERENCES `ratings_users`(user_id) FOREIGN KEY (user_id) REFERENCES `lists_users`(user_id) FOREIGN KEY (movie_id) REFERENCES `movies`(movie_id) );
|
96 |
+
|
97 |
+
|
98 |
+
์ฃผ์ด์ง ์ง๋ฌธ(user_question)์ ๋ํด์ ๋ฌธ๋ฒ์ ์ผ๋ก ์ฌ๋ฐ๋ฅธ MySQL ์ฟผ๋ฆฌ๋ฌธ์ ์์ฑํด ์ฃผ์ธ์.
|
99 |
+
<|im_end|>
|
100 |
+
<|im_start|>user
|
101 |
+
๊ฐ์ฅ ์ธ๊ธฐ ์๋ ์ํ๋ ๋ฌด์์ธ๊ฐ์? ๊ทธ ์ํ๋ ์ธ์ ๊ฐ๋ด๋์๊ณ ๋๊ฐ ๊ฐ๋
์ธ๊ฐ์?<|im_end|>
|
102 |
+
<|im_start|>assistant
|
103 |
+
```sql
|
104 |
+
SELECT movie_title, movie_release_year, director_name FROM movies ORDER BY movie_popularity DESC LIMIT 1 ;
|
105 |
+
```<|im_end|>
|
106 |
```
|
107 |
|
108 |
+
|
109 |
### Inference
|
110 |
|
111 |
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
112 |
|
113 |
```
|
114 |
+
messages = [
|
115 |
+
{"role": "system", "content": GENERAL_QUERY_PREFIX.format(context=context) + GENERATE_QUERY_INSTRUCTIONS},
|
116 |
+
{"role": "user", "content": "user_question: "+ user_question}
|
117 |
+
]
|
118 |
+
|
119 |
+
|
120 |
+
text = tokenizer.apply_chat_template(
|
121 |
+
messages,
|
122 |
+
tokenize=False,
|
123 |
+
add_generation_prompt=True
|
124 |
+
)
|
125 |
+
|
126 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
127 |
+
|
128 |
+
generated_ids = model.generate(
|
129 |
+
**model_inputs,
|
130 |
+
max_new_tokens=max_new_tokens
|
131 |
+
)
|
132 |
+
generated_ids = [
|
133 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
134 |
+
]
|
135 |
+
|
136 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
137 |
```
|
138 |
|
139 |
## Bias, Risks, and Limitations
|