Ejemplo n.º 1
0
def experiment_run_at_least_to_at_least_or_most(write_dir='data/exp3b',
                                                atl=0,
                                                atl2=1,
                                                atm=2):

    eparams = {
        'num_epochs': 4,
        'batch_size': 8,
        'generator_mode': 'g',
        'num_data': 100000,
        'eval_steps': 50,
        'stop_loss': 0.02
    }
    hparams = {
        'hidden_size':
        12,
        'num_layers':
        2,
        'max_len':
        20,
        'num_classes':
        2,
        'dropout':
        1.0,
        'quantifiers': [
            quantifiers.at_least_n(atl),
            quantifiers.at_least_n_or_at_most_m(atl2, atm)
        ]
    }
    num_trials = 30

    for idx in range(num_trials):
        run_trial(eparams, hparams, idx, write_dir)
Ejemplo n.º 2
0
def experiment_one_c(write_dir='data/exp1c'):

    eparams = {
        'num_epochs': 4,
        'batch_size': 8,
        'generator_mode': 'g',
        'num_data': 100000,
        'eval_steps': 50,
        'stop_loss': 0.02
    }
    hparams = {
        'hidden_size':
        12,
        'num_layers':
        2,
        'max_len':
        20,
        'num_classes':
        2,
        'dropout':
        1.0,
        'quantifiers':
        [quantifiers.at_least_n(4),
         quantifiers.between_m_and_n(6, 10)]
    }
    num_trials = 30

    for idx in range(num_trials):
        run_trial(eparams, hparams, idx, write_dir)
def transfer_test():

    params = {
        'checkpoint_path':
        'data/exp1a/trial_0/',
        'old_scope':
        '/',
        'hidden_size':
        12,
        'num_layers':
        2,
        'max_len':
        20,
        'num_classes':
        2,
        'dropout':
        1.0,
        'quantifiers':
        [quantifiers.at_least_n(4),
         quantifiers.at_least_n_or_at_most_m(6, 2)]
    }
    # print(params['quantifiers'][0]._name)
    model = tf.estimator.Estimator(model_fn=transfer_lstm_model_fn,
                                   params=params)

    generator = data_gen.DataGenerator(params['max_len'],
                                       params['quantifiers'],
                                       num_data_points=1000)

    some_data = generator.get_training_data()

    # must train before predict, so we'll give it one example
    model.train(input_fn=tf.estimator.inputs.numpy_input_fn(
        x={quant_verify.INPUT_FEATURE: np.array([some_data[0][0]])},
        y=np.array([some_data[0][1]]),
        shuffle=False))

    some_inputs = np.array([datum[0] for datum in some_data])
    predict_input_fn = tf.estimator.inputs.numpy_input_fn(
        x={quant_verify.INPUT_FEATURE: some_inputs}, shuffle=False)

    predictions = list(model.predict(input_fn=predict_input_fn))
    for idx in range(5):
        print('input: {}\nprobs: {}\n'.format(some_inputs[idx],
                                              predictions[idx]['probs']))
Ejemplo n.º 4
0
def test():
    eparams = {
        'num_epochs': 4,
        'batch_size': 8,
        'generator_mode': 'g',
        'num_data': 10000,
        'eval_steps': 50,
        'stop_loss': 0.02
    }
    hparams = {
        'hidden_size': 12,
        'num_layers': 2,
        'max_len': 20,
        'num_classes': 2,
        'dropout': 1.0,
        'quantifiers': [quantifiers.at_least_n(4), quantifiers.most]
    }
    for idx in range(2):
        run_trial(eparams, hparams, idx)