Instructions to use Vinuit/SentinelAI-Filter-ONNX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Vinuit/SentinelAI-Filter-ONNX with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: bert-base-uncased
|
| 3 |
+
library_name: peft
|
| 4 |
+
tags:
|
| 5 |
+
- mental-health
|
| 6 |
+
- burnout-detection
|
| 7 |
+
- lora
|
| 8 |
+
- dual-head-classifier
|
| 9 |
+
- workplace-wellbeing
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# SentinelAI BERT Filter - LoRA Adapters
|
| 13 |
+
|
| 14 |
+
LoRA fine-tuned BERT model for employee mental health classification in workplace messages. Part of the SentinelAI system for automated burnout detection via Slack message analysis.
|
| 15 |
+
|
| 16 |
+
## Model Description
|
| 17 |
+
|
| 18 |
+
- **Base Model:** bert-base-uncased (110M parameters)
|
| 19 |
+
- **Fine-tuning Method:** LoRA (Low-Rank Adaptation)
|
| 20 |
+
- **Task:** Dual-head classification (category + severity)
|
| 21 |
+
- **Trainable Parameters:** 303,371 / 109,785,611 (0.28%)
|
| 22 |
+
- **Developed by:** Team Rocket Number One, King's College London
|
| 23 |
+
- **License:** MIT (project-specific)
|
| 24 |
+
|
| 25 |
+
## Architecture
|
| 26 |
+
|
| 27 |
+
**Dual-Head Classifier:**
|
| 28 |
+
|
| 29 |
+
- **Category Head:** 7-class classification
|
| 30 |
+
- neutral, humor_sarcasm, stress, burnout, depression, harassment, suicidal_ideation
|
| 31 |
+
- **Severity Head:** 4-stage classification
|
| 32 |
+
- none, early, middle, late
|
| 33 |
+
- **Binary Routing:** 5 risk categories trigger escalation to LLM agents
|
| 34 |
+
|
| 35 |
+
## Training Details
|
| 36 |
+
|
| 37 |
+
### Dataset
|
| 38 |
+
|
| 39 |
+
- **Total Examples:** 7,000 (mixed dataset for quality + diversity)
|
| 40 |
+
- 5,000 from v0.1 (natural Slack-style phrasing)
|
| 41 |
+
- 2,000 from v0.2 (lexically diverse, synonym-enhanced)
|
| 42 |
+
- **Splits:** 80% train (5,600), 10% val (700), 10% test (700)
|
| 43 |
+
- **Lexical Diversity:** TTR 0.35 (exceeds 0.3 quality threshold)
|
| 44 |
+
- **Clinical Grounding:** Maslach Burnout Inventory (MBI), DSM-5, UK Equality Act 2010
|
| 45 |
+
|
| 46 |
+
### Hyperparameters
|
| 47 |
+
|
| 48 |
+
```yaml
|
| 49 |
+
LoRA Configuration:
|
| 50 |
+
r: 8
|
| 51 |
+
lora_alpha: 16
|
| 52 |
+
lora_dropout: 0.1
|
| 53 |
+
target_modules: ["query", "value"]
|
| 54 |
+
task_type: FEATURE_EXTRACTION
|
| 55 |
+
|
| 56 |
+
Training:
|
| 57 |
+
epochs: 3
|
| 58 |
+
batch_size: 16
|
| 59 |
+
learning_rate: 3e-4
|
| 60 |
+
optimizer: AdamW
|
| 61 |
+
scheduler: Linear warmup + decay
|
| 62 |
+
max_sequence_length: 128
|
| 63 |
+
loss_function: CrossEntropyLoss (category + severity summed)
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
### Hardware & Performance
|
| 67 |
+
|
| 68 |
+
- **GPU:** NVIDIA GeForce GTX 1080 (8GB VRAM)
|
| 69 |
+
- **Training Time:** ~3 minutes (1 min/epoch)
|
| 70 |
+
- **Training Regime:** fp32
|
| 71 |
+
|
| 72 |
+
## Results
|
| 73 |
+
|
| 74 |
+
### Test Set Performance
|
| 75 |
+
|
| 76 |
+
| Metric | Score |
|
| 77 |
+
| :----- | :---- |
|
| 78 |
+
| **Category Accuracy** | 76.29% |
|
| 79 |
+
| **Severity Accuracy** | 78.29% |
|
| 80 |
+
| **Test Loss** | 1.1840 |
|
| 81 |
+
|
| 82 |
+
**Performance Context:**
|
| 83 |
+
|
| 84 |
+
- Category: 5.3x better than random (7-class baseline: 14.3%)
|
| 85 |
+
- Severity: 3.1x better than random (4-class baseline: 25%)
|
| 86 |
+
- Low/no overfitting: Test accuracy matches validation accuracy
|
| 87 |
+
|
| 88 |
+
## Usage
|
| 89 |
+
|
| 90 |
+
### Loading the Model (Production Pattern)
|
| 91 |
+
|
| 92 |
+
The repository uses a centralised **Model Factory** to handle architecture initialisation and weight loading. It includes **Auto-Download** logic that pulls the latest checkpoint from Hugging Face Hub if it is not found locally.
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
import torch
|
| 96 |
+
from services.model_factory import load_production_model
|
| 97 |
+
|
| 98 |
+
# Inference
|
| 99 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 100 |
+
|
| 101 |
+
# This will:
|
| 102 |
+
|
| 103 |
+
# 1. Initialise DualHeadBERTClassifier
|
| 104 |
+
# 2. Apply LoRA adapters
|
| 105 |
+
# 3. Check for 'dual_head_classifier.pt' locally
|
| 106 |
+
# 4. If missing, download latest from OguzhanKOG/sentinelai-bert-filter
|
| 107 |
+
# 5. Load trained weights and return model in eval mode
|
| 108 |
+
|
| 109 |
+
model = load_production_model(device=device)
|
| 110 |
+
|
| 111 |
+
# Model is ready for inference
|
| 112 |
+
message = "I'm completely overwhelmed with work and can't sleep anymore"
|
| 113 |
+
# ... standard tokenization using config.MODEL_NAME ...
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
### Configuration
|
| 117 |
+
|
| 118 |
+
All parameters (LoRA rank, Alpha, Model Backbone, Paths) are centralised in `filter/config.py`. To change the backbone or parameters across the entire service, update this file only.
|
| 119 |
+
|
| 120 |
+
## Limitations
|
| 121 |
+
|
| 122 |
+
- **Synthetic Training Data:** Model trained on generated examples, not real workplace messages
|
| 123 |
+
- **English Only:** No multilingual support
|
| 124 |
+
- **Context Window:** Limited to 128 tokens (Slack message-sized)
|
| 125 |
+
- **Not a Clinical Tool:** Designed for workplace wellbeing monitoring, not medical diagnosis
|
| 126 |
+
- **Bias Risk:** May reflect biases in synthetic data generation process
|
| 127 |
+
|
| 128 |
+
## Intended Use
|
| 129 |
+
|
| 130 |
+
**Primary Use Case:** Fast, cost-effective gatekeeper filter in SentinelAI architecture. Routes high-risk messages to expensive LLM agents for detailed analysis, while filtering out low-risk neutral messages.
|
| 131 |
+
|
| 132 |
+
**Architecture Position:**
|
| 133 |
+
|
| 134 |
+
```text
|
| 135 |
+
Slack Message → BERT Filter (this model) → [if risk] → LLM Agent Analysis → HR Alert
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
**Not Intended For:**
|
| 139 |
+
|
| 140 |
+
- Clinical diagnosis or medical decision-making
|
| 141 |
+
- Standalone mental health assessment
|
| 142 |
+
- Real-time crisis intervention (human oversight required)
|
| 143 |
+
- Legal or disciplinary actions without human review
|
| 144 |
+
|
| 145 |
+
## Training Logs
|
| 146 |
+
|
| 147 |
+
Full training metrics available in `training_log.json`:
|
| 148 |
+
|
| 149 |
+
- Epoch-by-epoch train/val losses
|
| 150 |
+
- Category and severity accuracies per epoch
|
| 151 |
+
- Final test set evaluation results
|
| 152 |
+
|
| 153 |
+
## Repository
|
| 154 |
+
|
| 155 |
+
Full implementation available in the project repository (Private).
|
| 156 |
+
|
| 157 |
+
Branch: `feature/filter`
|
| 158 |
+
|
| 159 |
+
### Framework versions
|
| 160 |
+
|
| 161 |
+
- PEFT 0.18.1
|