Recurrent Neural Networks (RNNs) are fundamental for processing sequential data. However, they are notoriously difficult to train on long sequences due to the vanishing and exploding gradient problems. As dependencies stretch across thousands of time steps, traditional architectures struggle to maintain stable signal propagation.
In "Shuffling Recurrent Neural Networks" (SRNN), presented at AAAI-21, Michael Rotman and Lior Wolf propose a simple yet effective solution: replacing the learned hidden-to-hidden transition matrix with a fixed, parameter-free circular shift.
The Challenge of Long-Term Recurrence
The core mathematical instability in RNNs stems from the repeated application of a weight matrix $W_1$ in the recurrence relation $h_t = \sigma(W_1 h_{t-1} + W_2 x_t)$. The gradient of the loss function involves powers of $W_1$. If the eigenvalues of $W_1$ deviate from unity, gradients either explode or vanish exponentially. While gated architectures like LSTMs and GRUs mitigate this, they do not eliminate the underlying instability. Furthermore, standard RNNs exhibit a temporal bias, where earlier inputs are transformed by the weight matrix many more times than later ones.
The SRNN Architecture
The SRNN introduces a radical update rule that ensures mathematical stability by design: $$h_t = \sigma(W_p h_{t-1} + \beta(x_t))$$
Key components include:
- Fixed Permutation ($W_p$): Instead of learning a transition matrix, SRNN uses a fixed circular shift operator. This permutation matrix is inherently orthogonal, meaning the norm of the hidden state is perfectly preserved over time, preventing gradient instability.
- Learned Input Network ($\beta$): All learning is concentrated in a sub-network $\beta(x_t)$, typically an MLP with a self-gating mechanism. This network decides which information from the current input $x_t$ should be injected into the hidden state.
- Parallelism and Efficiency: Since $\beta(x_t)$ is independent of the previous state $h_{t-1}$, the input processing for an entire sequence can be computed in parallel. Additionally, the complexity is reduced from $O(T \cdot d_h^2)$ to $O(T \cdot d_h)$, where $d_h$ is the hidden state size.
Experimental Results
The authors evaluated SRNN on several benchmarks designed to test long-term memory, including synthetic tasks like the "Adding Problem" and "Copying Memory," as well as real-world sequential vision and music modeling tasks.
As shown in the results for the Adding Problem, SRNN (blue line) converges significantly faster than LSTMs and GRUs, maintaining a low Mean Squared Error (MSE) even as sequence lengths increase to 1500.
In sequential vision tasks like Permuted MNIST (pMNIST), SRNN achieved an accuracy of 96.43%, outperforming LSTMs (89.50%) and GRUs (91.87%). On a more challenging "Big pMNIST" task (4x larger), SRNN maintained 90.31% accuracy, while LSTMs failed to learn, dropping to 33.60%.
Conclusion
By replacing learned recurrence with a fixed shuffling mechanism, Shuffling Recurrent Neural Networks provide a robust solution to the gradient problems that have long plagued RNNs. The architecture's inherent orthogonality, computational efficiency, and superior performance on long-sequence tasks make it a compelling alternative to more complex gated models.
For implementation details, the code is available at https://github.com/rotmanmi/SRNN.
Summary updated