Using our model to get predictions

To get the predictions from our model, we need to take a sample from the output distribution. This sampling will get us the characters we need from that output distribution (sampling the output distribution is important because taking the argmax of it, as we would normally do, can easily get the model stuck in a loop).

tf.random.categorical does this sampling and tf.squeeze with axis=-1 removes the last dimension of the tensor, prior to displaying the indices.

The signature of tf.random.categorical is as follows:

tf.random.categorical(logits, num_samples, seed=None, name=None, output_dtype=None)

Comparing this with the call, we see that we are taking one sample (of length sequence_length = 100) from the ...

Get TensorFlow 2.0 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.