Skip to content

Instantly share code, notes, and snippets.

@BenTenmann
Last active April 19, 2021 20:48
Show Gist options
  • Save BenTenmann/eddf76e7ab868af45516fec5fd2c740e to your computer and use it in GitHub Desktop.
Save BenTenmann/eddf76e7ab868af45516fec5fd2c740e to your computer and use it in GitHub Desktop.
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