Ejemplo n.º 1
0
 def __init__(
     self,
     optimizer: Optimizer,  # optimizer for training
     criterion: nn.Module,  # loss function
     trainset_list: list,  # list of training dataset
     validset: SpectrogramDataset,  # validation dataset
     num_workers: int,  # number of threads
     device: str,  # device - cuda or cpu
     print_every: int,  # number of timesteps to save result after
     save_result_every: int,  # nimber of timesteps to save result after
     checkpoint_every: int,  # number of timesteps to checkpoint after
     teacher_forcing_step:
     float = 0.2,  # step of teacher forcing ratio decrease per epoch.
     min_teacher_forcing_ratio:
     float = 0.8,  # minimum value of teacher forcing ratio
     architecture: str = 'las'  # architecture to train - las, transformer
 ) -> None:
     self.num_workers = num_workers
     self.optimizer = optimizer
     self.criterion = criterion
     self.trainset_list = trainset_list
     self.validset = validset
     self.print_every = print_every
     self.save_result_every = save_result_every
     self.checkpoint_every = checkpoint_every
     self.device = device
     self.teacher_forcing_step = teacher_forcing_step
     self.min_teacher_forcing_ratio = min_teacher_forcing_ratio
     self.metric = CharacterErrorRate(id2char, EOS_token)
     self.architecture = architecture.lower()
 def __init__(self,
              optimizer,
              criterion,
              trainset_list,
              validset,
              high_plateau_lr,
              low_plateau_lr,
              exp_decay_period,
              num_workers,
              device,
              decay_threshold,
              print_every,
              save_result_every,
              checkpoint_every,
              teacher_forcing_step=0.0,
              min_teacher_forcing_ratio=0.7):
     self.num_workers = num_workers
     self.optimizer = optimizer
     self.criterion = criterion
     self.trainset_list = trainset_list
     self.validset = validset
     self.high_plateau_lr = high_plateau_lr
     self.low_plateau_lr = low_plateau_lr
     self.exp_decay_period = exp_decay_period
     self.print_every = print_every
     self.save_result_every = save_result_every
     self.checkpoint_every = checkpoint_every
     self.decay_threshold = decay_threshold
     self.device = device
     self.teacher_forcing_step = teacher_forcing_step
     self.min_teacher_forcing_ratio = min_teacher_forcing_ratio
     self.metric = CharacterErrorRate(id2char, EOS_token)
Ejemplo n.º 3
0
    def __init__(self, metric: str = 'char'):
        self.target_list = list()
        self.predict_list = list()

        if metric == 'char':
            self.metric = CharacterErrorRate(id2char, EOS_token)
        elif metric == 'word':
            self.metric = WordErrorRate(id2char, EOS_token)
        else:
            raise ValueError("Unsupported metric : {0}".format(metric))
Ejemplo n.º 4
0
    def __init__(self, vocab, metric: str = 'char'):
        self.target_list = list()
        self.predict_list = list()
        self.vocab = vocab

        if metric == 'char':
            self.metric = CharacterErrorRate(vocab)
        elif metric == 'word':
            self.metric = WordErrorRate(vocab)
        else:
            raise ValueError("Unsupported metric : {0}".format(metric))
