3 ms·
> Fundamentally, I have never understood why a conventional neural network cannot learn self-attention. Here's how I think about it: Yes, you can learn everyth
by thomasahle 4y ago
> Fundamentally, I have never understood why a conventional neural network cannot learn self-attention.
Here's how I think about it: Yes, you can learn everything with an MLP, since universal approximation and so on, but it is not efficient. And (modern) ML is all about scale.
Here's one way to see the difference: Self-attention takes as input N channels of dimension D. It maps to N keys and Queries with a DxD matrix, time = O(ND^2). Next it computes all pair-wise Key-Query inner products: time = O(N^2D). Finally
softmax takes time = O(N^2) and computing "probability times values" takes O(DN^2).
All in all self-attention takes O(DN^2+ND^2) time to map ND values to ND values.
How long would an MLP take to do the same thing? O((ND)^2).
So, in a typical case of D~1000 and N~1000 we save a factor 1000.
For the price of 1 MLP layer, you could afford 1000 self-attention layers.
It's a pretty major difference.
- candiodari 4y agoI think there's some room for the second factor too: generalization. If you have 2 models for the same phenomenon, and they're equally good, the model with less parameters is the better one. Not because it calculates faster, but because it will actually be more accurate.