Chapter 7 Neural Networks with Keras Flashcards

1
Q

How are models defined in Keras? P 53

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the first thing we should make sure of, when creating a Keras NN model? What’s its keyword arg? P 53

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do we know the number of layers to use and their types? P 53

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fully connected layers in Keras are defined using the … class. P 56

A

Dense

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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 ))

A

*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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Compiling the model uses the numerical libraries (so-called backend) such as TensorFlow. True/False P 57

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the things we need to define while using Keras’s model.compile()? P 57

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Logarithmic loss, for a binary classification problem is defined in Keras as…. P 57

A

Binary_crossentropy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write a model compile code in Keras, that uses binary crossentropy loss function, adam optimizer and accuracy metric. P 57

A

model.compile(loss= binary_crossentropy , optimizer= adam , metrics=[ accuracy ])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write a model fit code in Keras with 150 epochs and batch size 10. P 58

A

Fit the model

model.fit(X, Y, epochs=150, batch_size=10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can we evaluate a trained model in Keras? Code P 58

A

evaluate the model

scores = model.evaluate(X, Y)
print(“%s: %.2f%%” % (model.metrics_names[1], scores[1]*100))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly