Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,19 +1,172 @@
|
|
| 1 |
---
|
| 2 |
-
title: InjuryDetection
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: red
|
| 6 |
sdk: docker
|
| 7 |
app_port: 8501
|
| 8 |
tags:
|
| 9 |
-
- streamlit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
pinned: false
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
forums](https://discuss.streamlit.io).
|
|
|
|
| 1 |
---
|
| 2 |
+
title: π InjuryDetection
|
| 3 |
+
emoji: π
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: red
|
| 6 |
sdk: docker
|
| 7 |
app_port: 8501
|
| 8 |
tags:
|
| 9 |
+
- streamlit
|
| 10 |
+
- transformers
|
| 11 |
+
- nlp
|
| 12 |
+
- pytorch
|
| 13 |
+
- nba
|
| 14 |
+
- healthcare
|
| 15 |
+
- sports
|
| 16 |
pinned: false
|
| 17 |
+
description: Predict NBA injury type and duration using a fine-tuned DistilBERT + structured features.
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# π Injury Detection & Recovery Duration Estimator
|
| 22 |
+
|
| 23 |
+
A powerful **Streamlit app** powered by a fine-tuned **DistilBERT** transformer that predicts:
|
| 24 |
+
|
| 25 |
+
- π **Injury Type** (e.g., bone, muscle, joint, illness, concussion)
|
| 26 |
+
- β³ **Recovery Duration**:
|
| 27 |
+
- `short` (< 7 days)
|
| 28 |
+
- `medium` (7β45 days)
|
| 29 |
+
- `long` (> 45 days)
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## π Why This Project?
|
| 34 |
+
|
| 35 |
+
NBA injuries are unpredictable, and doctors often rely on vague reports or historical intuition. I wanted to go beyond zero-shot text classification by:
|
| 36 |
+
|
| 37 |
+
- Cleaning and normalizing raw injury logs (1950β2022)
|
| 38 |
+
- Labeling 8K+ examples by type and duration
|
| 39 |
+
- Incrementally testing feature combinations
|
| 40 |
+
- Analyzing attention weights and feature influence
|
| 41 |
+
- Making predictions explainable and interactive via Streamlit
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## π§ Model Highlights
|
| 46 |
+
|
| 47 |
+
| Component | Description |
|
| 48 |
+
|------------------|-----------------------------------------|
|
| 49 |
+
| Model | `distilbert-base-uncased` |
|
| 50 |
+
| Task | Dual classification |
|
| 51 |
+
| Inputs | Text + prior injuries, position, type ID|
|
| 52 |
+
| Output Heads | `label_type_id` and `label_duration_id` |
|
| 53 |
+
| Loss | Weighted cross-entropy (multi-task) |
|
| 54 |
+
| Extras | Attention score input for interpretability|
|
| 55 |
+
|
| 56 |
---
|
| 57 |
|
| 58 |
+
## π‘ Features
|
| 59 |
+
|
| 60 |
+
- π **Free-text input** for injury reports
|
| 61 |
+
- π§± **Structured context**: prior injuries, position, injury category
|
| 62 |
+
- π― **Fine-tuned BERT** with dual-head classification
|
| 63 |
+
- π **Live predictions** with **confidence scores**
|
| 64 |
+
- π **Built-in feature importance + attention hooks**
|
| 65 |
+
- π **Streamlit UI** with dropdowns, metrics, and sample cases
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
## ποΈ File Structure
|
| 70 |
+
```text
|
| 71 |
+
project/
|
| 72 |
+
βββ src/
|
| 73 |
+
β βββ streamlit_app.py # main Streamlit UI app
|
| 74 |
+
β βββ predict_utils.py # logic for prediction function
|
| 75 |
+
β βββ final_injury_model.pt # fine-tuned dual-head transformer model (DistilBERT)
|
| 76 |
+
βββ requirements.txt # all dependencies (Torch, HF Transformers, Streamlit, etc.)
|
| 77 |
+
βββ modeling_notebooks/ # experimentation, feature importance, attention
|
| 78 |
+
βββ cleaned_data/ # cleaned dataset used for training
|
| 79 |
+
βββ raw_data/ # original source CSVs
|
| 80 |
+
βββ README.md # this file
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## βοΈ Setup
|
| 86 |
+
|
| 87 |
+
1. **Install dependencies**
|
| 88 |
+
|
| 89 |
+
```bash
|
| 90 |
+
pip install -r requirements.txt
|
| 91 |
+
```
|
| 92 |
+
2. **Run App**
|
| 93 |
+
```bash
|
| 94 |
+
streamlit run app.py
|
| 95 |
+
```
|
| 96 |
+
---
|
| 97 |
+
|
| 98 |
+
## βοΈ Model Overview
|
| 99 |
+
|
| 100 |
+
| **Component** | **Description** |
|
| 101 |
+
| ---------------------- | --------------------------------------------------------- |
|
| 102 |
+
| **Base Model** | `distilbert-base-uncased` |
|
| 103 |
+
| **Input** | Injury description text + structured inputs |
|
| 104 |
+
| **Structured Inputs** | Prior injuries, position ID, injury type ID |
|
| 105 |
+
| **Output Heads** | `label_type_id`, `label_duration_id` |
|
| 106 |
+
| **Optimization** | Multi-task cross-entropy loss |
|
| 107 |
+
| **Performance Boosts** | Attention score injection, feature dropout, class weights |
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
+
|
| 111 |
+
## π Results Summary
|
| 112 |
+
|
| 113 |
+
| Metric | Value | Description |
|
| 114 |
+
|---------------------|---------|---------------------------------------------------------------|
|
| 115 |
+
| **Type Accuracy** | 99.5% | Nearly perfect prediction for general injury type |
|
| 116 |
+
| **Duration Accuracy** | 65.0% | More challenging task due to overlap in medium/long classes |
|
| 117 |
+
| **Macro F1 (Duration)** | ~0.64 | Balanced F1 across duration classes |
|
| 118 |
+
| **Most Confused Pair** | `long` vs `medium` | Long and medium often overlapped in symptoms and context |
|
| 119 |
+
| **Evaluation Set Size** | 200 samples | Held-out test subset from full dataset |
|
| 120 |
+
| **Unknown Labels Removed** | β
| Improved class balance and duration accuracy |
|
| 121 |
+
| **Feature Importance** | moderate | Prior injuries most useful, attention least influential |
|
| 122 |
+
|
| 123 |
+
---
|
| 124 |
+
|
| 125 |
+
## What I learned
|
| 126 |
+
|
| 127 |
+
Structured + Textual fusion drastically improves performance over text-only
|
| 128 |
+
|
| 129 |
+
Class balancing + weighted loss helped fix bias toward short injuries
|
| 130 |
+
|
| 131 |
+
Adding features like injury type, position, prior injuries sequentially allowed modular experimentation
|
| 132 |
+
|
| 133 |
+
Attention scores showed low influence, but modeling it validated model interpretability
|
| 134 |
+
|
| 135 |
+
---
|
| 136 |
+
|
| 137 |
+
## π¬ Sample Predictions
|
| 138 |
+
|
| 139 |
+
"torn ACL expected to miss rest of season"
|
| 140 |
+
β Type: **joint** (99%), Duration: **long** (91%)
|
| 141 |
+
|
| 142 |
+
"minor hamstring strain"
|
| 143 |
+
β Type: **muscle** (96%), Duration: **short** (87%)
|
| 144 |
+
|
| 145 |
+
"fractured tibia, placed on IL"
|
| 146 |
+
β Type: **bone** (98%), Duration: **long** (89%)
|
| 147 |
+
|
| 148 |
+
---
|
| 149 |
+
|
| 150 |
+
## Hugging Face Transformers & Datasets
|
| 151 |
+
|
| 152 |
+
PyTorch, Scikit-learn, and Streamlit for all underlying tech
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
|
| 156 |
+
## Datasets
|
| 157 |
+
- Player_Info: [NBA Players stats since 1950](https://www.kaggle.com/datasets/drgilermo/nba-players-stats?select=player_data.csv)
|
| 158 |
+
- Player_Info:[NBA Players data (1950 to 2022)](https://www.kaggle.com/datasets/blitzapurv/nba-players-data-1950-to-2021?select=player_data.csv)
|
| 159 |
+
- Injury Info: [π NBA Injury Stats (1951β2023)](https://www.kaggle.com/datasets/loganlauton/nba-injury-stats-1951-2023)
|
| 160 |
+
|
| 161 |
+
---
|
| 162 |
+
|
| 163 |
+
## π§ Try it Out Now
|
| 164 |
+
Enter a short injury description, and get:
|
| 165 |
+
|
| 166 |
+
β
Predicted injury type
|
| 167 |
+
|
| 168 |
+
β³ Estimated recovery time
|
| 169 |
|
| 170 |
+
π Confidence scores
|
| 171 |
|
| 172 |
+
β¨ Fork this space and customize it to your league, team, or medical use case.
|
|
|