DecodeAI
← Question Bank

Deep Learning & Generative AI

Neural Networks

Interview questions on Neural Networks.

55 questions

Perceptron

Q1. Neural network in simple Numpy.

Sign in to bookmark
  1. Write in plain NumPy the forward and backward pass for a two-layer feed-forward neural network with a ReLU layer in between.
  2. Implement vanilla dropout for the forward and backward pass in NumPy.

Perceptron

Q2. In a single-layer feed-forward NN, there are [...] input(s) and [...]. output layer(s) and no [...] connections at all.

Sign in to bookmark

Perceptron

Q3. In its simplest form, a perceptron (8.16) accepts only a binary input and emits a binary output. The output, can be evaluated as follows:

Sign in to bookmark

output={0,if j(wjxj+b)0,1,if j(wjxj+b)>0output = \begin{cases} 0, & \text{if } \sum_j(w_jx_j + b) \leq 0, \\ 1, & \text{if } \sum_j(w_jx_j + b) > 0 \end{cases} Where weights are denoted by wj and biases are denoted by b. Answer the following questions:

  1. True or False: If such a perceptron is trained using a labelled corpus, for each participating neuron the values wjw_j and bb are learned automatically.
  2. True or False: If we instead use a new perceptron (sigmoidal) defined as follows: σ(wx+b)\sigma(wx + b) where σ\sigma is the sigmoid function σ(z)=11+ez\sigma(z) = \frac{1}{1+e^{-z}} Then the new perceptron can process inputs ranging between 0 and 1 and emit output ranging between 0 and 1.

Perceptron

Q4. Write the cost function associated with the sigmoidial neuron.

Sign in to bookmark

Perceptron

Q5. Complete the sentence: To solve this mathematical equation, we have to apply $[...]$?

Sign in to bookmark

Perceptron

Q6. What does the following equation stands for?

Sign in to bookmark

C=1nxCx\nabla{C} = \frac{1}{n}\sum_x\nabla{C_x} Where: Cx=12y(x)a(x,w,b)2C_x = \frac{1}{2}\|y(x) - a(x,w,b)\|^2

Perceptron

Q7. Complete the sentence: Due to the time-consuming nature of computing gradients for each entry in the training corpus, modern DL libraries utilize a technique that gauges the gradient by first randomly sampling a subset from the training corpus, and then averaging only this subset in every epoch. This approach is known as $[...]$. The actual number of randomly chosen samples in each epoch is termed $[...]$. The gradient itself is obtained by an algorithm known as $[...]$.

Sign in to bookmark

Perceptron

Q8. The following questions refer to the MLP depicted in (9.1).The inputs to the MLP are $x1 = 0.9$ and $x2 = 0.7$ respectively, and the weights $w1 = −0.3$ and $w2 = 0.15$ respectively. There is a single hidden node, $H1$. The bias term,$ B1 $equals$0.001$.

Sign in to bookmark

Perceptron

Q9. The following questions refer to the MLP depicted in (8.15).

Sign in to bookmark
  1. Further to the above, the ReLU non-linear activation function g(z)=max0,zg(z) = max{0, z} is applied (8.15) to the output of the linear transformation. What is the value of the output (out2) now?

Perceptron

Q10. Activation functions.

Sign in to bookmark
  1. Draw the graphs for sigmoid, tanh, ReLU, and leaky ReLU.
  2. Pros and cons of each activation function.
  3. Is ReLU differentiable? What to do when it’s not differentiable?
  4. Derive derivatives for sigmoid function when is a vector.

Perceptron

Q11. Why shouldn’t we have two consecutive linear layers in a neural network?

Sign in to bookmark

Perceptron

Q12. Can a neural network with only RELU (non-linearity) act as a linear classifier?

Sign in to bookmark

Perceptron

Q13. Your co-worker, an postgraduate student at M.I.T, suggests using the following activa-

Sign in to bookmark

tion functions in a MLP. Which ones can never be back-propagated and why?

  1. f(x)=xf(x) = |x|2.f(x)=f(x) f(x) = f(x)3.f(x)={0,if x=0,xsin(1x),if x0. f(x)= \begin{cases} 0, & \text{if } x = 0, \\ x \sin\left(\frac{1}{x}\right), & \text{if } x \neq 0. \end{cases}4.f(x)={0if x=0xif x<0x2if x>0 f(x)= \begin{cases} 0 & \text{if } x = 0 \\ -x & \text{if } x < 0 \\ x^2 & \text{if } x > 0 \end{cases}

Perceptron

Q14. You are provided with the following MLP as depicted in 8.16.

Sign in to bookmark

Perceptron

Q15. If someone is quoted saying: MLP networks are universal function approximators. What does he mean?

Sign in to bookmark

Perceptron

Q16. **True or False**: the output of a perceptron is 0 or 1.

Sign in to bookmark

Perceptron

Q17. **True or False:** A multi-layer perceptron falls under the category of supervised machine learning.

Sign in to bookmark

Perceptron

Q18. **True or False:** The accuracy of a perceptron is calculated as the number of correctly

Sign in to bookmark

classified samples divided by the total number of incorrectly classified samples.

Perceptron

Q19. The following questions refer to the SLP depicted in (8.18). The weights in the SLP are $w1 = 1$ and $w2 = 1$ respectively. There is a single hidden node, H1. The bias term, B1 equals $−2.5$.

Sign in to bookmark

Perceptron

Q20. Repeat the above assuming now that the bias term B1 was amended and equals −0.25.

Sign in to bookmark

Perceptron

Q22. What was the most crucial difference between Rosenblatt’s original algorithm and Hinton’s fundamental papers of 1986: <a href="">Learning representations by back-propagating errors</a> and 2012:

Sign in to bookmark

ImageNet Classification with Deep Convolutional Neural Networks”

Perceptron

Q23. The AND logic gate is defined by the following table:

Sign in to bookmark

Perceptron

Q24. Design the smallest neural network that can function as an XOR gate.

Sign in to bookmark

Perceptron

Q25. The Sigmoid s(x) = 1 , also commonly known as the logistic function (Fig. 8.20), $s_c(x) = \frac{1}{1+e^-cx}$ is widely used in binary classification and as a neuron activation function in artificial neural networks. Typically, during the training of an ANN, a Sigmoid layer applies the Sigmoid function to elements in the forward pass, while in the backward pass the chain rule is being utilized as part of the backpropagation algorithm. In 8.20 the constant c was selected arbitrarily as 2 and 5 respectively.

Sign in to bookmark

Perceptron

Q26. The Hyperbolic tangent nonlinearity, or the tanh function (Fig. 8.23), is a widely used neuron activation function in artificial neural networks:

Sign in to bookmark

ftanh(x)=sinh(x)cosh(x)=exexex+exf_{tanh}(x) = \frac{sinh(x)}{cosh(x)} = \frac{e^x - e^-x}{e^x + e^-x}

Perceptron

Q27. The code snippet in 8.24 makes use of the tanh function.

Sign in to bookmark
  import torch
  nn001 = nn.Sequential(
  nn.Linear(200, 512),
  nn.Tanh(),
  nn.Linear(512, 512),
  nn.Tanh(),
  nn.Linear(512, 10),
  nn.LogSoftmax(dim=1)
  )
  1. What type of a neural network does nn001 in 8.24 represent?
  2. How many hidden layers does the layer entitles nn001 have?

Perceptron

Q28. Your friend, a veteran of the DL community claims that MLPs based on tanh activation function, have a symmetry around 0 and consequently cannot be saturated. Saturation, so he claims is a phenomenon typical of the top hidden layers in sigmoid based MLPs. Is he right or wrong?

Sign in to bookmark

Perceptron

Q29. If we initialize the weights of a tanh based NN, which of the following approaches will lead to the vanishing gradients problem?

Sign in to bookmark
  1. Using the normal distribution, with parameter initialization method as suggested by Kaiming [14].
  2. Using the uniform distribution, with parameter initialization method as suggested by Xavier Glorot [9].
  3. Initialize all parameters to a constant zero value.

Perceptron

Q30. You friend, who is experimenting with the tanh activation function designed a small CNN with only one hidden layer and a linear output (8.25):

Sign in to bookmark

Perceptron

Q31. The rectified linear unit, or ReLU $g(z) = max{0, z}$ is the default for many CNN architectures. It is defined by the following function:

Sign in to bookmark

fReLU=max(0,x)f_{ReLU} = max(0, x)

  1. In what sense is the ReLU better than traditional sigmoidal activation functions?

Perceptron

Q32. You are experimenting with the ReLU activation function, and you design a small CNN (8.26) which accepts an RGB image as an input. Each CNN kernel is denoted by $w$.

Sign in to bookmark

Perceptron

Q33. Name the following activation function where $a ∈ (0, 1)$:

Sign in to bookmark

f(x)={xif x>0axotherwisef(x) = \begin{cases} x & \text{if } x > 0 \\ ax & \text{otherwise} \end{cases}

Perceptron

Q34. In many interviews, you will be given a paper that you have never encountered before, and be required to read and subsequently discuss it. Please read <a href="https://arxiv.org/pdf/1710.05941.pdf">Searching for Activation Functions</a> before attempting the questions in this question.

Sign in to bookmark
  1. In, researchers employed an automatic pipeline for searching what exactly?
  2. What types of functions did the researchers include in their search space?
  3. What were the main findings of their research and why were the results surprising? 4. Write the formulae for the Swish activation function.
  4. Plot the Swish activation function.

Perceptron

Q35. Given an input of size of $n×n $, filters of size$ f×f $and a stride of$ s $with padding of$ p$, what is the output dimension?

Sign in to bookmark

Perceptron

Q36. Referring the code snippet in Fig. (8.31), answer the following questions regarding the VGG11 architecture [25]:

Sign in to bookmark
  import torchvision
  import torch
  def main():
  vgg11 = torchvision.models.vgg11(pretrained=True)
  vgg_layers = vgg11.features
  for param in vgg_layers.parameters():
  param.requires_grad = False
  example = [torch.rand(1, 3, 224, 224),
  torch.rand(1, 3, 512, 512),
  torch.rand(1, 3, 704, 1024)]
  vgg11.eval()
  for e in example:
    out=vgg_layers(e)
    print(out.shape)
  if __name__ == "__main__":
    main()^^I^^I
  1. In each case for the input variable example , determine the dimensions of the tensor which is the output of applying the VGG11 CNN to the respective input.
  2. Choose the correct option. The last layer of the VGG11 architecture is:
    1. Conv2d
    2. MaxPool2d
    3. ReLU

Perceptron

Q37. Still referring the code snippet in Fig. (8.31), and specifically to line 7, the code is amended so that the line is replaced by the line: `vgg_layers=vgg11.features[:3]`.

Sign in to bookmark
  1. What type of block is now represented by the new line? Print it using PyTorch. 2. In each case for the input variable example , determine the dimensions of the tensor which is the output of applying the block: vgg_layers=vgg11.features[:3] to the respective input.

Perceptron

Q38. Table (8.1) presents an incomplete listing of the of the VGG11 architecture [25]. As depicted, for each layer the number of filters (i. e., neurons with unique set of parameters) are presented.

Sign in to bookmark

Perceptron

Q39. A Dropout layer [26] (Fig. 8.32) is commonly used to regularize a neural network model by randomly equating several outputs (the crossed-out hidden node H) to 0.

Sign in to bookmark

Perceptron

Q40. A co-worker claims he discovered an equivalence theorem where, two consecutive Dropout layers [26] can be replaced and represented by a single Dropout layer 8.34.

Sign in to bookmark

Perceptron

Q41. If he uses the following filter for the convolutional operation, what would be the resulting

Sign in to bookmark

tensor after the application of the convolutional layer?

Perceptron

Q42. What would be the resulting tensor after the application of the ReLU layer (8.37)?

Sign in to bookmark

Perceptron

Q43. What would be the resulting tensor after the application of the MaxPool layer (8.78)?

Sign in to bookmark

Perceptron

Q44. The following input 8.38 is subjected to a MaxPool2D(2,2) operation having 2 × 2 max-pooling filter with a stride of 2 and no padding at all.

Sign in to bookmark

Perceptron

Q45. While reading a paper about the MaxPool operation, you encounter the following code snippet $9.1$ of a PyTorch module that the authors implemented. You download their pre- trained model, and evaluate its behaviour during inference:

Sign in to bookmark
import torch
from torch import nn
class MaxPool001(nn.Module):
    def __init__(self): 
        super(MaxPool001, self).__init__() 
        self.math = torch.nn.Sequential(
        torch.nn.Conv2d(3, 32, kernel_size=7, padding=2),
        torch.nn.BatchNorm2d(32),
        torch.nn.MaxPool2d(2, 2),
        torch.nn.MaxPool2d(2, 2),
        )
def forward(self, x):
     print (x.data.shape)
    x = self.math(x)
    print (x.data.shape)
    x = x.view(x.size(0), -1)
    print ("Final shape:{}",x.data.shape)
    return x
model = MaxPool001()
model.eval()
x = torch.rand(1, 3, 224, 224)
out=model.forward(x)

The architecture is presented in 9.2:

Perceptron

Q46. Weight normalization separates a weight vector’s norm from its gradient. How would it help with training?

Sign in to bookmark

Perceptron

Q47. In python, the probability density function for a normal distribution is given by 8.40:

Sign in to bookmark
import scipy
scipy.stats.norm.pdf(x, mu, sigma)
1. Without using Scipy, implement the normal distribution from scratch in Python.
2. Assume, you want to back propagate on the normal distribution, and therefore you need the derivative. Using Scipy write a function for the derivative.

Perceptron

Q48. Your friend, a novice data scientist, uses an RGB image (8.41) which he then subjects to BN as part of training a CNN.

Sign in to bookmark

Perceptron

Q49. **True or false**: An activation function applied after a Dropout, is equivalent to an activation function applied before a dropout.

Sign in to bookmark

Perceptron

Q50. Which of the following core building blocks may be used to construct CNNs? Choose all the options that apply:

Sign in to bookmark
  1. Pooling layers
  2. Convolutional layers
  3. Normalization layers
  4. Non-linear activation function
  5. Linear activation function

Perceptron

Q51. You are designing a CNN which has a single BN layer. Which of the following core CNN designs are valid? Choose all the options that apply:

Sign in to bookmark
  1. CONV→act→BN→Dropout→...
  2. CONV→act→Dropout→BN→...
  3. CONV→BN→act→Dropout→...
  4. BN→CONV→act→Dropout→...
  5. CONV→Dropout→BN→act→...
  6. Dropout→CONV→BN→act→...

Perceptron

Q52. The following operator is known as the Hadamard product:

Sign in to bookmark

OUT=ABOUT = A⊙B Where: (AB)i,j:=(A)i,j(B)i,j(A⊙B)i,j :=(A)i,j(B)i,j A scientist, constructs a Dropout layer using the following algorithm:

  1. Assign a probability of p for zeroing the output of any neuron.
  2. Accept an input tensor T , having a shape S
  3. Generate a new tensor T ‘ ∈ {0, 1}^S
  4. Assign each element in T‘a randomly and independently sampled value from a Bernoulli distribution: TiB(1,p)T‘i ∼ B(1,p)
  5. Calculate the OUT tensor as follows:OUT=TTOUT = T‘⊙TYou are surprised to find out that his last step is to multiply the output of a dropout layer with: 11p\frac{1}{1-p} Explain what is the purpose of multiplying by the term 11p\frac{1}{1-p}

Perceptron

Q53. Visualized in (8.43) from a high-level view, is an MLP which implements a well-known idiom in DL.

Sign in to bookmark

Perceptron

Q54. Answer the following questions regarding residual networks.

Sign in to bookmark
  1. Mathematically, the residual block may be represented by: y=x+F(x)y = x + F(x) What is the function F?
  2. In one sentence, what was the main idea behind deep residual networks (ResNets) as introduced in the original paper?

Perceptron

Q55. Your friend was thinking about ResNet blocks, and tried to visualize them in (8.45).

Sign in to bookmark