Update README.md
Browse files
README.md
CHANGED
@@ -121,14 +121,51 @@ We welcome collaboration with:
|
|
121 |
|
122 |
```python
|
123 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
---
|