Defining the model

We will be using a different approach from the Keras model used earlier in the project to build this model. To build a more complex model, we will use Tensorflow to write each layer from scratch. Tensorflow gives us as Data Scientists and Deep Learning Engineers more fine-tuned control over our model architecture. 

For this model, we will use the code in this block to create 2 placeholders which will store the input and output values:

import tensorflow as tf
import pickle
from tensorflow.contrib import rnn

def build(self, input_number, sequence_length, layers_number, units_number, output_number):
self.x = tf.placeholder("float", [None, sequence_length, input_number])
self.y = tf.placeholder("float", [None, output_number])
self.sequence_length = sequence_length

Next, we need to store the weights and bias in variables we create:

        self.weights = {
'out': tf.Variable(tf.random_normal([units_number, output_number]))
}
self.biases = {
'out': tf.Variable(tf.random_normal([output_number]))
}

x = tf.transpose(self.x, [1, 0, 2])
x = tf.reshape(x, [-1, input_number])
x = tf.split(x, sequence_length, 0)

We build this model using multiple LSTM layers with the basic LSTM cells assigning each layer with the specified number of cells as shown in the figure below:

        lstm_layers = []
for i in range(0, layers_number):
lstm_layer = rnn.BasicLSTMCell(units_number)
lstm_layers.append(lstm_layer)

deep_lstm = rnn.MultiRNNCell(lstm_layers)

self.outputs, states = rnn.static_rnn(deep_lstm, x, dtype=tf.float32)

print "Build model with input_number: {}, sequence_length: {}, layers_number: {}, "
"units_number: {}, output_number: {}".format(input_number, sequence_length, layers_number,
units_number, output_number)
# This method is using to dump the model configurations
self.save(input_number, sequence_length, layers_number, units_number, output_number)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.226.121