import keras from keras.datasets import imdb import numpy as np from keras import models from keras import layers from keras import optimizers from keras import regularizers np.random.seed(4747) # to replicate the results. def vectorize_sequences(sequences, dimension=10000): # Create an all-zero matrix of shape (len(sequences), dimension) results = np.zeros((len(sequences), dimension)) for i, sequence in enumerate(sequences): results[i, sequence] = 1. # set specific indices of results[i] to 1s return results def main(reg_param=0.001,n0_of_epochs=5, bat_size=512, act='relu', no_of_h_nodes = 4 , validate=1): (train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000,seed=100) # Our vectorized training data x_train = vectorize_sequences(train_data) # Our vectorized test data x_test = vectorize_sequences(test_data) # Our vectorized labels y_train = np.asarray(train_labels).astype('float32') y_test = np.asarray(test_labels).astype('float32') model = models.Sequential() # modify to add layers with regularizer and activation function model.add() # modify to add optimizer, loss function and metric model.compile() #model.summary() # to see the summary of the model built # Biuld the model output = model.fit() # Evaluate the model with test data accuracy = model.evaluate() print('Test accuracy') print(score[1])