Class: Transformers::Bert::BertSelfOutput

Inherits:
Torch::NN::Module
  • Object
show all
Defined in:
lib/transformers/models/bert/modeling_bert.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ BertSelfOutput

Returns a new instance of BertSelfOutput.



202
203
204
205
206
207
# File 'lib/transformers/models/bert/modeling_bert.rb', line 202

def initialize(config)
  super()
  @dense = Torch::NN::Linear.new(config.hidden_size, config.hidden_size)
  @LayerNorm = Torch::NN::LayerNorm.new(config.hidden_size, eps: config.layer_norm_eps)
  @dropout = Torch::NN::Dropout.new(p: config.hidden_dropout_prob)
end

Instance Method Details

#forward(hidden_states, input_tensor) ⇒ Object



209
210
211
212
213
214
# File 'lib/transformers/models/bert/modeling_bert.rb', line 209

def forward(hidden_states, input_tensor)
  hidden_states = @dense.(hidden_states)
  hidden_states = @dropout.(hidden_states)
  hidden_states = @LayerNorm.(hidden_states + input_tensor)
  hidden_states
end