def get_model(state_num, action_num): model = NeuralRegressor(state_num) model.stack( Dense(HIDDEN_UNITS, activation='tanh', init=GaussianInitializer(deviation=0.01)), Dense(action_num, init=GaussianInitializer(deviation=0.01))) return model
valid_set = data[:valid_size] dataset = SequentialDataset(train_set, valid=valid_set) dataset.report() batch_set = MiniBatches(dataset, batch_size=32) if __name__ == '__main__': ap = ArgumentParser() ap.add_argument("--model", default=os.path.join(os.path.dirname(__file__), "models", "sequence_adding_100_2.gz")) args = ap.parse_args() model = NeuralRegressor(input_dim=2, input_tensor=3) model.stack(IRNN(hidden_size=100, input_type="sequence", output_type="one"), Dense(1)) if os.path.exists(args.model): model.load_params(args.model) conf = TrainerConfig() conf.learning_rate = LearningRateAnnealer.learning_rate(0.01) conf.gradient_clipping = 3 conf.patience = 50 conf.gradient_tolerance = 5 conf.avoid_nan = False trainer = SGDTrainer(model, conf) annealer = LearningRateAnnealer(patience=20)
def get_model(state_num, action_num): model = NeuralRegressor(state_num) model.stack(Dense(HIDDEN_UNITS, activation='tanh', init=GaussianInitializer(deviation=0.01)), Dense(action_num, init=GaussianInitializer(deviation=0.01))) return model