Exemplo n.º 1
0
# ------------------------------------------------------------------------------


model_file_path = ''.join([str(item) for item in config['model_file_path']])

word2vec_file_path = config['word2vec_model_file_path']
word2vec_file_path = word2vec_file_path%config['word_embedding_dim']
print(model_file_path)
print(word2vec_file_path)
for seed in [10,100,500,1337,2000,300]:
    w2v_embedding_cnn = WordEmbeddingCNN(
        rand_seed=seed,
        verbose=verbose,
        input_dim=feature_encoder.vocabulary_size + 1,
        word_embedding_dim=config['word_embedding_dim'],
        embedding_init_weight=feature_encoder.to_embedding_weight(word2vec_file_path),
        input_length=config['padding_length'],
        num_labels=len(label_to_index),
        conv_filter_type=config['conv_filter_type'],
        k=config['kmax_k'],
        embedding_dropout_rate=config['embedding_dropout_rate'],
        output_dropout_rate=config['output_dropout_rate'],
        nb_epoch=int(config['cnn_nb_epoch']),
        earlyStoping_patience=config['earlyStoping_patience'],
        feature_encoder=feature_encoder.vocabulary_size+1,
        optimizers='sgd',
        lr= 1e-1,
        batch_size = 128,
    )
    w2v_embedding_cnn.print_model_descibe()
Exemplo n.º 2
0
    test_cnn_feature_file_path = test_cnn_feature_file_path % seed

    word2vec_file_path = (config['word2vec_file_path'])%config['word_embedding_dim']

    print model_file_path
    print result_file_path
    print train_cnn_feature_file_path
    print test_cnn_feature_file_path
    print word2vec_file_path

    rand_embedding_cnn = WordEmbeddingCNN(
        rand_seed=seed,
        verbose=verbose,
        input_dim=feature_encoder.vocabulary_size + 1,
        word_embedding_dim=config['word_embedding_dim'],
        embedding_init_weight=feature_encoder.to_embedding_weight(word2vec_file_path),
        input_length=config['sentence_padding_length'],
        num_labels=len(label_to_index),
        conv_filter_type=config['conv_filter_type'],
        k=config['kmax_k'],
        embedding_dropout_rate=config['embedding_dropout_rate'],
        output_dropout_rate=config['output_dropout_rate'],
        nb_epoch=int(config['cnn_nb_epoch']),
        earlyStoping_patience=config['earlyStoping_patience'],
    )
    rand_embedding_cnn.print_model_descibe()

    if config['refresh_all_model'] or not os.path.exists(model_file_path):
        # 训练模型
        rand_embedding_cnn.fit((feature_encoder.train_padding_index, train_y),
                               (map(feature_encoder.transform_sentence, test_X), test_y))