def test_phoneme_table_add_labels():
    phoneme_table = PhonemeTable()
    phoneme_table.add_labels(['a', 'i'])
    assert phoneme_table.num_labels() == 4
    assert phoneme_table.get_label_id('a') == 2
    assert phoneme_table.get_label(2) == 'a'
    assert phoneme_table.get_label_id('i') == 3
    assert phoneme_table.get_label(3) == 'i'
Пример #2
0
                                        args.development_data_dirname)
repository_dev = DevelopmentDatasetRepository(development_data_dirpath)
dataloaders_dev = []
for dataset_dev in AudioDataset.load_all(repository_dev, phoneme_table):
    dataloader_dev = DataLoader(dataset_dev,
                                batch_size=args.batch_size,
                                collate_fn=collate_for_ctc)
    dataloaders_dev.append(dataloader_dev)

feature_params_path = os.path.join(args.workdir, args.feature_params_file)
feature_params = FeatureParams.load(feature_params_path)

model_path = os.path.join(args.workdir, args.model_file)
if args.resume is True:
    print('Loading model ...')
    model = EESENAcousticModel.load(model_path)
else:
    print('Initializing model ...')
    blank = phoneme_table.get_blank_id()
    model = EESENAcousticModel(feature_params.feature_size,
                               args.hidden_size,
                               args.num_layers,
                               phoneme_table.num_labels(),
                               blank=blank)
model.to(torch.device(args.device))
model.set_optimizer(args.optimizer, args.lr)
print('Training ...')
model.train(dataloader_tr, dataloaders_dev, args.epochs)
print('Saving model ...')
model.save(model_path)
def test_phoneme_table_add_label():
    phoneme_table = PhonemeTable()
    phoneme_table.add_label('a')
    assert phoneme_table.num_labels() == 3
    assert phoneme_table.get_label_id('a') == 2
    assert phoneme_table.get_label(2) == 'a'