def batch_train(train, val, model_path): trainX, trainY = train valX, valY = val nn = Classifier( layers=[ Convolution('Rectifier', channels=100, kernel_shape=(5, WORD_DIM), border_mode='valid' #pool_shape=(3,1), #pool_type='max' ), Layer('Rectifier', units=900, dropout=0.5), Layer('Softmax') ], batch_size=50, learning_rate=0.02, normalize='dropout', verbose=True) nn.n_iter = 100 print 'Net created...' try: nn.fit(trainX, trainY) except KeyboardInterrupt: pickle.dump(nn, open(model_path, 'wb')) pickle.dump(nn, open(model_path, 'wb')) print 'Done, final model saved' print 'Testing' #Accuracy on the validation set print 'Validation accuracy:', batch_test(model_path, val)
def batch_train(train,val,model_path): trainX,trainY = train valX,valY = val nn = Classifier(layers = [ Convolution('Rectifier', channels=100, kernel_shape=(5,WORD_DIM), border_mode='valid' #pool_shape=(3,1), #pool_type='max' ), Layer('Rectifier',units=900,dropout=0.5), Layer('Softmax')], batch_size = 50, learning_rate = 0.02, normalize='dropout', verbose = True) nn.n_iter = 100 print 'Net created...' try: nn.fit(trainX,trainY) except KeyboardInterrupt: pickle.dump(nn,open(model_path,'wb')) pickle.dump(nn,open(model_path,'wb')) print 'Done, final model saved' print 'Testing' #Accuracy on the validation set print 'Validation accuracy:',batch_test(model_path,val)
def train(X, Y): print X.shape print Y.shape trainX = X[:int(X.shape[0] * 0.7), :, :] trainY = Y[:int(Y.shape[0] * 0.7), :] valX = X[int(X.shape[0] * 0.7):int(X.shape[0] * 0.8), :, :] valY = Y[int(Y.shape[0] * 0.7):int(Y.shape[0] * 0.8), :] testX = X[int(X.shape[0] * 0.8):, :, :] testY = Y[int(Y.shape[0] * 0.8):, :] print 'Train, Val, Test' print trainX.shape, ',', trainY.shape, '--', valX.shape, ',', valY.shape, '--', testX.shape, ',', testY.shape nn = Classifier( layers=[ Convolution('Rectifier', channels=1, kernel_shape=(5, WORD_DIM)), Layer('Rectifier', units=300), Layer('Rectifier', units=300), Layer('Softmax') ], #valid_set = (valX,valY), learning_rate=0.02, #0.05, #0.001, #normalize='batch', verbose=True) print 'Net created...' #Load net here --always CHECK HERE before starting -- DO THIS NOW, WE WANT TO CONTINUE FROM HERE ON nn = pickle.load(open(model_path, 'rb')) for i in range(100): try: nn.n_iter = 5 nn.fit(trainX, trainY) pickle.dump(nn, open(model_path, 'wb')) nn = pickle.load(open(model_path, 'rb')) except KeyboardInterrupt: pickle.dump(nn, open(model_path, 'wb')) print 'Saved model after keyboard interrupt' pickle.dump(nn, open(model_path, 'wb')) print 'Temp model saved' #try: # nn.fit(trainX,trainY) #except KeyboardInterrupt: # pickle.dump(nn,open(model_path,'wb')) print 'Done, final model saved'
def train(X,Y): print X.shape print Y.shape trainX = X[:int(X.shape[0]*0.7),:,:] trainY = Y[:int(Y.shape[0]*0.7),:] valX = X[int(X.shape[0]*0.7):int(X.shape[0]*0.8),:,:] valY = Y[int(Y.shape[0]*0.7):int(Y.shape[0]*0.8),:] testX = X[int(X.shape[0]*0.8):,:,:] testY = Y[int(Y.shape[0]*0.8):,:] print 'Train, Val, Test' print trainX.shape,',',trainY.shape,'--',valX.shape,',',valY.shape,'--',testX.shape,',',testY.shape nn = Classifier( layers = [ Convolution('Rectifier',channels=1,kernel_shape=(5,WORD_DIM)), Layer('Rectifier',units=300), Layer('Rectifier',units=300), Layer('Softmax')], #valid_set = (valX,valY), learning_rate = 0.02, #0.05, #0.001, #normalize='batch', verbose = True) print 'Net created...' #Load net here --always CHECK HERE before starting -- DO THIS NOW, WE WANT TO CONTINUE FROM HERE ON nn = pickle.load(open(model_path,'rb')) for i in range(100): try: nn.n_iter = 5 nn.fit(trainX,trainY) pickle.dump(nn,open(model_path,'wb')) nn = pickle.load(open(model_path,'rb')) except KeyboardInterrupt: pickle.dump(nn,open(model_path,'wb')) print 'Saved model after keyboard interrupt' pickle.dump(nn,open(model_path,'wb')) print 'Temp model saved' #try: # nn.fit(trainX,trainY) #except KeyboardInterrupt: # pickle.dump(nn,open(model_path,'wb')) print 'Done, final model saved'