deeppavlov/core/models/lr_scheduled_model.py
def process_event(self, event_name: str, data: dict) -> None:
        """
        Update learning rate and momentum variables after event (given by `event_name`)

        Args:
            event_name: name of event after which the method was called.
                    Set of values: `"after_validation"`, `"after_batch"`, `"after_epoch"`, `"after_train_log"`
            data: dictionary with parameters values

        Returns:
            None
        """
        if event_name == "after_validation":
            if data['impatience'] > self._learning_rate_last_impatience:
                self._learning_rate_cur_impatience += 1
            else:
                self._learning_rate_cur_impatience = 0

            self._learning_rate_last_impatience = data['impatience']

            if (self._learning_rate_drop_patience is not None) and\
                    (self._learning_rate_cur_impatience >=
                     self._learning_rate_drop_patience):
                self._learning_rate_cur_impatience = 0
                self._learning_rate_cur_div *= self._learning_rate_drop_div
                self._lr /= self._learning_rate_drop_div
                self._update_graph_variables(learning_rate=self._lr)
                log.info(f"New learning rate dividor = {self._learning_rate_cur_div}")
        if event_name == 'after_batch':
            if (self._lr is not None) and self._lr_update_on_batch:
                self._lr = self._lr_schedule.next_val() / self._learning_rate_cur_div
                self._update_graph_variables(learning_rate=self._lr)
            if (self._mom is not None) and self._mom_update_on_batch:
                self._mom = min(1., max(0., self._mom_schedule.next_val()))
                self._update_graph_variables(momentum=self._mom)
        if event_name == 'after_epoch':
            if (self._lr is not None) and not self._lr_update_on_batch:
                self._lr = self._lr_schedule.next_val() / self._learning_rate_cur_div
                self._update_graph_variables(learning_rate=self._lr)
            if (self._mom is not None) and not self._mom_update_on_batch:
                self._mom = min(1., max(0., self._mom_schedule.next_val()))
                self._update_graph_variables(momentum=self._mom)
        if event_name == 'after_train_log':
            if (self._lr is not None) and ('learning_rate' not in data):
                data['learning_rate'] = self._lr
            if (self._mom is not None) and ('momentum' not in data):
                data['momentum'] = self._mom
def process_event(self, event_name: str, data: dict) -> None:
        """
        Update learning rate and momentum variables after event (given by `event_name`)

        Args:
            event_name: name of event after which the method was called.
                    Set of values: `"after_validation"`, `"after_batch"`, `"after_epoch"`, `"after_train_log"`
            data: dictionary with parameters values

        Returns:
            None
        """
        if event_name == "after_validation":
            if data['impatience'] > self._learning_rate_last_impatience:
                self._learning_rate_cur_impatience += 1
            else:
                self._learning_rate_cur_impatience = 0

            self._learning_rate_last_impatience = data['impatience']

            if (self._learning_rate_drop_patience is not None) and\
                    (self._learning_rate_cur_impatience >=
                     self._learning_rate_drop_patience):
                self._learning_rate_cur_impatience = 0
                self._learning_rate_cur_div *= self._learning_rate_drop_div
                self._lr /= self._learning_rate_drop_div
                self._update_graph_variables(learning_rate=self._lr)
                log.info(f"New learning rate dividor = {self._learning_rate_cur_div}")
        if event_name == 'after_batch':
            if (self._lr is not None) and self._lr_update_on_batch:
                self._lr = self._lr_schedule.next_val() / self._learning_rate_cur_div
                self._update_graph_variables(learning_rate=self._lr)
            if (self._mom is not None) and self._mom_update_on_batch:
                self._mom = min(1., max(0., self._mom_schedule.next_val()))
                self._update_graph_variables(momentum=self._mom)
        if event_name == 'after_epoch':
            if (self._lr is not None) and not self._lr_update_on_batch:
                self._lr = self._lr_schedule.next_val() / self._learning_rate_cur_div
                self._update_graph_variables(learning_rate=self._lr)
            if (self._mom is not None) and not self._mom_update_on_batch:
                self._mom = min(1., max(0., self._mom_schedule.next_val()))
                self._update_graph_variables(momentum=self._mom)
        if event_name == 'after_train_log':
            if (self._lr is not None) and ('learning_rate' not in data):
                data['learning_rate'] = self._lr
            if (self._mom is not None) and ('momentum' not in data):
                data['momentum'] = self._mom
def process_event ( self , event_name : str , data : dict ) -> None : if event_name == "after_validation" : if data [ 'impatience' ] > self . _learning_rate_last_impatience : self . _learning_rate_cur_impatience += 1 else : self . _learning_rate_cur_impatience = 0 self . _learning_rate_last_impatience = data [ 'impatience' ] if ( self . _learning_rate_drop_patience is not None ) and ( self . _learning_rate_cur_impatience >= self . _learning_rate_drop_patience ) : self . _learning_rate_cur_impatience = 0 self . _learning_rate_cur_div *= self . _learning_rate_drop_div self . _lr /= self . _learning_rate_drop_div self . _update_graph_variables ( learning_rate = self . _lr ) log . info ( f"New learning rate dividor = {self._learning_rate_cur_div}" ) if event_name == 'after_batch' : if ( self . _lr is not None ) and self . _lr_update_on_batch : self . _lr = self . _lr_schedule . next_val ( ) / self . _learning_rate_cur_div self . _update_graph_variables ( learning_rate = self . _lr ) if ( self . _mom is not None ) and self . _mom_update_on_batch : self . _mom = min ( 1. , max ( 0. , self . _mom_schedule . next_val ( ) ) ) self . _update_graph_variables ( momentum = self . _mom ) if event_name == 'after_epoch' : if ( self . _lr is not None ) and not self . _lr_update_on_batch : self . _lr = self . _lr_schedule . next_val ( ) / self . _learning_rate_cur_div self . _update_graph_variables ( learning_rate = self . _lr ) if ( self . _mom is not None ) and not self . _mom_update_on_batch : self . _mom = min ( 1. , max ( 0. , self . _mom_schedule . next_val ( ) ) ) self . _update_graph_variables ( momentum = self . _mom ) if event_name == 'after_train_log' : if ( self . _lr is not None ) and ( 'learning_rate' not in data ) : data [ 'learning_rate' ] = self . _lr if ( self . _mom is not None ) and ( 'momentum' not in data ) : data [ 'momentum' ] = self . _mom
Update learning rate and momentum variables after event (given by `event_name`)

        Args:
            event_name: name of event after which the method was called.
                    Set of values: `"after_validation"`, `"after_batch"`, `"after_epoch"`, `"after_train_log"`
            data: dictionary with parameters values

        Returns:
            None
Update learning rate and momentum variables after event ( given by event_name )