def test_train(self): train_path = internal_resource("lm_test/train") valid_path = internal_resource("lm_test/valid") vocab = Vocab() vocab.load(train_path) train_data = RNNDataGenerator(vocab, train_path, target_vector=False, history_len=-1, _just_test=False, fixed_length=False, progress=True) valid_data = RNNDataGenerator(vocab, valid_path, target_vector=False, history_len=-1, _just_test=False, fixed_length=False, progress=True) net_conf = NetworkConfig(input_size=vocab.size) net_conf.layers = [RecurrentLayer(size=50, activation='relu')] trainer_conf = TrainerConfig() trainer_conf.learning_rate = 0.1 trainer_conf.weight_l2 = 0.0001 trainer_conf.hidden_l2 = 0.0001 trainer_conf.monitor_frequency = trainer_conf.validation_frequency = trainer_conf.test_frequency = 1 network = RecurrentNetwork(net_conf) trainer = SGDTrainer(network, config=trainer_conf) start_time = time.time() for k in list(trainer.train(train_data, valid_data)): pass print k end_time = time.time() network.save_params("/tmp/lmparam.gz") print "elapsed time:", (end_time - start_time) / 60, "mins"
def get_wre_network(model_path=""): net_conf = NetworkConfig(input_size=300) net_conf.layers = [WRELayer(size=300)] trainer_conf = TrainerConfig() trainer_conf.learning_rate = 0.01 trainer_conf.weight_l2 = 0.0001 trainer_conf.hidden_l2 = 0.0001 trainer_conf.monitor_frequency = trainer_conf.validation_frequency = trainer_conf.test_frequency = 1 network = GeneralAutoEncoder(net_conf) if os.path.exists(model_path): network.load_params(model_path) return network
print "[ARGS]", args builder = WordDataBuilder( "/home/hadoop/data/morpho/data/topwords.1500.txt") """ Setup network """ pretrain_model = args.premodel model_path = args.model net_conf = NetworkConfig(input_size=builder.input_size) net_conf.layers = [WRELayer(size=100)] trainer_conf = TrainerConfig() trainer_conf.learning_rate = 0.01 trainer_conf.weight_l2 = 0.0001 trainer_conf.hidden_l2 = 0.0001 trainer_conf.monitor_frequency = trainer_conf.validation_frequency = trainer_conf.test_frequency = 1 network = GeneralAutoEncoder(net_conf) trainer = AdaGradTrainer(network, config=trainer_conf) """ Run the network """ start_time = time.time() if os.path.exists(pretrain_model): network.load_params(pretrain_model) # elif os.path.exists(model_path):
if __name__ == '__main__': builder = ParaphraseClassifierDataBuilder("/home/hadoop/data/paraphrase/mspr/train3.pkl.gz", "/home/hadoop/data/paraphrase/mspr/test3.pkl.gz") # builder = ParaphraseClassifierDataBuilder("/home/hadoop/data/paraphrase/data/bank_classify_train2.pkl.gz", # "/home/hadoop/data/paraphrase/data/bank_classify_test2.pkl.gz") model_path = "/home/hadoop/play/model_zoo/parahrase_classifier4.gz" net = get_classify_network() if os.path.exists(model_path) and False: net.load_params(model_path) trainer_conf = TrainerConfig() trainer_conf.learning_rate = 0.01 # trainer_conf.update_l1 = 0.0001 trainer_conf.weight_l2 = 0.0001 trainer_conf.hidden_l2 = 0.0001 trainer_conf.monitor_frequency = trainer_conf.validation_frequency = trainer_conf.test_frequency = 1 trainer = AdaDeltaTrainer(net, config=trainer_conf) start_time = time.time() c = 1 for _ in trainer.train(builder.train_data(), builder.valid_data(), builder.test_data()): c += 1 if c >= 80: trainer.test(0, builder.test_data()) break