Class: Torch::NN::Bilinear

Inherits:
Module
  • Object
show all
Defined in:
lib/torch/nn/bilinear.rb

Instance Attribute Summary

Attributes inherited from Module

#training

Instance Method Summary collapse

Methods inherited from Module

#_apply, #add_module, #apply, #buffers, #call, #children, #cpu, #cuda, #deep_dup, #double, #eval, #float, #half, #inspect, #load_state_dict, #method_missing, #modules, #named_buffers, #named_children, #named_modules, #named_parameters, #parameters, #register_buffer, #register_parameter, #requires_grad!, #respond_to?, #share_memory, #state_dict, #to, #train, #type, #zero_grad

Methods included from Utils

#_activation_fn, #_clones, #_ntuple, #_pair, #_quadrupal, #_single, #_triple

Constructor Details

#initialize(in1_features, in2_features, out_features, bias: true) ⇒ Bilinear

Returns a new instance of Bilinear.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/torch/nn/bilinear.rb', line 4

def initialize(in1_features, in2_features, out_features, bias: true)
  super()

  @in1_features = in1_features
  @in2_features = in2_features
  @out_features = out_features
  @weight = Parameter.new(Tensor.new(out_features, in1_features, in2_features))

  if bias
    @bias = Parameter.new(Tensor.new(out_features))
  else
    raise NotImplementedYet
  end

  reset_parameters
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Torch::NN::Module

Instance Method Details

#extra_inspectObject



33
34
35
# File 'lib/torch/nn/bilinear.rb', line 33

def extra_inspect
  format("in1_features: %s, in2_features: %s, out_features: %s, bias: %s", @in1_features, @in2_features, @out_features, !@bias.nil?)
end

#forward(input1, input2) ⇒ Object



29
30
31
# File 'lib/torch/nn/bilinear.rb', line 29

def forward(input1, input2)
  F.bilinear(input1, input2, @weight, @bias)
end

#reset_parametersObject



21
22
23
24
25
26
27
# File 'lib/torch/nn/bilinear.rb', line 21

def reset_parameters
  bound = 1 / Math.sqrt(@weight.size(1))
  Init.uniform!(@weight, a: -bound, b: bound)
  if @bias
    Init.uniform!(@bias, a: -bound, b: bound)
  end
end