How to do it...

The RNN models in TensorFlow can easily be extended to Deep RNN models by using MultiRNNCell. The previous rnn function can be replaced with the stacked_rnnfunction to achieve a deep RNN architecture:

  1. Define the number of layers in the deep RNN architecture:
num_layers <- 3 
  1. Define a stacked_rnn function to perform multi-hidden layers deep RNN:
stacked_rnn<-function(x, weight, bias){ 
  # Unstack input into step_size 
  x = tf$unstack(x, step_size, 1) 
   
  # Define a most basic RNN  
  network = tf$contrib$rnn$GRUCell(n.hidden) 
  
  # Then, assign stacked RNN cells 
  network = tf$contrib$rnn$MultiRNNCell(lapply(1:num_layers,function(k,network){network},network)) 
   
  # create a Recurrent Neural Network 
  cell_output = tf$contrib$rnn$static_rnn(network, x, dtype=tf$float32) 
   
  # Linear activation, using rnn inner loop  
  last_vec=tail(cell_output[[1]], n=1)[[1]] 
  return(tf$matmul(last_vec, weights) + bias) 
} 
..................Content has been hidden....................

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