Deep neural networks building blocks
In this section, we are going to present the key functions that will allow our deep learning project to work. Starting from batch feeding (providing chunks of data to learn to the deep neural network) we will prepare the building blocks of a complex LSTM architecture.
Note
The LSTM architecture is presented in a hands-on and detailed way in Chapter 7, Stock Price Prediction with LSTM, inside the Long short-term memory – LSTM 101 section
The first function we start working with is the prepare_batches
one. This function takes the question sequences and based on a step value (the batch size), returns a list of lists, where the internal lists are the sequence batches to be learned:
defprepare_batches(seq,step):n=len(seq)res=[]foriinrange(0,n,step):res.append(seq[i:i+step])returnres
The dense function will create a dense layer of neurons based on the provided size and activate and initialize them with random normally distributed numbers that have a mean of zero...