DeathReaper0965 commited on
Commit
4eca7c1
·
verified ·
1 Parent(s): 13b13d3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -16
README.md CHANGED
@@ -34,12 +34,14 @@ config = PeftConfig.from_pretrained("DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoni
34
 
35
  model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-3B-Instruct", max_length=2560)
36
  model = PeftModel.from_pretrained(model, "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO", is_trainable=False)
 
37
  tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-3B-Instruct", max_length = 2560)
38
 
39
- prompt = [
40
- {
41
- 'role': 'system',
42
- 'content': """\
 
43
  You are an expert SQL Query Writer.
44
  Given relevant Schemas and the Question, you first understand the problem entirely and then reason about the best possible approach to come up with an answer.
45
  Once, you are confident in your reasoning, you will then start generating the SQL Query as the answer that accurately solves the given question leveraging some or all schemas.
@@ -58,13 +60,26 @@ FROM TABLE_NAME
58
  WHERE
59
  CONDITION
60
  </answer>"""
61
- },
62
- {
63
- 'role': 'user',
64
- 'content': """\
65
  SCHEMAS:
66
  ---------------
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  CREATE TABLE lab (
69
  subject_id text,
70
  hadm_id text,
@@ -127,23 +142,23 @@ CREATE TABLE prescriptions (
127
  formulary_drug_cd text,
128
  route text,
129
  drug_dose text
130
- )
 
131
 
132
- ---------------
133
 
134
- QUESTION: "how many patients whose admission type is emergency and diagnoses icd9 code is 56210?"
135
- """
136
- }
137
- ]
138
 
139
- inputs = tokenizer.apply_chat_template(prompt,
140
  tokenize=True,
141
  add_generation_prompt=True,
142
  return_dict=True,
143
  return_tensors="pt")
144
 
145
  with torch.inference_mode():
146
- outputs = model.generate(**inputs, max_new_tokens=256)
147
 
148
  outputs = tokenizer.batch_decode(outputs)
149
  print(outputs[0].split("<|im_start|>assistant")[-1])
 
34
 
35
  model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-3B-Instruct", max_length=2560)
36
  model = PeftModel.from_pretrained(model, "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO", is_trainable=False)
37
+
38
  tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-3B-Instruct", max_length = 2560)
39
 
40
+ def create_prompt(schemas, question):
41
+ prompt = [
42
+ {
43
+ 'role': 'system',
44
+ 'content': """\
45
  You are an expert SQL Query Writer.
46
  Given relevant Schemas and the Question, you first understand the problem entirely and then reason about the best possible approach to come up with an answer.
47
  Once, you are confident in your reasoning, you will then start generating the SQL Query as the answer that accurately solves the given question leveraging some or all schemas.
 
60
  WHERE
61
  CONDITION
62
  </answer>"""
63
+ },
64
+ {
65
+ 'role': 'user',
66
+ 'content': f"""\
67
  SCHEMAS:
68
  ---------------
69
 
70
+ {schemas}
71
+
72
+ ---------------
73
+
74
+ QUESTION: "{question}"\
75
+ """
76
+ }
77
+ ]
78
+
79
+ return prompt
80
+
81
+
82
+ schemas = """\
83
  CREATE TABLE lab (
84
  subject_id text,
85
  hadm_id text,
 
142
  formulary_drug_cd text,
143
  route text,
144
  drug_dose text
145
+ )\
146
+ """
147
 
148
+ question = "How many patients whose admission type is emergency and diagnoses icd9 code is 56210?"
149
 
150
+ example_prompt = create_prompt(schemas, question)
151
+
152
+ streamer = TextStreamer(tokenizer, skip_prompt=True)
 
153
 
154
+ inputs = tokenizer.apply_chat_template(example_prompt,
155
  tokenize=True,
156
  add_generation_prompt=True,
157
  return_dict=True,
158
  return_tensors="pt")
159
 
160
  with torch.inference_mode():
161
+ outputs = model.generate(**inputs, max_new_tokens=1024, streamer=streamer)
162
 
163
  outputs = tokenizer.batch_decode(outputs)
164
  print(outputs[0].split("<|im_start|>assistant")[-1])