owned this note
owned this note
Published
Linked with GitHub
###### tags: `Introduction to Deep Learning`
# ItDL Final Exam
pdf: https://drive.google.com/file/d/1AnOwJi5VVfr9XUI5sWloOLme5e_FZcTj/view?usp=sharing
---
Deep Learning Final Exam
There are five part in this final exam. Please pick at least 2 questions in each part to answer.
You can answer up to 12 questions. Each answered question accounts for 10 points. If you
answer more than 12 questions, only the first 12 answers will be graded. There are 20
bonus points in this exam.
## I. Multi-Layer Perceptron
#### 1. TensorFlow uses reverse-mode autodiff to perform gradient descent. Briefly explain what it is and list two advantages of it.
> Adventages of autodiff:
> 1. 當 inputs 的數量 > outputs 的數量的時候,因為它只需要一次正向&一次反向,就可以算出所有 output 對 input 的導數了
> 2. Most importantly, it can deal with functions defined by arbitrary code. (看不懂 arbitrary code?)
> 3. 它可以處理 not entirely differentiable 的函數,因為你可以用 partial derivartives 讓它變得可以微分
#### 2. Let f(x, y) = xy2 + x + 2, use reverse-mode autodiff to compute 𝜕𝑓(4,3)/𝜕𝑥 and 𝜕𝑓(4,3)/𝜕𝑦 .
>解:
> 
#### 3.
A. What are the two APIs available in Keras to create layers in a neural network?
>解:
Dense layer
LSTM layer
>Convolution layer
B. If multiple inputs or multiple outputs are in a neural network, which API should we use to create the network?
>解:
(參考的pdf第一頁章節名稱是Deep Learning Introduction to Artificial Neural Networks with Keras)
(參考pdf第54頁)
Dense layer即可完成多維輸入及多維輸出的功能。
> 可以使用 keras.Model(inputs = [input_A, input_B], outputs = [output_A,output_B]) 此函式在中括號中設定多個輸入以及輸出。
#### 4. In model training, the dataset is usually divided into three subsets. What are they?Briefly explain the role of each subset during model training.
>解:
通常會將資料集拆分成訓練集、驗證集以及測試集,其中我們訓練模型會依靠訓練集以及驗證集來做使用,訓練集會去學習模型參數,驗證集負責驗證目前學習狀況以及協助模型的修正。模型訓練完畢後才放入測試集,對此模型做最後的評分。
>
## II. Model Tuning
#### 5. Briefly describe the situation where the following initialization used most often.
參考講義 TrainingDeepNeuralNets - p.7
**A. Xavier Initialization**
:::success
For the signal to flow properly, the authors argue that we need the variance of the outputs of each layer to be equal to the variance of its inputs, and we also need the gradients to have equal variance before and after flowing through a layer in the reverse direction
> 在每一層的 input 和 output 的 variance 都要一樣 and
> 在反向傳遞的時候 (gradient),傳遞進來前的 variance 要和傳遞出去的 variance 要一樣
他們提出了一個做法
the connection weights of each layer must be initialized randomly as described in the equation in the next slide, This initialization strategy is called **Xavier initialization** or Glorot initialization,
> 參考 TrainingDeepNeuralNets, page.8
> 就是隨機初始化連階層間的權重,依照投影片給的公式 (但我看不出來她哪裡隨機了?)

