



Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!




▪ MACHINE LEARNING = programming computers to optimize performance criteria using data or experiences. Machine learning methods have
a domain-specific part (describing data with feature that a computer can understand → feature extraction made by humans) and a learning
algorithm (optimize the weights on features to make a final prediction).
▪ The input can be represented based on the feature vectors ( attribute-based ) or on first-order logic ( relational ).
▪ ML can be empirical (knowledge-free) or analytical (knowledge-guided).
▪ ML needs feedbacks in order to work, they can be supervised (empirical or analytical learning), unsupervised (learning from data by itself) or
reinforcement (learn from rough and approximate supervised learning signals).
▪ Supervised learning : we have a target function 𝑓: 𝑋 → 𝑌 (maps from input X to output Y)
▪ Neural network = parametrized family of nonlinear functions, ca be feed-forward (acyclic) or recurrent (cyclic).
Learning of neural networks: the idea is to adjust the weights to change the function represented by NN ( learning = optimization in weight
space ). We can iteratively adjust the weights to reduce the error (difference between NN output and targeted output). The weight update
rule can be the backpropagation algorithm or optimization methods.
▪ Support vector machines ( SVM ): map nonlinearly separable data to higher-dimensional space, where they will be linearly separable. SVM
aim at designing the optimal classifiers for data. An optimal linear separator is one that has the largest margin between the classes.
▪ Unsupervised learning : learn patterns from unlabelled data (clustering or density estimation)
▪ Reinforcement learning : finding an optimal policy, when both the model and the desired output are unknown
▪ Model-free reinforcement learning: learn a controller without learning a model
▪ Model-based reinforcement learning: learn a model first and then a controller
▪ Data mining : non-trivial process of identifying valid, novel, potentially useful and ultimately understandable patterns in data.
▪ DEEP LEARNING is the future of machine learning: feature extraction and classification are merged together inside the DL (the DL can directly
extract features from data). Feature extraction and classification attempt to learn (multiple levels of) representation by using a hierarchy of
multiple layers. DL learns in both unsupervised and supervised modes,
▪ NODE FUNCTIONS : help NN to learn complex patterns in data. All node functions have their own advantages and disadvantages (choices are
made case-by-case)
▪ Linear node function: quite useless
▪ Non-linear node function: smooths data
▪ Sigmoid node function: ϕ
1
1 +𝑒
−𝑧
with outputs in [ 0 ,1]. Pros: smooth gradient and differentiable (no jumps in the output), Cons:
vanishing gradients, not centered in 0, exponential operation is complex to calculate, if we have a lot of layers the error can
backpropagate. Used to classify the data samples in the output layer. The first derivative of sigmoid is always > 0.
▪ Hyperbolic tangent node function: 𝑓(𝑥) = tanh(𝑥), outputs in [-1,1], it’s 0-centered and used for classification in hidden layers,
because the outputs can have both negative and positive values. Doesn’t solve the issue of vanishing gradient → for that we need to
choose a ReLU (Rectified Linear Unit)
▪ ReLU (Rectified Linear Unit) node function: 𝜎(𝑥) = max( 0 , 𝑥) , 𝑥 ≥ 0 , 0 otherwise. ReLU is simpler → faster calculation, solve the
problem of vanishing gradient, the problem is that for 𝑥 < 0 you always get 0 (dead relu problem)
▪ Softplus node function: smoothen approximation of ReLU, 𝑓(𝑥) = ln( 1 + 𝑒
𝑥
), we have two function inside → more difficult to
calculate but can offer some kind of smoothness.
▪ Leaky ReLU node function: 𝑓
, usually with 𝑎 = 0. 01 , complete the ReLU giving non-zero outputs from every kind of
outputs. Problem: it’s linear
▪ ELU (Exponential Liner Units) node function: complete ReLU with a non-linear function for 𝑥 < 0 with parameter 𝑎, computationally
intensive.
▪ SELU (Scaled Exponential Linear Unit) node function: two parameters 𝜆 (scaled parameter) and 𝛼 (parameter). Somehow similar to ELU
and together they give slightly better performances than ReLU.
Normalization transform the data into something with mean=0 and variance=1, it’s useful to compare different features and can speed
up the training velocity. If we select two specific 𝛼, 𝜆 in SELU we can get normalized outputs.
▪ GELU (Gaussian Error Linear Unit) node function: 𝑓(𝑥) = 𝑥Φ(𝑥), input data is assumed normal, it’s a smoother ELU.
▪ Swish node function: 𝑓(𝑥) = 𝑥 ⋅ 𝜎(𝛽𝑥), we can train 𝛽, 𝛽 = 1 is the normal choice. For 𝑥 small the function is almost 0, when 𝑥 is
large the output will increase and we have a gate in which the input is non-zero. The first derivative can assume all values. Swish can
skew the data samples (smoother surface make training easier). Swish is more robust wrt layer variation and can give stronger NN with
different batch sizes.
▪ PReLU (Parametric ReLU) node function: we add a trainable 𝛼 at the ReLU function for 𝑥 < 0.
▪ Mish (state-of-the-art) node function: tanh of softplus, similar to swish but more robust against noise
▪ Softmax node function: usually used in the last layer (output layer) because is suitable for multiclass classification (probability of
feature belonging to a specific class). In sigmoid the probabilities are independent of each other while in SoftMax we have dependent
probabilities : all the other outputs inside the same layer are taken into account.
▪ LogSoftmax node function: variant of Softmax, introduced for enhance computational stability (outputs near 0 can cause instability in
probability computation).
▪ Maxout node function: makes a piecewise linear approximation to an arbitrary convex function. Can approximate any continuous
function arbitrarily well but needs more inputs.
▪ Dropout is a DL technique which consists in freezing some neurons during the training (dropout rate = 0.5 means that each neuron has
probability 50% of being disconnected) → this helps to predict overfitting.
▪ General rules for selecting node functions :
▪ Sigmoid works well but suffer from vanishing gradient problem
▪ ReLU is used in the hidden layers
▪ Leaky ReLU is useful for avoiding dead/dying neurons
▪ PReLU is for huge training set
▪ Softmax is used in the output layer for multiclass classification
▪ The major tradeoff is convergence & computation
▪ Weight initialization = we have to choose the initial value for the weights, usually we choose random and small values, not zeros.
▪ Uniform distribution: [−
1
√
𝑛 𝑖𝑛𝑝𝑢𝑡
1
√
𝑛 𝑖𝑛𝑝𝑢𝑡
𝑖𝑛𝑝𝑢𝑡
refers to the input of the neuron
▪ Normal distribution: mean = 0, variance =
2
𝑛 𝑖𝑛𝑝𝑢𝑡
▪ Xavier weight distribution: for the uniform distribution we take [− √
6
𝑛 𝑖𝑛𝑝𝑢𝑡
+𝑛 𝑜𝑢𝑡𝑝𝑢𝑡
6
𝑛 𝑖𝑛𝑝𝑢𝑡
+𝑛 𝑜𝑢𝑡𝑝𝑢𝑡
], where 𝑛
𝑜𝑢𝑡𝑝𝑢𝑡
is the number of
outputs from the neuron, and for the normal we take mean = 0 and variance =
2
𝑛 𝑖𝑛𝑝𝑢𝑡
+𝑛 𝑜𝑢𝑡𝑝𝑢𝑡
LEARNING RATE = one of the most difficult hyper-parameters to set/tune in deep neural networks training → adaptive learning rate
algorithms are proposed (the LR changes during the training).
▪ Small LR : requires many updates before reaching the minimum point, can lead to the solution but the process can be really slow.
▪ Large LR : causes dramatically updates which lead to divergent behaviors, the step is quite large and the training can move in the wrong
direction (instable)
▪ Optimal LR : swiftly reaches the minimum point, the speed is not so low.
▪ Heuristic Learning Rate : every adjustable network weight should have its own individual learning rate,
▪ Every learning rate should vary with iterations (error surface can behave differently in different regions of weight dimensions).
▪ A fixed LR may not suit all portions of the approximation error surface and all stages of the training process.
▪ If the sign of the gradient remains the same consecutively, the learning rate has to be increased (because you’re going in the same
direction) → increased learning rate can speed up the training process. If the sign of the gradient alters consecutively, the LR needs to
be decreased → decreased LR can combat with the oscillating problem in valleys of error surface.
▪ Adaptive Learning Rates :
▪ Purely decreasing learning rates may cause training to be trapped into local minima.
▪ Cyclical learning rates are the most common choices for DL NN → used to escape local minima, but it’s difficult to determine the
periods and magnitudes of cyclical LR schemes.
▪ For estimating the best LR: evaluate the behavior of the loss function → the optimal value of LR is the one that lead a rapid decrease of the
loss function:
One-cycle policy for LEARNING RATE : consists in
three phases (warm up, cool down, annihilation). In
the annihilation we reduce LR to very small values
(almost 0)
▪ Saddle points : we have a local minimum in one direction but a local maximum in one other direction and this can confuse the training → we
must handle them: small gradients near the saddle points result in slow training progress, so increasing the LR can help the network loss
more quickly continue its downward progression.
compute gradient with the data in the minibatch: 𝑔 ←
1
𝑚
𝜃
𝑖
(𝐿: loss function)
accumulate squared gradient : 𝑟 ← 𝜌𝑟 + ( 1 − 𝜌)𝑔⨀𝑔 (= 𝑔
2
compute the update in the parameters : Δ𝜃 = −
𝜖
𝛿+ √
𝑟
⨀𝑔, 𝑔 is the learning direction
apply the update: 𝜃 ← 𝜃 + Δ𝜃
end
The accumulation of the square gradient is an exponentially weighted average (based on regression theory), in which the most recent values
have highest weights (the exponential weighted average can suffer of bias).
▪ Adam (Adaptive movement introduced): combination of RMSProp and the first order moment of the gradient (= momentum), bias
correction are added to estimates of both 1
st
dn 2
nd
order moments of gradient.
Adam algorithm :
Initial requirements: step size 𝜖, initial parameters 𝜃, small constant 𝛿 for numerical stability, exponential decay rates 𝜌
1
2
initialize gradients accumulation variables 𝑟 = 0 (
st
order), 𝑠 = 0 (
nd
order), time step 𝑡 = 0
while (! stopping criterion) do
sample a minibatch of 𝑚 from the training set {𝑥
1
𝑚
} with corresponding targets 𝑦
𝑖
compute gradient with the data in the minibatch: 𝑔 ←
1
𝑚
𝜃
𝑖
(𝐿: loss function)
update time instant 𝑡 ← 𝑡 + 1
update first order moment estimate : 𝑠 ← 𝜌
1
1
update second order moment estimate : 𝑟 ← 𝜌 2
2
correct bias in 1
st
order moment: 𝑠̂ ←
𝑠
1 −𝑝
1
𝑡
correct bias in 2
nd
order moment: 𝑟̂ ←
𝑟
1 −𝑝
2
𝑡
compute the update in the parameters : Δ𝜃 = −
𝜖 𝑠̂
𝛿+√𝑟̂
apply the update: 𝜃 ← 𝜃 + Δ𝜃
end
𝑟 can be considered to be a SNR (Signal-Noise Ratio) → in case of smooth error/loss surface we have larger learning rate (𝑠/ √
𝑟 = 1 ) and
in case of rough error/loss surface we have smaller learning rate (𝑠/ √
𝑟 small).
We need bias correction because the estimation of the 1
st
order moment gradient can introduce bias.
Corrections that we can made for ensuring Adam convergence:
▪ Set the update of 𝑟 as the maximum between the actual 𝑟 and the previous value: 𝑟 ← max
𝑡
𝑡− 1
▪ Switch between Adam and SGD.
Differences between these three methods:
▪ Adam uses 1
st
and 2
nd
order moment gradient while the others uses just the 2
nd
order (𝑔⨀𝑔).
▪ RMSProp uses a decay rate 𝜌 in the accumulation of the squared gradient (in order to obtain an exponentially weighted average), Adam
uses two decay rates 𝜌
1
and 𝜌
2
because we have two gradients.
▪ Adam uses time step to correct the bias in the moments → the correction can smooth the error.
▪ Adam may not converge (LR can vary leading to possible instability in training) while SGD and AdaGrad usually converge.
▪ RAdam (Rectified Adam): variant of Adam introducing a term to rectify the variance of the adaptive learning rate (in Adam the adaptive
learning rate has undesirably large variance in the early stage of training, due to limited amount of training samples used). To reduce the
variance, smaller learning rates can be used in the first few training epochs ( warm-up heuristic ). RAdam is better than Adam and a little bit
worse than SGD, but it’s faster than SGD.
Adam algorithm :
Initial requirements: step size
𝑡
𝑡= 1
𝑇
, decay rate
1
2
, initial parameter 𝜃 0
, stochastic objective function 𝑓 𝑡
Outputs: resulting parameters 𝜃
𝑡
initialize moving 1
st
and 2
nd
moment 𝑚
0
0
initialize 𝜌
∞
2
1 −𝛽 2
− 1 maximum length of the approximated SMA ( Simple Moving Average )
while 𝑡 =
do
calculate gradients wrt stochastic objective 𝑔 𝑡
𝜃
𝑡
𝑡− 1
update exponential moving 2
nd
moment 𝑣 𝑡
1
𝛽 2
𝑣 𝑡− 1
2
𝑡
2
update exponential moving 1
st
moment 𝑚
𝑡
1
𝛽 1
𝑣 𝑡− 1
1
𝑡
compute bias-corrected moving average 𝑚̂
𝑡
𝑚 𝑡
1 −𝛽
1
𝑡
compute the length of the approximated SMA 𝜌
𝑡
∞
2 𝑡𝛽
2
𝑡
1 −𝛽
2
𝑡
if the variance is tractable , i.e. 𝜌
𝑡
4 , then
compute adaptive learning rate 𝑙
𝑡
2
𝑡
𝑡
compute the variance rectification term 𝑟
𝑡
update parameters with adaptive momentum 𝜃
𝑡
𝑡− 1
𝑡
𝑡
𝑡
𝑡
(applying rectification)
else
update parameters with un-adapted momentum 𝜃
𝑡
𝑡− 1
𝑡
𝑡
end
end
return 𝜃
𝑇
▪ AdaMax : generalization of Adam by replacing the 2-norm in Adam to 𝑝-norm (𝑝 → ∞).
▪ Adadelta : extenstion of AdaGrad, introduces the scaled gradient and takes into account the exponentially weighted average of only the
past 𝒏 gradients instead of all of them.
PERFORMANCE COMPARISON : it’s difficult to choose the best gradient method, performance comparison is usually based on trial and error ,
we can also introduce artificial functions to test and compare the performances of the gradient methods.
in DL, we need to find a way to handle the saddle points.
of gradient descent , DL can be accelerated with momentum.
MOMENTUM : it’s the first order moment of the gradient.
▪ One-cycle policy for MOMENTUM : cool down and then warm up,
decreasing momentum while increasing LR leads to better training
results.
▪ Can speed up training if has
the same direction of the
current gradient → accumulates
an exponentially decay moving
average of past gradients and
continues to move towards their
direction
▪ SGD with momentum: the
velocity update is 𝑣 ← 𝛼𝑣 − 𝜖𝑔
and then 𝜃 ← 𝜃 + 𝑣
▪ Demon Adam : uses momentum for speed-up in the beginning but
decays momentum throughout training, preventing NN from
growing too fast. Strategy for tuning the parameters.
▪ Nesterov momentum : adds a correction factor to the standard method of momentum, evaluates gradient after the current velocity
(momentum) is applied, can accelerate the convergence in the standard batch momentum method but not in the SGD case.
▪ Aggregated momentum (AggMo) : averages the velocities when updating the parameters.
▪ Quasi-hyperbolic momentum (QHM) : averages standard SGD and SGD with momentum.
▪ Quasi-hyperbolic Adam (QHAdam) : replaces both of Adam’s moment estimators with quasi-hyperbolic terms (weighted averages
momentum and plain SGD).
▪ NAdam : we include Nesterov momentum in Adam (the update of the gradient is made with 𝜃
and used in the calculation of 𝑠 and 𝑟).
is changed or clipped to a threshold during backward propagation through the network, and using the clipped gradients to update the
weights).
training loss floating around the flood level.
Core idea: calculate mean and variance and using them we normalize the output.
network activations due to change in network parameters (weights) during training (each layer has different covariate distribution) →
harmful in DL. Everything is made at batch level (mean and variance of the batch).
filters), can do parameter reduction (= total number of parameters is reduced).
𝑇
𝑇
normal convolution, 𝑂
𝑇
𝑇
𝑇
transposed convolution: it’s not inverse convolution and cannot restore the original images.
Two methods: data augmentation (data-based) and transfer learning (parameter-based)