RNNs are not only powerful to parse and classify text. RNNs can also be used to generate text. In it's simplest form, text is generated on character level. More specifically, the text is generated character per character. Before we can generate text, we need to train a decoder on full sentences. By including a GRU layer in our decoder, the model does not only depend on the previous input but does try to predict the next character based on the context around it. In the following recipe, we will demonstrate how to implement a character-level text generator with PyTorch.
Character-level text generation
How to do it...
- Let's start with importing the libraries as follows:
import unidecode
import string
import random...