Exemplo n.º 1
0
    vocab_size = 4
    for word in vocab:
        word2id[word] = vocab_size
        vocab_size += 1
    
    region2id , numRegions = getRegionLabels(train_set)
    period2id , numPeriods = getPeriodLabels(train_set)
    
    train_input , train_output_region , train_output_time = getInput(train_set , word2id , period2id , region2id , maxL)
    test_input , test_output_region , test_output_time = getInput(test_set , word2id , period2id , region2id , maxL) 
    
    print(train_set[0])
    print(train_input[0])
    print(train_output_region[0])
    print(train_output_time[0])

    model = RNN_Model(embed_size=args.embed_size,
                        hidden_size=args.hidden_size,
                        vocab_len=vocab_size,
                        epoch=args.epoch_size,
                        learning_rate=args.lr, 
                        batch_size=args.batch_size)

    model.train(numpy.asarray(train_input) , numpy.asarray(train_output_region) , numpy.asarray(train_output_time)) 
    model.test(test_input , test_output_region , test_output_time)
    print()
    print()
    print("Training Results:")
    print()
    model.test(train_input , train_output_region , train_output_time)
Exemplo n.º 2
0
                                             config.direction,
                                             config.cell_type,
                                             str(config.layers))
    config.model_dir = join(config.output_dir, config.model_name)

    if not exists(config.output_dir):
        mkdir(config.output_dir)
    if not exists(config.model_dir):
        mkdir(config.model_dir)

    model = RNN_Model(config)

    if config.testing:
        test_ids, test_data, _ = load_timit(config, data_set='test')
        test_ids = np.expand_dims(test_ids, 1)

        predictions = model.test(test_data)
        predictions = np.expand_dims(
            post_processing(config, predictions, threshold=2), 1)

        outputs = np.append(test_ids, predictions, axis=1)
        df = pd.DataFrame(outputs).to_csv(join(
            config.model_dir, '{}.csv'.format(config.model_name)),
                                          index=False,
                                          header=['id', 'phone_sequence'])

    else:
        train_ids, train_data, train_labels = load_timit(config,
                                                         data_set='train')
        model.train(train_data, train_labels)