mode = 'tr'

model = ENC_DEC(n_u, n_h, n_d, n_y, n_epochs, n_chapter, n_batch, n_gen_maxlen,
                n_words_x, n_words_y, dim_word, momentum_switchover, lr,
                learning_rate_decay, snapshot_Freq, sample_Freq)
model.add(BiDirectionGRU(n_u, n_h))
model.add(decoder(n_h, n_d, n_y))
model.build()

filepath = 'data/ted.pkl'

if mode == 'tr':
    if os.path.isfile(filepath): model.load(filepath)

    model.train(seq, seq_mask, targets, targets_mask, input, output, verbose,
                optimizer)
    model.save(filepath)

    ##draw error graph
    plt.close('all')
    fig = plt.figure()
    ax3 = plt.subplot(111)
    plt.plot(model.errors)
    plt.grid()
    ax3.set_title('Training error')
    plt.savefig('error.png')

elif mode == 'te':
    if os.path.isfile(filepath): model.load(filepath)
    else:
        raise IOError('loading error...')
示例#2
0
文件: Main.py 项目: chuckgu/RNN
mode='tr'

seq=seq.transpose(1,0,2)
targets_onehot=targets_onehot.transpose(1,0,2)

model = ENC_DEC(n_u,n_h*2,n_d,n_y,0.001,n_epochs,n_batch,n_maxlen)
model.add(BiDirectionLSTM(n_u,n_h))
model.add(decoder(n_h*2,n_d,n_y))

model.build('softmax')



if mode=='tr':
    model.train(seq,targets_onehot)
    model.save('encdec_new.pkl')
else:model.load('encdec_new.pkl')

i=20
plt.close('all')
fig = plt.figure()
ax1 = plt.subplot(311)
plt.plot(seq[:,i])
plt.grid()
ax1.set_title('input')
ax2 = plt.subplot(312)

plt.scatter(xrange(time_steps_y), targets[i], marker = 'o', c = 'b')
plt.grid()
示例#3
0
targets_onehot = np.zeros((n_seq, time_steps_y, n_y), dtype=np.int)

targets_onehot[:, :, 0][targets[:, :] == 0] = 1
targets_onehot[:, :, 1][targets[:, :] == 1] = 1
targets_onehot[:, :, 2][targets[:, :] == 2] = 1

mode = 'tr1'

model = ENC_DEC(n_u, n_h, n_d, n_y, time_steps_x, time_steps_y, 0.001, 200)
model.add(hidden(n_u, n_h))
model.add(decoder(n_h, n_d, n_y, time_steps_x, time_steps_y))

model.build('softmax')

if mode == 'tr':
    model.train(seq, targets)
    model.save('encdec_new.pkl')
else:
    model.load('encdec_new.pkl')

i = 20
plt.close('all')
fig = plt.figure()
ax1 = plt.subplot(311)
plt.plot(seq[i])
plt.grid()
ax1.set_title('input')
ax2 = plt.subplot(312)

plt.scatter(xrange(time_steps_y), targets[i], marker='o', c='b')
plt.grid()
示例#4
0
文件: Main.py 项目: rubeeny/RNN
targets_onehot = np.cast[theano.config.floatX](targets_onehot)

mode = 'tr'

seq = seq.transpose(1, 0, 2)
targets_onehot = targets_onehot.transpose(1, 0, 2)

model = ENC_DEC(n_u, n_h * 2, n_d, n_y, 0.001, n_epochs, n_batch, n_maxlen)
model.add(BiDirectionLSTM(n_u, n_h))
model.add(decoder(n_h * 2, n_d, n_y))

model.build('softmax')

if mode == 'tr':
    model.train(seq, targets_onehot)
    model.save('encdec_new.pkl')
else:
    model.load('encdec_new.pkl')

i = 20
plt.close('all')
fig = plt.figure()
ax1 = plt.subplot(311)
plt.plot(seq[:, i])
plt.grid()
ax1.set_title('input')
ax2 = plt.subplot(312)

plt.scatter(xrange(time_steps_y), targets[i], marker='o', c='b')
plt.grid()
model = ENC_DEC(n_u,n_h,n_d,n_y,n_epochs,n_chapter,n_batch,n_gen_maxlen,n_words_x,n_words_y,dim_word,
            momentum_switchover,lr,learning_rate_decay,snapshot_Freq,sample_Freq)
model.add(BiDirectionGRU(n_u,n_h))
model.add(decoder(n_h,n_d,n_y))
model.build()



filepath='data/ted.pkl'

if mode=='tr':
    if os.path.isfile(filepath): model.load(filepath)
    
    
    model.train(seq,seq_mask,targets,targets_mask,input,output,verbose,optimizer)
    model.save(filepath)
    
    ##draw error graph 
    plt.close('all')
    fig = plt.figure()
    ax3 = plt.subplot(111)   
    plt.plot(model.errors)
    plt.grid()
    ax3.set_title('Training error')    
    plt.savefig('error.png')
    
    
elif mode=='te':
    if os.path.isfile(filepath): model.load(filepath)
    else: 
示例#6
0
文件: Main.py 项目: chuckgu/RNN
targets_onehot[:, :, 0][targets[:, :] == 0] = 1
targets_onehot[:, :, 1][targets[:, :] == 1] = 1
targets_onehot[:, :, 2][targets[:, :] == 2] = 1

mode = "tr1"

model = ENC_DEC(n_u, n_h, n_d, n_y, time_steps_x, time_steps_y, 0.001, 200)
model.add(hidden(n_u, n_h))
model.add(decoder(n_h, n_d, n_y, time_steps_x, time_steps_y))

model.build("softmax")


if mode == "tr":
    model.train(seq, targets)
    model.save("encdec_new.pkl")
else:
    model.load("encdec_new.pkl")

i = 20
plt.close("all")
fig = plt.figure()
ax1 = plt.subplot(311)
plt.plot(seq[i])
plt.grid()
ax1.set_title("input")
ax2 = plt.subplot(312)

plt.scatter(xrange(time_steps_y), targets[i], marker="o", c="b")
plt.grid()