Different Types of Attention
and are source hidden states and target hidden state, the shape is (n,1). is the final context vector, and is alignment score.
Global(Soft) VS Local(Hard)
Global Attention takes all source hidden states into account, and local attention only use part of the source hidden states.
Content-based VS Location-based
Content-based Attention uses both source hidden states and target hidden states, but location-based attention only use source hidden states.
Here are several popular attention mechanisms:
Dot-Product
Scaled Dot-Product
where n is the vectors dimension. Google’s Transformer model has similar scaling factor when calculate self-attention:
Location-Base
General
’s shape is (n,n)
Concat
’s shape is (x,1), and ’s shape is (x,x). This is similar to a neural network with one hidden layer.
When I doing a slot filling project, I compare these mechanisms. Concat attention produce the best result.