Transformer Architecture Internals · Problem 3 of 7
Implement multi-head attention from scratch in PyTorch incl. causal mask and output projection.
Implement the function/class skeleton in the editor. Any correct approach is accepted.
import torch
import torch.nn as nn
import torch.nn.functional as F
class MultiHeadAttention(nn.Module):
def __init__(self, d_model, n_heads):
raise NotImplementedError
def forward(self, x):
raise NotImplementedErrorReady when you are
Submit your solution and a structured review appears here — verdict, score, and concrete feedback. Any correct approach passes.
Implement multi-head attention from scratch in PyTorch incl. causal mask and output projection.
Implement the function/class skeleton in the editor. Any correct approach is accepted.