When comparing RNNs and Transformers, the question of whether they exhibit Markovian or non-Markovian properties requires careful examination of how they process sequential information.
RNNs and Markovian Properties
Recurrent Neural Networks (RNNs) might appear Markovian at first glance since their hidden state update mechanism only depends on:
- The current input
- The previous hidden state
This creates a recursive formula where:
h_t = f(h_{t-1}, x_t)
This recursive update seems to follow a Markovian principle, where the next state depends only on the current state and input[6]. However, this view is somewhat misleading.
Looking deeper, RNNs are actually modeling the distribution:
p(a_t|s_t, s_{t-1}, s_{t-2}, ...)
This means an RNN's output at time t technically depends on the entire history of inputs encoded within its hidden state[6]. The hidden state serves as a compressed representation of all previous inputs, making RNNs essentially non-Markovian with respect to the original input sequence.
As one explanation notes, "what they actually model is something like p(a_t|s_t, s_{t-1}, s_{t-2}, ...) and that is explicitly not Markovian because it depends on all the history instead of just the current and/or the current and the last state"[6].
Transformers and Non-Markovian Properties
Transformers are definitively non-Markovian in their approach to sequence processing. Instead of relying on recurrent connections that process data sequentially, Transformers use self-attention mechanisms that:
- Process the entire sequence in parallel
- Allow each element to directly interact with every other element in the sequence
- Compute attention scores across the entire context regardless of distance
The self-attention mechanism "quantifies the relevance of all parts of the input data to each other"[3] and "enables the model to consider the entire sequence when computing attention scores, enabling it to capture relationships between distant words"[1].
A key difference is explained well in search result [8], which provides this analogy:
"RNN: The one who vaguely remembers their kids names after a while
Transformer: The one who remembers their kids name perfectly as long as they are in sight."
Comparative Analysis
The fundamental architectural differences highlight why RNNs have characteristics that could be considered partially Markovian while Transformers are definitively non-Markovian:
| Model | Processing Style | Dependency Handling | Information Access |
|---|
| RNN | Sequential, step-by-step | Hidden state as compressed history | Indirect access to past inputs |
| Transformer | Parallel processing | Direct attention between all positions | Direct access to all input elements |
While RNNs rely on their hidden state to maintain information (creating a Markov-like update rule but with non-Markovian capabilities), Transformers explicitly model relationships between all elements regardless of their positions in the sequence[3][4].
To conclude, it's an oversimplification to say RNNs are purely Markovian - they're better described as having a Markovian update mechanism but non-Markovian capabilities. Transformers, on the other hand, are clearly non-Markovian by design.