Standalone Deep Learning

KAIST Idea factory YouTube lecture


Theory

RNN

  • Classical Approach for Time Series Analysis
    • Time domain analysis: width, step, height of signal
    • Frequency domain analysis: Fourier analysis || wavelets
    • Nearest neighbors analysis: Dynamic time warping
    • Probabilistic Model: Language modeling
    • (S)AR(I)MA(X) models: Autocorrelation inside of time series
    • Decomposition: Time series = trend part + seasonal part + residuals (decomposition)
    • Nonlinear Dynamics: Differential Equation
    • Machine Learning: hand made features → use ML model
  • One hot encoding: converting a vocabulary set into numbers so that computers can understand it
  • The structure of RNN

    Figure

  • So how is the new input combined with the output of the previous hidden state?

    Figure

    \[h_t = f_W(h_{t-1}, x_t)\]

    💡

    Why are they ‘added’ element-wise?

    • In terms of the formula, the new \(h_t\) becomes the result of taking both \(h_{t-1}\) and \(x_t\) as inputs and processing them with a function called \(f_W\). Here, \(f_W\) uses functions such as tanh.
      • Depending on the case, for complex tasks, an MLP can be used as f!
    • Inside \(f_W\), the weight matrix \(W\) is multiplied by \(h_{t-1}, x_t\). Here, this \(W\) is shared as the same value across all time steps within a single layer.
    • That is, rewriting the formula in the image gives

      \[h_t = tanh(W_{hh}h_{t-1} + W_{xh}X_t)\]

      and here, there are three kinds of \(W\):

      • \(W_{xh}\) used for input data X → h
      • \(W_{hh}\) used for h → h (a square matrix)
      • \(W_{hy}\) used for h → Y
  • So what kinds of Sequential Data can be handled with RNNs?

    Figure

    Expand examples
    • One-to-many

      e.g., Image Captioning (image → sequence of words)

      • Input: only initial time step
      • Output: outputs from every output layers of each time step
    • Many-to-one

      e.g., Sentiment Classification (sequence of words → sentiment)

      • Input: sequence
      • Output: an output from a single time step
    • Sequence-to-sequence 1 (Many-to-many)

      e.g., Machine Translation (sequence of words → sequence of words)

      • Input: sequence of words
      • Output: after all the inputs are taken, outputs sequence of words
    • Sequence-to-sequence 2 (Many-to-many)

      e.g., Video Classification on Frame Level

      • Input: sequence
      • Output: on real-time, outputs sequence for every time steps

💡

In an RNN, then, what is one epoch, one iteration…? Didn’t understand the lecture

  • Multiple sequences can be forwarded in parallel within a single batch

What if the Input or Output Sequence lengths differ?

  • Set a max input length and truncate
  • Utilize eos, ios tokens
  • Evaluation of RNN
    • Calculate Loss of RNN

      e.g., many to many

      Figure

      • For Loss, use CE for classification, and MSE for regression problems
    • Problems of vanilla RNN

      • Gradient Vanishing ⇒ solved with LSTM, etc.