<commit_before>local WeightedSmoothL1Criterion, parent = torch.class('detection.WeightedSmoothL1Criterion', 'nn.Criterion')

function WeightedSmoothL1Criterion:__init(sizeAverage)
   parent.__init(self)
   -- Local SmoothL1Loss
   self._smoothL1Loss = nn.SmoothL1Criterion(sizeAverage)
end

function WeightedSmoothL1Criterion:updateOutput(input, target)
	-- input contains the output of the network
	-- target has the labels as the first element and loss weights as the second element
	local repeat_size = input:size(2) / target[1]:size(2) 
	local targets = target[1]:repeatTensor(1,repeat_size)
	local weights = target[2]

	self.output = self._smoothL1Loss:forward(input[weights],targets[weights])	
   return self.output
end

function WeightedSmoothL1Criterion:updateGradInput(input, target)
   local repeat_size = input:size(2) / target[1]:size(2) 
   local targets = target[1]:repeatTensor(1,repeat_size)
   local weights = target[2]
   local smoothL1grad = self._smoothL1Loss:backward(input[weights],targets[weights])
   self.gradInput:resizeAs(input):zero()
   self.gradInput[weights] = smoothL1grad
   return self.gradInput
end<commit_msg>Added normalization to the layer<commit_after>local WeightedSmoothL1Criterion, parent = torch.class('detection.WeightedSmoothL1Criterion', 'nn.Criterion')

function WeightedSmoothL1Criterion:__init(sizeAverage)
   parent.__init(self)
   -- Local SmoothL1Loss
   self._smoothL1Loss = nn.SmoothL1Criterion()
   self._smoothL1Loss.sizeAverage = false
end

function WeightedSmoothL1Criterion:updateOutput(input, target)
	-- input contains the output of the network
	-- target has the labels as the first element and loss weights as the second element
   local repeat_size = input:size(2) / target[1]:size(2) 
	local targets = target[1]:repeatTensor(1,repeat_size)
	local weights = target[2]
   local n_row = targets:size(1)
	self.output = self._smoothL1Loss:forward(input[weights],targets[weights])	
   self.output = self.output / n_row
   return self.output
end

function WeightedSmoothL1Criterion:updateGradInput(input, target)
   local repeat_size = input:size(2) / target[1]:size(2) 
   local targets = target[1]:repeatTensor(1,repeat_size)
   local weights = target[2]
   local n_row = targets:size(1)
   local smoothL1grad = self._smoothL1Loss:backward(input[weights],targets[weights])/n_row
   self.gradInput:resizeAs(input):zero()
   self.gradInput[weights] = smoothL1grad
   return self.gradInput
end
{'fraction_non_alphanumeric': 0.09959183673469388, 'fraction_numerical': 0.020816326530612245, 'mean_word_length': 5.923728813559322, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7571299', 'n_tokens_mistral': 806, 'n_tokens_neox': 775, 'n_words': 164}