AI-Assisted Telemedicine and Virtual Health
Module: Healthcare AI | Difficulty: Advanced
Triage Algorithm
Clinical Decision Tree
Conversation Quality Metrics
| Metric | Formula | Target |
|---|---|---|
| Response Accuracy | correct/total | >0.90 |
| Completeness | covered_topics/all_topics | >0.85 |
| Safety | 1 - unsafe/total | >0.99 |
| Empathy Score | NLP_empathy | >0.70 |
import torch
import torch.nn as nn
class MedicalChatbot(nn.Module):
def __init__(self, vocab_size=30000, hidden_dim=256, num_intents=20):
super().__init__()
self.embedding = nn.Embedding(vocab_size, hidden_dim)
self.lstm = nn.LSTM(hidden_dim, hidden_dim, batch_first=True, bidirectional=True)
self.intent_head = nn.Linear(hidden_dim * 2, num_intents)
self.entity_head = nn.Linear(hidden_dim * 2, 10)
self.response_head = nn.Linear(hidden_dim * 2, vocab_size)
def forward(self, input_ids):
embedded = self.embedding(input_ids)
lstm_out, _ = self.lstm(embedded)
context = lstm_out[:, -1, :]
intents = self.intent_head(context)
entities = self.entity_head(lstm_out)
response = self.response_head(context)
return intents, entities, response
class TriageBot(nn.Module):
def __init__(self, input_dim=100, hidden_dim=64):
super().__init__()
self.symptom_encoder = nn.Sequential(
nn.Linear(input_dim, hidden_dim), nn.ReLU(),
nn.Dropout(0.3), nn.Linear(hidden_dim, hidden_dim))
self.urgency_head = nn.Linear(hidden_dim, 5)
self.specialty_head = nn.Linear(hidden_dim, 20)
def forward(self, symptoms):
encoded = self.symptom_encoder(symptoms)
urgency = self.urgency_head(encoded)
specialty = self.specialty_head(encoded)
return urgency, specialty
chatbot = MedicalChatbot()
input_ids = torch.randint(0, 30000, (1, 100))
intents, entities, response = chatbot(input_ids)
print(f'Intents: {intents.shape}, Entities: {entities.shape}')
triage_bot = TriageBot()
symptoms = torch.randn(1, 100)
urgency, specialty = triage_bot(symptoms)
print(f'Urgency: {urgency.shape}, Specialty: {specialty.shape}')
Research Insight: Telemedicine AI must handle the full spectrum of patient interactions while maintaining safety. The most successful approaches use a hybrid architecture: a fast triage model for initial assessment, followed by a more detailed diagnostic model for complex cases. Human-in-the-loop design ensures that AI recommendations are reviewed by clinicians before final decisions.