Created
November 13, 2020 14:04
-
-
Save denizyuret/a21c3e71e44dc4b0dcb3d68e4cd31c58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# given some encoder states X, decoder state y, matrices Q, K, V | |
for i in 1:N | |
keys[i] = K * X[i] | |
values[i] = V * X[i] | |
end | |
query = Q * y | |
for i in 1:N | |
relevance[i] = query ⋅ keys[i] | |
end | |
relevance = softmax(relevance) | |
output = 0 | |
for i in 1:N | |
output += relevance[i] * values[i] | |
end | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment