g = torch.Generator().manual_seed(2147483647) for i in range(5): out = [] ix = 0 while True: p = P[ix] ix = torch.multinomial(p, num_samples=1, replacement=True, generator=g).item() out.append(itos[ix]) if ix == 0: break print(''.join(out))