This application is based on one provided by Google under an Apache 2 license.
As usual, we will break the code down into snippets and refer you to the repository for the license and the full working version. Firstly, we have module imports, as follows:
import tensorflow as tfimport numpy as npimport osimport time
Next, we have the download link for the text file.
You can easily change this to any text you wish by specifying the file name in file and the full URL of the file in url:
file='1400-0.txt'url='https://www.gutenberg.org/files/1400/1400-0.txt' # Great Expectations by Charles Dickens
And then we set up the Keras get_file() utility for that file, shown as follows:
path = tf.keras.utils.get_file(file,url) ...