Python torch.nn.functional.bilinear() Examples
The following are 8
code examples of torch.nn.functional.bilinear().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
torch.nn.functional
, or try the search function
.
Example #1
Source File: bilinear.py From gtos with MIT License | 6 votes |
def forward(self, input_left, input_right): ''' Args: input_left: Tensor the left input tensor with shape = [batch1, batch2, ..., left_features] input_right: Tensor the right input tensor with shape = [batch1, batch2, ..., right_features] Returns: ''' left_size = input_left.size() right_size = input_right.size() assert left_size[:-1] == right_size[:-1], \ "batch size of left and right inputs mis-match: (%s, %s)" % (left_size[:-1], right_size[:-1]) batch = int(np.prod(left_size[:-1])) # convert left and right input to matrices [batch, left_features], [batch, right_features] input_left = input_left.view(batch, self.left_features) input_right = input_right.view(batch, self.right_features) # output [batch, out_features] output = F.bilinear(input_left, input_right, self.U, self.bias) output = output + F.linear(input_left, self.W_l, None) + F.linear(input_right, self.W_r, None) # convert back to [batch1, batch2, ..., out_features] return output.view(left_size[:-1] + (self.out_features, ))
Example #2
Source File: modules.py From NeuroNLP2 with GNU General Public License v3.0 | 6 votes |
def forward(self, input_left, input_right): """ Args: input_left: Tensor the left input tensor with shape = [batch1, batch2, ..., left_features] input_right: Tensor the right input tensor with shape = [batch1, batch2, ..., right_features] Returns: """ batch_size = input_left.size()[:-1] batch = int(np.prod(batch_size)) # convert left and right input to matrices [batch, left_features], [batch, right_features] input_left = input_left.view(batch, self.left_features) input_right = input_right.view(batch, self.right_features) # output [batch, out_features] output = F.bilinear(input_left, input_right, self.U, self.bias) output = output + F.linear(input_left, self.weight_left, None) + F.linear(input_right, self.weight_right, None) # convert back to [batch1, batch2, ..., out_features] return output.view(batch_size + (self.out_features, ))
Example #3
Source File: bilinear.py From stog with MIT License | 6 votes |
def forward(self, input_left, input_right): ''' Args: input_left: Tensor the left input tensor with shape = [batch1, batch2, ..., left_features] input_right: Tensor the right input tensor with shape = [batch1, batch2, ..., right_features] Returns: ''' left_size = input_left.size() right_size = input_right.size() assert left_size[:-1] == right_size[:-1], \ "batch size of left and right inputs mis-match: (%s, %s)" % (left_size[:-1], right_size[:-1]) batch = int(np.prod(left_size[:-1])) # convert left and right input to matrices [batch, left_features], [batch, right_features] input_left = input_left.view(batch, self.left_features) input_right = input_right.view(batch, self.right_features) # output [batch, out_features] output = F.bilinear(input_left, input_right, self.U, self.bias) output = output + F.linear(input_left, self.W_l, None) + F.linear(input_right, self.W_r, None) # convert back to [batch1, batch2, ..., out_features] return output.view(left_size[:-1] + (self.out_features, ))
Example #4
Source File: linear.py From GraphIE with GNU General Public License v3.0 | 5 votes |
def forward(self, input_left, input_right): ''' Args: input_left: Tensor the left input tensor with shape = [batch1, batch2, ..., left_features] input_right: Tensor the right input tensor with shape = [batch1, batch2, ..., right_features] Returns: ''' left_size = input_left.size() right_size = input_right.size() assert left_size[:-1] == right_size[:-1], \ "batch size of left and right inputs mis-match: (%s, %s)" % (left_size[:-1], right_size[:-1]) batch = int(np.prod(left_size[:-1])) # convert left and right input to matrices [batch, left_features], [batch, right_features] input_left = input_left.view(batch, self.left_features) input_right = input_right.view(batch, self.right_features) # output [batch, out_features] output = F.bilinear(input_left, input_right, self.U, self.bias) output = output + F.linear(input_left, self.W_l, None) + F.linear(input_right, self.W_r, None) # convert back to [batch1, batch2, ..., out_features] return output.view(left_size[:-1] + (self.out_features, ))
Example #5
Source File: nn.py From torchkit with MIT License | 5 votes |
def forward(self, input1, input2): dir_ = self.direction direction = dir_.div(dir_.pow(2).sum(1).sum(1).sqrt()[:,N_,N_]) weight = self.scale[:,N_,N_].mul(direction) return F.bilinear(input1, input2, weight, self.bias)
Example #6
Source File: probability.py From Jacinle with MIT License | 5 votes |
def forward(self, input1, input2): weight = self._regulize_parameter(self.weight) output = F.bilinear(input1, input2, weight, None) if self.norm: output = normalize_prob(output) return output
Example #7
Source File: linear.py From pytorch-meta with MIT License | 5 votes |
def forward(self, input1, input2, params=None): if params is None: params = OrderedDict(self.named_parameters()) bias = params.get('bias', None) return F.bilinear(input1, input2, params['weight'], bias)
Example #8
Source File: test_pyprof_nvtx.py From apex with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_grid_sample(self): inp = torch.randn(16, 8, 64, 64, device='cuda', dtype=self.dtype) grid = torch.randn(16, 32, 32, 2, device='cuda', dtype=self.dtype) output = F.grid_sample(inp, grid, mode='bilinear', padding_mode='zeros')