mfile = 'models/en2de.model.h5' lr_scheduler = LRSchedulerPerStep( d_model, 4000) # there is a warning that it is slow, however, it's ok. #lr_scheduler = LRSchedulerPerEpoch(d_model, 4000, Xtrain.shape[0]/64) # this scheduler only update lr per epoch model_saver = ModelCheckpoint(mfile, save_best_only=True, save_weights_only=True) s2s.compile(Adam(0.001, 0.9, 0.98, epsilon=1e-9)) s2s.model.summary() try: s2s.model.load_weights(mfile) except: print('\n\nnew model') if 'test' in sys.argv: print( s2s.decode_sequence_fast('A black dog eats food .'.split(), delimiter=' ')) while True: quest = input('> ') print(s2s.decode_sequence_fast(quest.split(), delimiter=' ')) rets = s2s.beam_search(quest.split(), delimiter=' ') #for x, y in rets: print(x, y) else: s2s.model.fit([Xtrain, Ytrain], None, batch_size=64, epochs=5, \ validation_split=.1, \ callbacks=[lr_scheduler, model_saver])
rr = next(gen) print(rr[0][0].shape, rr[0][1].shape) rr = next(gen) print(rr[0][0].shape, rr[0][1].shape) s2s.compile(opt, active_layers=1) #s2s.model.fit_generator(gen, steps_per_epoch=2000, epochs=5, callbacks=[lr_scheduler, model_saver]) s2s.model.fit_generator(gen, steps_per_epoch=5, epochs=1, callbacks=[lr_scheduler, model_saver]) s2s.compile(opt, active_layers=2) s2s.model.fit_generator(gen, steps_per_epoch=5, epochs=1, callbacks=[lr_scheduler, model_saver]) s2s.compile(opt, active_layers=3) s2s.model.fit_generator(gen, steps_per_epoch=5, epochs=1, callbacks=[lr_scheduler, model_saver]) elif 'test' in cmds: print( s2s.decode_sequence_fast( 'Two young , White males are outside near many bushes .'.split())) while True: quest = input('> ') print(s2s.decode_sequence_fast(quest.split())) rets = s2s.beam_search(quest.split()) for x, y in rets: print(x, y)
mfile = 'models/en2de.model.h5' lr_scheduler = LRSchedulerPerStep(d_model, 4000) model_saver = ModelCheckpoint(mfile, save_best_only=True, save_weights_only=True) s2s.compile(Adam(0.001, 0.9, 0.98, epsilon=1e-9)) try: s2s.model.load_weights(mfile) except: print('\n\nnew model') if 'eval' in sys.argv: for x, y in s2s.beam_search('A black dog eats food .'.split(), delimiter=' '): print(x, y) print( s2s.decode_sequence_readout('A black dog eats food .'.split(), delimiter=' ')) print( s2s.decode_sequence_fast('A black dog eats food .'.split(), delimiter=' ')) while True: quest = input('> ') print(s2s.decode_sequence_fast(quest.split(), delimiter=' ')) rets = s2s.beam_search(quest.split(), delimiter=' ') for x, y in rets: print(x, y) elif 'test' in sys.argv: import ljqpy