DecodeAI
← Question Bank

Deep Learning & Generative AI

Neural Networks

Interview questions on Neural Networks.

40 questions

Training and Hyperparameters

Q1. A certain training pipeline for the classification of large images (1024 x 1024) uses the following Hyperparameters (8.46):

Sign in to bookmark

Initial learning rate 0.1 Weight decay 0.0001 Momentum 0.9 Batch size 1024

optimizer = optim.SGD(model.parameters(), lr=0.1, momentum=0.9,weight_decay=0.0001)
 ...
trainLoader = torch.utils.data.DataLoader(
    datasets.LARGE('../data', train=True, download=True, 7 transform=transforms.Compose([
    transforms.ToTensor(),
])),
batch_size=1024, shuffle=True)

In your opinion, what could possibly go wrong with this training pipeline?

Training and Hyperparameters

Q2. A junior data scientist in your team who is interested in Hyperparameter tuning, wrote the following code (8.5) for spiting his corpus into two distinct sets and fitting an LR model:

Sign in to bookmark
from sklearn.model_selection import train_test_split
dataset = datasets.load_iris()
X_train, X_test, y_train, y_test =
train_test_split(dataset.data, dataset.target, test_size=0.2) 
clf = LogisticRegression(data_norm=12)
clf.fit(X_train, y_train)

He then evaluated the performance of the trained model on the Xtest set.

  1. Explain why his methodology is far from perfect.
  2. Help him resolve the problem by utilizing a difference splitting methodology.
  3. Your friend now amends the code an uses:
clf = GridSearchCV(method, params, scoring='roc_auc', cv=5) clf.fit(train_X, train_y)

Explain why his new approach may work better?

Training and Hyperparameters

Q3. In the context of Hyperparameter optimization, explain the difference between grid search and random search.

Sign in to bookmark

Training and Hyperparameters

Q4. Non-invasive methods that forecast the existence of lung nodules (8.47), is a precursor to lung cancer. Yet, in spite of acquisition standardization attempts, the manual detection of lung nodules still remains predisposed to inter mechanical and observer variability. What is more, it is a highly laborious task.

Sign in to bookmark

Training and Hyperparameters

Q5. Answer the following questions regarding the validation curve visualized in (8.48):

Sign in to bookmark

Training and Hyperparameters

Q6. Learning rate.

Sign in to bookmark
  1. Draw a graph number of training epochs vs training error for when the learning rate is:
    1. too high
    2. too low
    3. acceptable.
  2. What’s learning rate warmup? Why do we need it?

Training and Hyperparameters

Q7. It’s a common practice for the learning rate to be reduced throughout the training.

Sign in to bookmark
  1. What’s the motivation?
    1. What might be the exceptions?

Training and Hyperparameters

Q8. Refer to the validation log-loss curve visualized in (8.49) and answer the following questions:

Sign in to bookmark

Training and Hyperparameters

Q9. Why don’t we just initialize all weights in a neural network to zero?

Sign in to bookmark

Training and Hyperparameters

Q10. You finished training a face recognition algorithm, which uses a feature vector of 128

Sign in to bookmark

elements. During inference, you notice that the performance is not that good. A friend tells you that in computer vision faces are gathered in various poses and perspectives. He there- fore suggests that during inference you would augment the incoming face five times, run inference on each augmented image and then fuse the output probability distributions by averaging.

  1. Name the method he is suggesting.
  2. Provide several examples of augmentation that you might use during inference.

Training and Hyperparameters

Q11. Complete the sentence: If the training loss is insignificant while the test loss is significantly higher, the network has almost certainly learned features which are not present in an `[...]` set. This phenomena is referred to as `[...]`

Sign in to bookmark

Training and Hyperparameters

Q12. What does the term stochastic in SGD actually mean? Does it use any random number generator?

Sign in to bookmark

Training and Hyperparameters

Q13. Stochasticity.

Sign in to bookmark
  1. What are some sources of randomness in a neural network?
  2. Sometimes stochasticity is desirable when training neural networks. Why is that?

Training and Hyperparameters

Q14. Gradient descent vs SGD vs mini-batch SGD.

Sign in to bookmark

Training and Hyperparameters

Q15. Write the vanilla gradient update.

Sign in to bookmark

Training and Hyperparameters

Q16. Explain why in SGD, the number of epochs required to surpass a certain loss threshold increases as the batch size decreases?

Sign in to bookmark

Training and Hyperparameters

Q17. It’s a common practice to train deep learning models using epochs: we sample batches from data without replacement. Why would we use epochs instead of just sampling data with replacement?

Sign in to bookmark

Training and Hyperparameters

Q18. Batch size.

Sign in to bookmark
  1. What happens to your model training when you decrease the batch size to 1?
  2. What happens when you use the entire training data in a batch?
  3. How should we adjust the learning rate as we increase or decrease the batch size?

Training and Hyperparameters

Q19. Vanishing and exploding gradients.

Sign in to bookmark
  1. How do we know that gradients are exploding? How do we prevent it?
  2. Why are RNNs especially susceptible to vanishing and exploding gradients?

Training and Hyperparameters

