Beispiel #1
0
except NameError:
    # relasfile doesn't exist
    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:
Beispiel #2
0
        rela = line.split()[1]
        relas[index] = rela
except NameError:
    # relasfile doesn't exist
    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):
Beispiel #3
0
    C[:,-1] = 1
    V[:,-1] = 1
    # G
    G = bf2f.np.random.normal(scale=0.01, size=(R, d+1, d+1))
    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
Beispiel #4
0
except IndexError:
    sys.exit('ERROR: requires cfg file.')

try:
    epoch = sys.argv[2]
except IndexError:
    sys.exit('ERROR: requires epoch')

# --- unroll options --- #
output_root = options['output_root']
wordlist = options['wordlist']
relalist = options['relalist']

# --- load parameters --- #
params_path = output_root+'_epoch'+epoch+'_XXX.txt'
pp = bf2f.params(params_path, options, (wordlist, relalist))
print 'loaded params from', params_path

# --- save results? --- #
if save:
    # note: appending
    socher_auc_test_path = output_root+'_auc_test.txt'
    socher_auc_test_file = open(socher_auc_test_path, 'a')
    socher_acc_test_path = output_root+'_acc_test.txt'
    socher_acc_test_file = open(socher_acc_test_path, 'a')

# --- load the evaluation data  --- #
if simple_socher:
    droot = '/cbio/grlab/home/hyland/data/nips13-dataset/Wordnet/simplified_vocab/'
    dev_path = droot + 'dev_triples_simple.txt'
    dev = bf2f.np.array(map(lambda x: map(int, x.strip('\n').split(' ')), open(dev_path,'r').readlines()))