Update README file
Browse files
README.md
CHANGED
|
@@ -1,70 +1,242 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
| 3 |
license: apache-2.0
|
| 4 |
-
base_model: distilbert/distilbert-base-uncased
|
| 5 |
tags:
|
| 6 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
metrics:
|
| 8 |
- accuracy
|
| 9 |
model-index:
|
| 10 |
- name: emergency_blood_request_classifier
|
| 11 |
-
results:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
It achieves the following results on the evaluation set:
|
| 21 |
-
- Loss: 0.0000
|
| 22 |
-
- Accuracy: 1.0
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
##
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
- learning_rate: 0.0001
|
| 42 |
-
- train_batch_size: 32
|
| 43 |
-
- eval_batch_size: 32
|
| 44 |
-
- seed: 42
|
| 45 |
-
- optimizer: Use OptimizerNames.ADAMW_TORCH_FUSED with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
|
| 46 |
-
- lr_scheduler_type: linear
|
| 47 |
-
- num_epochs: 10
|
| 48 |
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|:-------------:|:-----:|:----:|:---------------:|:--------:|
|
| 53 |
-
| 0.0954 | 1.0 | 63 | 0.0107 | 0.998 |
|
| 54 |
-
| 0.0041 | 2.0 | 126 | 0.0010 | 1.0 |
|
| 55 |
-
| 0.0109 | 3.0 | 189 | 0.0017 | 0.998 |
|
| 56 |
-
| 0.0001 | 4.0 | 252 | 0.0001 | 1.0 |
|
| 57 |
-
| 0.0001 | 5.0 | 315 | 0.0000 | 1.0 |
|
| 58 |
-
| 0.0000 | 6.0 | 378 | 0.0000 | 1.0 |
|
| 59 |
-
| 0.0000 | 7.0 | 441 | 0.0000 | 1.0 |
|
| 60 |
-
| 0.0000 | 8.0 | 504 | 0.0000 | 1.0 |
|
| 61 |
-
| 0.0000 | 9.0 | 567 | 0.0000 | 1.0 |
|
| 62 |
-
| 0.0000 | 10.0 | 630 | 0.0000 | 1.0 |
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
- Pytorch 2.11.0+cu128
|
| 69 |
-
- Datasets 5.0.0
|
| 70 |
-
- Tokenizers 0.22.2
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
license: apache-2.0
|
|
|
|
| 5 |
tags:
|
| 6 |
+
- text-classification
|
| 7 |
+
- blood-donation
|
| 8 |
+
- emergency-detection
|
| 9 |
+
- medical
|
| 10 |
+
- healthcare
|
| 11 |
+
- sri-lanka
|
| 12 |
+
- distilbert
|
| 13 |
+
- fine-tuned
|
| 14 |
+
datasets:
|
| 15 |
+
- AshenFdo/synthetic_blood_request_urgency_dataset
|
| 16 |
+
base_model: distilbert/distilbert-base-uncased
|
| 17 |
+
pipeline_tag: text-classification
|
| 18 |
metrics:
|
| 19 |
- accuracy
|
| 20 |
model-index:
|
| 21 |
- name: emergency_blood_request_classifier
|
| 22 |
+
results:
|
| 23 |
+
- task:
|
| 24 |
+
type: text-classification
|
| 25 |
+
dataset:
|
| 26 |
+
name: synthetic_blood_request_urgency_dataset
|
| 27 |
+
type: AshenFdo/synthetic_blood_request_urgency_dataset
|
| 28 |
+
metrics:
|
| 29 |
+
- type: accuracy
|
| 30 |
+
value: 1.0
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
# π©Έ Emergency Blood Request Classifier
|
| 34 |
+
|
| 35 |
+
A fine-tuned **DistilBERT** model for **binary text classification** that automatically determines whether a blood donation request is an **emergency** or **not an emergency**.
|
| 36 |
+
|
| 37 |
+
This model is part of my personal project to build an AI-powered blood donation mobile application for Sri Lanka β designed to prioritize life-critical requests and alert nearby donors faster.
|
| 38 |
+
|
| 39 |
---
|
| 40 |
|
| 41 |
+
## π Model Summary
|
| 42 |
+
|
| 43 |
+
| Property | Details |
|
| 44 |
+
|---|---|
|
| 45 |
+
| **Base Model** | [distilbert/distilbert-base-uncased](https://huggingface.co/distilbert/distilbert-base-uncased) |
|
| 46 |
+
| **Task** | Binary Text Classification |
|
| 47 |
+
| **Labels** | `emergency`, `not_emergency` |
|
| 48 |
+
| **Training Dataset** | [AshenFdo/synthetic_blood_request_urgency_dataset](https://huggingface.co/datasets/AshenFdo/synthetic_blood_request_urgency_dataset) |
|
| 49 |
+
| **Evaluation Accuracy** | **100%** (eval set) |
|
| 50 |
+
| **Training Epochs** | 10 |
|
| 51 |
+
| **Language** | English |
|
| 52 |
+
| **Domain** | Healthcare / Blood Donation (Sri Lanka) |
|
| 53 |
+
| **License** | Apache 2.0 |
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## π― Intended Use
|
| 58 |
+
|
| 59 |
+
### Primary Use
|
| 60 |
+
This model is designed to be integrated into a **Sri Lanka blood donation mobile application**. When a user posts a blood request, the model reads the description and classifies it as:
|
| 61 |
+
|
| 62 |
+
- π¨ `emergency` β triggers immediate alerts to nearby donors
|
| 63 |
+
- π `not_emergency` β listed normally in the donor feed
|
| 64 |
+
|
| 65 |
+
### How It Fits the Bigger Picture
|
| 66 |
+
|
| 67 |
+
```
|
| 68 |
+
Blood Donation App (Sri Lanka)
|
| 69 |
+
β
|
| 70 |
+
βΌ
|
| 71 |
+
User posts a blood request
|
| 72 |
+
β
|
| 73 |
+
βΌ
|
| 74 |
+
π€ This Model (Emergency Classifier)
|
| 75 |
+
βββββββββββββββββββββββββββββββββββββ
|
| 76 |
+
Reads the request description
|
| 77 |
+
β
|
| 78 |
+
ββββΆ emergency β π¨ Immediately alert nearby donors
|
| 79 |
+
β
|
| 80 |
+
ββββΆ not_emergency β π List normally in the donor feed
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
### Other Potential Uses
|
| 84 |
+
- Urgency triage in healthcare communication platforms
|
| 85 |
+
- Benchmarking lightweight NLP models on medical emergency detection
|
| 86 |
+
- Research on urgency language patterns in South Asian healthcare contexts
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## β οΈ Limitations
|
| 91 |
+
|
| 92 |
+
- **Synthetic training data** β The model was trained on AI-generated data. Real-world requests may use different phrasing, slang, abbreviations, or informal language not well-represented in training.
|
| 93 |
+
- **English only** β Sri Lankan blood requests often appear in Sinhala or Tamil. This model does not support those languages.
|
| 94 |
+
- **Sri Lanka context** β The dataset references Sri Lankan hospitals and cities. Performance on requests from other regions may vary.
|
| 95 |
+
- **Not for clinical use** β This model must not be used as a substitute for medical triage or clinical decision-making. It is an assistive tool for a donor coordination platform only.
|
| 96 |
+
|
| 97 |
+
---
|
| 98 |
+
|
| 99 |
+
## π Quick Start
|
| 100 |
+
|
| 101 |
+
### Using the Pipeline (Recommended)
|
| 102 |
|
| 103 |
+
```python
|
| 104 |
+
from transformers import pipeline
|
| 105 |
|
| 106 |
+
classifier = pipeline("text-classification", model="AshenFdo/emergency_blood_request_classifier")
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
result = classifier("O negative blood required urgently at Karapitiya Hospital. We are out of time.")
|
| 109 |
+
print(result)
|
| 110 |
+
# [{'label': 'emergency', 'score': 0.999...}]
|
| 111 |
|
| 112 |
+
result = classifier("Organizing AB+ blood for an upcoming planned operation at Kandy National Hospital.")
|
| 113 |
+
print(result)
|
| 114 |
+
# [{'label': 'not_emergency', 'score': 0.999...}]
|
| 115 |
+
```
|
| 116 |
|
| 117 |
+
### Loading Model Directly
|
| 118 |
|
| 119 |
+
```python
|
| 120 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 121 |
+
import torch
|
| 122 |
|
| 123 |
+
tokenizer = AutoTokenizer.from_pretrained("AshenFdo/emergency_blood_request_classifier")
|
| 124 |
+
model = AutoModelForSequenceClassification.from_pretrained("AshenFdo/emergency_blood_request_classifier")
|
| 125 |
|
| 126 |
+
text = "EMERGENCY: Kandy National Hospital ICU urgently needs A- blood. Patient is critical."
|
| 127 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
|
| 128 |
|
| 129 |
+
with torch.no_grad():
|
| 130 |
+
logits = model(**inputs).logits
|
| 131 |
|
| 132 |
+
predicted_class_id = logits.argmax().item()
|
| 133 |
+
label = model.config.id2label[predicted_class_id]
|
| 134 |
+
print(f"Prediction: {label}")
|
| 135 |
+
# Prediction: emergency
|
| 136 |
+
```
|
| 137 |
|
| 138 |
+
### Batch Inference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
+
```python
|
| 141 |
+
from transformers import pipeline
|
| 142 |
|
| 143 |
+
classifier = pipeline("text-classification", model="AshenFdo/emergency_blood_request_classifier")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
+
requests = [
|
| 146 |
+
"Need O- blood for a routine hospital visit at Negombo Hospital.",
|
| 147 |
+
"My sister is in Kandy Hospital ICU with organ failure. We desperately need B+ blood. Pls help!",
|
| 148 |
+
"Community blood donation drive at Colombo town hall this Saturday.",
|
| 149 |
+
"URGENT: Karapitiya hospital needs AB- blood. Bus accident, multiple casualties.",
|
| 150 |
+
]
|
| 151 |
|
| 152 |
+
results = classifier(requests)
|
| 153 |
+
for req, res in zip(requests, results):
|
| 154 |
+
print(f"[{res['label']}] {req[:60]}...")
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
---
|
| 158 |
+
|
| 159 |
+
## π Training Details
|
| 160 |
+
|
| 161 |
+
### Dataset
|
| 162 |
+
- **2,500** synthetic blood request descriptions
|
| 163 |
+
- **Balanced** β 1,250 `emergency` and 1,250 `not_emergency`
|
| 164 |
+
- Sri Lanka-specific hospital names and geographic references
|
| 165 |
+
- See the full dataset: [AshenFdo/synthetic_blood_request_urgency_dataset](https://huggingface.co/datasets/AshenFdo/synthetic_blood_request_urgency_dataset)
|
| 166 |
+
|
| 167 |
+
### Label Definitions
|
| 168 |
+
|
| 169 |
+
| Label | Description |
|
| 170 |
+
|---|---|
|
| 171 |
+
| `emergency` | Patient is in a critical or life-threatening condition requiring blood immediately. Typically includes keywords like "urgent", "critical", "out of time", "severe hemorrhage", ICU references, or accident/trauma scenarios. |
|
| 172 |
+
| `not_emergency` | Routine, planned, or replacement donation requests. Includes scheduled surgeries, chronic condition support, community blood drives, and replacement donor programs. |
|
| 173 |
+
|
| 174 |
+
### Hyperparameters
|
| 175 |
+
|
| 176 |
+
| Parameter | Value |
|
| 177 |
+
|---|---|
|
| 178 |
+
| Learning Rate | `1e-4` |
|
| 179 |
+
| Train Batch Size | `32` |
|
| 180 |
+
| Eval Batch Size | `32` |
|
| 181 |
+
| Epochs | `10` |
|
| 182 |
+
| Optimizer | AdamW (fused) |
|
| 183 |
+
| LR Scheduler | Linear |
|
| 184 |
+
| Seed | `42` |
|
| 185 |
+
|
| 186 |
+
### Training Results
|
| 187 |
+
|
| 188 |
+
| Epoch | Training Loss | Validation Loss | Accuracy |
|
| 189 |
+
|---|---|---|---|
|
| 190 |
+
| 1 | 0.0954 | 0.0107 | 0.998 |
|
| 191 |
+
| 2 | 0.0041 | 0.0010 | 1.000 |
|
| 192 |
+
| 3 | 0.0109 | 0.0017 | 0.998 |
|
| 193 |
+
| 4 | 0.0001 | 0.0001 | 1.000 |
|
| 194 |
+
| 5β10 | ~0.0000 | ~0.0000 | 1.000 |
|
| 195 |
+
|
| 196 |
+
### Framework Versions
|
| 197 |
+
- Transformers: 5.10.1
|
| 198 |
+
- PyTorch: 2.11.0+cu128
|
| 199 |
+
- Datasets: 5.0.0
|
| 200 |
+
- Tokenizers: 0.22.2
|
| 201 |
+
- Training Environment: Google Colab (GPU)
|
| 202 |
+
|
| 203 |
+
---
|
| 204 |
+
|
| 205 |
+
## ποΈ Example Predictions
|
| 206 |
+
|
| 207 |
+
| Description | Expected Label |
|
| 208 |
+
|---|---|
|
| 209 |
+
| *"HOSPITAL EMERGENCY: Ratnapura Hospital urgently requires AB- blood for a critical patient."* | `emergency` |
|
| 210 |
+
| *"O negative blood required urgently at Karapitiya Hospital. We are out of time."* | `emergency` |
|
| 211 |
+
| *"Need O+ blood ASAP. Friend is in Ragama hospital surgical ICU with a burst spleen."* | `emergency` |
|
| 212 |
+
| *"Organizing AB+ blood for an upcoming planned operation at Kandy National Hospital."* | `not_emergency` |
|
| 213 |
+
| *"Blood donation campaign at the Ratnapura clock tower organized by the local association."* | `not_emergency` |
|
| 214 |
+
| *"Advance donor support for an elective surgery at Ratnapura Hospital. A- needed."* | `not_emergency` |
|
| 215 |
+
|
| 216 |
+
---
|
| 217 |
+
|
| 218 |
+
## π Related Resources
|
| 219 |
+
|
| 220 |
+
- π **Full Project on GitHub:** [AshenFdo/Blood-Request-Emergency-Classification-Model](https://github.com/AshenFdo/Blood-Request-Emergency-Classification-Model)
|
| 221 |
+
- ποΈ **Training Dataset:** [AshenFdo/synthetic_blood_request_urgency_dataset](https://huggingface.co/datasets/AshenFdo/synthetic_blood_request_urgency_dataset)
|
| 222 |
+
- π€ **Base Model:** [distilbert/distilbert-base-uncased](https://huggingface.co/distilbert/distilbert-base-uncased)
|
| 223 |
+
|
| 224 |
+
---
|
| 225 |
+
|
| 226 |
+
## οΏ½οΏ½οΏ½οΏ½ Citation
|
| 227 |
+
|
| 228 |
+
If you use this model in your research or project, please cite it as:
|
| 229 |
+
|
| 230 |
+
```bibtex
|
| 231 |
+
@model{AshenFdo_emergency_blood_request_classifier_2025,
|
| 232 |
+
author = {AshenFdo},
|
| 233 |
+
title = {Emergency Blood Request Classifier},
|
| 234 |
+
year = {2025},
|
| 235 |
+
publisher = {HuggingFace},
|
| 236 |
+
url = {https://huggingface.co/AshenFdo/emergency_blood_request_classifier}
|
| 237 |
+
}
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
---
|
| 241 |
|
| 242 |
+
*Built with the goal of saving lives β one donation at a time. π©Έ*
|
|
|
|
|
|
|
|
|