varshamishra commited on
Commit
4c957e9
·
verified ·
1 Parent(s): 2b627a2

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +101 -0
README.md ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Text-to-Text Transfer Transformer (T5) Quantized Model for Medical Chatbot
2
+
3
+ This repository hosts a quantized version of the T5 model, fine-tuned for Medical Chatbot tasks. The model has been optimized for efficient deployment while maintaining high accuracy, making it suitable for resource-constrained environments.
4
+
5
+ ## Model Details
6
+ - **Model Architecture:** T5
7
+ - **Task:** Medical Chatbot
8
+ - **Dataset:** Hugging Face's ‘medical-qa-datasets’
9
+
10
+ - **Quantization:** Float16
11
+ - **Fine-tuning Framework:** Hugging Face Transformers
12
+
13
+ ## Usage
14
+ ### Installation
15
+ ```sh
16
+ pip install transformers torch
17
+ ```
18
+
19
+ ### Loading the Model
20
+ ```python
21
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
22
+ import torch
23
+
24
+ device = "cuda" if torch.cuda.is_available() else "cpu"
25
+
26
+ model_name = "AventIQ-AI/t5-medical-chatbot”
27
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
28
+ model = T5ForConditionalGeneration.from_pretrained(model_name).to(device)
29
+
30
+ def test_medical_t5(instruction, input_text, model, tokenizer):
31
+     """Format input like the training dataset and test the quantized model."""
32
+     formatted_input = f"Instruction: {instruction} Input: {input_text}"
33
+  
34
+     # ✅ Tokenize input & move to correct device
35
+     inputs = tokenizer(
36
+         formatted_input, return_tensors="pt", padding=True, truncation=True, max_length=512
37
+     ).to(device)
38
+  
39
+     # ✅ Generate response with optimized settings
40
+     with torch.no_grad():
41
+         outputs = model.generate(
42
+             input_ids=inputs["input_ids"],  # Explicitly specify input tensor
43
+             attention_mask=inputs["attention_mask"],
44
+             max_length=200,
45
+             num_return_sequences=1,
46
+             temperature=0.6,
47
+             top_k=40,
48
+             top_p=0.85,
49
+             repetition_penalty=2.0,
50
+             no_repeat_ngram_size=3,
51
+             early_stopping=True
52
+         )
53
+  
54
+     # ✅ Decode output
55
+     response = tokenizer.decode(outputs[0], skip_special_tokens=True)
56
+     return response
57
+
58
+
59
+ # Test Example
60
+ instruction = "As a medical expert, provide a detailed and accurate diagnosis based on the patient's symptoms."
61
+ input_text = "A patient is experiencing persistent hair fall, dizziness, and nausea. What could be the underlying cause and recommended next steps?"
62
+ ```
63
+
64
+ ## 📊 ROUGE Evaluation Results
65
+ After fine-tuning the T5-Small model for Medical Chatbot, we obtained the following ROUGE scores:
66
+
67
+ | **Metric** | **Score** | **Meaning** |
68
+ |------------|---------|--------------------------------------------------------------|
69
+ | **ROUGE-1** | 1.0 (~100%) | Measures overlap of unigrams (single words) between the reference and generated text. |
70
+ | **ROUGE-2** | 0.5 (~50%) | Measures overlap of bigrams (two-word phrases), indicating coherence and fluency. |
71
+ | **ROUGE-L** | 1.0 (~100%) | Measures longest matching word sequences, testing sentence structure preservation. |
72
+ | **ROUGE-Lsum** | 0.95 (~95%) | Similar to ROUGE-L but optimized for summarization tasks. |
73
+
74
+ ## Fine-Tuning Details
75
+ ### Dataset
76
+ The Hugging Face's `medical-qa-datasets’ dataset was used, containing different types of Patient and Doctor Questions and respective Answers.
77
+
78
+ ### Training
79
+ - **Number of epochs:** 3
80
+ - **Batch size:** 8
81
+ - **Evaluation strategy:** epoch
82
+
83
+ ### Quantization
84
+ Post-training quantization was applied using PyTorch's built-in quantization framework to reduce the model size and improve inference efficiency.
85
+
86
+ ## Repository Structure
87
+ ```
88
+ .
89
+ ├── model/ # Contains the quantized model files
90
+ ├── tokenizer_config/ # Tokenizer configuration and vocabulary files
91
+ ├── model.safetensors/ # Quantized Model
92
+ ├── README.md # Model documentation
93
+ ```
94
+
95
+ ## Limitations
96
+ - The model may not generalize well to domains outside the fine-tuning dataset.
97
+ - Currently, it only supports English to French translations.
98
+ - Quantization may result in minor accuracy degradation compared to full-precision models.
99
+
100
+ ## Contributing
101
+ Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.