Views
No views yet
Please note that the English and Vietnamese versions of this document are translated from the Chinese version using LLM, with manual proofreading. However, discrepancies may still exist. In case of inconsistencies between the English or Vietnamese versions and the Chinese version, the Chinese version shall prevail.
Qwen2.5-3B-Instruct. The fine-tuning process employs the LoRA algorithm and is conducted in two stages, focusing solely on the Chinese language. Initially, during the Pretrain phase, the model undergoes incremental training using medical textbooks, medical records, and healthcare-related articles. Subsequently, Supervised Fine-Tuning (SFT) is performed using corpora that include symptoms and corresponding medical records, doctor-patient dialogues (symptom descriptions and diagnoses), medical knowledge Q&A, and dialogue corpora based on the "LLM Discussion Mechanism." The total data volume is approximately 2.88GB.7GB of VRAM is required. If the VRAM capacity is insufficient or if no dedicated GPU is available, the MKTY-3B large model can also run using CPU + 7GB RAM.Qwen2.5-3B-Instruct model, it can be quickly loaded and launched using the transformers library.1from transformers import AutoModelForCausalLM, AutoTokenizer
2def load_model_and_tokenizer(model_name):
3 model = AutoModelForCausalLM.from_pretrained(
4 model_name,
5 torch_dtype="auto",
6 device_map="auto"
7 )
8 tokenizer = AutoTokenizer.from_pretrained(model_name)
9 return model, tokenizer
10def generate_response(prompt, messages, model, tokenizer, max_new_tokens=2000):
11 messages.append({"role": "user", "content": prompt})
12 text = tokenizer.apply_chat_template(
13 messages,
14 tokenize=False,
15 add_generation_prompt=True
16 )
17 model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
18 generated_ids = model.generate(
19 **model_inputs,
20 max_new_tokens=max_new_tokens
21 )
22 generated_ids = [
23 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
24 ]
25 response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
26 messages.append({"role": "assistant", "content": response})
27 return response1if __name__ == "__main__":
2 model_name = r"MKTY-3B-Chat"
3 messages = []
4 model, tokenizer = load_model_and_tokenizer(model_name)
5 while True:
6 prompt = input("User> ")
7 if prompt == "exit":
8 break
9 response = generate_response(prompt, messages, model, tokenizer)
10 print("MKTY>", response)1if __name__ == "__main__":
2 model_name = "MKTY-3B-Chat"
3 discuss_rounds = 3
4 agent_number = 3
5 model, tokenizer = load_model_and_tokenizer(model_name)
6 messages_arr = [[] for _ in range(agent_number)]
7 while True:
8 prompt = input("User> ")
9 if prompt == "exit":
10 break
11 moderator_opinion = "暂无"
12 for i in range(discuss_rounds):
13 responses_arr = []
14 prompt_per_round = "- 问题:\n" + prompt + "\n - 上轮讨论主持人意见:\n" + moderator_opinion + "\n - 请你结合主持人意见,对上述医疗或医学专业的问题发表详细观点,可以质疑并说明理由。\n"
15 for j in range(agent_number):
16 messages = messages_arr[j]
17 response = generate_response(prompt_per_round, messages, model, tokenizer)
18 responses_arr.append(response)
19 print(f"第{i + 1}轮讨论,LLM {j + 1}观点>\n", response)
20 print("-------------------")
21 moderator_prompt = "- 问题:\n" + prompt + "\n\n"
22 for res_index in range(len(responses_arr)):
23 moderator_prompt = moderator_prompt + f"- LLM {res_index + 1}观点:\n" + responses_arr[res_index] + "\n\n"
24 moderator_prompt = moderator_prompt + "对于给定的医疗相关问题,请综合各LLM观点,结合自身知识,得出你自己的判断,尽可能详尽,全部都分析到位,还要充分说明理由。\n"
25 moderator_opinion = generate_response(moderator_prompt, [], model, tokenizer)
26 print(f"第{i + 1}轮讨论,主持人的意见>\n", moderator_opinion)
27 print("-------------------")
28 clear_history(messages_arr)
29 ██\ ██\ ██\ ██\ ████████\ ██\ ██\
███\ ███ | ██ | ██ | \__██ __| \██\ ██ |
████\ ████ | ██ |██ / ██ | \██\ ██ /
██\██\██ ██ | █████ / ██ | \████ /
██ \███ ██ | ██ ██< ██ | \██ /
██ |\█ /██ | ██ |\██\ ██ | ██ |
██ | \_/ ██ |██\ ██ | \██\ ██\ ██ |██\ ██ |██\
\__| \__|\__|\__| \__|\__| \__|\__| \__|\__|@software{du_2025_17444889,
author = {Du, Yu},
title = {Minh Khoe Tue Y Smart Healthcare System},
month = oct,
year = 2025,
publisher = {Zenodo},
version = {v1.1.2},
doi = {10.5281/zenodo.17444889},
url = {https://github.com/duyu09/MKTY-System},
swhid = {swh:1:dir:a633243bf04e6ba18e2d5ffcf92ea57f73566f43
;origin=https://doi.org/10.5281/zenodo.17444888;vi
sit=swh:1:snp:37dc91d2c166a07c7dc8ebac0b4be97961b0
267b;anchor=swh:1:rel:a88f82a5ca10d278bcc10734f5cf
a560286a8b47;path=duyu09-MKTY-System-8edd0c9
},
}