TensorFlow Interview Questions
A list of top frequently asked TensorFlow Interview Questions and Answers are given below.
1) What is TensorFlow?
TensorFlow is a Python -based library which is used for creating machine learning applications. It is a low-level toolkit to perform complex mathematics. It offers users the customizability option to build experimental learning architectures. It also helps the users to work with them, and to turn them into running software. It was initially created by researchers and engineers working on the Google Brain Team , and It became open source in 2015.
TensorFlow is made up of two words Tensor and Flow ; a tensor is known as data representation for multi-dimensional array and flow means a series of operations performed on tensors.
2) What do you know about Tensors?
The Tensor is a generalization of vectors or matrices of the n-dimensional array which is used in computer programming. It represents a multitude of data in the form of numbers. There are few other n-dimensional array libraries which are available on the internet such as Numpy , but TensorFlow stands apart from those libraries. It provides methods to create tensor functions and automatically compute derivatives.
A graph can conduct all operations in the Tensor. We can say that the edge of the node is known as Tensor. We need a feature vector as the initial input to implement a Tensor. The models are fed with the list of objects in the machine learning, and these objects are called feature vectors .
We can understand the Tensors with the help of the diagram given below:
Here, the arrow represents multi-dimensions. There is a Tensor which is known as stress , and it describes things happening in two directions.
3) How many types of Tensors are there?
There are three types of Tensors used to create neural network models:
- Constant Tensor
Constant Tensors are used as constants, as the name suggests. They create a node that takes a value and does not change it. A constant can be created using tf.constant.
tf.constant (value, dtype=None, shape=None, name=‘Const’, verify_shape=False)
It accepts the five arguments. - Variable Tensor
Variable Tensors are the nodes which provide their current value as output. It means that they can retain their value over multiple executions of a graph. - Place Holder Tensor
Placeholders Tensors are essential than variables. These are used to assign data in a later time. Placeholders are the nodes whose value is fed at the time of execution. Assume, we have inputs to our network which are dependent on some external data. Also, we do not want our graph to depend on any real value while developing the graph, then Placeholders are useful datatype. We can even build a graph without any data.
Therefore, placeholders do not require any initial value. They only need a datatype (such as float32) and a tensor shape, so the graph still knows what to compute with even though it does not have any stored values.
4) Explain TensorBoard?
TensorBoard is a suite of visualizing tools for inspecting and understanding TensorFlow runs and graphs. It is an easy solution to Tensorflow offered by the creators that let us visualize the graphs. It plots quantitative metrics about the graph with additional data like images to pass through it.TensorBoard currently supports five visualizations techniques such as scalars , images , audio , histograms , and graphs . It improves the accuracy and flow of graphs.
5) What is the main feature of TensorFlow?
Tensorflow has APIs support for a wide variety of languages such as Matlab and C++ . Researchers are continuously trying to making it better. A javascript library, tensorflow.js , has also been introduced for training and deploying machine learning models.
6) What are the advantages of TensorFlow?
Some of the main advantages of TensorFlow are given below:
- It can be easily trained on CPU as well as GPU for distributed computing.
- It has auto differentiation capabilities.
- It has platform flexibility.
- It is easily customizable and open-source.
- It has advanced support for threads, asynchronous computations, and queues.
7) List a few limitations of Tensorflow.
TensorFlow has some limitations, as mentioned here:
- It does not provide support for OpenCL (Open Computing Language).
- It requires prior knowledge of advanced calculus and linear algebra along with a pretty good understanding of Machine learning.
- It has GPU memory conflicts with Theano if imported in the same scope.
8) Which client languages are supported in TensorFlow?
TensorFlow provides support for multiple client languages, one of the best among them is Python . There are some experimental interfaces which are available for C++, Java, and Go. A language bindings for many other languages such as C# , Julia , Ruby , and Scala are created and supported by the open-source community.
9) What are the three working components of TensorFlow Architecture?
TensorFlow architecture works in three parts:
- Preprocessing the data
- Building the model
- Training and estimating the model
10) Explain few options to load data into TensorFlow.
Loading the data into TensorFlow is the first step before training a machine learning algorithm. There are two ways to load the data:
- Load data in memory
It is the easiest method. All the data is loaded into memory as a single array. One can write a Python code which is unrelated to TensorFlow. - Tensorflow data pipeline
TensorFlow has built-in APIs which help to load the data, perform the operations, and feed the machine learning algorithm easily. This method is mostly used when there is a large dataset.
11) Describe the common steps to most TensorFlow algorithms?
- Import data, generate data, or setting a data-pipeline through placeholders.
- Feed the data through the computational graph.
- Evaluate output on the loss function.
- Use backpropagation to modify the variables.
- Repeat until stopping condition.
12) Mention the name of some methods to deal with the overfitting in TensorFlow.
- Dropout Technique
- Regularization
- Batch Normalization
13) What do you know about TensorFlow Managers?
The TensorFlow managers are responsible for loading, unloading, lookup, and lifetime management of all servable objects via their loaders. TensorFlow Managers control the full lifecycle of Servables, including:
- Loading Servables
- Serving Servables
- Unloading Servables
It is an abstract class. Its syntax is:
- #include <manager.h>
14) What are TensorFlow servables? Also, explain TensorFlow Serving.
The clients use some objects to perform the computations, and these objects are known as Servables. The size of the servable is flexible. A single servable might contain anything from a lookup table to a single model to a tuple of inference models. These servables are the central rudimentary units in TensorFlow Serving.
TensorFlow Serving is designed for production environments. It is a flexible, high-performance serving system used for machine learning models. TensorFlow Serving easily deploys new algorithms and experiments while keeping the same server architecture and APIs. TensorFlow Serving provides out-of-the-box integration with TensorFlow models. It can also be easily extended to serve other types of models and data whenever required.
15) What are the use cases of TensorFlow?
Tensorflow is an essential tool for deep learning. It has mainly five use cases, they are:
- Text-Based Applications
- Voice/Sound Recognition
- Time Series
- Image Recognition
- Video Detection
16) Where can you run a TensorFlow?
TensorFlow can run on different platforms:
- Operating System such as Windows, OS, and Linux
- Cloud Web Service
- Mobile OS like IOS and Android
17) When will you find overfit condition of a model in TensorFlow?
There are variations in the training data, and this data needs to be verified through TensorFlow. Overfitting can be probably seen if the variations are huge in the data. The best possible solution is to remove the noise from the available data upto the possible extent.
18) What are the loaders of TensorFlow?
The loader can be implemented to load, unload, and access a new type of servable machine learning model. These loaders are used for adding algorithms and data on the backend. The function load() is used to load the model from the saved model.
19) List some products that are built using TensorFlow.
There are a few products built using TensorFlow:
- Nsynth
- Giorgio Cam
- Hand Writing Recognition
- Teachable Machine
20) What are the sources in TensorFlow?
Sources are that type of modules which identify and provide servables. Each source provides zero or many servable streams. A single loader is supplied for each servable version makes it accessible so that it can be loaded.
21) What are the benefits of TensorFlow over other libraries? Explain.
There are many benefits of TensorFlow over other libraries which are given below:
- Scalability
TensorFlow provides easily scaled machine learning applications and infrastructure. - Visualization of Data
Visualizing the graph is very straight-forward in TensorFlow. TensorBoard (a suite of visualization tools) is used to visualize TensorFlow graphs. - Debugging Facility
tfdbg is a specialized debugger for TensorFlow. It lets us view the internal structure and states of running TensorFlow graphs during training and inference. - Pipelining
TensorFlow’s Dataset module tf.data is used to build efficient pipelines for images and text.
22) What do you understand by Deep Speech?
DeepSpeech is an open-source engine used to convert Speech into Text. It uses a model which is trained by machine learning techniques. It is based on Baidu’s Deep Speech research paper. It uses Google’s TensorFlow to make the implementation easier.
We can list the command line options through deep Speech, and the syntax for that is given below:
- ./deepspeech.py
23) What do you know about TensorFlow abstractions?
TensorFlow contains abstraction libraries such as TF-Slim and kereas , which provides simplified high-level access to TensorFlow. Such abstractions help to streamline the construction of data flow graphs.
TensorFlow abstractions not only help to make the code cleaner but also reduce the length of codes drastically. As a result, it significantly reduces development time.
24) How does TensorFlow use Python API?
Python is the primary language when it comes to TensorFlow and its development. It is the first and most recognizable language supported by TensorFlow and still supporting most of the features. It seems like the functionality of TensorFlow was initially defined in Python and later moved to C++.
25) What are the APIs used inside the TensorFlow project?
Most of the APIs inside TensorFlow are based on Python language. They have low-level options for the users such as tf.manual or tf.nn.relu used to build Neural Network Architecture. These APIs are also used to design a deep neural network having higher levels of abstraction.
26) What are the APIs used outside the TensorFlow project?
There are a few APIs used outside the TensorFlow project, which are:
- TFLearn
TFLearn provides a high-level API which makes neural network building and training fast and easy. This API is fully compatible with Tensorflow. Its API can be indicated as tf.contrib.learn . - TensorLayer
TensorLayer is a TensorFlow-based deep learning and reinforcement learning library. It is designed for researchers and engineers. It provides an extensive collection of customizable neural layers/functions which are crucial for building real-world AI applications. - PrettyTensor
Pretty Tensor delivers high-level builder API for TensorFlow. It offers thin wrappers on Tensors so that you can easily build multi-layer neural networks.
Pretty Tensor provides a set of objects that behave likes Tensors. It also supports a chainable object syntax to define neural networks and other layered architectures in TensorFlow quickly. - Sonnet
Sonnet is a library which is built on top of TensorFlow for creating complex neural networks. It is a part of Google’s DeepMind project, which features a modular approach.
27) How do we create tensors from Python objects?
We can create tensors such as numpy arrays and lists with the help of Python objects. We can easily perform it using tf.convert_to_tensor() operation.
28) What are the variables in TensorFlow?
Variables in TensorFlow are also known as tensor objects. These objects hold the values which can be modified during the execution of the program.
A TensorFlow variable is the best way which is used to represent a shared, persistent state manipulated by the program.
29) What is the lifetime of a variable?
A variable is created when we first run the tf.Variable.initializer operation for that variable in a session. It gets destroyed when tf.Session.close is processed.
30) Differentiate between tf.variable and tf.placeholder.
The tf.variable and tf.placeholder both are almost similar to each other, but there are some differences as following:
tf.variable | tf.placeholder |
---|---|
* It defines variable values which are modified with time. | * It defines specific input data that does not change with time. |
* It requires an initial value at the time of definition. | * It does not require an initial value at the time of definition. |
31) What is Scalar Dashboard?
Scaler Dashboard visualizes scaler statistics that vary over time. It uses a simple API for performing such visualizations. For example, We might want to examine the model’s loss or learning rate.
We can compare multiple runs, and the data is established by tag.
32) What is a Histogram Dashboard?
The Histogram Dashboard is used to display how the statistical distribution of a Tensor varies overtime. It helps to visualize the data recorded via tf.summary.histogram . Each chart displays the temporal “slices” of data, where each slice is a histogram of the tensor at a given step. It is arranged with the oldest timestep in the back, and the most recent timestep in front.
If a Histogram mode is changed from “offset” to “overlay”, the perspective will rotate. As a result, every histogram slice is rendered as a line and overlaid with one another.
33) What do you know about Distribution Dashboard in TensorFlow?
The Distribution Dashboard is another way that is used to visualize histogram data from t f.summary.histogram . It displays some high-level statistics on a distribution. Each line on the chart is used to represent a percentile in the distribution over the data. For example, the bottom line displays how the minimum value changes over time and the line in the middle displays how the median changes. Reading it from top to bottom, the lines provide the following meaning: [maximum, 93%, 84%, 69%, 50%, 31%, 16%, 7%, minimum].
34) What is Image Dashboard in TensorBoard?
The Image Dashboard is used to display png files that were saved via a tf.summary.image . The dashboard is configured in such a way so that each row corresponds to a different tag, and each column corresponds to a run. The image dashboard also supports arbitrary pngs which can be used to embed custom visualizations (e.g.,matplotlib scatterplots) into TensorBoard. This dashboard always shows the latest image for each tag.
35) What do you know about Audio Dashboard?
The Audio Dashboard is used to embed playable audio widgets for audio stored via a tf.summary.audio . The dashboard is configured so that each row corresponds to a different tag, and each column corresponds to a run. The Audio dashboard always embeds the latest audio for each tag.
36) Describe Graph Explorer in TensorFlow?
The Graph Explorer can be used while visualizing a TensorBoard graph. It is also responsible for enabling inspection of the TensorFlow model. To get the best use of the graph visualizer, one should use name scopes to group the ops in a graph hierarchically. Otherwise, the graph may be challenging to decipher.
37) What is Embedding Projector?
The Embedding Projector allows visualizing high-dimensional data. For example, one can view input data after it has been embedded in a high- dimensional space by model. The embedding projector reads data from the model checkpoint file. It may be configured with additional metadata, like a vocabulary file or sprite images .
38) What do you understand by Text Dashboard?
The Text Dashboard is used to display text snippets stored via tf.summary.text . Other features, such as hyperlinks , lists , and tables , are also supported.
39) Can I run TensorBoard without TensorFlow?
If you do not have TensorFlow installed then, TensorBoard 1.14+ can be run but with a reduced feature set. The primary limitation is that as of TensorFlow 1.14, only the following plugins are supported: scalars, custom scalars, image, audio, graph, projector (partial), distributions, histograms, text, PR curves, mesh . Also, there is no support for log directories on Google Cloud Storage.
40) What are the different dashboards in TensorFlow?
There are different types of dashboards in TensorBoard which perform various tasks in the tensor board:
- Scalar Dashboard
- Histogram Dashboard
- Distributer Dashboard
- Image Dashboard
- Audio Dashboard
- Graph Explorer
- Projector
- Text Dashboard
41) What is the main operation in TensorFlow?
The main operation in TensorFlow is defined as passing values and assigning the output to another tensor.
42) What is more important to you between the performance and accuracy of a model, in machine learning based on TensorFlow?
It usually depends on the complete performance. Both performance and accuracy, weigh equal, although accuracy is prominent in most of the models.
43) Can TensorFlow be deployed in container software?
TensorFlow can be used with containerization tools such as Docker. It can be helpful to deploy a sentiment analysis model which uses character level ConvNet networks for text classification.
44) How can someone report a vulnerability in TensorFlow?
A person can report about any security issue directly to security@tensorflow.org . The report to this email is delivered to the security team at TensorFlow. The emails are then acknowledged within 24 hours, and detailed response is provided within a week along with the next steps.
45) What are the components used for deploying a lite model file in TensorFlow?
- Java API
Java API is a wrapper around C++ API on Android. - C++ API
C++ API loads the TensorFlow Lite model and calls the interpreter. - Interpreter
The interpreter can be used to execute the model. It uses particular kernel loading, which is a unique feature of TensorFlow Lite.
46) What are the differences between TensorFlow and PyTorch?
TensorFlow | PyTorch |
---|---|
* The TensorFlow is based on Theano library. | * PyTorch is a software-based on the Torch library. |
* It is produced by Google. | * It is developed by Facebook. |
* TensorFlow does not have any option at run time. | * PyTorch includes computational graph at the runtime. |
* TensorFlow has TensorBoard for visualizing machine learning model. | * PyTorch doesn’t have any feature like visualization. |
47) Can word embedding be used in TensorFlow? Name two models used in word embedding?
Word embedding is used in Natural Language Processing as a representation of words, and they can be used in TensorFlow where it is also known as Word2vec.
The two models used in word embedding are - The continuous bag of words model and the skip-gram model.
48) What do you understand by TensorFlow Estimators?
Estimators is a high-level API which reduces much of the code you previously needed to write while training a TensorFlow model. Estimators are very flexible, and it allows to override the default behavior if there is any specific requirement for the model.
There are two possible ways of building a model using Estimators:
- Pre-made Estimator
These are predefined estimators. These are created to generate a specific type of model, e.g., DNNClassifier, which is a pre-made estimator. - Estimator (base class)
It provides complete control of how a model should be created by using a model_fn function.
These functions are consumed by the class tf.estimator.Estimator . The functions return an initialized estimator, upon which we can call .train , .eval , and .predict .
A schematic of Estimator can be seen as:
49) What are some statistical distribution functions provided by TensorFlow?
A wide variety of statistical distributions is available which is provided by TensorFlow and located inside:
- tf.contrib.distributions
It contains distributions like Beta, Bernoulli, Chi2, Dirichlet, Gamma, Uniform, etc. These are important building blocks when it comes to building machine learning algorithms, especially for probabilistic approaches like Bayesian models.
50) What is the difference between Tensor.eval() and Session.run()?
In TensorFlow, we create graphs and provide values to that graph. The graph itself processes all the hardwork and generates the output based on the configuration that we have applied in the graph. Now, when we provide values to the graph, then first, we need to create a TensorFlow session.
- tf.Session()
Once the session is initialized, then we are supposed to use that session. It is necessary because all the variables and settings are now part of the session.
So, there are two possible ways that we can apply to pass external values to the graph so that the graph accepts them.
- The first one is to call the .run() while you are using the session and it is being executed.
- Another way to this is to use .eval() . The full syntax of .eval() is
tf.get_default_session().run(values)
At the place of values.eval() , we can put tf.get_default_session().run(values) and It will provide the same behavior. Here, eval is using the default session and then executing run().