Created
December 31, 2025 19:46
-
-
Save cjams/e02cd8bf2aa86e56a7028c3811047b55 to your computer and use it in GitHub Desktop.
Bengio sampling
This file contains hidden or 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
| story = ‘’ | |
| ctx = [0] * ctx_window # start with context full of “special” characters | |
| while True: | |
| x = torch.tensor([ctx], device=device) | |
| for layer in model: | |
| x = layer(x) | |
| counts = x.exp() | |
| probs = counts / counts.sum(dim=1, keepdim=True) | |
| i = torch.multinomial(probs, num_samples=1, replacement=True, generator=g).item() | |
| s = itos[i] | |
| story += s | |
| ctx = ctx[1:] + [i] | |
| if i == 0: | |
| break | |
| print(f”Story time: {story}”) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment