Additive scoring lets a small neural network assign each representation a context-dependent attention score. It concatenates an item state hₜ with a context vector, transforms the result with a learned layer and tanh, then produces one scalar through another learned layer. section 10.2.3 section 10.2
A batched implementation follows these steps:
- Repeat the context from (B, H) to (B, T, H), matching the sequence of states. section 10.2.3
- Concatenate states and context along the feature dimension, producing (B, T, 2H). section 10.2.3
- Apply a linear layer from 2H to H, tanh, and a final linear layer from H to 1, returning (B, T, 1). section 10.2.3
PyTorch shape pattern
Use nn.Linear(2*H, H) for the hidden layer and nn.Linear(H, 1) for the output layer; concatenate with torch.cat(..., dim=2) so all T scores are computed at once.
