AI for Rare Disease Diagnosis and Research
Module: Healthcare AI | Difficulty: Advanced
Few-Shot Learning (Prototypical)
where .
Knowledge Graph Embedding
Rare Disease Statistics
| Statistic | Value |
|---|---|
| Known rare diseases | 7,000+ |
| Patients affected | 300M+ worldwide |
| Average diagnostic delay | 5-7 years |
| Genetic cause identified | ~80% |
| Treatment available | ~5% |
import torch
import torch.nn as nn
class PrototypicalNetwork(nn.Module):
def __init__(self, input_dim=100, hidden_dim=64, embedding_dim=32):
super().__init__()
self.encoder = nn.Sequential(
nn.Linear(input_dim, hidden_dim), nn.ReLU(),
nn.Linear(hidden_dim, hidden_dim), nn.ReLU(),
nn.Linear(hidden_dim, embedding_dim))
def forward(self, support_set, query):
support_embeddings = self.encoder(support_set)
query_embedding = self.encoder(query)
prototypes = support_embeddings.mean(dim=1)
distances = torch.cdist(query_embedding, prototypes)
return -distances
class RareDiseaseClassifier(nn.Module):
def __init__(self, num_symptoms=200, num_diseases=500):
super().__init__()
self.symptom_embed = nn.Embedding(num_symptoms, 32)
self.disease_embed = nn.Embedding(num_diseases, 32)
self.gating = nn.Sequential(
nn.Linear(32, 1), nn.Sigmoid())
def forward(self, symptom_ids, disease_ids):
symptom_emb = self.symptom_embed(symptom_ids).mean(dim=1)
disease_emb = self.disease_embed(disease_ids)
gate = self.gating(symptom_emb.unsqueeze(1) * disease_emb)
scores = (symptom_emb.unsqueeze(1) * disease_emb * gate).sum(dim=-1)
return scores
proto_net = PrototypicalNetwork(input_dim=200, embedding_dim=32)
support = torch.randn(5, 10, 200)
query = torch.randn(1, 200)
distances = proto_net(support, query)
print(f'Distances to prototypes: {distances.shape}')
disease_classifier = RareDiseaseClassifier(num_symptoms=200, num_diseases=500)
symptoms = torch.randint(0, 200, (1, 15))
diseases = torch.randint(0, 500, (1, 100))
scores = disease_classifier(symptoms, diseases)
print(f'Disease similarity scores: {scores.shape}')
Research Insight: Rare disease diagnosis is one of the most impactful applications of AI in healthcare. Few-shot learning approaches that can recognize diseases from just a handful of examples are particularly valuable. Knowledge graphs that connect genes, symptoms, and diseases provide a structured representation that can generalize to unseen diseases through relational reasoning.