Example #1
0
def main():
    cnn = TextCNN(sequence_length=SEQUENCE_LENGTH,
                  num_classes=6,
                  filter_sizes=FILTER_SIZES,
                  num_filters=NUM_FILTERS,
                  neurons_hidden=NEURONS_HIDDEN,
                  learning_rate=LEARNING_RATE,
                  embedding_size=300,
                  reg_lambda=L2_REG)

    logger = Logger(TITLE, COMMENT)
    logger.set_source(cnn)

    with tf.Session() as session:

        session.run(tf.initialize_all_variables())

        def collection_hook():
            tf.add_to_collection('features', cnn.h_pool_flat)
            tf.add_to_collection('input', cnn.input_vect)
            tf.add_to_collection('dropout_keep_prop', cnn.dropout_keep_prob)
            tf.add_to_collection('sequence_length', SEQUENCE_LENGTH)
            tf.add_to_collection('scores', cnn.scores)
            tf.add_to_collection('predictions', cnn.predictions)

        def train_step(in_batch, target_batch):
            feed_dict = {
                cnn.input_vect: in_batch,
                cnn.target_vect: target_batch,
                cnn.dropout_keep_prob: 0.5,
                cnn.class_weights: TrainingData().factors
            }
            _, acc, cost, summary = session.run(
                [cnn.train_op, cnn.accuracy, cnn.loss, cnn.merged],
                feed_dict=feed_dict)
            return acc, cost, summary

        def val_step(in_batch, target_batch):
            feed_dict = {
                cnn.input_vect: in_batch,
                cnn.target_vect: target_batch,
                cnn.dropout_keep_prob: 1.0
            }
            acc = session.run(cnn.accuracy, feed_dict)
            return acc

        train(training_step=train_step,
              preprocess=preprocess,
              num_batches=NUM_BATCHES,
              batch_size=BATCH_SIZE,
              collection_hook=collection_hook,
              logger=logger,
              name='CNN',
              full=TRAIN_ON_FULL_DATA)

        if not TRAIN_ON_FULL_DATA:
            validate(validation_step=val_step,
                     preprocess=preprocess,
                     batch_size=BATCH_SIZE,
                     logger=logger)
Example #2
0
def main():
    with tf.Session() as session:

        with tf.name_scope('Ensemble'):
            ffn = NumericFFN(NUM_FEATURES, NEURONS_HIDDEN, 6, LEARNING_RATE,
                             L2_REG)

        session.run(tf.initialize_all_variables())
        rebuild_subnets()

        logger = Logger(TITLE, COMMENT)
        logger.set_source(ffn)

        def collection_hook():
            tf.add_to_collection(
                'score',
                ffn.scores,
            )
            tf.add_to_collection('input', ffn.in_vector)
            tf.add_to_collection('dropout_keep_prop', ffn.dropout_keep_prob)
            tf.add_to_collection('predictions', ffn.predictions)
            tf.add_to_collection('category', ffn.category)

        def train_step(in_batch, target_batch):
            feed_dict = {
                ffn.in_vector: get_subnet_votes(in_batch),
                ffn.target_vect: target_batch,
                ffn.dropout_keep_prob: 0.5,
                ffn.class_weights: TrainingData().factors
            }
            _, acc, cost, summary = session.run(
                [ffn.train_op, ffn.accuracy, ffn.loss, ffn.merged],
                feed_dict=feed_dict)
            return acc, cost, summary

        def val_step(in_batch, target_batch):
            feed_dict = {
                ffn.in_vector: get_subnet_votes(in_batch),
                ffn.target_vect: target_batch,
                ffn.dropout_keep_prob: 1.0
            }
            acc = session.run(ffn.accuracy, feed_dict)
            return acc

        train(training_step=train_step,
              preprocess=lambda x: x,
              num_batches=NUM_BATCHES,
              batch_size=BATCH_SIZE,
              collection_hook=collection_hook,
              logger=logger,
              name=TITLE,
              full=TRAIN_ON_FULL_DATA)

        if not TRAIN_ON_FULL_DATA:
            validate(validation_step=val_step,
                     preprocess=lambda x: x,
                     batch_size=BATCH_SIZE,
                     logger=logger)
