Humans and language models diverge when predicting repeating text (2023)

Abstract: Language models that are trained on the next-word prediction task have been shown to accurately model human behavior in word prediction and reading speed. In contrast with these findings, we present a scenario in which the performance of humans and LMs diverges. We collected a dataset of human next-word predictions for five stimuli that are formed by repeating spans of text. Human and GPT-2 LM predictions are strongly aligned in the first presentation of a text span, but their performance quickly diverges when memory (or in-context learning) begins to play a role. We traced the cause of this divergence to specific attention heads in a middle layer. Adding a power-law recency bias to these attention heads yielded a model that performs much more similarly to humans. We hope that this scenario will spur future work in bringing LMs closer to human behavior.

## introduction transformer-based language models (lms) are neural networks that are trained to predict upcoming words from their preceding context. these models flexibly retrieve and combine information across a context that might span thousands of words, enabling them to learn from in-context examples @xcite @xcite , tell coherent stories @xcite , and perform many other advanced language tasks @xcite . these abilities far surpass any previous computational models or linguistic theories @xcite , leading many to use lms as models of human cognition. for example, lm surprisal-a measure of how well it can predict the next word-has been found to be highly correlated with both how long humans spend reading each word @xcite @xcite and the accuracy of human next-word predictions @xcite . these results suggest that lms and humans might be using similar mechanisms to structure and recall information from memory. however, these seeming parallels have not gone unchallenged. @xcite , for example, showed that lm surprisal and human reading time become decorrelated as models grow in size and power, suggesting a more superficial relationship than previously thought. in this work we test whether apparent similarities between lm and human next-word prediction accuracy reflect true similarities in memory mechanisms. to accomplish this we introduce a new task that combines memory with next-word prediction using repeating natural text stimuli. comparing human behavioral performance with an lm, we found that lm surprisal decorrelates from human predictions in this scenario. while human performance improves modestly with each repetition, the transformer-based lm gpt-2 @xcite reaches near-perfect performance after just one presentation. to better understand this behavior, we examined the patterns of memory access (via attention) in the model, revealing how the model solves this task. we then showed that the model can be made to perform more like the humans by adjusting these patterns to mimic human memory @xcite . this work demonstrates an important way in which human and lm memory mechanisms diverge, casting doubt on the use of existing lms as a model of human cognition. however, the framework we developed for making the model more human-like also provides a potential way forward. directly optimizing lms for human-like behaviorincluding but not limited to memory tasks like that used here-could lead to much better computational models of human cognition and memory. it is also possible that investigating the relationship between human and model memory could provide guidance for developing better, more efficient neural network models. ## related works human performance on recall tasks, like the experiment we propose here, is primarily limited by shortterm memory @xcite . in these tasks, humans show both recency biases (i.e. better recall for the most recent items) and primacy biases (better for the first items) @xcite . recall tasks often show repetition effects; presenting a stimulus multiple times successively decreases the recall error rate @xcite @xcite . some have suggested a link between language deficits and the number of presentations needed to reach perfect verbatim sentence recall @xcite . many studies have also shown that human memory decay follows a power law @xcite , where, for example, the number of items accurately recalled from a list will decrease over time t proportional to t -d for some constant decay rate d. transformers neural networks, in contrast with humans, can attend to exact token identities hundreds or thousands of tokens in the past at no additional cost, subject only to the context length. one limitation of the standard attention implementation is that memory and runtime scale quadratically with the number of tokens, making longer inputs prohibitively expensive. recently, significant work has gone into extending the maximum context length for transformers while avoiding these computational issues. transformer-xl caches hidden states to allow attention to tokens beyond the immediate input @xcite . flashattention is an optimized attention algorithm that exploits the hardware architecture to train models with context lengths up to 64k tokens @xcite . the alibi method @xcite replaces sinusoidal positional embeddings with a recency bias on the attention scores, such that closer query-key pairs are weighted higher than more distant pairs. using alibi necessitates retraining a model with the new attention mechanism, though once trained it can generalize to longer lengths. ## human behavioral study we first designed an experiment to evaluate human memory in a next-word prediction task with repeated word sequences. we then compared the humans against an lm on the same stimuli to evaluate the lm's memory. ## behavioral study results figure 2a shows human performance on one text span; as they are shown more words, human accuracy generally increases. many stop words are predicted well even during the first presentation, while non-stop words improve more linearly with the number of presentations. humans consistently improve as they are shown more presentations of the same text span, as seen in figure 2b . while the model accuracy is similar to humans on the first presentation, it quickly jumps to a much higher level thereafter. a more detailed view appears in figure 2c , where we show accuracy for both model and human on each probe word. gpt-2 accuracy is strongly correlated with human accuracy for the initial presentation of this span (@xmath0.87), replicating earlier findings @xcite . however, model and human accuracies markedly diverge thereafter, with the correlation dropping to @xmath1.24 in the second presentation and @xmath2.05 in the third. these results provide a potent counterexample to previous claims of alignment: humans and lms only seem to behave similarly in the initial presentation of a stimulus, but produce uncorrelated behavior once short-term memory comes into play. this suggests that the model and humans are exploiting very different memory mechanisms to solve this task. the humans must rely on lossy short-term memory, while the model can leverage in-context learning to provide super-human, near-perfect recall. while earlier reports suggested that such detailed recall might mimic human working memory @xcite , these results suggest that the models go well beyond human capabilities. ## patterns in model attention our behavioral results show that human and lm next-word prediction diverge sharply when shortterm memory is involved, suggesting that the two systems use substantially different memory mechanisms. to gain insight into the cause of these differences, we next sought to understand how exactly the model was able to achieve such high performance on this task. "memory" in transformer models is implemented by using dot-product attention over previous words. each of the 12 layers in this model contains 12 attention heads, each of which looks for specific features in the content or location of previous words. the action of each attention head can be summarized in an attention matrix, a, which shows how much attention token i is paying to token j for all @xmath3. attention weights are normalized so that each row a i of the attention matrix sums to 1. the values in the attention matrix can thus show us how and where the model is "recalling" past information. previous work on simplified transformer models has identified the emergence of specific attention heads that recognize patterns in the input and produce outputs that complete those patterns @xcite . these induction heads specifically attend to the token after the previous presentation of the current (input) token, essentially allowing the model to read out the completion from a previous instance of the same pattern. for inputs that are constructed from repeating sequences-like those used in our behavioral experiment-induction heads should thus produce a highly stereotypical attention matrix: if a stimulus consists of repeating spans of length k, the head attends to the token k -1 tokens in the past. we examined the attention matrices of gpt-2 small for our stimuli and found multiple heads across many layers that exhibit induction behavior. figure 3a depicts example attention matrices for four heads in layer 6. while attention values are non-negative and sum to 1 in each row, we use log-scaled values here to highlight subtle effects. for this test the stimulus consisted of three presentations of a 65-word span, so an induction head should attend to the word appearing 64 positions ago, which is exactly the word that the model should output at each point. this should manifest as strong diagonals in the attention matrix. this is exactly the pattern that we see for attention heads 1 and 2. further, when processing tokens in the third presentation, these heads attend to previous instances in both of the first two presentations (64 and 129 tokens in the past). to illustrate that this pattern is not found everywhere in the model, we also show two other attention heads (3 and 4) from the same layer, which exhibit no induction-like behavior, but instead attend to recent words. to more efficiently find induction-like behavior in the model, we can summarize how well the attention matrix for each head matches a few different patterns. for each layer, we quantified the average probability mass attributable to the heads attending to: figure 3b shows the probability mass given to each attention pattern in each layer, averaged across all 12 heads. we see that the induction attention pattern arises sharply and specifically in layer 6 and continues through the output layer (layer 12). these results suggest that these layers-and especially layer 6-have a causal role in copying words from previous repetitions of the text span, and thus may be the source of the divergence in human-lm accuracy. in the next section, we test this hypothesis by selectively disrupting each layer in an attempt to make the model more human-like. ## attention optimization our previous results showed that human and lm next-word prediction accuracy diverge when shortterm memory comes into play, suggesting that human and model memory mechanisms behave very differently. we then showed this divergence might be caused by the model's induction heads, which we hypothesized enable it to identify and recall patterns with superhuman accuracy. we next asked if it is possible to modify the model so that its memory behaves more like the human. because the lm is superhuman, such a modification will selectively hurt the lm's performance. since memory in this model is implemented through attention, we approached this problem by modifying the attention matrices of the model. we learn an additive bias b h for the attention matrix of each head h in one layer such that adding this bias to the pre-softmax attention weights will produce outputs that are more human-like. namely, we modify the attention mechanism in the model to be each stimulus consists of an s-token span presented r times, for a total stimulus length @xmath4. human and model top-1 accuracy for prompted word i is denoted p human (correct i ) and p model (correct i ), respectively, and n i is the number of participants that responded to that prompt. let b @xmath5, and @xmath6. we optimize over {b 1 , . . . , b h } to minimize the mean squared error (mse) between p human (correct) and p model (correct), weighted by the number of subjects who responded to each prompt (n i ). w is the number of words that were prompted for at least one subject. what form should b h take? the model is superhuman in its long-distance memory, so we sought to reduce the impact of long-distance attention by giving the model a recency bias. much earlier work has shown that human memory tends to decay as a power law with time @xcite . a similar form of decay is also seen in mutual information between words as a function of their separation @xcite , and this has been previously exploited in designing efficient language models @xcite . to capture this type of behavior, we parameterized b h with α h , β @xmath7: ## conclusions despite widely published results showing that human and lm prediction performance is comparable, we have found a scenario wherein humans and gpt-2 show a substantial divergence. by examining the model's attention maps for non-initial presentations, we identify specific attention heads and layers that attend across presentation boundaries to copy the next token. we finally demonstrate a procedure that augments these heads' attention maps with a recency bias, disrupting their copying behavior. the intervention reliably improves human-lm similarity across held-out stimuli in later presentations, at the cost of increased perplexity. with the behavioral data we collected, we have used an lm to build an explicit model of human memory. our findings here show that human memory has a stronger recency bias than gpt-2, and in the future we hope to use this model to learn more about human memory. additionally, it suggests that attending over long distances may result in diminishing returns-an alternate form of attention may be able to exploit this phenomenon for increased efficiency. further work must be done to describe the change in model states during repeated presentations of a stimulus. characterizing this experiment as a test of in-context learning (icl), we may be able to exploit recent work @xcite that suggests icl is analogous to finetuning model weights.