RNN++ (Model Architectures)
Modify RNN
Note that text can be long, the early observation may be very important. However, truncation may miss such important information, or it may also decay in the long sequence. Therefore, we can use a memory cell to remember all the important information.
Besides, some information is meaningless, such as the HTML tags, we can simply skip such meaningless tokens.
Furthermore, text may consists of some logic break, such as a new chapter, to separate those chapters we want to reset the hidden state.

We need some gates to turn the information on or off
- Memorize: Memorize the early observation
- Skip: Skip the current input $\mathbf{H}_t = w\mathbf{H}_{t-1} + 0 \times X_t$
- Reset: Reset all previous states $\mathbf{H}_t = 0 \times \mathbf{H}_{t-1} + wX_t$

- Add the reset operation:
- Reset: $\mathbf{R}_t$: Binary vector (values are either 0 or 1)
- Add the skip operation:
- Skip: $\mathbf{Z}_t$: Binary vector (values are either 0 or 1)
- Add the memorize operation: we hope the current value is almost the same as the previous value
The optimal memorize case: $\mathbf{H}_{t} = \mathbf{H}_{t-1}$, $\mathbf{H}_{t-1} = \mathbf{H}_{t-2}$, …, $\mathbf{H}_{2} = \mathbf{H}_{1}$, such that $\mathbf{H}_{t} = \mathbf{H}_{1}$- Skip: $\mathbf{P}_t$: Binary vector (values are either 0 or 1)
- Note that if $\mathbf{P}_t$ is 1, all other terms should be zero to achieve the purpose of memorization
Gated Recurrent Units

The update $\mathbf{H}_t$ is either come from the candidate hidden state $\widetilde{\mathbf{H}}_t$ or the previous hidden state $\mathbf{H}_{t-1}$
- $\mathbf{R}_t$ and $\mathbf{Z}_t$ are binary vectors (values are either 0 or 1)
- Reset gates $\mathbf{R}_t$ helps capture short-term dependencies in sequences
It controls the information from the previous hidden state $\mathbf{H}_{t-1}$. If the reset gate $\mathbf{R}_t$ is set to be 0, then all the information from the previous hidden state $\mathbf{H}_{t-1}$ will be deleted. The output state $\mathbf{H}_t$ only depends on the current input $\mathbf{X}_t$. Thus, it captures the short-term dependencies in sequences.
- Update gates $\mathbf{Z}_t$ helps capture long-term dependencies in sequences
It controls the information from the input state $\mathbf{X}_{t}$. If the update gate $\mathbf{Z}_t$ is set to be 0, then all the information from the input state $\mathbf{X}_{t}$ will be deleted. The output state $\mathbf{H}_t$ only depends on the previous hidden state $\mathbf{H}_{t-1}$. Thus, it captures the long-term dependencies in sequences.
Long Short-Term Memory

- Forget gate: controls how much we should forget in the memory cell
- Input gate: controls how much information from the candidate memory will be stored in the new memory
The design does not contain the skip gate, because the input gate can replace with the skip gate by setting the input gate to 0, so the input would not be incorporated into the candidate memory - Candidate memory: combines the information from current input and the hidden state
- Output gate: extracts the information from the memory cell and gets the observation for the hidden state in the next time step

- Memory cell: is similar to the hidden state but stores the long-term information which is another level of abstraction from the hidden state
GRU and LSTM: The gates can be implemented using the logistic regression function, the update gate in GRU and memory cell in LSTM enhance the model’s ability in handling long-term dependence. The traditional RNN is a special case of GRU (when $\mathbf{Z}_t$ is 0 and $\mathbf{R}_t$ is 1, the GRU is equivalent to the traditional RNN).
Bidirectional Model
Given the improved version of RNNs with larger model capacity by adding more hidden layers (not hidden states).
Further improvement: Considering the sequential inputs, the hidden state can not just depend on the current input state and the previous hidden state, it can also consider the further input states. For example, the hidden state $\mathbf{H}_2^{(1)}$ can also take the information from $\mathbf{X}_1$ and $\mathbf{X}_3$, such that the current hidden state does not just depend on the previous and current information but also the future information. Exmaple: I am __ hungry, the generation can also depend on the downstream and future information which is also very helpful. Exmaple: I am __ hungry, and I can eat half a pig.

Such that the final output will depend on all the information within the sentence.
Problems and Limitations:
- Inefficient: Forward propagation requires both forward and backward recursions, for example the output in time step 1, it depends on $\overrightarrow{\mathbf{H}}_1$ in the forward and $\overleftarrow{\mathbf{H}}_1$ in the backward while the $\overleftarrow{\mathbf{H}}_1$ depends on the $\overleftarrow{\mathbf{H}}_T$ in the backward. Thus, the entire model is very slow
- Poor performance: Training with information of both direction, testing only one direction.
Sequence-to-sequence Model
Machine Translation
An automatic translation of a sequence from one language to another language
- Observations: Sequences of different lengths (implies that there is no direct mapping from word to word)

- Encoder: transform the input into a state with a fixed shape
- Decoder: map the encoded state to a variable-length sequence
Model Architecture

Encoder:
Decoder:
Loss function: For each of the position, we can treat it as a classification task using the cross-entropy loss
Prediction: The prediction is completed when it is predicting <eos>
Evaluation: Bilingual Evaluation Understudy (BLEU)
Precision of n-grams:
Example:
The target sequence is “ABCDEF” and the predicted sequence is “ABBCD”- $p_1 = \frac{|\{\text{A,B,C,D}\}|}{|\{\text{A,B,B,C,D}\}|} = \frac{4}{5}$
- $p_2 = \frac{|\{\text{AB,BC,CD}\}|}{|\{\text{AB,BB,BC,CD}\}|} = \frac{3}{4}$
- $p_3 = \frac{|\{\text{BCD}\}|}{|\{\text{ABB,BBC,BCD}\}|} = \frac{1}{3}$
- $p_4 = \frac{|\phi|}{|\{\text{ABBCD}\}|} = 0$
Problems: Note that for example we are using softmax function to do the prediction, it picks the choice with the maximum probability, but the future results depend on the current choice, which implies that it is actually a greedy search algorithm that take the local maximum chance. However, greedy algorithm does not guarantee an optimal solution

Due to the efficiency problem, if we use exhaustive search, the computational cost would be very high
Beam search: An improved version of greedy search, given a beam size $k$, select $k$ candidates from $k|D|$ possible choices at the beginning (time step 0)
Problems and Limitations: Note that hidden state in very important within a model, but sequence-to-sequence model only has one hidden state to aggregate the information of the input, which implies that the hidden state flows across the sentence that cannot ensure the representation for each word is proper
Questions
- Although the bidirectional model is slower than the corresponding RNN model, it usually has better generalization power than the unidirectional model (false: poor performance problem of bidirectional model, in most of the situations, if the testing data do not have the future information, it may not guarantee a better generalization)
- The later layer of the deep RNN model will learn the high-level trend in the input sequences (false)
- The time complexity of beam search is higher than greedy search but lower than exhaustive search (true)
- With the help of the
<eos>token, we can generate sequences with variant lengths (false)


