File size: 2,881 Bytes
935df2c
 
 
 
 
 
 
 
 
 
 
 
a3bb362
 
33756e4
2fc7a45
 
 
 
 
 
 
 
 
 
 
09df5a8
 
 
 
 
2fc7a45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ae5825
 
2fc7a45
5ae5825
 
2fc7a45
 
 
 
 
 
 
 
33756e4
 
 
 
 
 
 
 
 
 
 
a3bb362
33756e4
a3bb362
33756e4
a3bb362
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
license: mit
datasets:
- AGBonnet/augmented-clinical-notes
language:
- en
base_model:
- BioMistral/BioMistral-7B
pipeline_tag: text-generation
tags:
- clinical
- biology
---
# Model Card for Model ID
More code details can be found at Github: https://github.com/Incredible88/BioMistral-Clinical-7B
## How to use

Loading the model from Hunggingface:
```python
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("ZiweiChen/BioMistral-Clinical-7B")
model = AutoModelForCausalLM.from_pretrained("ZiweiChen/BioMistral-Clinical-7B")
```
Lightweight model loading can be used - using 4-bit quantization!
```python
!pip install -q -U bitsandbytes
!pip install -q -U git+https://github.com/huggingface/transformers.git
!pip install -q -U git+https://github.com/huggingface/peft.git
!pip install -q -U git+https://github.com/huggingface/accelerate.git

from transformers import  AutoTokenizer, BitsAndBytesConfig, AutoModelForCausalLM
import torch

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16
)

tokenizer = AutoTokenizer.from_pretrained("ZiweiChen/BioMistral-Clinical-7B")
model = AutoModelForCausalLM.from_pretrained("ZiweiChen/BioMistral-Clinical-7B", quantization_config=bnb_config)

```
How to Generate text:
```python
model_device = next(model.parameters()).device

prompt = """
### Question:

How to treat severe obesity?

### Answer:
"""
model_input = tokenizer(prompt, return_tensors="pt").to(model_device)

with torch.no_grad():
    output = model.generate(**model_input, max_new_tokens=100)
    answer = tokenizer.decode(output[0], skip_special_tokens=True)
    print(answer)
```
## Incremental learning
The process of  incremental learning:  
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64850ea733e82e2c99337143/7i75kNDOR08WU4SXIhdb5.png)
The  training process records:  
![image/png](https://cdn-uploads.huggingface.co/production/uploads/64850ea733e82e2c99337143/E1ES03zUNw8-mZ98Tz9lh.png)

## Clinical Scenario Analysis
More informative answer than BioMistral-7B:  
![image](https://github.com/user-attachments/assets/21a21e75-6014-43cf-8a40-0f296c0974a6)

##  Supervised Fine-tuning Benchmark

![image](https://github.com/user-attachments/assets/8c0f08e7-cad0-4203-8b8c-fcf648831fb5)

**CAUTION!** Both direct and downstream users need to be informed about the risks, biases, and constraints inherent in the model. While the model can produce natural language text, our exploration of its capabilities and limitations is just beginning. In fields such as medicine, comprehending these limitations is crucial. Hence, we strongly advise against deploying this model for natural language generation in production or for professional tasks in the realm of health and medicine.