Chapter 7 Neural Networks with Keras Flashcards
How are models defined in Keras? P 53
Models in Keras are defined as a sequence of layers. We create a Sequential model and add layers one at a time until we are happy with our network topology.
What is the first thing we should make sure of, when creating a Keras NN model? What’s its keyword arg? P 53
The first thing to get right is to ensure the input layer has the right number of inputs. This can be specified when creating the first layer with the input_dim argument.
How do we know the number of layers to use and their types? P 53
This is a very hard question. There are heuristics that we can use and often the best network structure is found through a process of trial and error experimentation. Generally, you need a network large enough to capture the structure of the problem if that helps at all.
Fully connected layers in Keras are defined using the … class. P 56
Dense
What does below code do? P 56
model = Sequential()
model.add(Dense(12, input_dim=8 , activation= relu ))
model.add(Dense(8, activation= relu ))
model.add(Dense(1, activation= sigmoid ))
*Specified input dimension when creating the first layer with the input_dim argument.
*For next layers, we specify the number of neurons in the layer as the first argument
*specify the activation function using the activation argument
Compiling the model uses the numerical libraries (so-called backend) such as TensorFlow. True/False P 57
True, Keras is a model-level library, providing high-level building blocks for developing deep learning models. It does not handle itself low-level operations such as tensor products, convolutions and so on.
What are the things we need to define while using Keras’s model.compile()? P 57
We must specify the loss function to use to evaluate a set of weights, using “loss=” arg,
The optimizer used to search through different weights for the network, using “optimizer=” arg,
Any optional metrics we would like to collect and report during training. using “metrics=” arg.
Logarithmic loss, for a binary classification problem is defined in Keras as…. P 57
Binary_crossentropy
Write a model compile code in Keras, that uses binary crossentropy loss function, adam optimizer and accuracy metric. P 57
model.compile(loss= binary_crossentropy , optimizer= adam , metrics=[ accuracy ])
Write a model fit code in Keras with 150 epochs and batch size 10. P 58
Fit the model
model.fit(X, Y, epochs=150, batch_size=10)
How can we evaluate a trained model in Keras? Code P 58
evaluate the model
scores = model.evaluate(X, Y)
print(“%s: %.2f%%” % (model.metrics_names[1], scores[1]*100))