Ejemplo n.º 5
0
    def __init__(
            self,
            optimizer: Optimizer,  # optimizer for training
            criterion: nn.Module,  # loss function
            trainset_list: list,  # list of training dataset
            validset: SpectrogramDataset,  # validation dataset
            num_workers: int,  # number of threads
            device: torch.device,  # device - cuda or cpu
            print_every: int,  # number of timesteps to save result after
            save_result_every: int,  # nimber of timesteps to save result after
            checkpoint_every: int,  # number of timesteps to checkpoint after
            teacher_forcing_step:
        float = 0.2,  # step of teacher forcing ratio decrease per epoch.
            min_teacher_forcing_ratio:
        float = 0.8,  # minimum value of teacher forcing ratio
            architecture: str = 'las',  # model to train - las, transformer
            vocab: Vocabulary = None,  # vocabulary object
            joint_ctc_attention:
        bool = False,  # flag indication whether joint CTC-Attention or not
    ) -> None:
        self.num_workers = num_workers
        self.optimizer = optimizer
        self.criterion = criterion
        self.trainset_list = trainset_list
        self.validset = validset
        self.print_every = print_every
        self.save_result_every = save_result_every
        self.checkpoint_every = checkpoint_every
        self.device = device
        self.teacher_forcing_step = teacher_forcing_step
        self.min_teacher_forcing_ratio = min_teacher_forcing_ratio
        self.metric = CharacterErrorRate(vocab)
        self.architecture = architecture.lower()
        self.vocab = vocab
        self.joint_ctc_attention = joint_ctc_attention

        if self.joint_ctc_attention:
            self.log_format = "step: {:4d}/{:4d}, loss: {:.6f}, ctc_loss: {:.6f}, ce_loss: {:.6f}, " \
                              "cer: {:.2f}, elapsed: {:.2f}s {:.2f}m {:.2f}h, lr: {:.6f}"
        else:
            self.log_format = "step: {:4d}/{:4d}, loss: {:.6f}, " \
                              "cer: {:.2f}, elapsed: {:.2f}s {:.2f}m {:.2f}h, lr: {:.6f}"

        if self.architecture in ('rnnt', 'conformer'):
            self.rnnt_log_format = "step: {:4d}/{:4d}, loss: {:.6f}, " \
                                   "elapsed: {:.2f}s {:.2f}m {:.2f}h, lr: {:.6f}"
Ejemplo n.º 6
0
 def __init__(
     self,
     optimizer: Optimizer,  # optimizer for training
     criterion: nn.Module,  # loss function
     trainset_list: list,  # list of training dataset
     validset: SpectrogramDataset,  # validation dataset
     high_plateau_lr: float,  # high plateau learning rate
     low_plateau_lr: float,  # low plateau learning rate
     exp_decay_period: int,  # exponential decay learning rate period
     num_workers: int,  # number of threads
     device: str,  # device - cuda or cpu
     decay_threshold:
     float,  # criteria by which exp learning ratedecay is started
     print_every: int,  # number of timesteps to save result after
     save_result_every: int,  # nimber of timesteps to save result after
     checkpoint_every: int,  # number of timesteps to checkpoint after
     teacher_forcing_step:
     float = 0.2,  # step of teacher forcing ratio decrease per epoch.
     min_teacher_forcing_ratio:
     float = 0.8,  # minimum value of teacher forcing ratio
     architecture:
     str = 'seq2seq'  # architecture to train - seq2seq, transformer
 ) -> None:
     self.num_workers = num_workers
     self.optimizer = optimizer
     self.criterion = criterion
     self.trainset_list = trainset_list
     self.validset = validset
     self.high_plateau_lr = high_plateau_lr
     self.low_plateau_lr = low_plateau_lr
     self.exp_decay_period = exp_decay_period
     self.print_every = print_every
     self.save_result_every = save_result_every
     self.checkpoint_every = checkpoint_every
     self.decay_threshold = decay_threshold
     self.device = device
     self.teacher_forcing_step = teacher_forcing_step
     self.min_teacher_forcing_ratio = min_teacher_forcing_ratio
     self.metric = CharacterErrorRate(id2char, EOS_token)
     self.architecture = architecture.lower()
Ejemplo n.º 7
0
 def __init__(self):
     self.target_list = list()
     self.predict_list = list()
     self.metric = CharacterErrorRate(id2char, EOS_token)
Ejemplo n.º 8
0
 def __init__(self):
     self.target_list = list()
     self.hypothesis_list = list()
     self.metric = CharacterErrorRate(id2char, EOS_token)
     self.language_model = None  # load_language_model('../data/weight_file/epoch1.pt', 'cuda')
Ejemplo n.º 9
0
 def __init__(self):
     self.target_list = list()
     self.hypothesis_list = list()
     self.metric = CharacterErrorRate(id2char, EOS_token)
     self.language_model = load_language_model('lm_path', 'cuda')