<commit_before>------------------------------------------------------------------------
--[[ Confusion ]]--
-- Feedback
-- Adapter for optim.ConfusionMatrix
-- requires 'optim' package
------------------------------------------------------------------------
local Confusion, parent = torch.class("dp.Confusion", "dp.Feedback")
Confusion.isConfusion = true
   
function Confusion:__init(config)
   config = config or {}
   assert(torch.type(config) == 'table' and not config[1], 
      "Constructor requires key-value arguments")
   local args, name = xlua.unpack(
      {config},
      'Confusion', 
      'Adapter for optim.ConfusionMatrix',
      {arg='name', type='string', default='confusion',
       help='name identifying Feedback in reports'}
   )
   config.name = name
   parent.__init(self, config)
end

function Confusion:setup(config)
   parent.setup(self, config)
   self._mediator:subscribe("doneEpoch", self, "doneEpoch")
end

function Confusion:doneEpoch(report)
   if self._cm then
      print(self._id:toString().." accuracy = "..self._cm.totalValid)
   end
end

function Confusion:_add(batch, output, carry, report)
   if not self._cm then
      require 'optim'
      self._cm = optim.ConfusionMatrix(batch:targets():classes())
   end
   local act = output:forward('bf')
   if act ~= 'torch.DoubleTensor' and act ~= 'torch.FloatTensor' then<commit_msg>fixed small bug in Confusion<commit_after>------------------------------------------------------------------------
--[[ Confusion ]]--
-- Feedback
-- Adapter for optim.ConfusionMatrix
-- requires 'optim' package
------------------------------------------------------------------------
local Confusion, parent = torch.class("dp.Confusion", "dp.Feedback")
Confusion.isConfusion = true
   
function Confusion:__init(config)
   config = config or {}
   assert(torch.type(config) == 'table' and not config[1], 
      "Constructor requires key-value arguments")
   local args, name = xlua.unpack(
      {config},
      'Confusion', 
      'Adapter for optim.ConfusionMatrix',
      {arg='name', type='string', default='confusion',
       help='name identifying Feedback in reports'}
   )
   config.name = name
   parent.__init(self, config)
end

function Confusion:setup(config)
   parent.setup(self, config)
   self._mediator:subscribe("doneEpoch", self, "doneEpoch")
end

function Confusion:doneEpoch(report)
   if self._cm then
      print(self._id:toString().." accuracy = "..self._cm.totalValid)
   end
end

function Confusion:_add(batch, output, carry, report)
   if not self._cm then
      require 'optim'
      self._cm = optim.ConfusionMatrix(batch:targets():classes())
   end
   local act = output:forward('bf')
   local act_type = torch.type(act)
   if act_type ~= 'torch.DoubleTensor' and act_type ~= 'torch.FloatTensor' then
{'fraction_non_alphanumeric': 0.2220635487325955, 'fraction_numerical': 0.0007140307033202428, 'mean_word_length': 2.4635352286773795, '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': '732892', 'n_tokens_mistral': 785, 'n_tokens_neox': 778, 'n_words': 194}