























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A technical exam guide covering machine learning fundamentals, TensorFlow workflows, neural network development, model optimization, and deployment concepts. The guide includes coding scenarios, practice questions, and structured lessons designed to support aspiring TensorFlow developers.
Typology: Exams
1 / 95
This page cannot be seen from the preview
Don't miss anything!
























































































Question 1. Which TensorFlow function creates a tensor that can be updated during training? A) tf.constant() B) tf.Variable() C) tf.placeholder() D) tf.convert_to_tensor() Answer: B Explanation: tf.Variable() creates mutable tensors whose values can be changed by optimizers during training, unlike tf.constant() which is immutable. Question 2. In a PyCharm project configured for TensorFlow, which setting ensures the correct Python interpreter is used? A) Project Structure → Modules → Language level B) Settings → Project → Python Interpreter C) Run → Edit Configurations → Environment variables D) Tools → TensorFlow → Install Packages Answer: B Explanation: PyCharm’s “Python Interpreter” setting lets you select the interpreter that contains TensorFlow and other dependencies. Question 3. What is the shape of a tensor returned by tf.random.normal([2, 3, 4])? A) (2, 3) B) (3, 4) C) (2, 3, 4) D) (4, 2, 3) Answer: C
Explanation: The list [2, 3, 4] directly defines the tensor’s dimensions: 2 × 3 × 4. Question 4. Which Keras API method is used to view the documentation of a layer’s arguments directly from a notebook? A) layer.help() B) tf.keras.utils.get_source() C) tf.keras.utils.plot_model() D) layer.doc Answer: D Explanation: The __doc__ attribute of a Keras layer contains its docstring, showing available arguments. Question 5. When saving a model for later inference, which format preserves the full TensorFlow graph and variables? A) HDF5 (.h5) B) SavedModel directory C) JSON architecture only D) CSV file Answer: B Explanation: SavedModel stores the complete graph, weights, and assets, making it the recommended format for deployment. Question 6. Which loss function should be paired with a sigmoid activation in the final layer for binary classification? A) categorical_crossentropy B) binary_crossentropy
Question 9. EarlyStopping callback monitors which metric by default? A) loss B) accuracy C) val_loss D) val_accuracy Answer: C Explanation: EarlyStopping’s default monitor='val_loss' stops training when validation loss ceases improving. Question 10. Which plot is most useful for detecting overfitting during training? A) Training loss vs. epochs only B) Validation loss vs. epochs only C) Both training and validation loss on the same graph D) Model summary table Answer: C Explanation: Comparing training and validation loss curves reveals divergence, a classic sign of overfitting. Question 11. What does the tf.keras.layers.MaxPooling2D(pool_size=(2,2)) layer do? A) Increases the number of channels B) Reduces spatial dimensions by taking the maximum in each 2×2 window C) Performs convolution with a 2×2 kernel D) Flattens the tensor Answer: B Explanation: MaxPooling downsamples feature maps by selecting the maximum value in non‑overlapping 2×2 regions.
Question 12. Which of the following is NOT a typical data augmentation technique for image data? A) Random rotation B) Random zoom C) Random Gaussian noise addition to labels D) Horizontal flip Answer: C Explanation: Adding noise to labels corrupts supervision; augmentation operates on images, not on label values. Question 13. To freeze the base layers of a pre‑trained MobileNet model while training new top layers, which method is used? A) set trainable=False on the base model B) compile with loss='frozen' C) use tf.keras.layers.Freeze() D) delete the base model’s weights Answer: A Explanation: Setting base_model.trainable = False prevents its weights from being updated during back‑propagation. Question 14. In NLP preprocessing, which Keras utility converts text strings into integer sequences based on a vocabulary? A) tf.keras.layers.TextVectorization B) tf.keras.preprocessing.text.Tokenizer C) tf.keras.layers.Embedding
D) Depends on the batch size Answer: B Explanation: Bidirectional LSTM runs a forward and a backward LSTM; their outputs are concatenated, doubling the hidden dimension. Question 18. Which loss function is most appropriate for a multi‑class classification problem with mutually exclusive classes? A) binary_crossentropy B) categorical_crossentropy C) mean_absolute_error D) hinge Answer: B Explanation: categorical_crossentropy expects a probability distribution over mutually exclusive classes (softmax output). Question 19. In time‑series windowing, if you use a window size of 30 and a forecasting horizon of 5, how many timesteps does the model predict for each input window? A) 30 B) 5 C) 35 D) 25 Answer: B Explanation: The window provides 30 past steps as features, and the model outputs the next 5 steps (the horizon).
Question 20. Which metric is more sensitive to large errors in regression forecasts? A) MAE B) MSE C) R² D) Accuracy Answer: B Explanation: MSE squares the error term, giving higher weight to large deviations compared to MAE. Question 21. Which TensorFlow function converts a NumPy array into a constant tensor? A) tf.convert_to_tensor() B) tf.constant() C) tf.Variable() D) tf.cast() Answer: B Explanation: tf.constant() creates an immutable tensor directly from a NumPy array. Question 22. When building a functional model, how do you connect two layers A and B where B receives A’s output? A) B(A) B) A.connect(B) C) tf.keras.layers.add([A, B]) D) A >> B Answer: A Explanation: In the Functional API, you call the downstream layer with the upstream tensor, i.e., output = B(A_input).
D) softmax Answer: C Explanation: ReLU (Rectified Linear Unit) is simple, non‑saturating for positive inputs, and accelerates convergence. Question 26. In a convolutional layer, what does the filters argument specify? A) The size of the convolution kernel B) The number of output feature maps C) The stride length D) The padding mode Answer: B Explanation: filters determines how many distinct kernels are learned, each producing one output channel. Question 27. Which preprocessing step is essential before feeding raw pixel values (0‑255) into a CNN? A) One‑hot encoding B) Normalization (e.g., dividing by 255) C) Adding Gaussian noise D) Tokenization Answer: B Explanation: Scaling pixel values to [0,1] (or mean‑zero) improves numerical stability and speeds up training. Question 28. How does dropout improve model generalization? A) By increasing the number of parameters
B) By randomly setting a fraction of activations to zero during training C) By adding noise to the input data only D) By reducing the learning rate automatically Answer: B Explanation: Dropout prevents co‑adaptation of neurons by randomly deactivating them, which reduces overfitting. Question 29. Which Keras layer can be used to perform 1‑D convolution over time‑series data? A) Conv2D B) Conv1D C) SeparableConv1D D) Conv3D Answer: B Explanation: Conv1D slides a kernel along a single spatial (temporal) dimension, suitable for sequential data. Question 30. When fine‑tuning a pre‑trained model, why is it common to first train only the new top layers before unfreezing the base? A) To reduce GPU memory usage B) To let the new classifier adapt to the frozen feature extractor before adjusting the base weights C) To avoid any weight updates altogether D) To automatically increase batch size Answer: B Explanation: Training the classifier first stabilizes high‑level predictions; later unfreezing allows subtle adjustments in the base without destroying learned features.
Explanation: Binary cross‑entropy treats each output independently, matching the per‑label sigmoid activation. Question 34. What does the tf.keras.layers.Rescaling(1./255) layer accomplish? A) Converts integer labels to one‑hot vectors B) Normalizes image pixel values to the range [0,1] C) Performs feature scaling based on mean and variance D) Adds random noise to the input Answer: B Explanation: Dividing by 255 rescales 0‑255 pixel intensities to the unit interval. Question 35. Which callback can be used to reduce the learning rate when a metric has stopped improving? A) EarlyStopping B) ReduceLROnPlateau C) ModelCheckpoint D) TensorBoard Answer: B Explanation: ReduceLROnPlateau monitors a metric and lowers the learning rate when progress stalls. Question 36. When using tf.data.Dataset.batch(batch_size), what happens to the last batch if the dataset size isn’t divisible by batch_size? A) It is dropped automatically B) It is padded with zeros C) It contains the remaining elements (smaller batch)
D) An error is raised Answer: C Explanation: By default, the final batch holds the leftover examples; you can set drop_remainder=True to discard it. Question 37. Which of the following statements about tf.function is true? A) It converts eager code into a static graph for performance gains B) It disables GPU usage C) It automatically saves the model after each call D) It replaces the need for Keras layers Answer: A Explanation: tf.function decorates Python functions, tracing them into a TensorFlow graph that runs faster than eager execution. Question 38. Which method returns a summary of a Keras model, including layer names, output shapes, and parameter counts? A) model.info() B) model.describe() C) model.summary() D) model.print() Answer: C Explanation: model.summary() prints a table with architecture details. Question 39. In TensorFlow 2.x, which API is recommended for building custom training loops? A) tf.keras.Sequential.compile()
Question 42. When using tf.keras.preprocessing.image.ImageDataGenerator, which argument controls random horizontal flips? A) rotation_range B) width_shift_range C) horizontal_flip D) zoom_range Answer: C Explanation: Setting horizontal_flip=True enables random left‑right mirroring of images during training. Question 43. Which layer is typically placed after a Conv2D layer to reduce over‑fitting without discarding spatial information? A) MaxPooling2D B) Dropout C) Flatten D) Dense Answer: B Explanation: Dropout randomly zeroes activations, helping regularize the model while keeping spatial dimensions unchanged. Question 44. In a functional model, how can you create a model that has two inputs and one output? A) Use tf.keras.Model(inputs=[inp1, inp2], outputs=out) B) Concatenate the inputs and pass to a Sequential model C) Define two separate models and merge them later D) Not possible; functional API only supports single input
Answer: A Explanation: The Functional API accepts a list of input tensors, enabling multi‑input architectures. Question 45. Which optimizer is most appropriate when you need to handle sparse gradients, such as in NLP embedding layers? A) Adam B) RMSprop C) Adagrad D) SGD Answer: C Explanation: Adagrad adapts learning rates based on the frequency of updates, which works well for sparse features like word embeddings. Question 46. What does the tf.keras.layers.GlobalAveragePooling2D layer do? A) Flattens the feature maps into a vector B) Computes the average of each feature map, reducing spatial dimensions to 1× C) Performs max pooling over the entire feature map D) Adds a fully connected layer automatically Answer: B Explanation: Global average pooling takes the mean of each channel, producing a vector whose length equals the number of channels. Question 47. Which of the following is a benefit of using the TensorFlow Hub library? A) Automatic hyperparameter tuning B) Access to pre‑trained models that can be reused via a simple layer call
Question 50. What does the tf.keras.layers.BatchNormalization layer normalize? A) Input data before the first layer B) Activations of the previous layer across the batch dimension C) Model weights after each epoch D) Loss values during training Answer: B Explanation: BatchNormalization standardizes the activations (mean≈0, variance≈1) across each mini‑batch, stabilizing training. Question 51. Which TensorFlow function can be used to convert a Python list of strings into a tensor of type tf.string? A) tf.constant() B) tf.convert_to_tensor() C) tf.Variable() D) tf.strings.unicode_split() Answer: B Explanation: tf.convert_to_tensor() infers the dtype and creates a tensor; passing a list of strings yields a tf.string tensor. Question 52. When using tf.keras.layers.Embedding(input_dim=5000, output_dim=64), what does input_dim represent? A) Length of each embedding vector B) Number of unique tokens (vocabulary size) C) Number of training epochs D) Batch size Answer: B
Explanation: input_dim specifies the size of the vocabulary; each integer index from 0 to 4999 maps to a 64‑dimensional vector. Question 53. Which of the following callbacks writes training metrics to TensorBoard for visualization? A) ModelCheckpoint B) EarlyStopping C) TensorBoard D) ReduceLROnPlateau Answer: C Explanation: The TensorBoard callback logs scalars, histograms, and images for later inspection in the TensorBoard UI. Question 54. In a regression problem with outliers, which loss function is more robust than MSE? A) MAE B) Huber loss C) Log‑cosh loss D) All of the above Answer: D Explanation: MAE, Huber, and log‑cosh are less sensitive to large errors than MSE, making them suitable when outliers exist. Question 55. Which of the following is a correct way to set a random seed for reproducibility in TensorFlow? A) tf.random.set_seed(42) B) tf.set_random_seed(42)