Views
No views yet
bert-base-uncased for 3-class sentiment classification on patient questionnaire responses. The model predicts whether the patient's self-reported symptoms indicate positive, neutral, or negative health sentiment.| Label | Description |
|---|---|
| positive | No abnormal symptoms detected; patient reports "mild fatigue, stable breathing, no severe discomfort" |
| neutral | Some symptoms reported but tagged as low concern / low deterioration risk |
| negative | High concern symptoms affecting daily activities |
patient_dataset.csv (2,000 synthetic patient records)questionnaire_text column — patient symptom descriptions with giveaway phrases (concern level, daily-activity impact) stripped to prevent label leakagedeterioration_risk (0/1) plus text parsing for the 0→positive/neutral split| Config | Value |
|---|---|
| Base Model | bert-base-uncased |
| Epochs | 30 |
| Batch Size | 16 |
| Learning Rate | 2e-5 |
| Optimizer | AdamW |
| Max Sequence Length | 128 tokens |
| Class Weights | Inverse frequency (negative class weighted ~2.9x) |
| Threshold Tuning | Negative-class logits boosted by ~3.0x at inference |
| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| positive | 1.00 | 1.00 | 1.00 | 177 |
| neutral | 0.92 | 0.99 | 0.95 | 177 |
| negative | 0.94 | 0.67 | 0.78 | 46 |
| accuracy | 0.96 | 400 | ||
| macro avg | 0.95 | 0.89 | 0.91 | 400 |

1from transformers import BertTokenizer, BertForSequenceClassification
2import torch
3
4tokenizer = BertTokenizer.from_pretrained("models/bert_patient_risk_sentiment")
5model = BertForSequenceClassification.from_pretrained("models/bert_patient_risk_sentiment")
6
7text = "The patient reports shortness of breath, fever and body aches."
8inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
9
10with torch.no_grad():
11 logits = model(**inputs).logits
12 # Apply tuned threshold for negative class
13 logits[:, 2] *= 3.0
14 pred = torch.argmax(logits, dim=1).item()
15
16label_map = {0: "positive", 1: "neutral", 2: "negative"}
17print(label_map[pred])