G[0, :, :] = bf2f.np.eye(d+1) G[:, -1, :] = 0 G[:, -1, -1] = 1 initial_params = (C, G, V) if options['diagnostics_rate'] > 0: DIAGNOSTICS = True else: DIAGNOSTICS = False # --- initialise parameters --- # pp = bf2f.params(initial_params, options, vocab) # --- ll before --- # if options['calc_ll']: pre_ll = bf2f.log_likelihood(pp, train_data) print 'pre ll:', pre_ll # --- start the logfile --- # if DIAGNOSTICS: logf = open(output_root+'_logfile.txt','w') logf.write('n\ttime\tll\tdata_energy\tmodel_energy\tvaliset_energy\trandom_energy\tperm_energy\tC_lens\tG_lens\tV_lens\n') logf.close() # ---- TRAIN! --- # for epoch in xrange(options['n_epochs']): print 'epoch:', epoch cProfile.runctx('vali_set = bf2f.train(train_data, pp, options)', None, locals()) if options['online']: train_data = dstream.acquire_all(SHUFFLE=True)
# --- actually get the training data --- # if ONLINE: train_data = dstream else: train_data = dstream.acquire_all() # --- initialise parameters --- # pp = bf2f.params((C, G, V), vocab, fix_words=fix_words, fix_relas=fix_relas, trans_rela=trans_rela) # --- ll before --- # if CALC_LL: print 'pre ll:', bf2f.log_likelihood(pp, train_data) # --- start the logfile --- # if DIAGNOSTICS: logf = open(fname + '_logfile.txt', 'w') logf.write( 'n\ttime\tll\tdata_energy\tmodel_energy\tvaliset_energy\trandom_energy\tperm_energy\tC_lens\tG_lens\tV_lens\n' ) logf.close() else: print 'WARNING: no diagnostics.' # ---- TRAIN! --- # for epoch in xrange(n_epochs): print 'epoch:', epoch cProfile.runctx(
relas = map(str, range(R)) vocab = {'words':words, 'relas': relas} # --- actually get the training data --- # if ONLINE: train_data = dstream else: train_data = dstream.acquire_all() # --- initialise parameters --- # pp = bf2f.params((C, G, V), vocab, fix_words=fix_words, fix_relas=fix_relas, trans_rela=trans_rela) # --- ll before --- # if CALC_LL: print 'pre ll:', bf2f.log_likelihood(pp, train_data) # --- start the logfile --- # if DIAGNOSTICS: logf = open(fname+'_logfile.txt','w') logf.write('n\ttime\tll\tdata_energy\tmodel_energy\tvaliset_energy\trandom_energy\tperm_energy\tC_lens\tG_lens\tV_lens\n') logf.close() else: print 'WARNING: no diagnostics.' # ---- TRAIN! --- # for epoch in xrange(n_epochs): print 'epoch:', epoch cProfile.runctx('vali_set = bf2f.train(train_data, pp, options, EXACT, PERSISTENT, NOISE)', None, locals()) if ONLINE: # (the purpose of this is to shuffle the training data)