class_docstr: Class that manages the training loop. See speechbrain.core.Brain.
docstr: Gets called at the end of an epoch.
  
  Arguments
  ---------
  stage : sb.Stage
      One of sb.Stage.TRAIN, sb.Stage.VALID, sb.Stage.TEST
  stage_loss : float
      The average loss for all of the data processed in this stage.
  epoch : int
      The currently-starting epoch. This is passed
      `None` during the test stage.
docstr_tok: ["Gets","called","at","the","end","of","an","epoch",".","Arguments","--","--","--","--","-","stage",":","sb.Stage","One","of","sb.Stage.TRAIN",",","sb.Stage.VALID",",","sb.Stage.TEST","stage_loss",":","float","The","average","loss","for","all","of","the","data","processed","in","this","stage",".","epoch",":","int","The","currently-starting","epoch",".","This","is","passed","`","None","`","during","the","test","stage","."]
code: def on_stage_end(self, stage, stage_loss, epoch):
      """Gets called at the end of an epoch.
  
      Arguments
      ---------
      stage : sb.Stage
          One of sb.Stage.TRAIN, sb.Stage.VALID, sb.Stage.TEST
      stage_loss : float
          The average loss for all of the data processed in this stage.
      epoch : int
          The currently-starting epoch. This is passed
          `None` during the test stage.
      """
  
      # Store the train loss until the validation stage.
      if stage == sb.Stage.TRAIN:
          self.train_loss = stage_loss
  
      # Summarize the statistics from the stage for record-keeping.
      else:
          stats = {
              "loss": stage_loss,
          }
  
      # At the end of validation, we can wrote
      if stage == sb.Stage.VALID:
          # Update learning rate
          old_lr, new_lr = self.hparams.lr_annealing(stage_loss)
          sb.nnet.schedulers.update_learning_rate(
              self.optimizer, new_lr
          )
  
          # The train_logger writes a summary to stdout and to the logfile.
          self.hparams.train_logger.log_stats(
              {"Epoch": epoch},
              train_stats={"loss": self.train_loss},
              valid_stats=stats,
          )
  
          # Save the current checkpoint and delete previous checkpoints.
          self.checkpointer.save_and_keep_only(
              meta=stats, min_keys=["loss"]
          )
  
      # We also write statistics about test data to stdout and to the logfile.
      if stage == sb.Stage.TEST:
          self.hparams.train_logger.log_stats(
              {"Epoch loaded": self.hparams.epoch_counter.current},
              test_stats=stats,
          )
  
file_path: speechbrain/templates/speech_recognition/LM/train.py
imports: import sys
  import logging
  import torch
  from datasets import load_dataset
  from hyperpyyaml import load_hyperpyyaml
  import speechbrain
  from speechbrain.utils.distributed import run_on_main
label_desc: Use image node_id 4 for calling the LM obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types