SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2402.02969 · 2024

Towards Understanding the Word Sensitivity of Attention Layers: A Study via Random Features

arXiv · PDF · Open in the Atlas

Code that ran

We lifted 7 functions out of this paper's own repositories and ran 7 of them in a sandbox. "Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results.

RepositoryRoleRan
simone-bombari/attention-sensitivity canonical 7 of 7
FunctionStatusWhere it lives
attention_numpy_softmax Ran simone-bombari/attention-sensitivity/utils.py
pointer only (licence: NONE) · get_code("a41e0cab211ab570")
attention_softmax Ran simone-bombari/attention-sensitivity/utils.py
pointer only (licence: NONE) · get_code("6fe6d09e0eb26318")
create_imdb_dataset Ran simone-bombari/attention-sensitivity/utils_data.py
pointer only (licence: NONE) · get_code("cb5ef018c4158aba")
generate_embeddings Ran simone-bombari/attention-sensitivity/utils_data.py
pointer only (licence: NONE) · get_code("b21faea335185419")
import_in_df_adversarial Ran simone-bombari/attention-sensitivity/utils_plot.py
pointer only (licence: NONE) · get_code("87f4cc1f23b67d74")
import_in_df_sensitivity_rf Ran simone-bombari/attention-sensitivity/utils_plot.py
pointer only (licence: NONE) · get_code("22cbe841b6aefe93")
relu Ran simone-bombari/attention-sensitivity/utils.py
pointer only (licence: NONE) · get_code("9d27f9aa50a86a4b")

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Understanding the reasons behind the exceptional success of transformers requires a better analysis of why attention layers are suitable for NLP tasks. In particular, such tasks require predictive models to capture contextual meaning which often depends on one or few words, even if the sentence is long. Our work studies this key property, dubbed word sensitivity (WS), in the prototypical setting of random features. We show that attention layers enjoy high WS, namely, there exists a vector in the space of embeddings that largely perturbs the random attention features map. The argument critically exploits the role of the softmax in the attention layer, highlighting its benefit compared to other activations (e.g., ReLU). In contrast, the WS of standard random features is of order $1/\sqrt{n}$, $n$ being the number of words in the textual sample, and thus it decays with the length of the context. We then translate these results on the word sensitivity into generalization bounds: due to their low WS, random features provably cannot learn to distinguish between two sentences that differ only in a single word; in contrast, due to their high WS, random attention features have higher generalization capabilities. We validate our theoretical results with experimental evidence over the BERT-Base word embeddings of the imdb review dataset.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2402.02969")
get_code_for_paper("2402.02969")
have("2402.02969")

Connect an agent — have() is free.