4.1 - 4.4 Sequential Data & RNN Architecture
Standard feedforward neural networks assume all inputs and outputs are independent of each other. However, sequential data (e.g., sentences, audio streams, financial time-series, DNA sequences) possesses strong temporal / sequential dependencies where previous elements dictate the context of current elements.
RNN Hidden State & Mathematical Formulation:
At each time step $t$, an RNN maintains an internal memory called the hidden state ($\mathbf{h}_t$) computed from current input $\mathbf{x}_t$ and previous hidden state $\mathbf{h}_{t-1}$:
$$\mathbf{h}_t = \tanh(\mathbf{W}_{hh} \mathbf{h}_{t-1} + \mathbf{W}_{xh} \mathbf{x}_t + \mathbf{b}_h)$$ $$\hat{\mathbf{y}}_t = \text{Softmax}(\mathbf{W}_{hy} \mathbf{h}_t + \mathbf{b}_y)$$Types of RNN Sequences:
- One-to-One: Standard feedforward classification (non-sequential).
- One-to-Many: Image Captioning (single image input $\rightarrow$ sequence of words).
- Many-to-One: Sentiment Analysis / Text Classification (sequence of words $\rightarrow$ single sentiment class).
- Many-to-Many (Synced): Video Frame Classification / Named Entity Recognition (NER).
- Many-to-Many (Async / Seq2Seq): Machine Translation / Speech-to-Text (Encoder-Decoder model).