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
# This code doesn't work, and isn't intended to. | |
# The goal of this code is to explain how attention mechansisms work, in code. | |
# It is deliberately not vectorized to make it clearer. | |
def attention(self, X_in:List[Tensor]): | |
# For every token transform previous layer's out | |
for i in range(self.sequence_length): | |
query[i] = self.Q * X_in[i] | |
key[i] = self.K * X_in[i] | |
value[i] = self.V * X_in[i] |