Introduction
This repo contains Physician-Ko-8B, a medical language model with 8 billion parameters. This model builds upon the foundation of LLaMA-3-physician-8b-instruct model fine-tuned with a Korean dataset.
Datasets
- beomi/KoAlpaca-RealQA
- beomi/KoAlpaca-v1.1a
- https://www.aihub.or.kr/aihubdata/data/view.do?currMenu=115&topMenu=100&dataSetSn=71762
Approach 1
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_name = "eded0902/Physician-Ko-8B"
tokenizer_name = "YiDuo1999/Llama-3-Physician-8B-Instruct"
device_map = 'auto'
model = AutoModelForCausalLM.from_pretrained( model_name, trust_remote_code=True,use_cache=False,device_map=device_map)
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, trust_remote_code=True)
tokenizer.chat_template = "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}"
eos_token_id = [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|eot_id|>"), tokenizer.convert_tokens_to_ids("<|im_end|>")]
tokenizer.pad_token = tokenizer.eos_token
def askme(question):
sys_message = '''
You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and
provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help.
'''
# Create messages structured for the chat template
messages = [{"role": "system", "content": sys_message}, {"role": "user", "content": question}]
# Applying chat template
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=1000, use_cache=True)
# Extract and return the generated text, removing the prompt
response_text = tokenizer.batch_decode(outputs)[0].strip()
answer = response_text.split('<|im_start|>assistant')[-1].split('<|im_end|>')[0].strip()
return answer
# Example usage
# - Context: First describe your problem.
# - Question: Then make the question.
question = '''HIV๊ฐ ๋ญ์ผ?'''
print(askme(question))
the type of answer is:
'HIV๋ Human Immunodeficiency Virus์ ์ฝ์๋ก, ์ธ์ฒด ๋ฉด์ญ๊ฒฐํ ๋ฐ์ด๋ฌ์ค๋ผ๊ณ ๋ ๋ถ๋ฆฝ๋๋ค. ์ด ๋ฐ์ด๋ฌ์ค๋ ์ธ๊ฐ์ ๋ฉด์ญ ์ฒด๊ณ๋ฅผ ์ฝํ์ํค๋ ๋ฐ์ด๋ฌ์ค๋ก, ์ธ์ฒด์ ๋ฉด์ญ ์ธํฌ๋ฅผ ๊ณต๊ฒฉํ์ฌ ๋ฉด์ญ๋ ฅ์ ๊ฐ์์ํต๋๋ค. HIV์ ๊ฐ์ผ๋๋ฉด ์ธ์ฒด์ ๋ฉด์ญ ์ฒด๊ณ๊ฐ ์ฝํด์ ธ ๋ค์ํ ๊ฐ์ผ์ฑ ์งํ๊ณผ ์ข
์์ด ๋ฐ์ํ ์ ์์ต๋๋ค. HIV ๊ฐ์ผ์ ์๋ฐฉํ๊ธฐ ์ํด์๋ ์์ ํ ์ฑ๊ด๊ณ ์ ์ง, ํ์ก ๋ฐ ํ์ก ์ ์ ์ ๊ณต์ ๋ฅผ ํผํ๋ ๋ฑ์ ์๋ฐฉ ์กฐ์น๊ฐ ํ์ํฉ๋๋ค.
Approach 2
Using langchain
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
from langchain.llms.huggingface_pipeline import HuggingFacePipeline
from langchain_core.prompts import PromptTemplate
model_name = "eded0902/Physician-Ko-8B"
tokenizer_name = "YiDuo1999/Llama-3-Physician-8B-Instruct"
device_map = 'auto'
model = AutoModelForCausalLM.from_pretrained( model_name, trust_remote_code=True,use_cache=False,device_map=device_map)
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, trust_remote_code=True)
tokenizer.chat_template = "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}"
eos_token_id = [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|eot_id|>"), tokenizer.convert_tokens_to_ids("<|im_end|>")]
tokenizer.pad_token = tokenizer.eos_token
pipe = pipeline("text-generation",
model=model,
tokenizer=tokenizer,
max_new_tokens=512
)
hf = HuggingFacePipeline(pipeline=pipe)
sys_message = """ You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and
provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help.
"""
question = "HIV๊ฐ ๋ญ์ผ?"
# Create messages structured for the chat template
messages = [{"role": "system", "content": sys_message}, {"role": "user", "content": question}]
# Applying chat template
template = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
prompt = PromptTemplate.from_template(template)
chain = prompt | hf
print(chain.invoke({"question": question})[len(template):].split('<|im_end|>')[0].strip())
the type of answer is:
HIV๋ ์ธ๊ฐ ๋ฉด์ญ ๊ฒฐํ ๋ฐ์ด๋ฌ์ค(Human Immunodeficiency Virus, HIV)์ ์ฝ์์
๋๋ค. ์ด ๋ฐ์ด๋ฌ์ค๋ ์ธ์ฒด์ ๋ฉด์ญ ์ฒด๊ณ๋ฅผ ์ฝํ์์ผ ๊ฐ์ผ์ ์ผ์ผํค๋ ๋ฐ์ด๋ฌ์ค์
๋๋ค. HIV๋ ์ฃผ๋ก ์ฑ์ ์ ์ด, ํ์ก ์ ํ, ํ์ ๊ฐ์ผ ๋ฑ์ ํตํด ์ ํ๋ฉ๋๋ค. HIV์ ๊ฐ์ผ๋๋ฉด ๋ฉด์ญ ์ธํฌ๋ค์ด ํ๊ดด๋์ด ๋ค์ํ ๊ฐ์ผ์ฑ ์งํ๊ณผ ์ข
์์ด ๋ฐ์ํ ์ ์์ต๋๋ค. HIV ๊ฐ์ผ์ ์๋ฐฉํ๊ธฐ ์ํด์๋ ์์ ํ ์ฑํ์์ ํ์ก ๋ฐ ํ์ก ์ ํ์ ์์ ํ ์ฌ์ฉ์ด ์ค์ํฉ๋๋ค. ๋ํ HIV ๊ฐ์ผ ์ฌ๋ถ๋ฅผ ํ์ธํ๊ธฐ ์ํด ์ ๊ธฐ์ ์ธ ๊ฒ์ฌ๋ฅผ ๋ฐ๋ ๊ฒ์ด ํ์ํฉ๋๋ค.
- Downloads last month
- 0
Inference Providers
NEW
This model is not currently available via any of the supported third-party Inference Providers, and
the model is not deployed on the HF Inference API.
Model tree for eded0902/Physician-Ko-8B
Base model
YiDuo1999/Llama-3-Physician-8B-Instruct