easypyeong commited on
Commit
bb6834d
ยท
verified ยท
1 Parent(s): edfe719

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -8
README.md CHANGED
@@ -121,14 +121,51 @@ We welcome collaboration with:
121
 
122
  ```python
123
  from transformers import AutoTokenizer, AutoModelForCausalLM
124
-
125
- tokenizer = AutoTokenizer.from_pretrained("snuh/hari-q2.5")
126
- model = AutoModelForCausalLM.from_pretrained("snuh/hari-q2.5")
127
-
128
- prompt = "๋‹ค์Œ ํ™˜์ž์˜ ์ฃผ์š” ์ง„๋‹จ์€ ๋ฌด์—‡์ธ๊ฐ€์š”? ํ™˜์ž ์ •๋ณด: 60์„ธ ๋‚จ์„ฑ, ๋ณตํ†ต, ๋ฐœ์—ด, ๋ฐฑํ˜ˆ๊ตฌ ์ฆ๊ฐ€..."
129
- inputs = tokenizer(prompt, return_tensors="pt")
130
- outputs = model.generate(**inputs, max_new_tokens=100)
131
- print(tokenizer.decode(outputs[0], skip_special_tokens=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  ````
133
 
134
  ---
 
121
 
122
  ```python
123
  from transformers import AutoTokenizer, AutoModelForCausalLM
124
+ 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
 
171
  ---