Senior interview questionAsked at Citadel · interview write-up
In PyTorch, build a classifier for sequences of 6-feature points, then adapt it as lengths vary, order stops mattering and features go missing.
Model answer
Variable length: pad and carry a mask so padding never enters pooling. Order stops mattering: encode each point on its own and pool with a symmetric function, the Deep Sets recipe. Missing features: fill with zero and append a per-feature missing flag, so absence itself is a signal.
import torch
import torch.nn as nn
class SetClassifier(nn.Module):
def __init__(self, d=6, h=64, n_cls=2):
super().__init__()
self.phi = nn.Sequential(
nn.Linear(2 * d, h), nn.ReLU(),
nn.Linear(h, h), nn.ReLU())
self.head = nn.Linear(h, n_cls)
def forward(self, x, keep):
# x: (B, T, 6), NaN where a feature is missing
# keep: (B, T) bool, True for real points
miss = torch.isnan(x).float()
x = torch.nan_to_num(x, nan=0.0)
z = self.phi(torch.cat([x, miss], -1))
z = z * keep.unsqueeze(-1).float()
n = keep.sum(1, keepdim=True).clamp(min=1)
return self.head(z.sum(1) / n)
Interviewers check the masking and a permutation test: shuffled points must give the same logits.
Practise the rest
35 Training questions, 492 in all, each with a model answer. Free.
More from Citadel interview questions.
More Training interview questions
- Implement masked cross-entropy in NumPy that stays numerically stable, with label smoothing and a temperature.
- Build a pipeline that finds math documents in web crawls and scores their quality.
- Explain KL divergence for language models: which direction is which, what happens when supports don't match, and how it's used as a regulariser.
- When would you use mean squared error versus cross-entropy? And what is LoRA?
- Explain Adam and its bias correction, and why AdamW decouples weight decay.
- Explain policy types in RL and modern policy-gradient methods such as TRPO, PPO and GAE, then compare linear attention and grouped-query attention.