- Lab
- A Cloud Guru
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.
Path 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
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.