**Xavier Initialization 適合用在處理 Tanh/Sigmoid vanishing gradients**
by 昇
:::
**B. He Initialization**
:::success
使用 ReLU 當作 activation 的
**He Initialization 適合用在處理 ReLU/Leaky ReLU exploding gradients**
:::
**C. LeCun Initialization**
會配合 SeLU 使用
:::success
在 Xavier Initialization 的 Normal distribution 的那個方程式裡面,把 $fan_{avg}$ 換成 $fan_{in}$ 就是 LeCun Initialization
當 $fan_{in} = fan_{out}$ 的時候,LeCun initialization 等於 Xavier Initialization
:::
#### 6.
**A. Briefly explain the overfitting problem in model training and how to identify it.**
因為一個 model 裡面有非常多的神經元,有時候甚至可以達到數百萬個以上,因此他們具有非常高的彈性可以去 fit 給予的資料,而這時候就有可能造成 overfitting。
當模型在train時擁有很高的準確度或很低的loss,但是在test的時候,卻和train時的準確度與誤差相差很多,那就代表可能有overfitting的情形。
**B. Briefly explain L1 and L2 regularizations. Describe the situation where each of these regularizations should be used.**
在 loss function 中加上對應的L1及L2 penalty(懲罰),可以想成是在 loss function 中加上限制,讓模型的權重不會直接跑到最小的loss那個地方
Lasso(L1) Regularization
Ridge(L2) Regularization
L1 可能導致權重值等於0,因此可以得到一個比較小的網路,但模型的效果會沒有L2好
L1 適合用在 feature selection 上面 (應該是因為它會讓特徵的權重變為0,就可以做特徵提取,特別是在很多特徵的資料上)
> 講義說: 適合用在稀疏模型上
L2 比較不會讓權重值變為0,但會對較大的特徵值給予較大的權重 (但我就不知道適合用在哪裡了)
L2 適合處理 Multicollinearity
> Multicollinearity: 不同的特徵但擁有很高的相關性
#### 7.
**A. Briefly explain what Batch Normalization is.**
在layer與layer之間可以做 batch normalization,這樣可以防止網路發生 vanishing/exploding gradients
他會去計算每個batch的mean, standard deviation,然後對她做normalization
**B. In which situations do we use Batch Normalization?**
因為在訓練過程中,每一層的分布會不一樣,會增加學習難度,所以做 batch normalization
也可以緩解梯度飽和問題
**C. Batch Normalization does not perform the same computation during training and after training. Briefly explain why and the difference during and after training.**
在測試階段 (after training),我們可能沒有整個 batch 可以餵到 model 裡面
因此在訓練時會記下各個的 mean, standard deviation,然後在測試的時候直接套進去 (就是不會去算測試資料的 mean, standard deviation)
## III. Convolutional Neural Networks
#### 8.
**A. How many parameters are there for a fully connected layer with 150 × 100 neurons, each connected to all 150 × 100 × 3 inputs?**
> 看不懂題目... 或許這兩個用程式model直接summary? (那你考試要帶一台電腦過去)
>題目應該是在說,輸入是150x100x3個參數以及有一個全連接層,全連接層有150x100個神經元,請問這個網路架構中有多少個參數要訓練。
>每個全連接層的神經元會連接到150x100x3個來自輸入的參數,因此總共使用到的參數應該是**150x100x3x150x100**個在這個網路模型中。
**B. How many parameters are there for a convolutional layer with 5 × 5 filters, outputting 200 feature maps of size 150 × 100, with stride 1 and SAME padding? Assume that the input is a 150 × 100 RGB image (three channels).**
$(((5 \times 5 \times 3) + 1) \times 200)$
#### 9.
**A. Briefly explain what data augmentation is.**
將資料集的圖片經過旋轉、縮放,或者改變亮度色溫、翻轉等處理後,創造出更多的圖片來讓機器學習,彌補資料量不足的困擾。
B. List two advantages of data augmentation.
彌補資料量不足,避免過度擬合
C. Which famous CNN architecture that once won ImageNet ILSVRC challenge used data augmentation?
> AlexNet
#### 10.
**A. What is the most important component in GoogLenet? Briefly explain how it works.**
https://iter01.com/537759.html
Inception網路結構,將CNN中常用的卷積(1x1,3x3,5x5)、池化操作(3x3)堆疊在一起,增加了網路的寬度,也增加了網路對尺度的適應性
**B. What is the most important new concept in ResNet? Briefly explain how it works.**

- 殘差學習,網路架構簡單地增加一條路線做單純的加法,使深層網路訓練變得容易許多
- skip connection,解決了在 back propagation 的階段,因為權重變為0而無法再繼續往上回溯的問題
有了 skip connection,就能夠直接回到上兩層 (來源層)
**C. What is the most important new concept in SENet? Briefly explain how it works.**
SE Block, SE is Sequeeze and Excitation
- 對每個 channel 加權,讓模型可以更加關注資訊量最大的 channel 特徵,而抑制那些不重要的 channel 特徵。
- 透過學習的方式來知道每個特徵通道(channel)的重要程度,以此來提升有用的特徵並抑制不重要的特徵
## IV. Recurrent Neural Networks
#### 11.
**A. List four commonly used RNN architectures. Draw a simple diagram for each of them.**
看起來只是要我們回答,seq to seq, seq to vector, vector to sequence, encoder decoder
**應該是要畫圖** (參考講義SequencesUsingRNNsCNNs的pdf第7、8頁)

**B. Which one in these four architectures is the combination of two other architectures?**
encoder decoder
它是 seq to vector + vector to seq
**C. Provide one possible application for each of these architectures.**
seq to seq:股票預測,使用前N天的資料來預測下一天的資料,而預測出的新資料會被接著往後使用。
seq to vector:提供網路一個電影評論的形容詞,他會回應一個值來代表喜不喜歡此電影。
vector to seq:輸入一張影像,輸出此影像的標題。
seq to vector + vector to seq:輸入英文,輸出中文。
(上面例子是在講義第7頁中4段英文裡面所提到的例子)
#### 12.
**A. Briefly explain what TimeDistributed layer is and where it is used?**
將這個layer放在最後一層,我們就可以知道RNN每個時間所產出的輸出值。
**B. Batch Normalization is not effective for RNNs, what else can be used for RNNs that works similar to Batch Normalization?**
Layer Normalization
**C. Briefly explain what peephole connections are.**
原本的 LSTM 只有考慮上一個 output 的資訊,而 peephole connections 把 long-term 的資訊也拿進來考慮。
> peephole 有窺見未來的意義
#### 13.
**A. Which CNN architecture introduced in textbook can process time series data as good as RNNs (or even better)?**
WaveNet
**B. Briefly explain this CNN architecture.**

