def stage2(options, trainData, validData, testData, n_layer): # Initialize Model model = LSTM() n_output = 1 for i in range(n_layer): model.add(blstm_layer(1, 1)) # model.add(DropOut()) model.add(bi_avec_activate(1, n_output)) # Choose optimizer adadelta = ADADELTA() options["optimizer"] = adadelta # model.compile(options) # Unsupervised Training print("Unsupervised Pretraining") n_samples = len(trainData) pratrainingData = [] for i in range(n_samples): pratrainingData.append((trainData[i][1], trainData[i][1])) print(len(pratrainingData), len(validData), len(testData)) train_err, valid_err, test_err = model.fit(pratrainingData, validData, testData) """ # Supervised training model.load(options['saveto']+'_ccc.pkl') print('Supervised training') print(len(trainData), len(validData), len(testData)) train_err, valid_err, test_err = model.fit(trainData, validData, testData) """ del model return train_err, valid_err, test_err
def stage1(options, trainData, validData, testData, n_layer, n_hidden): # Initialize Model model = LSTM() # Build Neural Network n_input = 102 n_hidden = n_hidden n_output = 1 # logistic regression layer model.add(hidden_layer(n_input, n_hidden)) #model.add(blstm_layer(n_input, n_hidden)) # BLSTM layer for i in range(n_layer): model.add(blstm_layer(n_hidden, n_hidden)) # linear regression layer model.add(bi_avec_activate(n_hidden, 1)) # Choose optimizer adadelta = ADADELTA() options["optimizer"] = adadelta # compile model.compile(options) # Training train_err, valid_err, test_err = model.fit(trainData, validData, testData) del model return train_err, valid_err, test_err
def test(option, trainData, validData, testData, n_layer, n_hidden): # Initialize Model model = LSTM() # Build Neural Network n_input = 84 n_hidden = 64 # n_hidden = int(n_input*n_hidden) n_output = 1 model.add(lstm_layer(84, 200)) model.add(lstm_layer(200, 160)) # model.add(lstm_layer()) # for i in range(n_layer): # model.add(lstm_layer(n_hidden, n_hidden)) # model.add(DropOut()) model.add(avec_activate(160, n_output)) # model.add(DropOut()) # Choose optimizer adadelta = ADADELTA() options["optimizer"] = adadelta # model.compile(options) # Training train_err, valid_err, test_err = model.fit(trainData, validData, testData) del model return train_err, valid_err, test_err
def train_blstm(options, trainData, validData, testData, n_layer, n_hidden): # Initialize Model model = LSTM() # Build Neural Network n_input = 84 n_hidden = n_hidden n_output = 1 # model.add(blstm_layer(n_input, n_hidden)) # model.add(DropOut()) model.add(hidden_layer(n_input, n_hidden)) for i in range(n_layer): model.add(blstm_layer(n_hidden, n_hidden)) # model.add(DropOut()) model.add(bi_avec_activate(n_hidden, 1)) # Choose optimizer adadelta = ADADELTA() options["optimizer"] = adadelta # model.compile(options) # Training train_err, valid_err, test_err = model.fit(trainData, validData, testData) del model return train_err, valid_err, test_err
def stage2_blstm(options, trainData, validData, testData, n_layer): # Initialize Model model = LSTM() # Build Neural Network n_input = 1 n_hidden = 1 # n_hidden = int(n_input*n_hidden) n_output = 1 # model.add(hidden_layer(1,1)) # model.add(DropOut()) for i in range(n_layer): model.add(blstm_layer(1, 1)) # model.add(DropOut()) model.add(bi_avec_activate(1, n_output)) # model.add(DropOut()) # model.add(blstm_layer(n_output, n_output)) # model.add(bi_avec_activate(n_output, n_output)) # Choose optimizer adadelta = ADADELTA() options["optimizer"] = adadelta # model.compile(options) # Training print("pretraining") n_samples = len(trainData) pratrainingData = [] for i in range(n_samples): pratrainingData.append((trainData[i][1], trainData[i][1])) print(len(trainData), len(validData), len(testData)) train_err, valid_err, test_err = model.fit(pratrainingData, validData, testData) del model return train_err, valid_err, test_err
"dispFreq": 1, } np.random.seed(123) # Initialize Model model = LSTM() # Build Neural Network n_input = 1 n_layer = 1 n_hidden = 1 # model.add(DropOut()) for i in range(n_layer): model.add(blstm_layer(n_hidden, n_hidden)) # model.add(DropOut()) model.add(bi_avec_activate(n_hidden, 1)) # model.add(DropOut()) # Choose optimizer adadelta = ADADELTA() options["optimizer"] = adadelta # model.compile(options) print('\nStart Testing Stage 2 Model\n') for n_dim in [0, 1]: print("\n\n")