Class: DNN::Layers::SimpleRNN
- Inherits:
-
RNN
- Object
- Layer
- HasParamLayer
- Connection
- RNN
- DNN::Layers::SimpleRNN
- Includes:
- Activations
- Defined in:
- lib/dnn/core/rnn_layers.rb
Instance Attribute Summary collapse
-
#activation ⇒ Object
readonly
Returns the value of attribute activation.
Attributes inherited from RNN
#num_nodes, #recurrent_weight_initializer, #recurrent_weight_regularizer, #return_sequences, #stateful
Attributes inherited from Connection
#bias_initializer, #bias_regularizer, #weight_initializer, #weight_regularizer
Attributes inherited from HasParamLayer
Attributes inherited from Layer
Class Method Summary collapse
Instance Method Summary collapse
- #build(input_shape) ⇒ Object
-
#initialize(num_nodes, stateful: false, return_sequences: true, activation: Tanh.new, weight_initializer: RandomNormal.new, recurrent_weight_initializer: RandomNormal.new, bias_initializer: Zeros.new, weight_regularizer: nil, recurrent_weight_regularizer: nil, bias_regularizer: nil, use_bias: true) ⇒ SimpleRNN
constructor
A new instance of SimpleRNN.
- #to_hash ⇒ Object
Methods inherited from RNN
#backward, #forward, #output_shape, #regularizers, #reset_state
Methods inherited from Connection
Methods inherited from Layer
#backward, #built?, #forward, #output_shape
Constructor Details
#initialize(num_nodes, stateful: false, return_sequences: true, activation: Tanh.new, weight_initializer: RandomNormal.new, recurrent_weight_initializer: RandomNormal.new, bias_initializer: Zeros.new, weight_regularizer: nil, recurrent_weight_regularizer: nil, bias_regularizer: nil, use_bias: true) ⇒ SimpleRNN
Returns a new instance of SimpleRNN.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/dnn/core/rnn_layers.rb', line 166 def initialize(num_nodes, stateful: false, return_sequences: true, activation: Tanh.new, weight_initializer: RandomNormal.new, recurrent_weight_initializer: RandomNormal.new, bias_initializer: 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.
149 150 151 |
# File 'lib/dnn/core/rnn_layers.rb', line 149 def activation @activation end |
Class Method Details
.from_hash(hash) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/dnn/core/rnn_layers.rb', line 151 def self.from_hash(hash) simple_rnn = self.new(hash[:num_nodes], stateful: hash[:stateful], return_sequences: hash[:return_sequences], activation: Utils.from_hash(hash[:activation]), weight_initializer: Utils.from_hash(hash[:weight_initializer]), recurrent_weight_initializer: Utils.from_hash(hash[:recurrent_weight_initializer]), bias_initializer: Utils.from_hash(hash[:bias_initializer]), weight_regularizer: Utils.from_hash(hash[:weight_regularizer]), recurrent_weight_regularizer: Utils.from_hash(hash[:recurrent_weight_regularizer]), bias_regularizer: Utils.from_hash(hash[:bias_regularizer]), use_bias: hash[:use_bias]) simple_rnn end |
Instance Method Details
#build(input_shape) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/dnn/core/rnn_layers.rb', line 190 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 @time_length.times do |t| @layers << SimpleRNN_Dense.new(@weight, @recurrent_weight, @bias, @activation) end end |
#to_hash ⇒ Object
202 203 204 |
# File 'lib/dnn/core/rnn_layers.rb', line 202 def to_hash super({activation: @activation.to_hash}) end |