<commit_before>
local RecordableLinear, Parent = torch.class('nn.RecordableLinear', 'nn.Linear')

function RecordableLinear:__init(inputSize, outputSize, opt)
   Parent.__init(self, inputSize, outputSize)
   self.isRecording = 0
   self.inputRecord = nil
   self.outputRecord = nil

   -- initialize
   if opt.arch.weightInit ~= nil and opt.arch.weightInit ~= '' then
     self:initWeights(opt.arch.weightInit)
   end
end

function RecordableLinear:initWeights(formula)
  self.fanin = self.weight:size(2)
  self.fanout = self.weight:size(1)
  formula = string.gsub(formula,'fanin',self.fanin)
  formula = string.gsub(formula,'fanout',self.fanout)
  local u = tonumber(formula) or loadstring('return '..formula)
  if type(u) == 'function' then
    u = u()
  end
  self.weight:uniform(-u, u)
  self.bias:uniform(-u, u)
  return self
end

function RecordableLinear:updateOutput(input)
  if self.isRecording > 0 and self.train == true then -- record input
    if self.inputRecord ~= nil then
      self.inputRecord = torch.cat(self.inputRecord, input, 1)
    else
      self.inputRecord = input:clone()
    end
  end

  local output Parent.updateOutput(self, input)

  if self.isRecording > 0 and self.train == true then -- record output
    if self.outputRecord ~= nil then
      self.outputRecord = torch.cat(self.outputRecord, output, 1)
    else
      self.outputRecord = output:clone()
    end
  end

  return output
end


function RecordableLinear:__tostring__()
  local pauseStr = ''
  if self.isRecording > 0 then pauseStr = ' recording' end

  return torch.type(self) ..
      string.format('(%d -> %d)'..pauseStr, self.weight:size(2), self.weight:size(1))
end<commit_msg>fix: missing assignment operator<commit_after>
local RecordableLinear, Parent = torch.class('nn.RecordableLinear', 'nn.Linear')

function RecordableLinear:__init(inputSize, outputSize, opt)
   Parent.__init(self, inputSize, outputSize)
   self.isRecording = 0
   self.inputRecord = nil
   self.outputRecord = nil

   -- initialize
   if opt.arch.weightInit ~= nil and opt.arch.weightInit ~= '' then
     self:initWeights(opt.arch.weightInit)
   end
end

function RecordableLinear:initWeights(formula)
  self.fanin = self.weight:size(2)
  self.fanout = self.weight:size(1)
  formula = string.gsub(formula,'fanin',self.fanin)
  formula = string.gsub(formula,'fanout',self.fanout)
  local u = tonumber(formula) or loadstring('return '..formula)
  if type(u) == 'function' then
    u = u()
  end
  self.weight:uniform(-u, u)
  self.bias:uniform(-u, u)
  return self
end

function RecordableLinear:updateOutput(input)
  if self.isRecording > 0 and self.train == true then -- record input
    if self.inputRecord ~= nil then
      self.inputRecord = torch.cat(self.inputRecord, input, 1)
    else
      self.inputRecord = input:clone()
    end
  end

  local output = Parent.updateOutput(self, input)

  if self.isRecording > 0 and self.train == true then -- record output
    if self.outputRecord ~= nil then
      self.outputRecord = torch.cat(self.outputRecord, output, 1)
    else
      self.outputRecord = output:clone()
    end
  end

  return output
end


function RecordableLinear:__tostring__()
  local pauseStr = ''
  if self.isRecording > 0 then pauseStr = ' recording' end

  return torch.type(self) ..
      string.format('(%d -> %d)'..pauseStr, self.weight:size(2), self.weight:size(1))
end
{'fraction_non_alphanumeric': 0.12088888888888889, 'fraction_numerical': 0.005925925925925926, 'mean_word_length': 3.748241912798875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7278681', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1087, 'n_words': 262}