Update README.md
Browse files
README.md
CHANGED
|
@@ -1,238 +1,111 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
---
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
path_or_fileobj="model_card.md",
|
| 47 |
-
path_in_repo="README.md",
|
| 48 |
-
repo_id=repo_id,
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
## Model Details
|
| 52 |
-
|
| 53 |
-
### Model Description
|
| 54 |
-
|
| 55 |
-
<!-- Provide a longer summary of what this model is. -->
|
| 56 |
-
|
| 57 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
| 58 |
-
|
| 59 |
-
- **Developed by:** [More Information Needed]
|
| 60 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 61 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 62 |
-
- **Model type:** [More Information Needed]
|
| 63 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 64 |
-
- **License:** [More Information Needed]
|
| 65 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 66 |
-
|
| 67 |
-
### Model Sources [optional]
|
| 68 |
-
|
| 69 |
-
<!-- Provide the basic links for the model. -->
|
| 70 |
-
|
| 71 |
-
- **Repository:** [More Information Needed]
|
| 72 |
-
- **Paper [optional]:** [More Information Needed]
|
| 73 |
-
- **Demo [optional]:** [More Information Needed]
|
| 74 |
-
|
| 75 |
-
## Uses
|
| 76 |
-
|
| 77 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 78 |
-
|
| 79 |
-
### Direct Use
|
| 80 |
-
|
| 81 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 82 |
-
|
| 83 |
-
[More Information Needed]
|
| 84 |
-
|
| 85 |
-
### Downstream Use [optional]
|
| 86 |
-
|
| 87 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 88 |
-
|
| 89 |
-
[More Information Needed]
|
| 90 |
-
|
| 91 |
-
### Out-of-Scope Use
|
| 92 |
-
|
| 93 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 94 |
-
|
| 95 |
-
[More Information Needed]
|
| 96 |
-
|
| 97 |
-
## Bias, Risks, and Limitations
|
| 98 |
-
|
| 99 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
-
|
| 103 |
-
### Recommendations
|
| 104 |
-
|
| 105 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 106 |
-
|
| 107 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 108 |
-
|
| 109 |
-
## How to Get Started with the Model
|
| 110 |
-
|
| 111 |
-
Use the code below to get started with the model.
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
## Training Details
|
| 116 |
-
|
| 117 |
-
### Training Data
|
| 118 |
-
|
| 119 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 120 |
-
|
| 121 |
-
[More Information Needed]
|
| 122 |
-
|
| 123 |
-
### Training Procedure
|
| 124 |
-
|
| 125 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 126 |
-
|
| 127 |
-
#### Preprocessing [optional]
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
#### Training Hyperparameters
|
| 133 |
-
|
| 134 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 135 |
-
|
| 136 |
-
#### Speeds, Sizes, Times [optional]
|
| 137 |
-
|
| 138 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 139 |
-
|
| 140 |
-
[More Information Needed]
|
| 141 |
-
|
| 142 |
-
## Evaluation
|
| 143 |
-
|
| 144 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 145 |
-
|
| 146 |
-
### Testing Data, Factors & Metrics
|
| 147 |
-
|
| 148 |
-
#### Testing Data
|
| 149 |
-
|
| 150 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 151 |
-
|
| 152 |
-
[More Information Needed]
|
| 153 |
-
|
| 154 |
-
#### Factors
|
| 155 |
-
|
| 156 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 157 |
-
|
| 158 |
-
[More Information Needed]
|
| 159 |
-
|
| 160 |
-
#### Metrics
|
| 161 |
-
|
| 162 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 163 |
-
|
| 164 |
-
[More Information Needed]
|
| 165 |
-
|
| 166 |
-
### Results
|
| 167 |
-
|
| 168 |
-
[More Information Needed]
|
| 169 |
-
|
| 170 |
-
#### Summary
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
## Model Examination [optional]
|
| 175 |
-
|
| 176 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 177 |
-
|
| 178 |
-
[More Information Needed]
|
| 179 |
-
|
| 180 |
-
## Environmental Impact
|
| 181 |
-
|
| 182 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 183 |
-
|
| 184 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 185 |
-
|
| 186 |
-
- **Hardware Type:** [More Information Needed]
|
| 187 |
-
- **Hours used:** [More Information Needed]
|
| 188 |
-
- **Cloud Provider:** [More Information Needed]
|
| 189 |
-
- **Compute Region:** [More Information Needed]
|
| 190 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 191 |
-
|
| 192 |
-
## Technical Specifications [optional]
|
| 193 |
-
|
| 194 |
-
### Model Architecture and Objective
|
| 195 |
-
|
| 196 |
-
[More Information Needed]
|
| 197 |
-
|
| 198 |
-
### Compute Infrastructure
|
| 199 |
-
|
| 200 |
-
[More Information Needed]
|
| 201 |
-
|
| 202 |
-
#### Hardware
|
| 203 |
-
|
| 204 |
-
[More Information Needed]
|
| 205 |
-
|
| 206 |
-
#### Software
|
| 207 |
-
|
| 208 |
-
[More Information Needed]
|
| 209 |
-
|
| 210 |
-
## Citation [optional]
|
| 211 |
-
|
| 212 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 213 |
-
|
| 214 |
-
**BibTeX:**
|
| 215 |
-
|
| 216 |
-
[More Information Needed]
|
| 217 |
-
|
| 218 |
-
**APA:**
|
| 219 |
|
| 220 |
-
|
|
|
|
| 221 |
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
-
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
|
|
|
|
| 227 |
|
| 228 |
-
##
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
-
|
|
|
|
| 235 |
|
| 236 |
-
##
|
|
|
|
| 237 |
|
| 238 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# DeepSeek-R1-LoRA-medical
|
| 2 |
+
|
| 3 |
+
## Giới thiệu
|
| 4 |
+
|
| 5 |
+
Đây là bộ LoRA adapters được fine-tune trên mô hình gốc `unsloth/DeepSeek-R1-Distill-Llama-8B` để hỗ trợ trả lời các câu hỏi y khoa. Bộ adapters này được huấn luyện trên tập dữ liệu `hieulum/bacsiAI` (200 mẫu đầu tiên) với cấu hình LoRA tối ưu, giúp cải thiện khả năng trả lời các câu hỏi về chẩn đoán, điều trị và lập kế hoạch điều trị y tế.
|
| 6 |
+
|
| 7 |
+
### Thông tin mô hình
|
| 8 |
+
- **Mô hình gốc**: `unsloth/DeepSeek-R1-Distill-Llama-8B`
|
| 9 |
+
- **Dataset**: `hieulum/bacsiAI` (200 mẫu)
|
| 10 |
+
- **Cấu hình LoRA**:
|
| 11 |
+
- Rank (`r`): 16
|
| 12 |
+
- LoRA alpha: 16
|
| 13 |
+
- Các module mục tiêu: `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`
|
| 14 |
+
- **Thông tin huấn luyện**:
|
| 15 |
+
- Số epoch: 1
|
| 16 |
+
- Tổng số bước: 60
|
| 17 |
+
- Batch size hiệu quả: 8 (2 per device × 4 gradient accumulation steps)
|
| 18 |
+
- Learning rate: 2e-4
|
| 19 |
+
- Optimizer: AdamW 8-bit
|
| 20 |
+
- **Kích thước LoRA adapters**: ~168 MB
|
| 21 |
+
- **Giấy phép**: Apache 2.0 (hoặc thay bằng giấy phép bạn chọn)
|
| 22 |
+
|
| 23 |
+
## Các file trong repository
|
| 24 |
+
- `adapter_config.json`: Cấu hình LoRA adapters.
|
| 25 |
+
- `adapter_model.safetensors`: Trọng số LoRA adapters (168 MB).
|
| 26 |
+
- `tokenizer_config.json`: Cấu hình tokenizer.
|
| 27 |
+
- `tokenizer.json`: Từ vựng tokenizer.
|
| 28 |
+
- `special_tokens_map.json`: Ánh xạ các token đặc biệt.
|
| 29 |
+
|
| 30 |
+
## Hướng dẫn sử dụng
|
| 31 |
+
|
| 32 |
+
### Yêu cầu
|
| 33 |
+
- **Thư viện**:
|
| 34 |
+
```bash
|
| 35 |
+
pip install unsloth transformers huggingface_hub torch
|
| 36 |
+
```
|
| 37 |
+
- **Phần cứng**: GPU với ít nhất 16GB VRAM (ví dụ: NVIDIA Tesla T4).
|
| 38 |
+
- **Python**: 3.8 hoặc cao hơn.
|
| 39 |
+
- **Hugging Face token**: Để tải mô hình gốc (nếu cần).
|
| 40 |
+
|
| 41 |
+
### Bước 1: Cài đặt môi trường
|
| 42 |
+
Cài đặt các thư viện cần thiết:
|
| 43 |
+
```bash
|
| 44 |
+
pip install unsloth==2024.9 transformers huggingface_hub torch==2.4.0
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
### Bước 2: Tải mô hình gốc và LoRA adapters
|
| 48 |
+
Sử dụng đoạn code sau để tải mô hình gốc và áp dụng LoRA adapters:
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from unsloth import FastLanguageModel
|
| 52 |
+
import torch
|
| 53 |
+
|
| 54 |
+
# Tải mô hình gốc
|
| 55 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 56 |
+
model_name="unsloth/DeepSeek-R1-Distill-Llama-8B",
|
| 57 |
+
max_seq_length=1024, # Có thể điều chỉnh
|
| 58 |
+
load_in_4bit=True, # Sử dụng 4-bit quantization để tiết kiệm bộ nhớ
|
| 59 |
+
token="your_hugging_face_token", # Thay bằng token của bạn
|
| 60 |
)
|
| 61 |
|
| 62 |
+
# Tải LoRA adapters
|
| 63 |
+
model = FastLanguageModel.load_peft_model(
|
| 64 |
+
model,
|
| 65 |
+
"hieulum/DeepSeek-R1-LoRA-BacsiAI"
|
| 66 |
|
| 67 |
+
# Chuẩn bị mô hình cho inference
|
| 68 |
+
model = FastLanguageModel.for_inference(model)
|
| 69 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
### Bước 3: Chạy inference
|
| 72 |
+
Ví dụ về cách chạy inference với một câu hỏi y khoa:
|
| 73 |
|
| 74 |
+
```python
|
| 75 |
+
# Chuẩn bị input
|
| 76 |
+
question = "Phương pháp điều trị tăng huyết áp là gì?"
|
| 77 |
+
inputs = tokenizer(question, return_tensors="pt").to("cuda")
|
| 78 |
|
| 79 |
+
# Tạo output
|
| 80 |
+
outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.7)
|
| 81 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 82 |
|
| 83 |
+
print(response)
|
| 84 |
+
```
|
| 85 |
|
| 86 |
+
### Lưu ý
|
| 87 |
+
- **Max sequence length**: Được đặt thành 1024 trong code trên để tiết kiệm bộ nhớ. Nếu bạn cần xử lý các chuỗi dài hơn, tăng `max_seq_length` (ví dụ: 2048) nhưng hãy đảm bảo GPU có đủ VRAM.
|
| 88 |
+
- **4-bit quantization**: Được sử dụng để giảm yêu cầu bộ nhớ. Nếu bạn có GPU mạnh hơn, có thể tắt bằng cách đặt `load_in_4bit=False`.
|
| 89 |
+
- **Hugging Face token**: Cần thiết để tải mô hình gốc từ `unsloth`. Đảm bảo bạn đã đăng nhập hoặc cung cấp token qua `huggingface_hub.login()`.
|
| 90 |
|
| 91 |
+
### Đăng nhập Hugging Face (nếu cần)
|
| 92 |
+
Nếu bạn chưa đăng nhập, chạy:
|
| 93 |
+
```python
|
| 94 |
+
from huggingface_hub import login
|
| 95 |
+
login(token="your_hugging_face_token")
|
| 96 |
+
```
|
| 97 |
|
| 98 |
+
Hoặc qua terminal:
|
| 99 |
+
```bash
|
| 100 |
+
huggingface-cli login
|
| 101 |
+
```
|
| 102 |
|
| 103 |
+
## Hiệu suất
|
| 104 |
+
Bộ LoRA adapters này được tối ưu cho các câu hỏi y khoa, đặc biệt là chẩn đoán và điều trị. Mô hình có thể tạo ra các câu trả lời logic với chuỗi suy nghĩ (chain-of-thought) rõ ràng, nhờ vào định dạng prompt đặc biệt trong quá trình fine-tune.
|
| 105 |
|
| 106 |
+
## Liên hệ
|
| 107 |
+
Nếu bạn gặp vấn đề hoặc có câu hỏi, vui lòng mở issue trên repository này hoặc liên hệ qua Hugging Face.
|
| 108 |
|
| 109 |
+
## Lời cảm ơn
|
| 110 |
+
- Cảm ơn `unsloth` và Hugging Face đã cung cấp các công cụ mạnh mẽ để fine-tune và chia sẻ mô hình.
|
| 111 |
+
- Cảm ơn tác giả dataset `hieulum/bacsiAI` đã cung cấp dữ liệu chất lượng.
|