Q20. How does momentum work? Explain the role of exponential decay in the gradient descent update rule?

Sign in to bookmark

Training and Hyperparameters

Q21. Why is Adagrad sometimes favored in problems with sparse gradients?

Sign in to bookmark

Training and Hyperparameters

Q22. Adam vs. SGD.

Sign in to bookmark
  1. What can you say about the ability to converge and generalize of Adam vs. SGD?
  2. What else can you say about the difference between these two optimizers?

Training and Hyperparameters

Q23. With model parallelism, you might update your model weights using the gradients from each machine asynchronously or synchronously. What are the pros and cons of asynchronous SGD vs. synchronous SGD?

Sign in to bookmark

Training and Hyperparameters

Q24. In your training loop, you are using SGD and a logistic activation function which is

Sign in to bookmark

known to suffer from the phenomenon of saturated units.

  1. Explain the phenomenon.
  2. You switch to using the tanh activation instead of the logistic activation, in your opinion does the phenomenon still exists?
  3. In your opinion, is using the tanh function makes the SGD operation to converge better?

Training and Hyperparameters

Q25. Which of the following statements holds true?

Sign in to bookmark
  1. In stochastic gradient descent we first calculate the gradient and only then adjust weights for each data point in the training set.
  2. In stochastic gradient descent, the gradient for a single sample is not so different from the actual gradient, so this gives a more stable value, and converges faster.
  3. SGD usually avoids the trap of poor local minima.
  4. SGD usually requires more memory.

Training and Hyperparameters

Q26. Answer the following questions regarding norms.

Sign in to bookmark
  1. Which norm does the following equation represent? x1x2+y1y2|x1 − x2| + |y1 − y2|
  2. Which formulae does the following equation represent? i=1n(xiyi)2\sqrt{\sum_{i=1}^n(x_i - y_i)^2}
  3. When your read that someone penalized the L2 norm, was the euclidean or the Manhattan distance involved?
  4. Compute both the Euclidean and Manhattan distance of the vectors: x1x1 = [6,1,4,5] andx2 x2 = [2,8,3,−1].

Training and Hyperparameters

Q27. Why is squared L2 norm sometimes preferred to L2 norm for regularizing neural networks?

Sign in to bookmark

Training and Hyperparameters

Q28. You are provided with a pure Python code implementation of the Manhattan distance

Sign in to bookmark

function (8.51):

from scipy import spatial
x1=[6,1,4,5]
x2=[2,8,3,-1]
cityblock = spatial.distance.cityblock(x1, x2) 5 print("Manhattan:", cityblock)

In many cases, and for large vectors in particular, it is better to use a GPU for imple- menting numerical computations. PyTorch has full support for GPU’s (and its my favourite DL library ... ), use it to implement the Manhattan distance function on a GPU.

Training and Hyperparameters

Q29. Your friend is training a logistic regression model for a binary classification problem using the L2 loss for optimization. Explain to him why this is a bad choice and which loss he should be using instead.

Sign in to bookmark

Training and Hyperparameters

Q30. What’s the motivation for skip connection in neural works?

Sign in to bookmark

Training and Hyperparameters

Q31. When training a large neural network, say a language model with a billion parameters, you evaluate your model on a validation set at the end of every epoch. You realize that your validation loss is often lower than your train loss. What might be happening?

Sign in to bookmark

Training and Hyperparameters

Q32. Your model’ weights fluctuate a lot during training. How does that affect your model’s performance? What to do about it?

Sign in to bookmark

Training and Hyperparameters

Q33. Some models use weight decay: after each gradient update, the weights are multiplied by a factor slightly less than 1. What is this useful for?

Sign in to bookmark

Training and Hyperparameters

Q34. Dead neuron.

Sign in to bookmark
  1. What’s a dead neuron?
  2. How do we detect them in our neural network?
  3. How to prevent them?

Training and Hyperparameters

Q35. Pruning.

Sign in to bookmark
  1. Pruning is a popular technique where certain weights of a neural network are set to 0. Why is it desirable?
  2. How do you choose what to prune from a neural network?

Training and Hyperparameters

Q36. 1. What is batch normalization?

Sign in to bookmark
  1. The normal distribution is defined as follows: P(X)=1σ2πe(xμ)22σ2P(X) = \frac{1}{\sigma\sqrt{2\pi}}e^{\frac{-(x-\mu)^2}{2\sigma^2}} Generally i.i.d. XN(μ,σ2)X ∼ N (μ, σ2) however BN uses the standard normal distribution. What mean and variance does the standard normal distribution have?
  2. What is the mathematical process of normalization?
  3. Describe, how normalization works in BN.

Training and Hyperparameters

Q37. Compare batch norm and layer norm.

Sign in to bookmark

Training and Hyperparameters

Q38. Under what conditions would it be possible to recover training data from the weight checkpoints?

Sign in to bookmark

Training and Hyperparameters

Q39. Why do we try to reduce the size of a big trained model through techniques such as knowledge distillation instead of just training a small model from the beginning?

Sign in to bookmark

Training and Hyperparameters

Q40. You’re building a neural network and you want to use both numerical and textual features. How would you process those different features?

Sign in to bookmark