Week 6 • Day 7Week 6
Day 7:Week 6, Day 7 (Mini-Project): End-to-End PyTorch SRE Incident Severity Neural Classifier
Battle-tested daily lesson note • 100% runnable code, interview Q&A, test suite & interactive quiz
Week 6, Day 7 (Mini-Project): End-to-End PyTorch SRE Incident Severity Neural Classifier
1. Project Overview
In this Week 6 capstone mini-project, we combine every PyTorch concept from Days 1–6 into a clean, modular, production-grade PyTorch Incident Severity Neural Classifier:
- Custom
SimpleVocab&IncidentTextDatasetwith dynamic batch padding (dynamic_pad_collate_fn). - Neural Architecture (
IncidentNeuralClassifier):nn.Embedding(vocab_size, embed_dim, padding_idx=0)- Masked Mean Pooling over non-pad tokens ()
nn.LayerNorm(embed_dim)nn.Dropout(p)nn.Linear(embed_dim, hidden_dim)GELUnn.Linear(hidden_dim, num_classes)
- Production Training Loop:
nn.CrossEntropyLoss()torch.optim.AdamWwith decoupled weight decay- Global gradient clipping (
torch.nn.utils.clip_grad_norm_)
- Checkpoint Serialization (
state_dict+ Vocabulary) & Deterministic Inference undermodel.eval()+torch.inference_mode(). - Root
.envIntegration viaload_root_dotenv().
In Simple English: Putting Week 6 Together (Your First Neural Net App)
This mini-project bridges raw text and a real PyTorch Multi-Layer Perceptron (MLP) classifier:
- Tokenizer & Vocabulary: Converts raw SRE alerts (
"PostgreSQL connection pool exhausted") into integer IDs. nn.Embedding+ Mean Pooling: Looks up a dense semantic vector for each word, uses an Attention Mask to ignore<PAD>tokens, and averages the sentence into one clean feature vector.- Linear + ReLU + Linear Classifier Head: Predicts severity probabilities (
P1_CRITICAL,P2_HIGH,P3_LOW). - Full 5-Step Training Loop: Trains with
AdamW, gradient clipping, and validation accuracy tracking!
Interview Prep Note
In senior ML interviews, expect: "Why did you use an attention mask before mean pooling instead of naive x.mean(dim=1)?" Answer: Without masking, short padded sentences get dragged toward the <PAD> vector!