Skip to content

Instantly share code, notes, and snippets.

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