Skip to content

Commit fd7924f

Browse files
committed
code release
1 parent 276a361 commit fd7924f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1257
-3808
lines changed

ABOUT_THIS_TEMPLATE.md

Lines changed: 0 additions & 131 deletions
This file was deleted.

NOTICE.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

README.md

Lines changed: 30 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,115 +2,54 @@
22
<img src='logo.png' width='200'>
33
</p>
44

5-
# arxiv2025_icl_investigation
6-
[![Arxiv](https://img.shields.io/badge/Arxiv-YYMM.NNNNN-red?style=flat-square&logo=arxiv&logoColor=white)](https://put-here-your-paper.com)
7-
[![License](https://img.shields.io/github/license/UKPLab/arxiv2025-icl-investigation)](https://opensource.org/licenses/Apache-2.0)
8-
[![Python Versions](https://img.shields.io/badge/Python-3.9-blue.svg?style=flat&logo=python&logoColor=white)](https://www.python.org/)
9-
[![CI](https://github.com/UKPLab/arxiv2025-icl-investigation/actions/workflows/main.yml/badge.svg)](https://github.com/UKPLab/arxiv2025-icl-investigation/actions/workflows/main.yml)
5+
# Illusion or Algorithm?
6+
[![Arxiv](https://img.shields.io/badge/Arxiv-2505.11004-red?style=flat-square&logo=arxiv&logoColor=white)](https://arxiv.org/abs/2505.11004)
107

11-
This is the official template for new Python projects at UKP Lab. It was adapted for the needs of UKP Lab from the excellent [python-project-template](https://github.com/rochacbruno/python-project-template/) by [rochacbruno](https://github.com/rochacbruno).
8+
This repository contains the code to generate the data and results to the paper: [Illusion or Algorithm? Investigating Memorization, Emergence, and Symbolic Processing in In-Context Learning](https://arxiv.org/abs/2505.11004).
129

13-
It should help you start your project and give you continuous status updates on the development through [GitHub Actions](https://docs.github.com/en/actions).
10+
> **Abstract:** Large-scale Transformer language models (LMs) trained solely on next-token prediction with web-scale data can solve a wide range of tasks after seeing just a few examples. The mechanism behind this capability, known as in-context learning (ICL), remains both controversial and poorly understood. Some studies argue that it is merely the result of memorizing vast amounts of data, while others contend that it reflects a fundamental, symbolic algorithmic development in LMs. In this work, we introduce a suite of investigative tasks and a novel method to systematically investigate ICL by leveraging the full Pythia scaling suite, including interim checkpoints that capture progressively larger amount of training data. By carefully exploring ICL performance on downstream tasks and simultaneously conducting a mechanistic analysis of the residual stream's subspace, we demonstrate that ICL extends beyond mere "memorization" of the training corpus, yet does not amount to the implementation of an independent symbolic algorithm. Our results also clarify several aspects of ICL, including the influence of training dynamics, model capabilities, and elements of mechanistic interpretability. Overall, our work advances the understanding of ICL and its implications, offering model developers insights into potential improvements and providing AI security practitioners with a basis for more informed guidelines.
1411

15-
> **Abstract:** The study of natural language processing (NLP) has gained increasing importance in recent years, with applications ranging from machine translation to sentiment analysis. Properly managing Python projects in this domain is of paramount importance to ensure reproducibility and facilitate collaboration. The template provides a structured starting point for projects and offers continuous status updates on development through GitHub Actions. Key features include a basic setup.py file for installation, packaging, and distribution, documentation structure using mkdocs, testing structure using pytest, code linting with pylint, and entry points for executing the program with basic CLI argument parsing. Additionally, the template incorporates continuous integration using GitHub Actions with jobs to check, lint, and test the project, ensuring robustness and reliability throughout the development process.
16-
17-
Contact person: [Federico Tiblias](mailto:[email protected])
18-
19-
[UKP Lab](https://www.ukp.tu-darmstadt.de/) | [TU Darmstadt](https://www.tu-darmstadt.de/
20-
)
12+
Contact: [Jingcheng Niu](mailto:[email protected]) and [Subhabrata Dutta](mailto:[email protected])
13+
@ [UKP Lab](https://www.ukp.tu-darmstadt.de/) | [TU Darmstadt](https://www.tu-darmstadt.de/)
2114

2215
Don't hesitate to send us an e-mail or report an issue, if something is broken (and it shouldn't be) or if you have further questions.
2316

17+
## ICL Tasks
2418

25-
## Getting Started
26-
27-
> **DO NOT CLONE OR FORK**
28-
29-
If you want to set up this template:
30-
31-
1. Request a repository on UKP Lab's GitHub by following the standard procedure on the wiki. It will install the template directly. Alternatively, set it up in your personal GitHub account by clicking **[Use this template](https://github.com/rochacbruno/python-project-template/generate)**.
32-
2. Wait until the first run of CI finishes. Github Actions will commit to your new repo with a "✅ Ready to clone and code" message.
33-
3. Delete optional files:
34-
- If you don't need automatic documentation generation, you can delete folder `docs`, file `.github\workflows\docs.yml` and `mkdocs.yml`
35-
- If you don't want automatic testing, you can delete folder `tests` and file `.github\workflows\tests.yml`
36-
- If you do not wish to have a project page, delete folder `static` and files `.nojekyll`, `index.html`
37-
4. Prepare a virtual environment:
38-
```bash
39-
python -m venv .venv
40-
source .venv/bin/activate
41-
pip install .
42-
pip install -r requirements-dev.txt # Only needed for development
43-
```
44-
5. Adapt anything else (for example this file) to your project.
45-
46-
6. Read the file [ABOUT_THIS_TEMPLATE.md](ABOUT_THIS_TEMPLATE.md) for more information about development.
47-
48-
## Usage
49-
50-
### Using the classes
51-
52-
To import classes/methods of `arxiv2025_icl_investigation` from inside the package itself you can use relative imports:
53-
54-
```py
55-
from .base import BaseClass # Notice how I omit the package name
56-
57-
BaseClass().something()
58-
```
59-
60-
To import classes/methods from outside the package (e.g. when you want to use the package in some other project) you can instead refer to the package name:
61-
62-
```py
63-
from arxiv2025_icl_investigation import BaseClass # Notice how I omit the file name
64-
from arxiv2025_icl_investigation.subpackage import SubPackageClass # Here it's necessary because it's a subpackage
65-
66-
BaseClass().something()
67-
SubPackageClass().something()
68-
```
19+
We produce the results in **Sections 4–6** of our paper using the ICL tasks implemented in this code base. These tasks are designed to probe different aspects of in-context learning, such as copying, symbolic substitution, and pattern induction.
6920

70-
### Using scripts
71-
72-
This is how you can use `arxiv2025_icl_investigation` from command line:
73-
74-
```bash
75-
$ python -m arxiv2025_icl_investigation
76-
```
21+
See [`example.ipynb`](./example.ipynb) for runnable demos and usage instructions showing how we generate and evaluate these tasks across Pythia model checkpoints.
7722

78-
### Expected results
23+
## Singular Residual Stream Direction Analysis (SUDA)
7924

80-
After running the experiments, you should expect the following results:
25+
Finally, we present a mechanistic connection between the development of ICL competence and specialization in the residual stream’s subspace through Singular Unembedding Direction Analysis (SUDA).
8126

82-
(Feel free to describe your expected results here...)
27+
SUDA is a diagnostic method that projects the residual stream onto the singular vectors of the unembedding matrix, allowing us to trace how models allocate subspace as they learn to perform in-context learning. Specifically, we:
8328

84-
### Parameter description
29+
1. Compute a singular value decomposition of the unembedding matrix: $SVD(W_U) = UST^\top$.
30+
2. Project the residual stream activations onto individual directions in $V$.
31+
3. Measure the task-relevant signal captured by each direction by evaluating how well the model performs when using only a subset of directions.
8532

86-
* `x, --xxxx`: This parameter does something nice
33+
Across a diverse set of ICL tasks, we observe that while the performance trajectories vary (some tasks improve steadily, others show late or abrupt development) the underlying trend of internal structural formation in the residual stream remains consistent. This suggests that models consistently learn to specialize subspaces in a task-relevant way as training progresses.
8734

88-
* ...
89-
90-
* `z, --zzzz`: This parameter does something even nicer
91-
92-
## Development
93-
94-
Read the FAQs in [ABOUT_THIS_TEMPLATE.md](ABOUT_THIS_TEMPLATE.md) to learn more about how this template works and where you should put your classes & methods. Make sure you've correctly installed `requirements-dev.txt` dependencies
35+
The implementation is available at [`icl_analysis/suda.py`](icl_analysis/suda.py).
9536

9637
## Cite
9738

9839
Please use the following citation:
9940

10041
```
101-
@InProceedings{smith:20xx:CONFERENCE_TITLE,
102-
author = {Smith, John},
103-
title = {My Paper Title},
104-
booktitle = {Proceedings of the 20XX Conference on XXXX},
105-
month = mmm,
106-
year = {20xx},
107-
address = {Gotham City, USA},
108-
publisher = {Association for XXX},
109-
pages = {XXXX--XXXX},
110-
url = {http://xxxx.xxx}
42+
@misc{niu2025illusionalgorithminvestigatingmemorization,
43+
title={Illusion or Algorithm? Investigating Memorization, Emergence, and Symbolic Processing in In-Context Learning},
44+
author={Jingcheng Niu and
45+
Subhabrata Dutta and
46+
Ahmed Elshabrawy and
47+
Harish Tayyar Madabushi and
48+
Iryna Gurevych},
49+
year={2025},
50+
eprint={2505.11004},
51+
archivePrefix={arXiv},
52+
primaryClass={cs.CL},
53+
url={https://arxiv.org/abs/2505.11004},
11154
}
112-
```
113-
114-
## Disclaimer
115-
116-
> This repository contains experimental software and is published for the sole purpose of giving additional background details on the respective publication.
55+
```

arxiv2025_icl_investigation/__init__.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

arxiv2025_icl_investigation/__main__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

arxiv2025_icl_investigation/base.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)