paper-with-me

Papers

How do Large Language Models Learn In-Context? Query and Key Matrices of In-Context Heads are Two Towers for Metric Learning

2024-02-05 · Zeping Yu, Sophia Ananiadou

We investigate the mechanism of in-context learning (ICL) on sentence classification tasks with semantically-unrelated labels ("foo"/"bar"). We find intervening in only 1\% heads (named "in-context heads") significantly affects ICL accuracy from 87.6\% to 24.4\%. To understand this phenomenon, we analyze the value-output vectors in these heads and discover that the vectors at each label position contain substantial information about the corresponding labels. Furthermore, we observe that the prediction shift from "foo" to "bar" is due to the respective reduction and increase in these heads' attention scores at "foo" and "bar" positions. Therefore, we propose a hypothesis for ICL: in in-context heads, the value-output matrices extract label features, while the query-key matrices compute the similarity between the features at the last position and those at each label position. The query and key matrices can be considered as two towers that learn the similarity metric between the last position's features and each demonstration at label positions. Using this hypothesis, we explain the majority label bias and recency bias in ICL and propose two methods to reduce these biases by 22\% and 17\%, respectively.

📄 PDF Abstract BibTeX arXiv:2402.02872

Code (2)

zepingyu0512/in-context-mechanism 공식 구현 pytorch
zepingyu0512/neuron-attribution pytorch

Tasks

In-Context LearningMetric LearningPositionSentenceSentence Classification

Similar Papers 제목 키워드 기반

SMART-RAG: Selection using Determinantal Matrices for Augmented Retrieval

2024-09-21 · Jiatao Li, Xinyu Hu, Xiaojun Wan

Retrieval-Augmented Generation (RAG) has greatly improved large language models (LLMs) by enabling them to generate accurate, contextually grounded responses through the integration of external information. However, conv…

DiversityPoint ProcessesQuestion AnsweringRAG+2

Semantic Faithfulness and Entropy Production Measures to Tame Your LLM Demons and Manage Hallucinations

2025-12-04 · Igor Halperin arxiv

Evaluating faithfulness of Large Language Models (LLMs) to a given task is a complex challenge. We propose two new unsupervised metrics for faithfulness evaluation using insights from information theory and thermodynamic…

Answer Generation

Efficient Low Rank Attention for Long-Context Inference in Large Language Models

2025-10-25 · Tenghui Li, Guoxu Zhou, Xuyang Zhao, Yuning Qiu 외 arxiv

As the length of input text increases, the key-value (KV) cache in LLMs imposes prohibitive GPU memory costs and limits long-context inference on resource constrained devices. Existing approaches, such as KV quantization…

Clustering in Causal Attention Masking

2024-11-07 · Nikita Karagodin, Yury Polyanskiy, Philippe Rigollet

This work presents a modification of the self-attention dynamics proposed by Geshkovski et al. (arXiv:2312.10794) to better reflect the practically relevant, causally masked attention used in transformer architectures fo…

Clustering

Implicit Regularization of Gradient Flow on One-Layer Softmax Attention

2024-03-13 · Heejune Sheen, Siyu Chen, Tianhao Wang, Harrison H. Zhou

We study gradient flow on the exponential loss for a classification problem with a one-layer softmax attention model, where the key and query weight matrices are trained separately. Under a separability assumption on the…