Created
July 20, 2021 13:08
-
-
Save lazuxd/5e802f254caf827239d336db0e0a789b to your computer and use it in GitHub Desktop.
This file contains 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
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