Tierney commited on
Commit
b9e60e4
·
verified ·
1 Parent(s): c5da26e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +47 -19
README.md CHANGED
@@ -1,18 +1,10 @@
1
- ---
2
- license: apache-2.0
3
- datasets:
4
- - FreedomIntelligence/medical-o1-reasoning-SFT
5
- language:
6
- - zh
7
- base_model:
8
- - deepseek-ai/DeepSeek-R1-Distill-Qwen-14B
9
- ---
10
- # DeepSeek-R1-14B Merged Model
11
 
12
  ## 📌 模型简介
 
13
  本模型基于 **DeepSeek-R1-Distill-Qwen-14B** 进行微调,并已合并 LoRA 适配器,形成独立可用的完整模型,适用于医学领域的问答和推理任务。
14
 
15
- - 🔹 **基座模型**: [deepseek-ai/DeepSeek-R1-Distill-Qwen-14B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B)
16
  - 🔹 **微调方法**: LoRA + 合并 (`merged_16bit`)
17
  - 🔹 **适用场景**: 医学文本问答、医学知识增强
18
  - 🔹 **模型格式**: `fp16`
@@ -22,27 +14,61 @@ base_model:
22
  ## 📂 使用方法
23
 
24
  ### 🔄 直接加载模型
 
25
  合并后的模型可以直接加载并进行推理,无需额外加载 LoRA 适配器。
 
26
  ```python
27
- from transformers import AutoModelForCausalLM, AutoTokenizer
 
 
 
28
 
29
- merged_model = "your-huggingface-username/deepseek-r1-14b-merged-med"
 
 
30
 
31
- tokenizer = AutoTokenizer.from_pretrained(merged_model)
32
- model = AutoModelForCausalLM.from_pretrained(merged_model, torch_dtype="auto", device_map="auto")
 
 
 
 
 
33
  ```
34
 
35
  ### 🚀 推理示例
 
36
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  input_text = "请问阿司匹林的主要适应症是什么?"
38
- inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
39
- outputs = model.generate(**inputs, max_length=200)
40
- print(tokenizer.decode(outputs[0], skip_special_tokens=True))
 
 
 
 
41
  ```
42
 
43
  ---
44
 
45
  ## 🏗️ 训练信息
 
46
  - **训练环境**: RTX 4090, CUDA 12.6, WSL Ubuntu
47
  - **训练框架**: `transformers` + `peft` + `unsloth`
48
  - **训练参数**:
@@ -55,9 +81,11 @@ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
55
  ---
56
 
57
  ## 📜 许可证
 
58
  本模型基于 **DeepSeek-R1-Distill-Qwen-14B**,请遵守其[官方许可证](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B)。
59
 
60
  ---
61
 
62
  ## 📞 联系方式
63
- 如果你有任何问题或建议,可以在 Hugging Face 讨论区留言,或者联系我!
 
 
1
+ # DeepSeek-R1-Distill-Qwen-14B Merged Model
 
 
 
 
 
 
 
 
 
2
 
3
  ## 📌 模型简介
4
+
5
  本模型基于 **DeepSeek-R1-Distill-Qwen-14B** 进行微调,并已合并 LoRA 适配器,形成独立可用的完整模型,适用于医学领域的问答和推理任务。
6
 
7
+ - 🔹 **基座模型**: [deepseek-ai/DeepSeek-R1-Distill-Qwen-14B](https://huggingface.co/models/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B)
8
  - 🔹 **微调方法**: LoRA + 合并 (`merged_16bit`)
9
  - 🔹 **适用场景**: 医学文本问答、医学知识增强
10
  - 🔹 **模型格式**: `fp16`
 
14
  ## 📂 使用方法
15
 
16
  ### 🔄 直接加载模型
17
+
18
  合并后的模型可以直接加载并进行推理,无需额外加载 LoRA 适配器。
19
+
20
  ```python
21
+ from unsloth import FastLanguageModel
22
+ from transformers import TextStreamer
23
+
24
+ merged_model = ""
25
 
26
+ max_seq_length = 1280
27
+ dtype = None
28
+ load_in_4bit = True
29
 
30
+ model, tokenizer = FastLanguageModel.from_pretrained(
31
+ "Tierney/DeepSeek-Qwen-14B-R1-Medical-Doctor",
32
+ max_seq_length=max_seq_length,
33
+ dtype=dtype,
34
+ load_in_4bit=load_in_4bit,
35
+ )
36
+ tokenizer.pad_token = "<|endoftext|>"
37
  ```
38
 
39
  ### 🚀 推理示例
40
+
41
  ```python
42
+ prompt_style = """以下是描述任务的说明,并附有提供进一步背景的输入。
43
+ 请写一个恰当的回应,完成该任务。
44
+ 在回答之前,请仔细思考问题,并创建一个逐步的思维链,以确保逻辑清晰且准确。
45
+
46
+ ### 任务描述:
47
+ 您是一位在临床推理、诊断和治疗计划方面具有高级知识的医学专家。
48
+ 请回答以下医学问题。
49
+
50
+ ### 问题:
51
+ {}
52
+
53
+ ### 回答:
54
+ {}"""
55
+ question = f"患者姓名:{name},年龄:{age},医疗情况:{medical},检查情况:{instra},请根据这些信息给出诊断和建议。"
56
+ prompt = prompt_style.format(question, "")
57
+
58
  input_text = "请问阿司匹林的主要适应症是什么?"
59
+ FastLanguageModel.for_inference(model)
60
+ inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
61
+
62
+ text_streamer = TextStreamer(tokenizer)
63
+ outputs = model.generate(**inputs, streamer=text_streamer, max_new_tokens=1024)
64
+ answer = tokenizer.decode(outputs[0], skip_special_tokens=True).split("### 回答:")[-1].strip()
65
+
66
  ```
67
 
68
  ---
69
 
70
  ## 🏗️ 训练信息
71
+
72
  - **训练环境**: RTX 4090, CUDA 12.6, WSL Ubuntu
73
  - **训练框架**: `transformers` + `peft` + `unsloth`
74
  - **训练参数**:
 
81
  ---
82
 
83
  ## 📜 许可证
84
+
85
  本模型基于 **DeepSeek-R1-Distill-Qwen-14B**,请遵守其[官方许可证](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B)。
86
 
87
  ---
88
 
89
  ## 📞 联系方式
90
+
91
+ 如果你有任何问题或建议,可以在讨论区留言,或者联系我!