**C. Briefly explain what dilation rate is. Assume the dilation rate is set to 4, what will be the resulting dilated filter for a 1 × 3 filter equal to [[1,2,3]]?**
> 看不懂
https://towardsdatascience.com/types-of-convolutions-in-deep-learning-717013397f4d
這個感覺有料
dilation rate 就是中間要空幾格的意思
如果是 dilation rate=4, 要空 4-1 格
> 所以答案是 [[1, _, _, _, 2, _, _, _, 3]] ??
## V. Autoencoders
#### 14.
**A. Briefly explain what Kullback–Leibler Divergence is.**
RepresentationLearningGenerativeLearningUsingAutoencodersGANs.pdf - p.54

>Ans:主要使用於兩個機率分布的接近程度,利用量化的方式去衡量(entropy)。
**B. What is the primary application of Kullback–Leibler Divergence outside of Deep Learning?**
去衡量兩個機率分布有多相似
>題目應該是在問說這個方法除了應用在深度學習之外,還有哪個地方在使用?
>Ans:可以用在人體姿態辨識(Openpose)。
>這個例子是老師上課自己講的。在2021/12/23深度學習介紹-2(中文影片)的50:15秒開始觀看可看到。
**C. Where is Kullback–Leibler Divergence used in autoencoder and why?**
encoder 會將輸入資料轉成另一個空間(通常叫 latent space),而希望在這個空間上的資料分布越接近 Normal distribution,所以才要用 KL divergence 來做
(希望資料高斯分布的想法,可以想成我們希望自己使用的資料能夠以比較自然的方式呈現。且高斯分布的公式我們是已知的,所以要做使用會比較方便。)
上面是我各人的理解不算在作答內,各位可以看一下有沒有辦法幫助理解底下說的內容~
>Ans:
>因為encoder想將輸入的資料轉到另一個空間的資料,而我們希望在這個空間的資料能夠盡量服從高斯分布,而這時就可以透過KL divergence來讓我們判斷encoder轉換出的空間所屬分布是否與高斯分布接近。
#### 15.
**A. Describe two generative models that can be used to generate sample data from random sampled numbers (i.e., codings).**
VAE:
將我們輸入的原始資料轉換到另一個空間,而這個空間的機率分布會服從高斯分布(常態分布),接著會從這個分布中隨機選取一個樣本點,用這個樣本點乘以encoder所提供的標準差並且加上encoder提供的平均值來當作這個空間的隨機採樣,採樣完之後用decoder來產生新資料。
GAN:
輸入透過generator產生一個輸出,再透過discriminator來判斷這個輸出是真的還假的。
generator希望輸出能騙過discriminator,discriminator目標是找出假的輸出結果,利用這種競爭關係來讓模型越來越好。
**B. List two major differences (not just their names) of these two generative models.**
VAE的架構基本上是一個對稱的形狀,也就是先encoder再decoder,並且希望輸入與輸出相同。
GAN的架構前面的generator雖然與VAE的decoder相似,但是他並沒有希望輸入與輸出相同,只是單純透過generator產生一個輸出。
VAE沒有discriminator。
**C. Briefly explain what semantic interpolation is.**
semantic interpolation 是在 latent space 上面做的 interpolation
**interpolation vs semantic interpolation**
老師上課用圖片的例子來說明,如果兩張圖做 interpolation,那就是把兩張圖的每個 pixel 相加除以 2。
但 semantic interpolation 是在 encoder 轉出來的 latent space 上面做 interpolation,然後再輸入進 decoder 裡面,因此轉出來的圖片是由 latent space 上的其中一個點轉出來的。
#### 16.
**A. Briefly explain the 2 phases of GAN training.**
訓練discriminator時,從真實影像拿出一部分以及generator拿出一部分假影像,比例基本上是1:1,組成一個batch來訓練,在這過程我們會固定generator中所使用到的參數(權重)。
訓練generator,使用generator產生影像並且將這個產生的影像標記為1(正確的影像),將產生的影像輸入給discriminator,discriminator會將誤差信號傳回給generator去修改權重。過程中discriminator的權重會固定。
過程中generator完全沒看過真實資料,他是依靠discriminator告知的訊息來修正自己的權重。
**B. List two reasons why GANs are difficult to train.**
1.會發生Mode collapse現象(集中產生某一種類別),generator為了騙過discriminator,可能會因為學習新的輸出而忘記舊的內容,而discriminator也會為了成功判斷出真假,忘記先前成功判斷過的內容。
2.容易受到參數的影響讓模型不穩定。
3.當真實分佈和虛假分佈彼此相距很遠時,訓練變得非常困難,因為生成器從判別器接收到非常微弱的梯度信號
**C. Provide two techniques that help to train GANs.**
1.Experience replay:可以透過一個容器來儲存generator曾經創造過的所有資料,使用的資料不再是直接拿取generator的輸出來使用,而是從前面所提到的容器中抓取資料來做使用。
2.Mini-Batch discrimination:如果generator輸出的一批資料太過於相似,我們就將這批資料刪除不做使用,我們希望generator產出的資料是比較多樣性的。