Update README.md
Browse files
README.md
CHANGED
|
@@ -11,24 +11,73 @@ tags:
|
|
| 11 |
|
| 12 |
Notable generation Of patient Text summaries through an Efficient approach based on direct preference optimization (DPO)
|
| 13 |
|
| 14 |
-
This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1).
|
| 15 |
|
| 16 |
-
## Model Details
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
- **Model type:** MistralForCausalLM
|
| 21 |
- **Language(s) (NLP):** English
|
| 22 |
- **License:** [CC-BY-NC-SA](https://creativecommons.org/licenses/by-nc-sa/4.0/)
|
| 23 |
- **Finetuned from model:** [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
- **Paper:** [NOTE](arvix.)
|
| 28 |
- **Demo:** [NOTE-DEMO](https://huggingface.co/spaces/jinee/note-demo)
|
| 29 |
|
| 30 |
## Usage
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
## Dataset
|
|
@@ -37,9 +86,39 @@ The model has been trained on a [MIMIC-III](https://physionet.org/content/mimici
|
|
| 37 |
Access to this databased requires a number of steps to obtain permission.
|
| 38 |
|
| 39 |
|
|
|
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
## Clinical appli
|
| 43 |
|
| 44 |
|
| 45 |
## Limitations
|
|
|
|
| 11 |
|
| 12 |
Notable generation Of patient Text summaries through an Efficient approach based on direct preference optimization (DPO)
|
| 13 |
|
|
|
|
| 14 |
|
|
|
|
| 15 |
|
| 16 |
+
## Model Description
|
| 17 |
|
| 18 |
- **Model type:** MistralForCausalLM
|
| 19 |
- **Language(s) (NLP):** English
|
| 20 |
- **License:** [CC-BY-NC-SA](https://creativecommons.org/licenses/by-nc-sa/4.0/)
|
| 21 |
- **Finetuned from model:** [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
|
| 22 |
|
| 23 |
+
## Model Sources
|
| 24 |
|
| 25 |
- **Paper:** [NOTE](arvix.)
|
| 26 |
- **Demo:** [NOTE-DEMO](https://huggingface.co/spaces/jinee/note-demo)
|
| 27 |
|
| 28 |
## Usage
|
| 29 |
|
| 30 |
+
~~~python
|
| 31 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 32 |
+
model = AutoModelForCausalLM.from_pretrained("jinee/note", load_in_4bit=True, device_map="auto")
|
| 33 |
+
tokenizer = AutoTokenizer.from_pretrained("jinee/note")
|
| 34 |
+
tokenizer.padding_side = 'right'
|
| 35 |
+
tokenizer.add_eos_token = True
|
| 36 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 37 |
+
tokenizer.add_eos_token, tokenizer.add_bos_token
|
| 38 |
+
|
| 39 |
+
instruction = '''
|
| 40 |
+
As a doctor, you need to create a discharge summary based on input data.
|
| 41 |
+
Never change the dates or numbers in the input data and use them as is. And please follow the format below for your report.
|
| 42 |
+
Also, never make up information that is not in the input data, and write a report only with information that can be identified from the input data.
|
| 43 |
+
|
| 44 |
+
1. Patient information (SUBJECT_ID, HADM_ID, hospitalization and discharge date, hospitalization period, gender, date of birth, age, allergy)
|
| 45 |
+
2. Diagnostic information and past history (if applicable)
|
| 46 |
+
3. Surgery or procedure information
|
| 47 |
+
4. Significant medication administration during hospitalization and discharge medication history
|
| 48 |
+
5. Meaningful lab tests during hospitalization
|
| 49 |
+
6. Summary of significant text records/notes
|
| 50 |
+
7. Discharge outcomes and treatment plan
|
| 51 |
+
8. Overall summary of at least 500 characters in lines including the above contents
|
| 52 |
+
'''
|
| 53 |
+
|
| 54 |
+
def generation(model, tokenizer, input_data):
|
| 55 |
+
pipe = pipeline('text-generation',
|
| 56 |
+
model = model,
|
| 57 |
+
tokenizer = tokenizer,
|
| 58 |
+
torch_dtype=torch.bfloat16,
|
| 59 |
+
device_map = 'auto')
|
| 60 |
+
global instruction
|
| 61 |
+
|
| 62 |
+
sequences = pipe(
|
| 63 |
+
f"[INST]{instruction}: {input_data} [/INST]",
|
| 64 |
+
do_sample=True,
|
| 65 |
+
max_new_tokens=1024,
|
| 66 |
+
temperature=0.7,
|
| 67 |
+
top_k=50,
|
| 68 |
+
top_p=0.95,
|
| 69 |
+
early_stopping =True,
|
| 70 |
+
num_return_sequences=1,)
|
| 71 |
+
|
| 72 |
+
text = sequences[0]['generated_text']
|
| 73 |
+
start_index = text.find('[/INST]')
|
| 74 |
+
if start_index != -1:
|
| 75 |
+
summary_ = text[start_index + len('[/INST]'):]
|
| 76 |
+
return(summary_)
|
| 77 |
+
else:
|
| 78 |
+
return("'[summary_] 'is not founded.")
|
| 79 |
+
|
| 80 |
+
~~~
|
| 81 |
|
| 82 |
|
| 83 |
## Dataset
|
|
|
|
| 86 |
Access to this databased requires a number of steps to obtain permission.
|
| 87 |
|
| 88 |
|
| 89 |
+
## Training and Hyper-parameters
|
| 90 |
|
| 91 |
+
### List of LoRA config
|
| 92 |
+
based on [Parameter-Efficient Fine-Tuning (PEFT)](https://github.com/huggingface/peft)
|
| 93 |
+
|
| 94 |
+
Parameter | SFT | DPO
|
| 95 |
+
:------:| :------:| :------:
|
| 96 |
+
r | 16 | 16
|
| 97 |
+
lora alpha | 16 | 16
|
| 98 |
+
lora dropout | 0.05 | 0.05
|
| 99 |
+
target | q, k, v, o, gate | q, k, v, o, gate
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
### List of Training arguments
|
| 103 |
+
based on [Transformer Reinforment Learning (TRL)](https://github.com/huggingface/trl)
|
| 104 |
+
|
| 105 |
+
Parameter | SFT | DPO
|
| 106 |
+
:------:| :------:| :------:
|
| 107 |
+
early stopping patience | 3 | 3
|
| 108 |
+
early stopping threshold | 0.0005 | 0.0005
|
| 109 |
+
train epochs | 20 | 3
|
| 110 |
+
per device train batch size | 4 | 1
|
| 111 |
+
per device eval batch size | 8 (default) | 1
|
| 112 |
+
optimizer | paged adamw 8bit | paged adamw 8bit
|
| 113 |
+
lr scheduler | cosine | cosine
|
| 114 |
+
wramup ratio | 0.3 | 0.1
|
| 115 |
+
gradient accumulation step | 2 | 2
|
| 116 |
+
evaluation strategy | step | step
|
| 117 |
+
eval step | 10 | 5
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
## Applicability in medicine
|
| 121 |
|
|
|
|
| 122 |
|
| 123 |
|
| 124 |
## Limitations
|