Data Science & ML

TensorFlow & Keras

Sequential API, Functional API, layers, callbacks, checkpoints, TensorBoard, model saving

22 interview questionsยท
Senior
1

What is the main difference between Keras Sequential API and Functional API?

Answer

Sequential API allows creating models layer by layer in a linear fashion, where each layer has exactly one input and one output. Functional API offers more flexibility by enabling complex architectures: multiple inputs, multiple outputs, residual connections, and shared layer graphs. Use Sequential for simple architectures and Functional for more advanced cases.

2

How to create a Sequential model with a 64-neuron Dense layer followed by a 10-neuron output layer?

Answer

The standard method is to instantiate tf.keras.Sequential() then use model.add() to add layers one by one, or pass a list of layers directly to the constructor. Each Dense layer takes the number of units as parameter, and the first layer requires specifying input_shape to define the input data shape.

3

What is the role of the 'softmax' activation function in an output layer?

Answer

The softmax function transforms logits (raw outputs) into probabilities that sum to 1, which is ideal for multi-class classification. Each output represents the probability of belonging to a class. It is typically used with categorical_crossentropy loss for one-hot labels or sparse_categorical_crossentropy for integer labels.

4

How to define a model with the Functional API having two distinct inputs?

5

Which callback to use to stop training when validation loss no longer improves?

+19 interview questions

Master Data Science & ML for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free