- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud

Generating Text Using TensorFlow
One fun thing we can do with machine learning is generating text! We can build a model that will predict the next word in a sequence. This combines interesting aspects of both sequence processing and natural language processing. This lab will give you more practice in both of these important areas of machine learning. ### Prerequisites This lab is designed to be completed in PyCharm running on your machine. You should have PyCharm and TensorFlow installed before attempting this lab. We will not be covering this setup in the lab.

Lab Info
Table of Contents
-
Challenge
Retrieve and Load the Tiny Frankenstein Data
- Download the Tiny Frankenstein dataset: https://storage.googleapis.com/acg-datasets/tiny_frankenstein.tgz.
- Load the raw text into the program.
- Convert the text to lowercase.
-
Challenge
Turn the Text Data into Token Sequences
- Train a tokenizer on the Frankenstein text using every available word.
- Find the total number of learned words.
- Convert the Frankenstein text to tokens.
- Convert the tokens to sequences.
-
Challenge
Build a Model to Predict Tokens
- Create a recurrent neural network to learn the token sequences.
- Hint: Bidirectional LSTMs work really well for this task!
- Compile the model with an appropriate loss function and optimizer.
- Hint: You might want to increase the learning rate of the optimizer. This model can take a very long time to converge with the default learning rate.
- Train your model for 10-20 epochs.
- Create a recurrent neural network to learn the token sequences.
-
Challenge
Generate Text!
- Create a reverse token lookup dictionary from the tokenizer's
word_index
. - Create tokenized text to start the predictions.
- Use the model to predict the next token.
- Append the predicted token to the text, truncating earlier values.
- Continue using the model to predict as many tokens as you'd like!
- Create a reverse token lookup dictionary from the tokenizer's
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.