Update README.md
Browse files
README.md
CHANGED
|
@@ -1,29 +1,44 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
-
language:
|
| 4 |
-
- en
|
| 5 |
-
base_model:
|
| 6 |
-
- mistralai/Mistral-7B-v0.1
|
| 7 |
-
pipeline_tag: text2text-generation
|
| 8 |
tags:
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
-
|
| 12 |
-
- mistral
|
| 13 |
-
-
|
| 14 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
---
|
| 16 |
-
# π§ LoRA Fine-Tuned Mistral-7B on MTS-Dialog Dataset
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
---
|
| 21 |
|
| 22 |
## π Model Summary
|
| 23 |
|
| 24 |
-
- **Base Model**: Mistral-7B
|
| 25 |
-
- **
|
| 26 |
-
- **
|
|
|
|
| 27 |
- **Task**: Medical dialogue summarization
|
| 28 |
- **Dataset**: [MTS-Dialog](https://github.com/abachaa/MTS-Dialog)
|
| 29 |
|
|
@@ -31,65 +46,26 @@ This repository contains a LoRA fine-tuned version of the [`mistralai/Mistral-7B
|
|
| 31 |
|
| 32 |
## π₯ Task Description
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
Each training sample follows this pattern:
|
| 37 |
-
|
| 38 |
-
"""
|
| 39 |
-
Example 1:
|
| 40 |
-
Dialogue:
|
| 41 |
-
Doctor: Hello, Mrs. Smith. What seems to be troubling you today?
|
| 42 |
-
Patient: Iβve been having shortness of breath and a mild cough for two weeks.
|
| 43 |
-
Doctor: Any history of asthma or allergies?
|
| 44 |
-
Patient: No, Iβve never had any breathing problems before.
|
| 45 |
-
Summary:
|
| 46 |
-
The patient, a middle-aged woman, presented with a two-week history of shortness of breath and mild cough without prior respiratory conditions. The physician asked about asthma/allergies, which the patient denied.
|
| 47 |
-
|
| 48 |
-
Example 2:
|
| 49 |
-
Dialogue:
|
| 50 |
-
Doctor: Good morning. How are you feeling since your last visit?
|
| 51 |
-
Patient: I still have a sharp pain in my right knee when I climb stairs.
|
| 52 |
-
Doctor: Does the pain radiate anywhere else?
|
| 53 |
-
Patient: No, itβs just in my knee. It started about a month ago.
|
| 54 |
-
Summary:
|
| 55 |
-
The patient continues to experience sharp knee pain exacerbated by stair climbing for one month, localized to the right knee with no radiation.
|
| 56 |
-
"""
|
| 57 |
-
|
| 58 |
-
new_dialogue_header = "GENHX"
|
| 59 |
-
new_dialogue_text = """
|
| 60 |
-
Doctor: What brings you back into the clinic today, miss?
|
| 61 |
-
Patient: I've had chest pain for the last few days.
|
| 62 |
-
Doctor: When did it start?
|
| 63 |
-
"""
|
| 64 |
-
|
| 65 |
-
inference_prompt = few_shot_prompts + f"""
|
| 66 |
-
|
| 67 |
-
Now you:
|
| 68 |
-
Summarize the following dialogue for section: {new_dialogue_header}
|
| 69 |
-
{new_dialogue_text}
|
| 70 |
-
Summary:
|
| 71 |
-
"""
|
| 72 |
-
|
| 73 |
-
|
| 74 |
|
| 75 |
---
|
| 76 |
|
| 77 |
-
##
|
| 78 |
|
| 79 |
-
|
| 80 |
-
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
Due to limited GPU resources (office laptop), training was
|
| 87 |
|
| 88 |
---
|
| 89 |
|
| 90 |
-
##
|
| 91 |
-
|
| 92 |
-
Final validation metrics after 3 epochs:
|
| 93 |
|
| 94 |
| Metric | Score |
|
| 95 |
|-----------|--------|
|
|
@@ -98,55 +74,43 @@ Final validation metrics after 3 epochs:
|
|
| 98 |
| ROUGE-L | 0.0900 |
|
| 99 |
| BLEU | 0.0260 |
|
| 100 |
|
| 101 |
-
> β οΈ **Note**: These results are lower than expected due to low-rank LoRA (`r=4`) and only 3 epochs. Further tuning (e.g. `r=8`, `epochs=10`) on better GPUs will likely improve performance.
|
| 102 |
-
|
| 103 |
---
|
| 104 |
|
| 105 |
-
## π‘
|
| 106 |
-
|
| 107 |
-
**Input**:
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
Doctor: Hello, Mr. Patel. Are you having any fever or chills?
|
| 115 |
-
Patient: Yes, Iβve had a 102Β°F fever since yesterday and chills last night.
|
| 116 |
-
Doctor: Any cough or stuffy nose?
|
| 117 |
-
Patient: Mild cough and some congestion.
|
| 118 |
-
Doctor: Do you have body aches?
|
| 119 |
-
Patient: Yes, I feel sore all over.
|
| 120 |
Summary:
|
| 121 |
-
"""
|
| 122 |
-
|
| 123 |
-
Example A Generated Summary:
|
| 124 |
-
This is a case of influenza with fever, cough, and myalgia. The patient also has a history of asthma and hypertension. He has not been vaccinated against the flu this year.
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
---
|
| 128 |
|
| 129 |
-
## π Files
|
| 130 |
|
| 131 |
-
|
| 132 |
-
- `adapter_model.bin` β LoRA adapter weights
|
| 133 |
-
- `tokenizer/` β Tokenizer files
|
| 134 |
-
- `README.md` β This model card
|
| 135 |
|
| 136 |
-
---
|
| 137 |
-
|
| 138 |
-
## π How to Use
|
| 139 |
-
|
| 140 |
-
```python
|
| 141 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 142 |
from peft import PeftModel
|
| 143 |
|
| 144 |
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1", load_in_4bit=True)
|
| 145 |
model = PeftModel.from_pretrained(model, "Imsachinsingh00/Fine_tuned_LoRA_Mistral_MTSDialog_Summarization")
|
|
|
|
| 146 |
|
| 147 |
tokenizer = AutoTokenizer.from_pretrained("Imsachinsingh00/Fine_tuned_LoRA_Mistral_MTSDialog_Summarization")
|
| 148 |
|
| 149 |
prompt = "Summarize the following dialogue for section: HPI\nDoctor: Hello, what brings you in?\nPatient: I've been dizzy for two days.\nSummary:"
|
| 150 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 151 |
output = model.generate(**inputs, max_new_tokens=150)
|
| 152 |
-
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
tags:
|
| 4 |
+
- medical
|
| 5 |
+
- summarization
|
| 6 |
+
- lora
|
| 7 |
+
- mistral
|
| 8 |
+
- dialogue
|
| 9 |
+
- peft
|
| 10 |
+
model-index:
|
| 11 |
+
- name: Fine-tuned Mistral-7B (LoRA) on MTS-Dialog
|
| 12 |
+
results:
|
| 13 |
+
- task:
|
| 14 |
+
type: summarization
|
| 15 |
+
metrics:
|
| 16 |
+
- name: ROUGE-1
|
| 17 |
+
type: rouge
|
| 18 |
+
value: 0.1318
|
| 19 |
+
- name: ROUGE-2
|
| 20 |
+
type: rouge
|
| 21 |
+
value: 0.0456
|
| 22 |
+
- name: ROUGE-L
|
| 23 |
+
type: rouge
|
| 24 |
+
value: 0.0900
|
| 25 |
+
- name: BLEU
|
| 26 |
+
type: bleu
|
| 27 |
+
value: 0.0260
|
| 28 |
---
|
|
|
|
| 29 |
|
| 30 |
+
# π§ LoRA Fine-Tuned Mistral-7B on MTS-Dialog
|
| 31 |
+
|
| 32 |
+
This repository contains a LoRA fine-tuned version of [`mistralai/Mistral-7B-v0.1`](https://huggingface.co/mistralai/Mistral-7B-v0.1) for medical dialogue summarization, trained on the [MTS-Dialog](https://github.com/abachaa/MTS-Dialog) dataset.
|
| 33 |
|
| 34 |
---
|
| 35 |
|
| 36 |
## π Model Summary
|
| 37 |
|
| 38 |
+
- **Base Model**: `mistralai/Mistral-7B-v0.1`
|
| 39 |
+
- **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
|
| 40 |
+
- **Frameworks**: π€ Transformers, PEFT, bitsandbytes
|
| 41 |
+
- **Quantization**: 4-bit
|
| 42 |
- **Task**: Medical dialogue summarization
|
| 43 |
- **Dataset**: [MTS-Dialog](https://github.com/abachaa/MTS-Dialog)
|
| 44 |
|
|
|
|
| 46 |
|
| 47 |
## π₯ Task Description
|
| 48 |
|
| 49 |
+
This model is trained to summarize doctor-patient conversations into concise clinical notes, categorized by sections such as `GENHX`, `HPI`, `ROS`, etc. These summaries assist with EHR documentation and clinical decision-making.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
---
|
| 52 |
|
| 53 |
+
## βοΈ Training Configuration
|
| 54 |
|
| 55 |
+
| Parameter | Value |
|
| 56 |
+
|--------------------|---------------|
|
| 57 |
+
| LoRA Rank | 4 |
|
| 58 |
+
| Epochs | 3 |
|
| 59 |
+
| Batch Size | 4 (Γ4 grad. acc.) |
|
| 60 |
+
| Learning Rate | 3e-4 |
|
| 61 |
+
| Device | CUDA:0 |
|
| 62 |
+
| Quantization | 4-bit (bnb) |
|
| 63 |
|
| 64 |
+
> β οΈ Due to limited GPU resources (office laptop), training was constrained to 3 epochs and a small LoRA rank. Performance is expected to improve significantly with extended training and better hardware.
|
| 65 |
|
| 66 |
---
|
| 67 |
|
| 68 |
+
## π Evaluation Metrics
|
|
|
|
|
|
|
| 69 |
|
| 70 |
| Metric | Score |
|
| 71 |
|-----------|--------|
|
|
|
|
| 74 |
| ROUGE-L | 0.0900 |
|
| 75 |
| BLEU | 0.0260 |
|
| 76 |
|
|
|
|
|
|
|
| 77 |
---
|
| 78 |
|
| 79 |
+
## π‘ Example Prompt
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
```text
|
| 82 |
+
Summarize the following dialogue for section: GENHX
|
| 83 |
+
Doctor: What brings you back into the clinic today, miss?
|
| 84 |
+
Patient: I've had chest pain for the last few days.
|
| 85 |
+
Doctor: When did it start?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
Summary:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
|
|
|
| 88 |
|
| 89 |
+
## π§ͺ Inference Code
|
|
|
|
|
|
|
|
|
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 92 |
from peft import PeftModel
|
| 93 |
|
| 94 |
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1", load_in_4bit=True)
|
| 95 |
model = PeftModel.from_pretrained(model, "Imsachinsingh00/Fine_tuned_LoRA_Mistral_MTSDialog_Summarization")
|
| 96 |
+
model.eval()
|
| 97 |
|
| 98 |
tokenizer = AutoTokenizer.from_pretrained("Imsachinsingh00/Fine_tuned_LoRA_Mistral_MTSDialog_Summarization")
|
| 99 |
|
| 100 |
prompt = "Summarize the following dialogue for section: HPI\nDoctor: Hello, what brings you in?\nPatient: I've been dizzy for two days.\nSummary:"
|
| 101 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 102 |
output = model.generate(**inputs, max_new_tokens=150)
|
| 103 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
## π Included Files
|
| 107 |
+
|
| 108 |
+
- `config.json` β PEFT configuration for LoRA
|
| 109 |
+
- `adapter_model.bin` β LoRA adapter weights
|
| 110 |
+
- `tokenizer/` β Tokenizer files
|
| 111 |
+
- `README.md` β This model card
|
| 112 |
+
|
| 113 |
+
## π Notes
|
| 114 |
+
|
| 115 |
+
- π« This is not a fully optimized clinical model β only a proof of concept.
|
| 116 |
+
- π‘ Consider training longer (`epochs=10`, `rank=8`) on GPUs with higher VRAM for better results.
|