Eye Gaze and Self-attention: How Humans and Transformers Attend Words in Sentences (2022)

Abstract: Attention describes cognitive processes that are important to many human phenomena including reading. The term is also used to describe the way in which transformer neural networks perform natural language processing. While attention appears to be very different under these two contexts, this paper presents an analysis of the correlations between transformer attention and overt human attention during reading tasks. An extensive analysis of human eye tracking datasets showed that the dwell times of human eye movements were strongly correlated with the attention patterns occurring in the early layers of pre-trained transformers such as BERT. Additionally, the strength of a correlation was not related to the number of parameters within a transformer. This suggests that something about the transformers’ architecture determined how closely the two measures were correlated.

## introduction attention is a process that is associated with both reading in humans and with natural language processing (nlp) by state-of-the-art deep neural networks (dnn) @xcite . in both cases, it is the words within a sentence that are attended to during processing. in dnns, attention results from mechanisms built into the network. specifically, in the current state-of-the-art method transformers @xcite , this attention process is the result of the dot product of two vectors that represent individual words in the text. for humans, attention processes are more complex as they can be broken into overt and covert attention @xcite . overt attention is characterized by observable physical movements of which eye gaze is a well known example that is relevant to reading @xcite . covert attention, on the other hand, is characterized by mental shifts in focus and, * email: josh.bensemann@auckland.ac.nz therefore, not directly observable. for this study we have focused on the overt attention measure of eye gaze, with words at the center of an eye fixation being the words that we assume were being attended. while attention in human reading processes and transformers appear to be completely different, this paper will present an analysis showing the relationship between the two foot_0 . specifically, attention in well-known transformers such as bert @xcite , and its derivatives are closely related to humans' eye fixations during reading. we observed strong to moderate strength correlations between the dwell times of eyes over words and the self-attention in transformers such as bert. we have explored some reasons for these different correlation levels and speculated on others. this analysis is part of an ongoing research line where we attempt to overcome attention limits in transformers. when using transformers, both memory and computational requirements grow quadratically as the sequence length increases because every token attends to all other tokens. in previous work, we have used the attention mechanisms of pre-trained transformers as attention filters that can reduce a sequence length for a sentiment analysis task by 99% while still maintaining 70% accuracy @xcite . our motivation for this paper was to explore the possibility of using models of eye gaze as an alternative filter. strong correlations between the attentions produced by transformers and the overt attention of humans would suggest that models of eye movements could potentially be used in computationally inexpensive methods for approximating transformer attention. alternatively we could use eye movements to train transformer attention towards overt attention patterns foot_1 . ## related work there have been attempts to combine dnns with eye data to perform various tasks. some basic tasks include predicting how an eye will move across presented stimuli, whether text-based @xcite or images in general @xcite @xcite @xcite . these predictions can be used to create saliency maps that show what areas of a visual display are attractive to the eye. in turn, saliency maps can be used to either understand biological visual processes or be incorporated as meta-data into machine learning models. the later endeavor has led to some improvements in task performance. in a recent example, @xcite achieved state-of-the-art results in a text compression task by creating a text saliency model (tsm) using a bilstm network that outputs embeddings into transformer self-attention layers. the tsm was pre-trained on synthetic data simulated by the e-z reader model @xcite and fine-tuned on human eye-tracking data. the model's output was used to neuromodulate @xcite a task-specific model via multiplicative attention. eye gaze data itself can be used to inspire new ways for neural networks to perform nlp tasks @xcite . for example, it is well known that the human eye does not fixate on every word during reading @xcite . nevertheless, humans, until recently, performed well above machines in many nlp tasks @xcite . these observations imply that the word skipping process is not detrimental to reading tasks. some researchers have exploited this process by explicitly training their models to ignore words @xcite @xcite . for example, @xcite trained lstm models to predict the number of words to skip while performing sentiment analysis and found that the model could skip several words at a time and still be as accurate, if not more accurate, than the non-skipping models. additionally, @xcite showed that the skipping processes could be modelled using actual eye movements and achieve the same result. these word skipping models exploit overt attention only, and it would be interesting to know what happens if skipping was modelled on covert attention instead. other research exploring the relationship between dnns and human data has examined how closely the metrics used to measure eye movement are related to metrics used for machine language models. studies of this type require identifying comparable processes between the two different systems and a suitable dataset. for example, @xcite compared model perplexity to psycholinguistic features. there have even been comparisons of dnn attention to what humans attend to during reading tasks. @xcite compared the attention of humans during a sentiment analysis task to rnn models. crowdsourced workers were asked to rate sentiments of yelp reviews and then highlight the important words for their decision-making process. they found correlations between the rnn outputs and human behavior. the strength of these correlations diminished as the length of the text increased. closely related to our study is the work of @xcite who attempted to compare eye gaze to the attention mechanisms of three different neural network architectures. one of the models was the bert-based transformer, xlnet @xcite . the other two networks were bespoke cnn and lstm models. all models were trained on the movieqa dataset @xcite , and attention values were taken from the later levels of the networks. several questions for the original dataset were selected for human testing, where the participants' eye gazes were tracked while they read and answered the questions. @xcite observed that the attention scores from both the cnn and lstm networks had strong negative correlations with the eye data. however, there was no significant correlation between eye gaze and xlnet. finally, there has been recent work using transformer representations to predict brain activity. for example, @xcite used layer representations of different transformers, including bert and transformer-xl, to predict activation in areas of the brain. they found that the middle layers best predict the activation as the context (sequence length) grew. @xcite tentatively suggested that this means there is a relationship between the layer and the type of processing occurring. to their surprise, they also found that modifying lower levels of bert to produce uniform attention improved prediction performance. @xcite performed a similar analysis using many of the models included in the present study. they found that the output of some transformers could be used to predict their participants brain behavior to almost perfect accuracy. prediction performance differed by model size and training regime, with gpt-2 performing best @xcite . surprisingly, @xcite found that untrained models also produced above chance prediction, leading them to suggest that the architecture of transformers captures important features of language before training occurs. ## analysis of self-attention against eye gaze all analyses used huggingface's @xcite version of the transformer and associated tokenizer. the models' weights were identical to those downloaded from huggingface; no fine-tuning was conducted. all analyses report spearman correlations @xcite to avoid data normality issues and provide a direct comparison to previously reported work. ## conclusion this paper analyzed the correlations between attention in pre-trained transformers and human attention derived from eye gaze. we found correlations between the two that were generally stronger in the earlier layers of the model and, in most cases, strongest in the first layer. these correlations were unaffected by the model's size, as different sized variants of models produced similar correlations. the training the models received did appear to matter, although the present study cannot determine the full extent of that relationship. we found that correlations were weaker from eye-tracking studies where the participants could actively guide their reading towards seeking the information they needed than when presented with questions after reading. while we found a relationship between overt human attention and attention in some pretrained transformers, additional research would be required before models of eye gaze could be used to replace attention in transformers.