Transformer-based Causal Language Models Perform Clustering

Xinbo Wu, Lav R. Varshney


Abstract
Even though large language models (LLMs) have demonstrated remarkable capability in solving various natural language tasks, the capability of an LLM to follow human instructions is still an area of active development. Recent works (Ouyang et al., 2022; Rafailov et al., 2023; Zhang et al., 2023) have shown great improvements in instruction-following capability through additional training for instruction-following tasks. However, the mechanisms responsible for effective instruction-following capabilities remain inadequately understood. Here, we introduce a simplified instruction-following task and use synthetic datasets to analyze a Transformer-based causal language model. Our findings suggest that the model learns task-specific information by clustering data within its hidden space, with this clustering process evolving dynamically during learning. We also demonstrate how this phenomenon assists the model in handling unseen instances, and validate our results in a more realistic setting. We further present applications in pre-training and alignment, inspired by clustering.
Anthology ID:
2025.findings-naacl.296
Volume:
Findings of the Association for Computational Linguistics: NAACL 2025
Month:
April
Year:
2025
Address:
Albuquerque, New Mexico
Editors:
Luis Chiruzzo, Alan Ritter, Lu Wang
Venue:
Findings
SIG:
Publisher:
Association for Computational Linguistics
Note:
Pages:
5347–5372
Language:
URL:
https://preview.aclanthology.org/Ingest-2025-COMPUTEL/2025.findings-naacl.296/
DOI:
Bibkey:
Cite (ACL):
Xinbo Wu and Lav R. Varshney. 2025. Transformer-based Causal Language Models Perform Clustering. In Findings of the Association for Computational Linguistics: NAACL 2025, pages 5347–5372, Albuquerque, New Mexico. Association for Computational Linguistics.
Cite (Informal):
Transformer-based Causal Language Models Perform Clustering (Wu & Varshney, Findings 2025)
Copy Citation:
PDF:
https://preview.aclanthology.org/Ingest-2025-COMPUTEL/2025.findings-naacl.296.pdf