def main():
    rnn = LSTM(HIDDEN_UNITS, 6, SERIES_LENGTH, LEARNING_RATE)

    logger = Logger(TITLE, COMMENT)
    logger.set_source(rnn)

    with tf.Session() as session:

        session.run(tf.initialize_all_variables())

        def collection_hook():
            tf.add_to_collection('input', rnn.input_vect)
            tf.add_to_collection('dropout_keep_prop', rnn.dropout_keep_prob)
            tf.add_to_collection('batch_size', rnn.batch_size)
            tf.add_to_collection('scores', rnn.scores)
            tf.add_to_collection('predictions', rnn.predictions)
            tf.add_to_collection('series_length', SERIES_LENGTH)

        def train_step(in_batch, target_batch):
            feed_dict = {
                rnn.input_vect: in_batch,
                rnn.target_vect: target_batch,
                rnn.dropout_keep_prob: 0.5,
                rnn.batch_size: len(in_batch),
                rnn.class_weights: TrainingData().factors
            }
            _, acc, cost, summary = session.run(
                [rnn.train_op, rnn.accuracy, rnn.loss, rnn.merged],
                feed_dict=feed_dict)
            return acc, cost, summary

        def val_step(in_batch, target_batch):
            feed_dict = {
                rnn.input_vect: in_batch,
                rnn.target_vect: target_batch,
                rnn.dropout_keep_prob: 1.0,
                rnn.batch_size: len(in_batch)
            }
            acc = session.run(rnn.accuracy, feed_dict)
            return acc

        train(training_step=train_step,
              preprocess=preprocess,
              num_batches=NUM_BATCHES,
              batch_size=BATCH_SIZE,
              collection_hook=collection_hook,
              logger=logger,
              name=TITLE,
              full=TRAIN_ON_FULL_DATA,
              log_interval=SAVE_INTERVAL)

        if not TRAIN_ON_FULL_DATA:
            validate(validation_step=val_step,
                     preprocess=preprocess,
                     batch_size=BATCH_SIZE,
                     logger=logger)
Example #4
0
def main():
    net = NumericFFN(parameters=NUM_EXTENSIONS,
                     neurons_hidden=NEURONS_HIDDEN,
                     categories=6,
                     learning_rate=LEARNING_RATE,
                     reg_lambda=L2_REG)

    vectorizer = ExtensionVectorizer()

    logger = Logger(TITLE, COMMENT)
    logger.set_source(net)

    with tf.Session() as session:

        session.run(tf.initialize_all_variables())

        # this is helpful should we later include this in an ensemble
        def collection_hook():
            tf.add_to_collection('dropout_keep_prop', net.dropout_keep_prob)
            tf.add_to_collection('scores', net.scores)
            tf.add_to_collection('predictions', net.predictions)

        def train_step(in_batch, target_batch):
            feed_dict = {
                net.in_vector: in_batch,
                net.target_vect: target_batch,
                net.dropout_keep_prob: 0.5,
                net.class_weights: TrainingData().factors
            }
            _, acc, cost, summary = session.run([net.train_op, net.accuracy, net.loss, net.merged],
                                                feed_dict=feed_dict)
            return acc, cost, summary

        def val_step(in_batch, target_batch):
            feed_dict = {
                net.in_vector: in_batch,
                net.target_vect: target_batch,
                net.dropout_keep_prob: 1.0
            }
            acc = session.run(net.accuracy, feed_dict)
            return acc

        train(training_step=train_step,
              preprocess=vectorizer.vectorize,
              num_batches=NUM_BATCHES,
              batch_size=BATCH_SIZE,
              collection_hook=collection_hook,
              logger=logger,
              name=TITLE,
              full=TRAIN_ON_FULL_DATA)

        if not TRAIN_ON_FULL_DATA:
            validate(validation_step=val_step,
                     preprocess=vectorizer.vectorize,
                     batch_size=BATCH_SIZE,
                     logger=logger)
Example #5
0
def main():
    ffn = NumericFFN(parameters=len(FEATURES),
                     neurons_hidden=NEURONS_HIDDEN,
                     categories=6,
                     learning_rate=LEARNING_RATE,
                     reg_lambda=0.01)

    logger = Logger(TITLE, COMMENT)
    logger.set_source(ffn)

    with tf.Session() as session:

        session.run(tf.initialize_all_variables())

        def collection_hook():
            tf.add_to_collection('score', ffn.scores)
            tf.add_to_collection('input', ffn.in_vector)
            tf.add_to_collection('dropout_keep_prop', ffn.dropout_keep_prob)
            tf.add_to_collection('predictions', ffn.predictions)
            tf.add_to_collection('category', ffn.category)

        def train_step(in_batch, target_batch):
            feed_dict = {
                ffn.in_vector: in_batch,
                ffn.target_vect: target_batch,
                ffn.dropout_keep_prob: 0.5,
                ffn.class_weights: TrainingData().factors
            }
            _, acc, cost, summary = session.run([ffn.train_op, ffn.accuracy, ffn.loss, ffn.merged],
                                                feed_dict=feed_dict)
            return acc, cost, summary

        def val_step(in_batch, target_batch):
            feed_dict = {
                ffn.in_vector: in_batch,
                ffn.target_vect: target_batch,
                ffn.dropout_keep_prob: 1.0
            }
            acc = session.run(ffn.accuracy, feed_dict)
            return acc

        train(training_step=train_step,
              preprocess=preprocess,
              num_batches=NUM_BATCHES,
              batch_size=BATCH_SIZE,
              collection_hook=collection_hook,
              logger=logger,
              name=TITLE,
              full=TRAIN_ON_FULL_DATA)

        if not TRAIN_ON_FULL_DATA:
            validate(
                validation_step=val_step,
                preprocess=preprocess,
                batch_size=BATCH_SIZE,
                logger=logger)