예제 #1
0
    def __init__(self, am_config, lm_config):

        self.am = AM(am_config)
        self.am.load_model(False)

        self.lm = LM(lm_config)
        self.lm.load_model(False)
예제 #2
0
 def __init__(self,config):
     self.config = config
     self.dg = LM_DataLoader(config)
     lm=LM(config)
     lm.load_model()
     self.model = lm.model
     self.optimizer = tf.keras.optimizers.Adamax(**config['optimizer_config'])
     self.runner = lm_runners.LMTrainer(self.config['running_config'],one2one=self.model.one2one)
     self.runner.set_total_train_steps(self.dg.get_per_epoch_steps() * self.config['running_config']['num_epochs'])
     self.runner.compile(self.model,self.optimizer)
예제 #3
0
    def __init__(self, am_config, lm_config, punc_config=None):

        self.am = AM(am_config)
        self.am.load_model(False)

        self.lm = LM(lm_config, punc_config)
        self.lm.load_model(False)
        if punc_config is not None:
            self.punc_recover = True
        else:
            self.punc_recover = False
예제 #4
0
    def __init__(self, config):
        self.config = config
        self.dg = LM_DataLoader(config, training=False)
        lm = LM(config)
        lm.load_model(training=False)
        self.model = lm.model

        self.runner = lm_tester.LMTester(
            self.config['running_config'],
            self.config['model_config']['one2one'])
        self.runner.set_progbar(self.dg.eval_per_epoch_steps())
        self.runner.compile(self.model)
예제 #5
0
    def __init__(self,config):
        self.config = config
        self.dg = LM_DataLoader(config)
        lm=LM(config)
        lm.load_model()
        self.model = lm.model

        all_train_step = self.dg.get_per_epoch_steps() * self.config['running_config']['num_epochs']
        lr = CustomSchedule(config['model_config']['d_model'], warmup_steps=int(all_train_step * 0.1))
        config['optimizer_config']['learning_rate'] = lr

        self.optimizer = tf.keras.optimizers.Adamax(**config['optimizer_config'])
        self.runner = lm_runners.LMTrainer(self.config['running_config'],one2one=self.model.one2one)
        self.runner.set_total_train_steps(self.dg.get_per_epoch_steps() * self.config['running_config']['num_epochs'])


        self.runner.compile(self.model,self.optimizer)
예제 #6
0
class ASR():
    def __init__(self, am_config, lm_config):

        self.am = AM(am_config)
        self.am.load_model(False)

        self.lm = LM(lm_config)
        self.lm.load_model()

    def decode_am_result(self, result):
        return self.am.decode_result(result[0])

    def stt(self, wav_path):

        am_result = self.am.predict(wav_path)

        lm_result = self.lm.predict(self.decode_am_result(am_result))

        return am_result, lm_result
예제 #7
0
class ASR():
    def __init__(self, am_config, lm_config):

        self.am = AM(am_config)
        self.am.load_model(False)

        self.lm = LM(lm_config)
        self.lm.load_model(False)

    def decode_am_result(self, result):
        return self.am.decode_result(result)

    def stt(self, wav_path):

        am_result = self.am.predict(wav_path)
        if self.am.model_type == 'Transducer':
            am_result = self.decode_am_result(am_result[1:-1])
            lm_result = self.lm.predict(am_result)
            lm_result = self.lm.decode(lm_result[0].numpy(),
                                       self.lm.lm_featurizer)
        else:
            am_result = self.decode_am_result(am_result[0])
            lm_result = self.lm.predict(am_result)
            lm_result = self.lm.decode(lm_result[0].numpy(),
                                       self.lm.lm_featurizer)
        return am_result, lm_result

    def am_test(self, wav_path):
        # am_result is token id
        am_result = self.am.predict(wav_path)
        # token to vocab
        if self.am.model_type == 'Transducer':
            am_result = self.decode_am_result(am_result[1:-1])
        else:
            am_result = self.decode_am_result(am_result[0])
        return am_result

    def lm_test(self, txt):
        if self.lm.config['am_token']['for_multi_task']:
            pys = pypinyin.pinyin(txt, 8, neutral_tone_with_five=True)
            input_py = [i[0] for i in pys]

        else:
            pys = pypinyin.pinyin(txt)
            input_py = [i[0] for i in pys]

        # now lm_result is token id
        lm_result = self.lm.predict(input_py)
        # token to vocab
        lm_result = self.lm.decode(lm_result[0].numpy(), self.lm.lm_featurizer)
        return lm_result
예제 #8
0
    def __init__(self, lm_config, punc_config):
        self.config = punc_config
        self.dg = Punc_DataLoader(punc_config)
        lm = LM(lm_config, punc_config)
        lm.load_model()
        self.model = lm.punc_model

        all_train_step = self.dg.get_per_epoch_steps(
        ) * self.config['running_config']['num_epochs']
        lr = CustomSchedule(self.config['model_config']['d_model'],
                            warmup_steps=int(all_train_step * 0.1))
        self.config['optimizer_config']['learning_rate'] = lr

        self.optimizer = tf.keras.optimizers.Adamax(
            **self.config['optimizer_config'])
        self.runner = punc_trainer.PuncTrainer(self.config['running_config'])
        self.runner.set_total_train_steps(
            self.dg.get_per_epoch_steps() *
            self.config['running_config']['num_epochs'])

        self.runner.compile(self.model, self.optimizer)