
























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























































































Question 1. Which TensorFlow API is primarily used for building models with a straightforward stack of layers? A) tf.keras.layers B) tf.keras.Sequential C) tf.keras.Model (Functional) D) tf.data.Dataset Answer: B Explanation: tf.keras.Sequential provides a linear stack of layers, making it ideal for simple feed‑forward architectures. Question 2. In TensorFlow 2.x, what does the tf.function decorator do? A) Converts a Python function into a TensorFlow graph for faster execution B) Enables eager execution of the function C) Saves the function as a SavedModel D) Automatically adds a loss function to the model Answer: A Explanation: tf.function traces the Python code and builds a graph, which can be optimized and executed more efficiently than eager mode. Question 3. When creating a virtual environment for TensorFlow development, which command installs a specific TensorFlow version without affecting the global Python installation? A) pip install tensorflow==2.9. B) conda install tensorflow=2.9.1 – name base C) python - m venv tf_env && source tf_env/bin/activate && pip install tensorflow==2.9. D) sudo apt-get install tensorflow‑2.9. Answer: C
Explanation: Using python - m venv creates an isolated environment, and installing TensorFlow inside it prevents version conflicts with the system Python. Question 4. Which method is used to load a SavedModel from disk for inference? A) tf.keras.models.load_model('path') B) tf.saved_model.load('path') C) tf.keras.models.load_weights('path') D) tf.load_model('path') Answer: B Explanation: tf.saved_model.load restores the SavedModel format, returning a callable object for inference. Question 5. How can you inspect the shape of a TensorFlow tensor t? A) t.shape() B) t.get_shape() C) t.shape D) tf.shape(t) returns a Tensor object, not a Python tuple Answer: C Explanation: The .shape attribute provides the static shape as a TensorShape object. Question 6. Which of the following is a correct way to slice the first 10 rows and all columns of a tensor x? A) x[:10, :] B) x[0:10] C) tf.slice(x, [0,0], [10,-1]) D) x.slice(0,10)
C) .h D) .model Answer: C Explanation: The H5 format stores the entire model (architecture, weights, optimizer state) in an HDF5 file with .h5. Question 10. Which callback stops training when the validation loss has not improved for 3 consecutive epochs? A) tf.keras.callbacks.ModelCheckpoint B) tf.keras.callbacks.EarlyStopping(patience=3) C) tf.keras.callbacks.ReduceLROnPlateau D) tf.keras.callbacks.TensorBoard Answer: B Explanation: EarlyStopping monitors a metric and halts training after a specified patience period without improvement. Question 11. For a binary classification problem, which loss function should you use? A) tf.keras.losses.CategoricalCrossentropy B) tf.keras.losses.BinaryCrossentropy C) tf.keras.losses.MeanSquaredError D) tf.keras.losses.Hinge Answer: B Explanation: BinaryCrossentropy is designed for two‑class problems and expects probabilities from a sigmoid output.
Question 12. Which optimizer adapts the learning rate per parameter based on first and second moments of gradients? A) SGD B) Adam C) RMSprop D) Adagrad Answer: B Explanation: Adam computes adaptive learning rates using estimates of both the mean (first moment) and variance (second moment) of gradients. Question 13. In a Keras model, what does the kernel_regularizer=tf.keras.regularizers.l2(0.01) argument do? A) Adds dropout to the layer B) Penalizes large weights to reduce overfitting C) Normalizes the output of the layer D) Clips gradients during backpropagation Answer: B Explanation: L2 regularization adds a penalty proportional to the square of the weights, encouraging smaller weight values. Question 14. Which activation function is most appropriate for the hidden layers of a deep neural network? A) Sigmoid B) Tanh C) ReLU D) Softmax
B) normalization=True C) scale= D) dtype='float32' Answer: A Explanation: Setting rescale=1./255 multiplies each pixel by 1/255, converting uint8 [0,255] to float [0,1]. Question 18. In a Conv2D layer, what does a kernel size of (3,3) represent? A) A filter that slides 3 pixels vertically and 3 horizontally B) A 3‑channel input and 3‑channel output C) A 3‑by‑3 weight matrix applied to each patch of the input image D) The stride of the convolution Answer: C Explanation: The kernel size defines the spatial dimensions of the filter; (3,3) means a 3× window of weights. Question 19. Which padding option preserves the input spatial dimensions after a Conv2D with stride 1? A) 'valid' B) 'same' C) 'full' D) No padding is needed Answer: B Explanation: 'same' padding adds zeros so that output height and width equal the input when stride=1.
Question 20. How does MaxPooling2D(pool_size=(2,2)) affect the dimensions of its input? A) Reduces each spatial dimension by a factor of 2 B) Increases each spatial dimension by a factor of 2 C) Leaves dimensions unchanged but reduces channel depth D) Performs average pooling instead of max pooling Answer: A Explanation: A 2×2 max pool with stride 2 downsamples height and width by half. Question 21. When fine‑tuning a pre‑trained MobileNet model, which step is essential before training the new top layers? A) Re‑initializing all MobileNet weights B) Setting trainable=False for the base model layers C) Changing the input shape to (224,224,3) D) Adding BatchNormalization after every MobileNet layer Answer: B Explanation: Freezing the base model prevents its weights from being updated while the new classifier learns. Question 22. Which TensorFlow function loads the TensorFlow Datasets (TFDS) catalog for the MNIST dataset? A) tf.keras.datasets.mnist.load_data() B) tfds.load('mnist', split='train') C) tf.data.TFRecordDataset('mnist.tfrecord') D) tf.io.read_file('mnist.tfrecord') Answer: B
C) It trains faster due to parallelism D) It eliminates the need for padding sequences Answer: B Explanation: Bidirectional LSTMs process the sequence forward and backward, providing information from both directions. Question 26. In a text generation model, which loss function is most appropriate? A) SparseCategoricalCrossentropy B) MeanSquaredError C) BinaryCrossentropy D) HuberLoss Answer: A Explanation: Text generation predicts the next token from a vocabulary; SparseCategoricalCrossentropy works with integer class labels. Question 27. Which of the following best describes the “windowing” technique for time‑series forecasting? A) Randomly shuffling the entire series before training B) Creating overlapping subsequences that serve as input‑output pairs C) Applying Fourier transform to the series D) Using only the last observation as input Answer: B Explanation: Windowing slides a fixed‑size window over the series, generating many supervised examples.
Question 28. When evaluating a regression model, why might you prefer Mean Absolute Error (MAE) over Mean Squared Error (MSE)? A) MAE penalizes large errors more heavily B) MAE is differentiable everywhere, whereas MSE is not C) MAE is in the same unit as the target variable, making interpretation easier D) MAE is always smaller than MSE, indicating better performance Answer: C Explanation: MAE represents average absolute deviation in the original units, facilitating intuitive interpretation. Question 29. Which TensorFlow callback reduces the learning rate when a metric has plateaued? A) EarlyStopping B) ReduceLROnPlateau C) ModelCheckpoint D) LearningRateScheduler Answer: B Explanation: ReduceLROnPlateau monitors a metric and lowers the learning rate if no improvement is seen for a set patience. Question 30. In a 1‑D convolution for time‑series data, what does the kernel_size parameter control? A) Number of output channels B) Length of the temporal filter applied to the input sequence C) Stride of the convolution D) Amount of padding applied
B) Random zoom C) Random Gaussian noise addition to pixel values D) Random label shuffling Answer: D Explanation: Shuffling labels destroys the relationship between images and their classes and is not an augmentation method. Question 34. In the context of TensorFlow, what does the term “eager execution” refer to? A) Compiling the entire graph before any operation runs B) Executing operations immediately as they are called, returning concrete values C) Running operations on a GPU only D) Deferring execution until tf.function is applied Answer: B Explanation: Eager execution evaluates ops instantly, making debugging and interactive development straightforward. Question 35. Which of the following layers can be used to convert a sequence of word indices into dense vectors before feeding them to an RNN? A) tf.keras.layers.Embedding B) tf.keras.layers.Dense C) tf.keras.layers.Conv1D D) tf.keras.layers.Flatten Answer: A Explanation: The Embedding layer maps integer indices to learned dense vectors (embeddings).
Question 36. When loading a CSV file with tf.data.experimental.make_csv_dataset, which argument specifies the batch size? A) batch_size B) num_epochs C) shuffle_buffer D) label_name Answer: A Explanation: batch_size determines how many rows are grouped into each dataset element. Question 37. Which activation function is most appropriate for the output layer of a multi‑class classification model with three classes? A) Sigmoid B) ReLU C) Softmax D) Linear Answer: C Explanation: Softmax converts logits into a probability distribution over mutually exclusive classes. Question 38. In a Keras ModelCheckpoint callback, what does setting save_best_only=True accomplish? A) Saves the model after every epoch B) Saves only the model weights, not the architecture C) Saves the model only when the monitored metric improves D) Overwrites the same file each epoch regardless of performance Answer: C
C) Conv1D increases the number of parameters dramatically D) Conv1D prevents gradient vanishing in the LSTM Answer: A Explanation: Conv1D can act as a feature extractor and down‑sample the sequence, providing a compact representation for the subsequent LSTM. Question 42. Which TensorFlow function can be used to convert a Python list of NumPy arrays into a single Tensor? A) tf.concat B) tf.stack C) tf.convert_to_tensor D) tf.expand_dims Answer: C Explanation: tf.convert_to_tensor accepts Python sequences (including lists) and creates a Tensor with appropriate shape. Question 43. What does the tf.keras.layers.GlobalAveragePooling2D layer do? A) Computes the average of each channel across spatial dimensions, reducing H×W to 1× B) Flattens the entire feature map into a vector C) Performs max pooling globally D) Adds a fully connected layer with average weights Answer: A Explanation: GlobalAveragePooling2D averages each channel’s spatial values, yielding a vector equal to the number of channels.
Question 44. In the context of TensorFlow model serving, which format is optimized for production inference on mobile and edge devices? A) SavedModel B) HDF5 (.h5) C) TensorFlow Lite (.tflite) D) Protocol Buffers (.pb) only Answer: C Explanation: TensorFlow Lite produces a lightweight, platform‑specific binary optimized for low‑latency inference. Question 45. Which loss function is appropriate for a multi‑label classification problem where each instance may belong to multiple classes? A) CategoricalCrossentropy B) BinaryCrossentropy C) SparseCategoricalCrossentropy D) Hinge Answer: B Explanation: BinaryCrossentropy treats each class independently as a binary problem, suitable for multi‑label scenarios. Question 46. When using tf.keras.preprocessing.image.ImageDataGenerator with horizontal_flip=True, what effect does this have on the data? A) Rotates images 90 degrees B) Mirrors images along the vertical axis randomly C) Randomly flips images left‑to‑right (horizontal) during training D) Inverts pixel intensities
B) To constrain outputs between 0 and 1 C) To output a single continuous value without transformation D) To apply softmax over multiple classes Answer: C Explanation: A linear activation leaves the output unchanged, suitable for predicting a real‑valued target. Question 50. Which TensorFlow API provides ready‑made functions for image preprocessing such as resizing, cropping, and flipping? A) tf.image B) tf.io C) tf.keras.preprocessing.image D) tf.data.experimental Answer: A Explanation: tf.image contains low‑level image manipulation ops like resize, central_crop, and flip_left_right. Question 51. When training a model on a GPU, which TensorFlow setting can limit GPU memory growth to avoid allocation errors? A) tf.config.experimental.set_memory_growth(gpu, True) B) tf.config.set_virtual_device_configuration C) tf.keras.backend.set_floatx('float64') D) tf.distribute.MirroredStrategy() Answer: A Explanation: set_memory_growth allows TensorFlow to allocate GPU memory incrementally rather than reserving all at once.
Question 52. In the context of Keras callbacks, what does the monitor='val_accuracy' argument specify? A) The metric that will be logged to TensorBoard B) The metric used to determine when to trigger the callback’s action C) The metric that will be plotted automatically D) The metric that will be saved in the model checkpoint file name Answer: B Explanation: monitor tells the callback which metric to observe (e.g., for EarlyStopping or ReduceLROnPlateau). Question 53. Which of the following correctly describes the effect of tf.keras.layers.TimeDistributed when wrapping a Dense layer? A) It applies the Dense layer independently to each timestep of a sequence input B) It distributes the computation across multiple GPUs automatically C) It converts a 2‑D input into a 3‑D output D) It adds temporal dropout to the input sequence Answer: A Explanation: TimeDistributed applies the wrapped layer to every temporal slice, preserving the sequence dimension. Question 54. What is the primary purpose of using tf.keras.layers.Lambda in a model? A) To implement custom operations not available as built‑in layers B) To automatically add L2 regularization C) To perform batch normalization D) To create a dropout layer with a custom rate