Poster
How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit Bias
Ruiquan Huang · Yingbin LIANG · Jing Yang
West Exhibition Hall B2-B3 #W-905
Language recognition tasks are essential tools in natural language processing (NLP), both for evaluating large language models and for understanding how they work. In this study, we take a closer look at two such tasks, namely 'even pairs' and 'parity check', which test whether certain patterns appear an even number of times in a sequence.We investigate how a one-layer transformer model can learn to solve these tasks. Through mathematical analysis, we track how the model changes as it is trained using gradient descent. We find that the training process happens in two stages. First, the attention layer quickly learns to highlight useful parts of the input. Then, the linear layer gradually learns to make the final decision, eventually drawing a clear boundary between correct and incorrect answers.Interestingly, we theoretically show that the model trained on the even pairs task can solve the parity check task through Chain-of-Thought reasoning. This reasoning can be further added during model training to enhance the power of transformers. Finally, we confirm our theoretical insights with experiments, showing that the model behaves just as our analysis predicts.
Live content is unavailable. Log in and register to view live content