Deep Learning · TEE · section

R23 Q1a

Re examination January 2023 fully solved

Question

Question (4 marks). Suggest and sketch an RNN architecture to synthesize a musical tune.

Answer — step by step

A recurrent neural network processes a sequence in order and maintains a hidden state that summarizes earlier information. Its weights are shared across time steps.

h_t=\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\quad p_t=\operatorname{softmax}(W_{hy}h_t+b_y)LaTeX: h_t=\tanh(W_{xh}x_t+W_{hh}h_{t-1}+b_h),\quad p_t=\operatorname{softmax}(W_{hy}h_t+b_y)
Current input and previous state jointly determine the new state Tap the diagram to enlarge.

At each step, transform the current token representation, transform the previous hidden state, add the bias and apply the activation. An output layer may produce a prediction at each step or only at the end. This allows a sequence's length to vary while the parameter set stays fixed.

For next-word prediction, tokenize text, represent each word numerically, update the state for each prefix token, and apply an output softmax over the vocabulary. Train against the actual next token using cross-entropy. For sentiment classification, use the sequence representation to predict positive, neutral or negative. Word order matters: “not good” should not be interpreted like “good”.

A basic feedforward model has no built-in recurrent state, though a fixed window can be supplied explicitly. RNNs provide recurrent context but have sequential computation costs and difficulty learning long dependencies because of vanishing or exploding gradients. An encoder-decoder RNN can encode a source sentence and generate a target sentence of a different length; this is a historical RNN translation explanation, not a claim about any commercial service's current architecture.

Represent notes as discrete tokens or suitable pitch-duration vectors. Train a recurrent decoder to predict the next note from preceding notes. A vocabulary softmax handles discrete note tokens; repeatedly feed generated notes to continue the tune until a stop condition. This is autoregressive sequence generation, typically a many-to-many next-token training pattern.

Music generation can predict a next note at every recurrent step Tap the diagram to enlarge.