Class: DNN::Layers::SimpleRNN
- Inherits:
-
RNN
- Object
- Layer
- TrainableLayer
- Connection
- RNN
- DNN::Layers::SimpleRNN
- Defined in:
- lib/dnn/core/layers/rnn_layers.rb
Instance Attribute Summary collapse
-
#activation ⇒ Object
readonly
Returns the value of attribute activation.
Attributes inherited from RNN
#hidden, #num_nodes, #recurrent_weight, #recurrent_weight_initializer, #recurrent_weight_regularizer, #return_sequences, #stateful
Attributes inherited from Connection
#bias, #bias_initializer, #bias_regularizer, #weight, #weight_initializer, #weight_regularizer
Attributes inherited from TrainableLayer
Attributes inherited from Layer
Instance Method Summary collapse
- #build(input_shape) ⇒ Object
- #create_hidden_layer ⇒ Object
-
#initialize(num_nodes, stateful: false, return_sequences: true, activation: Layers::Tanh.new, weight_initializer: Initializers::RandomNormal.new, recurrent_weight_initializer: Initializers::RandomNormal.new, bias_initializer: Initializers::Zeros.new, weight_regularizer: nil, recurrent_weight_regularizer: nil, bias_regularizer: nil, use_bias: true) ⇒ SimpleRNN
constructor
A new instance of SimpleRNN.
- #load_hash(hash) ⇒ Object
- #to_hash ⇒ Object
Methods inherited from RNN
#backward, #forward, #get_params, #output_shape, #regularizers, #reset_state
Methods inherited from Connection
#get_params, #regularizers, #use_bias
Methods inherited from TrainableLayer
Methods inherited from Layer
#backward, #built?, #call, call, #clean, #forward, from_hash, #output_shape
Constructor Details
#initialize(num_nodes, stateful: false, return_sequences: true, activation: Layers::Tanh.new, weight_initializer: Initializers::RandomNormal.new, recurrent_weight_initializer: Initializers::RandomNormal.new, bias_initializer: Initializers::Zeros.new, weight_regularizer: nil, recurrent_weight_regularizer: nil, bias_regularizer: nil, use_bias: true) ⇒ SimpleRNN
Returns a new instance of SimpleRNN.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 173 def initialize(num_nodes, stateful: false, return_sequences: true, activation: Layers::Tanh.new, weight_initializer: Initializers::RandomNormal.new, recurrent_weight_initializer: Initializers::RandomNormal.new, bias_initializer: Initializers::Zeros.new, weight_regularizer: nil, recurrent_weight_regularizer: nil, bias_regularizer: nil, use_bias: true) super(num_nodes, stateful: stateful, return_sequences: return_sequences, weight_initializer: weight_initializer, recurrent_weight_initializer: recurrent_weight_initializer, bias_initializer: bias_initializer, weight_regularizer: weight_regularizer, recurrent_weight_regularizer: recurrent_weight_regularizer, bias_regularizer: bias_regularizer, use_bias: use_bias) @activation = activation end |
Instance Attribute Details
#activation ⇒ Object (readonly)
Returns the value of attribute activation.
170 171 172 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 170 def activation @activation end |
Instance Method Details
#build(input_shape) ⇒ Object
197 198 199 200 201 202 203 204 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 197 def build(input_shape) super num_prev_nodes = input_shape[1] @weight.data = Xumo::SFloat.new(num_prev_nodes, @num_nodes) @recurrent_weight.data = Xumo::SFloat.new(@num_nodes, @num_nodes) @bias.data = Xumo::SFloat.new(@num_nodes) if @bias init_weight_and_bias end |
#create_hidden_layer ⇒ Object
206 207 208 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 206 def create_hidden_layer @hidden_layers = Array.new(@time_length) { SimpleRNNDense.new(@weight, @recurrent_weight, @bias, @activation) } end |
#load_hash(hash) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 214 def load_hash(hash) initialize(hash[:num_nodes], stateful: hash[:stateful], return_sequences: hash[:return_sequences], activation: Layers::Layer.from_hash(hash[:activation]), weight_initializer: Initializers::Initializer.from_hash(hash[:weight_initializer]), recurrent_weight_initializer: Initializers::Initializer.from_hash(hash[:recurrent_weight_initializer]), bias_initializer: Initializers::Initializer.from_hash(hash[:bias_initializer]), weight_regularizer: Regularizers::Regularizer.from_hash(hash[:weight_regularizer]), recurrent_weight_regularizer: Regularizers::Regularizer.from_hash(hash[:recurrent_weight_regularizer]), bias_regularizer: Regularizers::Regularizer.from_hash(hash[:bias_regularizer]), use_bias: hash[:use_bias]) end |
#to_hash ⇒ Object
210 211 212 |
# File 'lib/dnn/core/layers/rnn_layers.rb', line 210 def to_hash super(activation: @activation.to_hash) end |