Skip to content

Instantly share code, notes, and snippets.

@lazuxd
Created July 1, 2021 12:31
Show Gist options
  • Save lazuxd/f296cab1bec0f877150bb91a6fd06eae to your computer and use it in GitHub Desktop.
Save lazuxd/f296cab1bec0f877150bb91a6fd06eae to your computer and use it in GitHub Desktop.
def sample(self) -> str:
# sample a new sentence from the learned model
sentence = ''
a = np.zeros((1, self.a_size))
x = np.zeros((1, self.vocab_size))
while True:
a, y_hat = self(a, x)
word = sample_word(self.vocab, tf.reshape(y_hat, (-1,)))
if word == EOS:
break
sentence += ' '+word
x = words2onehot(self.vocab, [word])
return sentence[1:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment