(self)
Training End-to-end ASR system
Training End-to-end ASR system
Training End - to - end ASR system
def exec(self):
        ''' Training End-to-end ASR system '''
        self.verbose('Total training steps {}.'.format(
            human_format(self.max_step)))
        self.timer.set()

        while self.step < self.max_step:
            for data in self.tr_set:
                # Pre-step : update tf_rate/lr_rate and do zero_grad
                self.optimizer.pre_step(self.step)

                # Fetch data
                txt, txt_len = self.fetch_data(data)
                self.timer.cnt('rd')

                # Forward model
                pred, _ = self.model(txt[:, :-1], txt_len)

                # Compute all objectives
                lm_loss = self.seq_loss(
                    pred.view(-1, self.vocab_size), txt[:, 1:].reshape(-1))
                self.timer.cnt('fw')

                # Backprop
                grad_norm = self.backward(lm_loss)
                self.step += 1

                # Logger
                if self.step % self.PROGRESS_STEP == 0:
                    self.progress('Tr stat | Loss - {:.2f} | Grad. Norm - {:.2f} | {}'
                                  .format(lm_loss.cpu().item(), grad_norm, self.timer.show()))
                    self.write_log('entropy', {'tr': lm_loss})
                    self.write_log(
                        'perplexity', {'tr': torch.exp(lm_loss).cpu().item()})

                # Validation
                if (self.step == 1) or (self.step % self.valid_step == 0):
                    self.validate()

                # End of step
                self.timer.set()
                if self.step > self.max_step:
                    break
        self.log.close()
def exec ( self ) : self . verbose ( 'Total training steps {}.' . format ( human_format ( self . max_step ) ) ) self . timer . set ( ) while self . step < self . max_step : for data in self . tr_set : # Pre-step : update tf_rate/lr_rate and do zero_grad self . optimizer . pre_step ( self . step ) # Fetch data txt , txt_len = self . fetch_data ( data ) self . timer . cnt ( 'rd' ) # Forward model pred , _ = self . model ( txt [ : , : - 1 ] , txt_len ) # Compute all objectives lm_loss = self . seq_loss ( pred . view ( - 1 , self . vocab_size ) , txt [ : , 1 : ] . reshape ( - 1 ) ) self . timer . cnt ( 'fw' ) # Backprop grad_norm = self . backward ( lm_loss ) self . step += 1 # Logger if self . step % self . PROGRESS_STEP == 0 : self . progress ( 'Tr stat | Loss - {:.2f} | Grad. Norm - {:.2f} | {}' . format ( lm_loss . cpu ( ) . item ( ) , grad_norm , self . timer . show ( ) ) ) self . write_log ( 'entropy' , { 'tr' : lm_loss } ) self . write_log ( 'perplexity' , { 'tr' : torch . exp ( lm_loss ) . cpu ( ) . item ( ) } ) # Validation if ( self . step == 1 ) or ( self . step % self . valid_step == 0 ) : self . validate ( ) # End of step self . timer . set ( ) if self . step > self . max_step : break self . log . close ( )