Last active
April 19, 2021 20:48
-
-
Save BenTenmann/eddf76e7ab868af45516fec5fd2c740e 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
def softmax(y): | |
return np.exp(y) / np.sum(np.exp(y)) | |
class ModernHopfield: | |
def __init__(self, memories): | |
self.memories = memories | |
def update(self, query): | |
normalised_memories = self.memories / np.vstack(np.linalg.norm(self.memories, | |
axis=1)) | |
return softmax(normalised_memories @ query) @ self.memories |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment