<commit_before>------------------------------------------------------------------------
--[[ EarlyStopper ]]--
-- Observer.
-- Saves version of the subject with the lowest error and terminates
-- the experiment when no new minima is found for max_epochs.
-- Should only be called on Experiment, Propagator or Model subjects.
------------------------------------------------------------------------
local EarlyStopper, parent = torch.class("dp.EarlyStopper", "dp.Observer")
EarlyStopper.isEarlyStopper = true

function EarlyStopper:__init(config) 
   assert(type(config) == 'table', "Constructor requires key-value arguments")
   local args, start_epoch, error_report, error_channel, maximize, 
         save_strategy, max_epochs, max_error, min_epoch
      = xlua.unpack(
      {config},
      'EarlyStopper', 
      'Saves a model at each new minima of error. ' ..
      'Error can be obtained from experiment report or mediator ' ..
      'channel. If obtained from experiment report via error_func, ' ..
      'subscribes to onDoneEpoch channel.',
      {arg='start_epoch', type='number', default=5,
       help='when to start saving models.'},
      {arg='error_report', type='table', 
       help='a sequence of keys to access error from report. ' ..
       'Default is {"validator", "loss", "avgError"}, unless ' ..
       'of course an error_channel is specified.'},
      {arg='error_channel', type='string | table',
       help='channel to subscribe to for early stopping. Should ' ..
       'return an error for which the models should be minimized, ' ..
       'and the report of the experiment.'},
      {arg='maximize', type='boolean', default=false,
       help='when true, the error channel or report is negated. ' ..
       'This is useful when the channel returns an accuracy ' ..
       'that should be maximized, instead of an error that should not'},
      {arg='save_strategy', type='object', default=dp.SaveToFile(),
       help='a serializable object that has a :save(subject) method.'},
      {arg='max_epochs', type='number', default='30',
       help='maximum number of epochs to consider after a minima ' ..
       'has been found. After that, a terminate signal is published ' ..
       'to the mediator.'},
      {arg='max_error', type='number', default=0,
       help='maximum value for which the experiment should be ' ..
       'stopped after min_epochs. ' ..
       'If maximize is true, this is min value'},
      {arg='min_epoch', type='number', default=10000000,
       help='see max_value'}
   )
   self._start_epoch = start_epoch
   self._minima_epoch = start_epoch - 1<commit_msg>earlystopper fixes<commit_after>------------------------------------------------------------------------
--[[ EarlyStopper ]]--
-- Observer.
-- Saves version of the subject with the lowest error and terminates
-- the experiment when no new minima is found for max_epochs.
-- Should only be called on Experiment, Propagator or Model subjects.
------------------------------------------------------------------------
local EarlyStopper, parent = torch.class("dp.EarlyStopper", "dp.Observer")
EarlyStopper.isEarlyStopper = true

function EarlyStopper:__init(config) 
   assert(type(config) == 'table', "Constructor requires key-value arguments")
   local args, start_epoch, error_report, error_channel, maximize, 
         save_strategy, max_epochs, max_error, min_epoch
      = xlua.unpack(
      {config},
      'EarlyStopper', 
      'Saves a model at each new minima of error. ' ..
      'Error can be obtained from experiment report or mediator ' ..
      'channel. If obtained from experiment report via error_report, ' ..
      'subscribes to doneEpoch channel.',
      {arg='start_epoch', type='number', default=5,
       help='when to start saving experiments to disk.'},
      {arg='error_report', type='table', 
       help='a sequence of keys to access error from report. ' ..
       'Default is {"validator", "loss", "avgError"}, unless ' ..
       'of course an error_channel is specified.'},
      {arg='error_channel', type='string | table',
       help='channel to subscribe to for early stopping. Should ' ..
       'return an error for which the models should be minimized, ' ..
       'and the report of the experiment.'},
      {arg='maximize', type='boolean', default=false,
       help='when true, the error channel or report is negated. ' ..
       'This is useful when the channel returns an accuracy ' ..
       'that should be maximized, instead of an error that should not'},
      {arg='save_strategy', type='object', default=dp.SaveToFile(),
       help='a serializable object that has a :save(subject) method.'},
      {arg='max_epochs', type='number', default='30',
       help='maximum number of epochs to consider after a minima ' ..
       'has been found. After that, a terminate signal is published ' ..
       'to the mediator.'},
      {arg='max_error', type='number', default=0,
       help='maximum value for which the experiment should be ' ..
       'stopped after min_epochs. ' ..
       'If maximize is true, this is min value'},
      {arg='min_epoch', type='number', default=10000000,
       help='see max_value'}
   )
   self._start_epoch = start_epoch
   self._minima_epoch = start_epoch - 1
{'fraction_non_alphanumeric': 0.1659056316590563, 'fraction_numerical': 0.004946727549467275, 'mean_word_length': 2.5234584450402147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '2728043', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1382, 'n_words': 502}