Data Engineering & ML

TensorFlow interview questions

Interviewers probe for a candidate's practical understanding of building, training, and deploying machine learning models using TensorFlow, focusing on Keras API proficiency, understanding of core concepts like tensors and computational graphs, and ability to customize models for specific needs.

15 questions (2 easy · 9 medium · 4 hard), each with what a strong answer covers and where people lose the point. Free to read, no account.

On this page (15 questions)

1.What is a Tensor in TensorFlow, and what are its key attributes?

Warm-up

What a strong answer covers

  • Define a Tensor as a multi-dimensional array, similar to a NumPy array, but optimized for GPU/TPU computation.
  • Explain its primary attributes: `shape` (dimensions of the array) and `dtype` (data type of elements, e.g., `tf.float32`, `tf.int64`).
  • Mention that Tensors are immutable once created, and operations on them return new Tensors.
  • Provide a simple Python example of creating a Tensor and accessing its shape/dtype.

Where people lose the point

  • Confusing Tensors solely with scalars or vectors, rather than general multi-dimensional arrays.
  • Not mentioning the `dtype` attribute or its importance for memory and computation.
  • Incorrectly stating that Tensors are mutable like Python lists or NumPy arrays.
Link to this question

2.Explain the difference between eager execution and graph execution in TensorFlow 2.x. When might you still use graph execution?

Core

What a strong answer covers

  • Describe eager execution as an imperative programming environment where operations are executed immediately, returning concrete values, similar to standard Python.
  • Explain graph execution (or 'AutoGraph' in TF2.x) as building a symbolic computational graph first, which is then executed. This allows for optimizations, deployment, and distributed training.
  • Highlight the benefits of eager execution: easier debugging, more intuitive development, and direct Python control flow.
  • Discuss scenarios where graph execution is preferred: performance optimization (e.g., via `tf.function`), deployment (e.g., SavedModel, TF Serving), and distributed training.

Where people lose the point

  • Believing graph execution is entirely removed in TensorFlow 2.x, rather than being an underlying optimization triggered by `tf.function` or Keras `model.fit()`.
  • Not clearly articulating the 'immediate execution' vs. 'build then execute' paradigm.
  • Failing to mention the performance and deployment benefits of graph execution.
Link to this question

3.Compare and contrast the Keras Sequential API and Functional API. Provide a use case for each.

Core

What a strong answer covers

  • **Sequential API**: Describe it as a simple way to build models where layers are stacked linearly, suitable for single-input, single-output, feed-forward networks.
  • **Functional API**: Explain it as a more flexible way to build models by defining layers as functions that take and return tensors, allowing for complex topologies (multi-input/output, shared layers, non-linear connections).
  • **Use Case - Sequential**: A simple image classifier (e.g., MNIST) with a few `Dense` or `Conv2D` layers stacked sequentially.
  • **Use Case - Functional**: A model with multiple inputs (e.g., image and text), a Siamese network, or a ResNet-like architecture with skip connections.

Where people lose the point

  • Suggesting the Functional API is only for 'advanced' users, rather than for specific architectural needs.
  • Failing to provide concrete examples of model architectures that necessitate the Functional API.
  • Not mentioning that both APIs ultimately produce a `tf.keras.Model` object.
Link to this question

4.Explain the purpose of `model.compile()` and `model.fit()` methods in Keras, detailing their key arguments.

Core

What a strong answer covers

  • **`model.compile()`**: Explain its role in configuring the model for training. Key arguments include `optimizer` (how weights are updated), `loss` (function to minimize), and `metrics` (for monitoring performance).
  • **`model.fit()`**: Describe its role in executing the training process. Key arguments include `x` (training features), `y` (training labels), `epochs` (number of passes over the dataset), `batch_size` (samples per gradient update), and `validation_data` or `validation_split` (for monitoring generalization).
  • Clarify that `compile` sets up the 'how to learn' and `fit` executes the 'learning'.
  • Mention that `fit` returns a `History` object containing training metrics.

Where people lose the point

  • Confusing the roles of `loss` and `metrics` in `compile()` (loss drives optimization, metrics are for reporting).
  • Not mentioning the importance of `epochs` and `batch_size` in `fit()`.
  • Overlooking the `validation_data` argument in `fit()` for monitoring overfitting.
Link to this question

5.How would you implement a custom Keras layer? Provide a high-level overview of the methods you'd override.

Hard

