# -*- coding: utf-8 -*- #pylint: skip-file import time import sys import numpy as np import theano import theano.tensor as T from utils_pg import * from rnn import * use_gpu(1) import data drop_rate = 0. batch_size = 1 seqs, i2w, w2i, data_xy = data.load_hlm("/data/hlm/hlm.txt", batch_size) hidden_size = [400, 400] dim_x = len(w2i) dim_y = len(w2i) print dim_x, dim_y cell = "gru" # cell = "gru" or "lstm" optimizer = "adadelta" print "building..." model = RNN(dim_x, dim_y, hidden_size, cell, optimizer, drop_rate) print "load model..." model = load_model("./model/rnn_hlm.model", model) ''' num_x = 0.0
# __author__ = 'taowei' # -*- coding: utf-8 -*- import time from rnn import * import data # seqs, i2w, w2i = data.char_sequence("./data/toy.txt") seqs, i2w, w2i, data_xy = data.load_hlm("./data/toy.txt", 50) lr = 0.5 # layers = [] hidden_size = [100, 100, 100] cell = "gru" dim_x = len(w2i) dim_y = len(w2i) print dim_x, dim_y model = RNN(dim_x, dim_y, hidden_size, cell) # batch train start = time.time() for i in xrange(100): acc = 0.0 in_start = time.time() # for s in xrange(len(seqs)): # seq = seqs[s] # X = seq[0 : len(seq) - 1, ] # Y = seq[1 : len(seq), ] # model.batch_train(X, Y, lr)
import data # set use gpu programatically use_gpu(0) e = 0.01 lr = 0.1 drop_rate = 0. batch_size = 50 hidden_size = [400, 400] # try: gru, lstm cell = "gru" # try: sgd, momentum, rmsprop, adagrad, adadelta, adam optimizer = "adadelta" seqs, i2w, w2i, data_xy = data.load_hlm("/data/hlm/hlm.txt", batch_size) dim_x = len(w2i) dim_y = len(w2i) print "#features = ", dim_x, "#labels = ", dim_y print "compiling..." model = RNN(dim_x, dim_y, hidden_size, cell, optimizer, drop_rate) #model = load_model("./model/rnn_hlm.model", model) print "training..." start = time.time() g_error = 9999.9999 for i in xrange(100): error = 0.0 in_start = time.time() for batch_id, xy in data_xy.items(): X, Y, mask, local_batch_size = data.index2seqs(seqs, xy[0], w2i)