Class: Transformers::XlmRoberta::XLMRobertaPooler

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ XLMRobertaPooler

Returns a new instance of XLMRobertaPooler.



563
564
565
566
567
# File 'lib/transformers/models/xlm_roberta/modeling_xlm_roberta.rb', line 563

def initialize(config)
  super()
  @dense = Torch::NN::Linear.new(config.hidden_size, config.hidden_size)
  @activation = Torch::NN::Tanh.new
end

Instance Method Details

#forward(hidden_states) ⇒ Object



569
570
571
572
573
574
575
576
# File 'lib/transformers/models/xlm_roberta/modeling_xlm_roberta.rb', line 569

def forward(hidden_states)
  # We "pool" the model by simply taking the hidden state corresponding
  # to the first token.
  first_token_tensor = hidden_states[0.., 0]
  pooled_output = @dense.(first_token_tensor)
  pooled_output = @activation.(pooled_output)
  pooled_output
end