🚀 医疗-Llama3-8B-4bit:针对医疗问答微调的Llama3模型
本项目是基于LLAMA-3-8B的医疗微调版本,使用常见的开源数据集将其量化为4位。在多语言任务上表现出了显著的提升。采用了标准的比特量化技术进行微调后量化,降低了运行模型所需的计算时间复杂度和空间复杂度。整体架构完全基于LLAMA-3。
本仓库提供了强大的Llama3 8B模型的微调版本,专门设计用于以信息丰富的方式回答医疗问题。它利用了AI医疗聊天机器人数据集(ruslanmv/ai-medical-chatbot)中包含的丰富知识。
🚀 快速开始
本仓库提供了强大的Llama3 8B模型的微调版本,专门设计用于以信息丰富的方式回答医疗问题。它利用了AI医疗聊天机器人数据集(ruslanmv/ai-medical-chatbot)中包含的丰富知识。
✨ 主要特性
- 专注医疗领域:针对健康相关的询问进行了优化。
- 知识储备丰富:在全面的医疗聊天机器人数据集上进行训练。
- 文本生成能力:生成信息丰富且可能有帮助的回复。
📦 安装指南
该模型可通过Hugging Face Transformers库访问。使用pip进行安装:
pip install git+https://github.com/huggingface/accelerate.git
pip install git+https://github.com/huggingface/transformers.git
pip install bitsandbytes
💻 使用示例
基础用法
以下是一个Python代码片段,展示了如何与llama3-8B-medical
模型进行交互,并生成医疗问题的答案:
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import torch
model_id = "ruslanmv/llama3-8B-medical"
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = AutoModelForCausalLM.from_pretrained(model_id, config=quantization_config)
def create_prompt(user_query):
B_INST, E_INST = "<s>[INST]", "[/INST]"
B_SYS, E_SYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
DEFAULT_SYSTEM_PROMPT = """\
You are an AI Medical Chatbot Assistant, provide comprehensive and informative responses to your inquiries.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information."""
SYSTEM_PROMPT = B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS
instruction = f"User asks: {user_query}\n"
prompt = B_INST + SYSTEM_PROMPT + instruction + E_INST
return prompt.strip()
def generate_text(model, tokenizer, prompt,
max_length=200,
temperature=0.8,
num_return_sequences=1):
prompt = create_prompt(user_query)
input_ids = tokenizer.encode(prompt, return_tensors="pt").to(device)
output = model.generate(
input_ids=input_ids,
max_length=max_length,
temperature=temperature,
num_return_sequences=num_return_sequences,
pad_token_id=tokenizer.eos_token_id,
do_sample=True
)
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
generated_text = generated_text.split(prompt)[-1].strip()
return generated_text
user_query = "I'm a 35-year-old male experiencing symptoms like fatigue, increased sensitivity to cold, and dry, itchy skin. Could these be indicative of hypothyroidism?"
generated_text = generate_text(model, tokenizer, user_query)
print(generated_text)
回答类型如下:
Yes, it is possible. Hypothyroidism can present symptoms like increased sensitivity to cold, dry skin, and fatigue. These symptoms are characteristic of hypothyroidism. I recommend consulting with a healthcare provider. 2. Hypothyroidism can present symptoms like fever, increased sensitivity to cold, dry skin, and fatigue. These symptoms are characteristic of hypothyroidism.
📚 详细文档
模型与开发
- 开发者:ruslanmv
- 许可证:Apache-2.0
- 微调基础模型:meta-llama/Meta-Llama-3-8B
重要提示
⚠️ 重要提示
该模型仅用于信息参考,不能替代专业的医疗建议。如有任何医疗问题,请始终咨询合格的医疗保健提供者。
免责声明
💡 使用建议
虽然我们努力提供信息丰富的回复,但不能保证模型输出的准确性。因此,如需明确的医疗建议,务必咨询医生或其他医疗专业人员。
📄 许可证
该模型根据Apache许可证2.0进行分发(详情请参阅LICENSE文件)。
贡献
我们欢迎对本仓库进行贡献!如果您有改进建议或优化方案,请随时创建拉取请求。