Exemplo n.º 1
0
    def __init__(self,
                 word_embedding,
                 synonyms_filepath=io_utils.get_synonyms_filepath(),
                 train_indices=io_utils.train_indices(),
                 test_indices=io_utils.test_indices(),
                 words_per_news=25,
                 bag_size=1,
                 bags_per_minibatch=50,
                 callback=None):

        super(CNNModel, self).__init__(io=io_utils.NetworkIOProvider(),
                                       word_embedding=word_embedding,
                                       synonyms_filepath=synonyms_filepath,
                                       train_indices=train_indices,
                                       test_indices=test_indices,
                                       bag_size=bag_size,
                                       words_per_news=words_per_news,
                                       bags_per_minibatch=bags_per_minibatch,
                                       callback=callback)
Exemplo n.º 2
0
 def get_data_indices(self, data_type):
     if data_type == DataType.Test:
         return io_utils.test_indices()
     if data_type == DataType.Train:
         return io_utils.train_indices()
Exemplo n.º 3
0
    news_filepath = root + "art{}.txt".format(n)
    opin_filepath = root + "art{}.opin.txt".format(n)
    neutral_filepath = root + "art{}.neut.txt".format(n)

    print neutral_filepath

    entities = EntityCollection.from_file(entity_filepath)
    news = News.from_file(news_filepath, entities)
    opinions = OpinionCollection.from_file(opin_filepath,
                                           io_utils.get_synonyms_filepath())

    neutral_opins = make_neutrals(news, synonyms, opinions)
    neutral_opins.save(neutral_filepath)

#
# Test
#
root = io_utils.test_root()
for n in io_utils.test_indices():
    entity_filepath = path.join(root, "art{}.ann".format(n))
    news_filepath = path.join(root, "art{}.txt".format(n))
    neutral_filepath = path.join(root, "art{}.neut.txt".format(n))

    print neutral_filepath

    entities = EntityCollection.from_file(entity_filepath)
    news = News.from_file(news_filepath, entities)

    neutral_opins = make_neutrals(news, synonyms)
    neutral_opins.save(neutral_filepath)
Exemplo n.º 4
0
    pcnn_filepath = path.join(output_root, '{}.csv'.format(pcnn_name))

    cnn_callback = PandasLoggerCallback(epochs=config.Epochs,
                                        test_on_epochs=config.test_on_epochs,
                                        csv_filepath=cnn_filepath,
                                        model_name=cnn_name)
    pcnn_callback = PandasLoggerCallback(epochs=config.Epochs,
                                         test_on_epochs=config.test_on_epochs,
                                         csv_filepath=pcnn_filepath,
                                         model_name=pcnn_name)

    return [(CNNModel, cnn_callback),
            (PCNNModel, pcnn_callback)]


if __name__ == "__main__":

    gpu_memory_fraction = 0.35

    config = CNNConfig()
    models = compose_all_models(config)

    for _ in config.iterate_over_grid():
        for tf_model, callback in models:
            eval_model(config=config,
                       callback=callback,
                       model_type=tf_model,
                       train_indices=io_utils.train_indices(),
                       test_indices=io_utils.test_indices(),
                       gpu_memory_fraction=gpu_memory_fraction)