easypyeong commited on
Commit
acb6237
Β·
verified Β·
1 Parent(s): b416124

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -36
README.md CHANGED
@@ -125,46 +125,49 @@ import torch
125
 
126
  # Load tokenizer and model
127
  model_name = "snuh/hari-q2.5"
128
- tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
129
- model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
130
- model.eval()
131
 
132
- # Define multi-turn chat in ChatML format
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  messages = [
134
- {
135
- "role": "system",
136
- "content": "You are a helpful and knowledgeable Korean medical assistant. Answer the user's question accurately based on clinical reasoning."
137
- },
138
- {
139
- "role": "user",
140
- "content": (
141
- "60μ„Έ 남성이 볡톡과 λ°œμ—΄μ„ ν˜Έμ†Œν•˜λ©° λ‚΄μ›ν•˜μ˜€μŠ΅λ‹ˆλ‹€. "
142
- "ν˜ˆμ•‘ 검사 κ²°κ³Ό 백혈ꡬ μˆ˜μΉ˜κ°€ μƒμŠΉν–ˆκ³ , 우츑 ν•˜λ³΅λΆ€ 압톡이 ν™•μΈλ˜μ—ˆμŠ΅λ‹ˆλ‹€. "
143
- "κ°€μž₯ κ°€λŠ₯성이 높은 진단λͺ…은 λ¬΄μ—‡μΈκ°€μš”?"
144
- )
145
- }
 
 
 
 
146
  ]
147
 
148
- # Apply ChatML template
149
- prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
150
-
151
- # Tokenize input
152
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
153
-
154
- # Generate model output
155
- with torch.no_grad():
156
- outputs = model.generate(
157
- **inputs,
158
- max_new_tokens=128,
159
- do_sample=True,
160
- temperature=0.7,
161
- top_p=0.9,
162
- eos_token_id=tokenizer.eos_token_id,
163
- )
164
-
165
- # Decode and display response
166
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
167
- print("🧠 Model Response:\n")
168
  print(response)
169
  ````
170
 
 
125
 
126
  # Load tokenizer and model
127
  model_name = "snuh/hari-q2.5"
 
 
 
128
 
129
+ model = AutoModelForCausalLM.from_pretrained(
130
+ model_name,
131
+ torch_dtype="auto",
132
+ device_map="auto"
133
+ )
134
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
135
+
136
+ prompt = '''
137
+ ### Instruction:
138
+ 당신은 μž„μƒ 지식을 κ°–μΆ˜ 유λŠ₯ν•˜κ³  μ‹ λ’°ν•  수 μžˆλŠ” ν•œκ΅­μ–΄ 기반 의료 μ–΄μ‹œμŠ€ν„΄νŠΈμž…λ‹ˆλ‹€.
139
+ μ‚¬μš©μžμ˜ μ§ˆλ¬Έμ— λŒ€ν•΄ μ •ν™•ν•˜κ³  μ‹ μ€‘ν•œ μž„μƒ 좔둠을 λ°”νƒ•μœΌλ‘œ 진단 κ°€λŠ₯성을 μ œμ‹œν•΄ μ£Όμ„Έμš”.
140
+ λ°˜λ“œμ‹œ ν™˜μžμ˜ μ—°λ Ή, 증상, 검사 κ²°κ³Ό, 톡증 λΆ€μœ„ λ“± λͺ¨λ“  λ‹¨μ„œλ₯Ό μ’…ν•©μ μœΌλ‘œ κ³ λ €ν•˜μ—¬ μΆ”λ‘  κ³Όμ •κ³Ό 진단λͺ…을 μ œμ‹œν•΄μ•Ό ν•©λ‹ˆλ‹€.
141
+ μ˜ν•™μ μœΌλ‘œ μ •ν™•ν•œ μš©μ–΄λ₯Ό μ‚¬μš©ν•˜λ˜, ν•„μš”ν•˜λ‹€λ©΄ 일반인이 μ΄ν•΄ν•˜κΈ° μ‰¬μš΄ μš©μ–΄λ„ 병행해 μ„€λͺ…ν•΄ μ£Όμ„Έμš”.
142
+
143
+ ### Question:
144
+ 60μ„Έ 남성이 볡톡과 λ°œμ—΄μ„ ν˜Έμ†Œν•˜λ©° λ‚΄μ›ν•˜μ˜€μŠ΅λ‹ˆλ‹€.
145
+ ν˜ˆμ•‘ 검사 κ²°κ³Ό 백혈ꡬ μˆ˜μΉ˜κ°€ μƒμŠΉν–ˆκ³ , 우츑 ν•˜λ³΅λΆ€ 압톡이 ν™•μΈλ˜μ—ˆμŠ΅λ‹ˆλ‹€.
146
+ κ°€μž₯ κ°€λŠ₯성이 높은 진단λͺ…은 λ¬΄μ—‡μΈκ°€μš”?
147
+
148
+ ### Reasoning:
149
+ '''.strip()
150
+
151
  messages = [
152
+ {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
153
+ {"role": "user", "content": prompt}
154
+ ]
155
+ text = tokenizer.apply_chat_template(
156
+ messages,
157
+ tokenize=False,
158
+ add_generation_prompt=True
159
+ )
160
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
161
+
162
+ generated_ids = model.generate(
163
+ **model_inputs,
164
+ max_new_tokens=512
165
+ )
166
+ generated_ids = [
167
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
168
  ]
169
 
170
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  print(response)
172
  ````
173