def train_merge(): hyperparams = { 'batch_size': 50, 'learning_rate': 1e-4, 'num_updates': 20000, 'grad_norm_clip': 5 } model = MnistMergeModel(hyperparams) loss = tb.Crossentropy(hyperparams) acc = tb.CatAcc(hyperparams) evaluator = tb.Evaluator(hyperparams, loss, acc) optim = tb.AdamOptim(hyperparams) trainer = tb.Trainer(model, hyperparams, loss, optim, evaluator) mnist = load_data() train_xs = { 'image_1': mnist['train']['images'], 'image_2': mnist['train']['images'] } train_y = mnist['train']['labels'] val_xs = { 'image_1': mnist['test']['images'], 'image_2': mnist['test']['images'] } val_y = mnist['test']['labels'] trainer.train(train_xs, train_y, val_xs, val_y) evaluator.eval(model, val_xs, val_y)
def train(): hyperparams = {'batch_size': 50, 'learning_rate': 0.001, 'grad_decay': 0.99, 'grad_epsilon': 0.01, 'num_updates': 20000, 'grad_norm_clip': 5} model = CoinbaseModel(hyperparams) loss = tb.Crossentropy(hyperparams) acc = tb.CatAcc(hyperparams) evaluator = tb.Evaluator(hyperparams, loss, acc) optim = tb.RMSPropOptim(hyperparams) trainer = tb.Trainer(model, hyperparams, loss, optim, evaluator) split = 10000 data = np.load('data/coinbase_n1.npz') train_xs = {'first_ticks': data['first_ticks'][:split], 'last_ticks': data['last_ticks'][:split], 'features': data['features'][:split]} train_y = data['targets'][:split] val_xs = {'first_ticks': data['first_ticks'][split:], 'last_ticks': data['last_ticks'][split:], 'features': data['features'][split:]} val_y = data['targets'][split:] trainer.train(train_xs, train_y, val_xs, val_y, val_cmp=True) evaluator.eval(model, val_xs, val_y)
def train(): hyperparams = {'batch_size': 512, 'learning_rate': 0.0001, 'grad_decay': 0.95, 'grad_epsilon': 0.01, 'num_updates': 100000, 'grad_norm_clip': 5} with tf.device('/cpu:0'): model = CoinbaseModel(hyperparams) loss = tb.Crossentropy(hyperparams) acc = tb.CatAcc(hyperparams) evaluator = tb.Evaluator(hyperparams, loss, acc) optim = tb.RMSPropOptim(hyperparams) trainer = tb.Trainer(model, hyperparams, loss, optim, evaluator) split = 90000 data = np.load('data/coinbase-ticks-100000.npz') print(data['ticks'].shape) train_xs = {'ticks': data['ticks'][:split]} train_y = data['targets'][:split] val_xs = {'ticks': data['ticks'][split:]} val_y = data['targets'][split:] with tf.device('/cpu:0'): trainer.train(train_xs, train_y, val_xs, val_y, val_cmp=True) evaluator.eval(model, val_xs, val_y)
def train_char_rnn(): print("Building network ...") gen_info = load_data(seqlength=20, text_fnm='data/nietzsche.txt') train_xs = {'text': gen_info['data']['train']['text']} train_y = gen_info['data']['train']['targets'] test_xs = {'text': gen_info['data']['test']['text']} test_y = gen_info['data']['test']['targets'] print(train_xs['text'][:2]) print(train_y[:2]) hyperparams = { 'batch_size': 128, 'learning_rate': 0.001, 'num_updates': 50000, 'grad_norm_clip': 5, 'vocab_size': gen_info['vocab_size'], 'char_to_index': gen_info['char_to_index'], 'index_to_char': gen_info['index_to_char'], 'seqlength': gen_info['seqlength'] } model = LangModel(hyperparams) loss = tb.Crossentropy(hyperparams) acc = tb.Perplexity(hyperparams) evaluator = tb.SeqGenEvaluator(hyperparams, loss, acc, seed='the quick brown fox jumps') optim = tb.AdamOptim(hyperparams) trainer = tb.Trainer(model, hyperparams, loss, optim, evaluator) trainer.train(train_xs, train_y, test_xs, test_y, display_interval=100)
def train_brnn(): # gen_info = load_data(seqlength=20, # text_fnm='data/ptb/ptb.train.txt') # train_xs = {'text': gen_info['data']['train']['text']} # train_y = gen_info['data']['train']['targets'] # val_xs = {'text': gen_info['data']['test']['text']} # val_y = gen_info['data']['test']['targets'] # print(train_xs['text'][:2]) # print(train_y[:2]) # hyperparams = {'batch_size': 128, # 'learning_rate': 0.01, # 'num_updates': 50000, # 'grad_norm_clip': 5, # 'vocab_size': gen_info['vocab_size'], # 'char_to_index': gen_info['char_to_index'], # 'index_to_char': gen_info['index_to_char'], # 'seqlength': gen_info['seqlength']} seqlength = 20 vocab_size = 10000 data = load_data(seqlength=seqlength) train_xs = {'text': data['train']['text']} train_y = data['train']['targets'] val_xs = {'text': data['test']['text']} val_y = data['test']['targets'] hyperparams = {'batch_size': 128, 'learning_rate': 0.0001, 'num_updates': 50000, 'grad_norm_clip': 5, 'vocab_size': vocab_size, 'seqlength': seqlength} model = PTBBasic(hyperparams) loss = tb.Crossentropy(hyperparams) acc = tb.Perplexity(hyperparams) evaluator = tb.PerplexityEvaluator( hyperparams, loss, acc, seed='the quick brown fox jumps') optim = tb.AdamOptim(hyperparams) trainer = tb.Trainer(model, hyperparams, loss, optim, evaluator) print('Training...') trainer.train(train_xs, train_y, val_xs, val_y, val_cmp=False, display_interval=100) evaluator.eval(model, val_xs, val_y)