Understanding the Failure Modes of Transformers through the Lens of Graph Neural Networks