November 2017
Intermediate to advanced
274 pages
6h 16m
English
We will now use the TensorFlow API; the inner workings of the RNN are hidden under the hood. The TensorFlow rnn package unrolls the RNN and creates the graph automatically so that we can remove the for loop:
from __future__ import print_function, divisionimport tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt"""define all the constants"""numEpochs = 10seriesLength = 50000backpropagationLength = 15stateSize = 4numClasses = 2echoStep = 3batchSize = 5num_batches = seriesLength // batchSize // backpropagationLength"""generate data"""def generateData(): x = np.array(np.random.choice(2, seriesLength, p=[0.5, 0.5])) y = np.roll(x, echoStep) y[0:echoStep] = 0 x = x.reshape((batchSize, -1)) y = y.reshape((batchSize ...
Read now
Unlock full access