What a strong answer covers

  • Explain that custom layers are created by subclassing `tf.keras.layers.Layer`.
  • Describe the `__init__(self, *args, **kwargs)` method for defining layer-specific attributes and calling the parent constructor.
  • Detail the `build(self, input_shape)` method, where weights and biases are created using `self.add_weight()`, based on the input shape. This method is called once when the layer is first used.
  • Explain the `call(self, inputs)` method, which defines the layer's forward pass logic, performing computations on the input tensor(s) and returning the output tensor(s).
  • Mention the optional `get_config(self)` method for serialization of custom layer parameters.

Where people lose the point

  • Attempting to create weights in `__init__` without knowing the input shape, leading to errors.
  • Not calling `super().__init__()` in the `__init__` method.
  • Confusing `build` with `call` or not understanding when each is executed.
Link to this question

6.Explain the role of `tf.GradientTape` in TensorFlow, especially in the context of custom training loops.

Hard

What a strong answer covers

  • Define `tf.GradientTape` as a mechanism for automatic differentiation in TensorFlow, used to record operations performed inside its context.
  • Explain that it allows computing the gradient of a 'target' (e.g., a loss) with respect to one or more 'sources' (e.g., model variables/weights).
  • Describe its use in a custom training loop: operations within `with tf.GradientTape() as tape:` are recorded. Then, `tape.gradient(loss, model.trainable_variables)` computes gradients.
  • Mention that `tf.GradientTape` is crucial for implementing custom optimization algorithms or fine-grained control over the learning process beyond `model.fit()`.

Where people lose the point

  • Not understanding that `GradientTape` records operations, not just variables.
  • Failing to specify that `tape.gradient()` needs both the target (loss) and the sources (variables) to compute gradients.
  • Incorrectly assuming `GradientTape` is only for custom loops and not an underlying mechanism for `model.fit()` as well.
Link to this question

7.What is the TensorFlow SavedModel format, and what are its advantages for model deployment?

Core

What a strong answer covers

  • Define `SavedModel` as TensorFlow's universal, language-agnostic serialization format for entire models.
  • Explain that it bundles not just weights and architecture, but also the computational graph and any custom objects needed for inference.
  • List advantages for deployment: portability (can be used across different languages/platforms), self-contained (no need for original code), optimization (contains the graph for efficient execution), and ecosystem integration (TF Serving, TF Lite, TF.js).
  • Mention that it allows for consistent inference behavior regardless of the environment.

Where people lose the point

  • Confusing `SavedModel` with just saving model weights (e.g., HDF5 files), which don't include the graph or custom objects.
  • Not emphasizing its 'universal' and 'self-contained' nature.
  • Failing to connect `SavedModel` directly to deployment tools like TensorFlow Serving.
Link to this question

8.Describe how `tf.data` can be used to build efficient input pipelines for training deep learning models.

Core

What a strong answer covers

  • Explain `tf.data` as an API for building flexible and efficient data input pipelines, especially for large datasets that don't fit in memory.
  • Describe common operations: `from_tensor_slices()` or `from_generator()` for creating datasets, `map()` for preprocessing, `batch()` for grouping samples, `shuffle()` for randomization, and `prefetch()` for overlapping data loading and model execution.
  • Highlight benefits: improved performance (parallel processing, prefetching), memory efficiency (loading data on demand), and ease of use for complex transformations.
  • Provide a high-level example of chaining `tf.data` methods to create a pipeline.

Where people lose the point

  • Underestimating the performance benefits of `tf.data` compared to manual data loading.
  • Not mentioning key methods like `map`, `batch`, `shuffle`, and `prefetch`.
  • Failing to explain how `tf.data` handles datasets larger than memory.
Link to this question

9.Discuss common regularization techniques in TensorFlow/Keras and how they prevent overfitting.

Core

What a strong answer covers

  • Define overfitting as a model learning the training data too well, including noise, leading to poor generalization on unseen data.
  • Explain **L1/L2 Regularization**: adding a penalty to the loss function based on the magnitude of weights, encouraging smaller weights and simpler models. Mention `kernel_regularizer` in Keras layers.
  • Describe **Dropout**: randomly setting a fraction of neuron outputs to zero during training, forcing the network to learn more robust features and preventing over-reliance on specific neurons.
  • Discuss **Early Stopping**: monitoring validation loss during training and stopping when it starts to increase, preventing the model from training too long and overfitting.
  • Mention other techniques like Data Augmentation (increasing training data diversity) or Batch Normalization (stabilizing learning).

Where people lose the point

  • Confusing regularization with optimization techniques.
  • Not explaining *how* each technique helps prevent overfitting (e.g., dropout forcing redundancy).
  • Failing to mention how to implement these in Keras (e.g., `tf.keras.regularizers`, `tf.keras.layers.Dropout`, `tf.keras.callbacks.EarlyStopping`).
