Skip to content

Instantly share code, notes, and snippets.

@szagoruyko
Forked from soumith/gist:0f95facad88cbea68c6d
Last active August 29, 2015 14:27
Show Gist options
  • Save szagoruyko/5a85d194c0ed61e1a729 to your computer and use it in GitHub Desktop.
Save szagoruyko/5a85d194c0ed61e1a729 to your computer and use it in GitHub Desktop.
linear with no bias
local Linear, parent = torch.class('nn.NoBiasLinear', 'nn.Linear')
function Linear:__init(inputSize, outputSize)
parent.__init(self, inputSize, outputSize)
self.bias:fill(0)
end
function Linear:accGradParameters(input, gradOutput, scale)
scale = scale or 1
if input:dim() == 1 then
self.gradWeight:addr(scale, gradOutput, input)
elseif input:dim() == 2 then
self.gradWeight:addmm(scale, gradOutput:t(), input)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment