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.
Listening to the Wise Few: Query-Key Alignment Unlocks Latent Correct Answers in Large Language Models
Skolkovo Institute of Science and Technology(斯科尔科沃科学技术研究院);AI Foundation and Algorithm Lab(人工智能基金会与算法实验室);Moscow Institute of Physics and Technology(莫斯科物理技术学院);Artificial Intelligence Research Institute (AIRI)(人工智能研究院);CNRS(法国国家科学研究中心);Université Paris Cité(巴黎西岱大学)
Autonomy-of-Heads: Data-Free Sparse Attention from Frozen Query-Key Geometry
Institute of Computing Technology, Chinese Academy of Sciences(中国科学院计算技术研究所);University of Chinese Academy of Sciences(中国科学院大学);Beijing University of Posts and Telecommunications(北京邮电大学);Baidu Inc.(百度公司)
TrackList: Tracing Back Query Linguistic Diversity for Head and Tail Knowledge in Open Large Language Models
ATILF, University of Lorraine - CNRS, France(ATILF,洛林大学 - CNRS,法国);Center for Data Science in Humanities, Chosun University, South Korea(人文数据科学中心,全州大学,韩国)
Query-focused and Memory-aware Reranker for Long Context Processing
Institute of Information Engineering, Chinese Academy of Sciences(中国科学院信息工程研究所);School of Cyber Security, University of Chinese Academy of Sciences(中国科学院大学网络安全学院);Pattern Recognition Center, WeChat AI, Tencent(腾讯微信人工智能研究院模式识别中心);East China Normal University(华东师范大学)
Quantifying Logical Consistency in Transformers via Query-Key Alignment
Skolkovo Institute of Science and Technology(斯科尔科沃科学技术研究所);Moscow Institute of Physics and Technology(莫斯科物理技术学院);CNRS(法国国家科学研究中心);Université Paris Cité(巴黎西岱大学);Artificial Intelligence Research Institute (AIRI)(人工智能研究所(AIRI))
DHA: Learning Decoupled-Head Attention from Transformer Checkpoints via Adaptive Heads Fusion
Institute of Information Engineering, Chinese Academy of Sciences(中国科学院信息工程研究所);School of Cyber Security, University of Chinese Academy of Sciences(中国科学院大学网络空间安全学院);Baidu Inc.(百度公司)
RecurFormer: Not All Transformer Heads Need Self-Attention
Nanyang Technological University(南洋理工大学);The University of New South Wales(新南威尔士大学);Shanghai Jiao Tong University(上海交通大学);The College of William and Mary(威廉玛丽学院)
LongHeads: Multi-Head Attention is Secretly a Long Context Processor
School of Computer Science, Fudan University(复旦大学计算机科学学院);Institute of Modern Languages and Linguistics, Fudan University(复旦大学现代语言与语言学研究所);International Human Phenome Institutes, Shanghai, China(国际人类表型组研究院(上海))