Link to this question

10.Explain the utility of Keras Callbacks during model training. Give examples of common callbacks.

Core

What a strong answer covers

  • Define Keras Callbacks as objects that can perform actions at various stages of training (e.g., start/end of epoch, start/end of batch).
  • Explain their utility: automating tasks, monitoring model state, modifying training behavior, and saving models without interrupting the training loop.
  • Provide examples: `ModelCheckpoint` (save best model), `EarlyStopping` (stop training when validation metric plateaus/worsens), `ReduceLROnPlateau` (reduce learning rate), `TensorBoard` (logging for visualization).
  • Mention how to use them by passing a list of callback instances to `model.fit()`.

Where people lose the point

  • Not understanding that callbacks are executed *during* the `fit()` method.
  • Failing to provide concrete, widely used examples of callbacks.
  • Confusing callbacks with custom training loops, which offer more granular control but require manual implementation.
Link to this question

11.How would you implement a custom loss function in Keras? Provide a simple example.

Core

What a strong answer covers

  • Explain that a custom loss function in Keras is a callable (function or class) that takes two arguments: `y_true` (ground truth labels) and `y_pred` (model predictions).
  • State that it should return a scalar tensor representing the loss value.
  • Provide a simple example, such as a custom Mean Absolute Error (MAE) or Huber loss, demonstrating the use of TensorFlow operations (e.g., `tf.abs`, `tf.reduce_mean`).
  • Mention that for more complex, stateful losses, one can subclass `tf.keras.losses.Loss` and implement `call()` and `get_config()`.

Where people lose the point

  • Returning a non-scalar tensor as the loss value.
  • Not using TensorFlow operations within the loss function, which would break graph compilation.
  • Forgetting that the loss function operates on batches of data, so `tf.reduce_mean` or similar aggregation is often needed.
Link to this question

12.When would you use `tf.keras.Model` subclassing instead of the Functional API for building a model?

Hard

What a strong answer covers

  • Explain that `tf.keras.Model` subclassing offers the highest level of flexibility and control, allowing for dynamic architectures and custom forward passes.
  • Identify use cases: models with dynamic graphs (e.g., recurrent networks with variable unrolling, models with conditional logic), models that require custom training logic not easily expressed by `model.fit()`, or highly experimental architectures.
  • Contrast with Functional API: Functional API is declarative and builds a static graph, which is great for most complex models but less flexible for truly dynamic behavior.
  • Mention that subclassing requires more boilerplate code (`__init__`, `call`) and can be harder to debug or serialize without `get_config()`.

Where people lose the point

  • Suggesting subclassing is always superior or necessary for any complex model, rather than for specific dynamic needs.
  • Not acknowledging the benefits of the Functional API (easier debugging, serialization, static graph optimizations).
  • Failing to mention the increased complexity and boilerplate associated with subclassing.
Link to this question

13.Briefly describe one approach to distributed training in TensorFlow.

Hard

What a strong answer covers

  • Introduce `tf.distribute.Strategy` as TensorFlow's API for distributed training.
  • Describe **`MirroredStrategy`** as a common approach for synchronous data parallelism on a single machine with multiple GPUs.
  • Explain its mechanism: each GPU gets a copy of the model, processes a slice of the batch, computes gradients, and then gradients are aggregated (e.g., summed) and averaged across all devices before updating the model's weights synchronously.
  • Mention benefits: easy to use (often just wrapping model creation and `compile`/`fit` calls), scales well for single-host multi-GPU setups, and maintains model convergence properties.

Where people lose the point

  • Confusing data parallelism with model parallelism.
  • Not mentioning the synchronous nature of `MirroredStrategy`'s gradient updates.
  • Failing to specify that it's primarily for single-host, multi-GPU setups.
Link to this question

14.What are `tf.feature_columns` and when would you use them in TensorFlow?

Core

What a strong answer covers

  • Define `tf.feature_columns` as a way to represent and transform various types of raw input data (e.g., categorical, numerical, text) into a format suitable for TensorFlow models.
  • Explain their purpose: bridging the gap between raw data and model input, handling common preprocessing tasks like one-hot encoding, embedding, and bucketing.
  • Provide examples: `numeric_column`, `categorical_column_with_vocabulary_list`, `indicator_column`, `embedding_column`, `bucketized_column`.
  • Discuss use cases: primarily with `tf.keras.layers.DenseFeatures` or `tf.estimator` API for structured data, simplifying feature engineering and ensuring consistent data transformations.

