Master Assignment π
Collection
Models trained for master coursework assignment
β’
8 items
β’
Updated
β’
1
This repository contains fine-tuned BERT models for classifying healthcare questionnaire responses into risk categories.
BERT-base-uncased models have been fine-tuned for healthcare risk assessment:
The models predict three risk categories:
from transformers import BertTokenizer, BertForSequenceClassification
import torch
# Load tokenizer
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
# Load fatigue model
fatigue_model = BertForSequenceClassification.from_pretrained('keanteng/bert-fatigue-response-classification-wqd7005')
def predict_risk(text, model, tokenizer, max_length=128):
# Tokenize input
inputs = tokenizer(
text,
padding='max_length',
truncation=True,
max_length=max_length,
return_tensors='pt'
)
# Make prediction
model.eval()
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predicted_class = torch.argmax(predictions, dim=-1)
# Map to risk categories
risk_labels = ['Low Risk', 'Moderate Risk', 'High Risk']
return risk_labels[predicted_class.item()], predictions[0].tolist()
# Example usage
fatigue_text = "I feel extremely tired all the time and can't complete daily tasks"
risk_category, confidence_scores = predict_risk(fatigue_text, fatigue_model, tokenizer)
print(f"Risk Category: {risk_category}")
print(f"Confidence Scores: {confidence_scores}")
The models were trained and evaluated on healthcare questionnaire data with the following label mapping:
Fatigue Model:
The models were trained on questionnaire responses containing:
Data was split 80/20 for training and validation with stratified sampling.
These models are designed for:
Important: These models are for research and screening purposes only and should not replace professional medical diagnosis.
Base model
google-bert/bert-base-uncased