Workspace
To open this notebook, you have two options:
- Go to the next page in the classroom (recommended)
- Clone the repo from Github and open the notebook IMDB_in_Keras.ipynb in the imdb_keras folder. You can either download the repository with
git clone https://github.com/udacity/deep-learning.git
, or download it as an archive file from this link.
My Solution -> Accuracy: 0.86116
# TODO: Build the model architecture
model = Sequential()
model.add(Dense(512, input_dim=x_train.shape[1]))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(32))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(2))
model.add(Activation('softmax'))
# TODO: Compile the model using a loss function and an optimizer.
model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
# TODO: Run the model. Feel free to experiment with different batch sizes and number of epochs.
model.fit(x_train, y_train, epochs=12, batch_size=128)
score = model.evaluate(x_test, y_test, verbose=0)
print("Accuracy: ", score[1])
Udacity Solution -> Accuracy: 0.85328
# Building the model architecture with one layer of length 100
model = Sequential()
model.add(Dense(512, activation='relu', input_dim=1000))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
model.summary()
# Compiling the model using categorical_crossentropy loss, and rmsprop optimizer.
model.compile(loss='categorical_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
# Running and evaluating the model
hist = model.fit(x_train, y_train,
batch_size=32,
epochs=10,
validation_data=(x_test, y_test),
verbose=2)