Where people lose the point

  • Confusing `feature_columns` with general data preprocessing libraries like Pandas or Scikit-learn, rather than TensorFlow-specific input transformations.
  • Not mentioning their primary use with structured data and `DenseFeatures` layer.
  • Failing to explain how they convert raw data into numerical representations for model input.
Link to this question

15.Explain the role of activation functions in neural networks and name two common ones, describing their characteristics.

Warm-up

What a strong answer covers

  • Define activation functions as non-linear transformations applied to the output of a neuron, introducing non-linearity into the network.
  • Explain their role: enabling neural networks to learn complex patterns and approximate non-linear functions, which would be impossible with only linear transformations.
  • Describe **ReLU (Rectified Linear Unit)**: `f(x) = max(0, x)`. Characteristics: computationally efficient, mitigates vanishing gradient problem, but can suffer from 'dying ReLU' problem.
  • Describe **Sigmoid**: `f(x) = 1 / (1 + e^-x)`. Characteristics: squashes output to (0, 1), useful for binary classification output layers, but suffers from vanishing gradients for extreme inputs.
  • Mention **Softmax**: often used in the output layer for multi-class classification, converting raw scores into probabilities that sum to 1.

Where people lose the point

  • Not emphasizing the non-linear aspect of activation functions.
  • Confusing activation functions with loss functions or optimizers.
  • Incorrectly describing the mathematical properties or common issues (e.g., vanishing gradients) of specific activation functions.
Link to this question
No account needed

Answer one real TensorFlow question now

A question a TensorFlow panel actually asks, answered out loud, scored on what you said and how you said it. Under two minutes, and nothing to sign up for.

What is a Tensor in TensorFlow, and what are its key attributes?

We never store the audio. Your answer is deleted within 24 hours unless you save the result.

How TensorFlow answers get judged

The weights a TensorFlow interviewer is holding, whether or not they say so out loud. Round Zero scores your practice answers against exactly these, and quotes your own words back as the evidence for each.

Technical Correctness

30%

The accuracy of the TensorFlow concepts, API usage, and code examples provided. Answers should be factually sound and demonstrate a solid understanding of how TensorFlow works.

Conceptual Depth

25%

The level of understanding demonstrated beyond surface-level definitions. This includes explaining 'why' certain approaches are taken, underlying mechanisms, and implications of design choices.

Problem-Solving Approach

20%

Ability to apply TensorFlow knowledge to solve hypothetical problems, design appropriate model architectures, or debug common issues. This includes demonstrating practical application of concepts.

Code Quality & Best Practices

15%

When applicable, the clarity, efficiency, and adherence to TensorFlow/Keras best practices in code snippets or architectural descriptions. This includes using idiomatic TensorFlow.

Clarity & Communication

10%

The ability to articulate complex TensorFlow concepts clearly, concisely, and logically. This includes structuring explanations effectively and using appropriate technical terminology.

Related Data Engineering & ML skills

All skills →

Now say them out loud

You have read what strong TensorFlow answers contain. The next thing that moves the needle is producing one under time, out loud, and finding out where it falls apart.

  • These questions asked back, with follow-ups
  • Flashcards for the ones you keep missing
  • A scored mock that quotes your own answers

Browse every skill

Practising TensorFlow: common questions

What TensorFlow interview questions should I practice?
Start with the core areas TensorFlow interviewers probe: What is a Tensor in TensorFlow, and what are its key attributes; Explain the difference between eager execution and graph execution in TensorFlow 2.x. When might you still use graph execution; Compare and contrast the Keras Sequential API and Functional API. Provide a use case for each.. This page outlines strong answers and common mistakes, and the scored path drills each one with follow-ups.
Is the TensorFlow practice free?
Yes. The TensorFlow path runs free inside Round Zero: lessons, practice questions and flashcards. Drills are unlimited on every plan, free included. So is the full scorecard. Free also covers 3 complete scored interviews, no card.
How is this different from a TensorFlow question list?
A static list gives you questions with no feedback. Round Zero runs a live scored practice that probes your actual answers, rotates difficulty, and tells you exactly what to fix, grounded in a TensorFlow rubric.
How should I prepare for a TensorFlow interview?
Learn the concepts, drill the questions until answers come fast, then prove it in a scored mock. Round Zero sequences all three so you know you are ready, not just that you read about TensorFlow.
How is a TensorFlow answer scored?
TensorFlow answers are scored on technical correctness, conceptual depth, problem-solving approach, code quality & best practices, clarity & communication, with evidence quoted from what you actually said, so feedback is specific instead of generic praise.