https://github.com/cyberagentailab/x2-icl

[ACL 2025] Code for "Exploring Explanations Improves the Robustness of In-Context Learning"

https://github.com/cyberagentailab/x2-icl

Science Score: 39.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.0%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

[ACL 2025] Code for "Exploring Explanations Improves the Robustness of In-Context Learning"

Basic Info
  • Host: GitHub
  • Owner: CyberAgentAILab
  • License: mit
  • Language: Shell
  • Default Branch: main
  • Homepage:
  • Size: 171 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

Exploring Explanations Improves the Robustness of In-Context Learning

This repository implements the main experiments of our ACL 2025 paper, Exploring Explanations Improves the Robustness of In-Context Learning. In our paper, we introduce an advanced ICL framework, X^2-ICL, which systematically explores explanations for all possible labels during inference. This approach enables more comprehensive and robust decision-making, especially when faced with out-of-distribution data.

The code is intended solely for reproducing the experiments. It is based on the X-ICL repository, and we gratefully acknowledge the authors of that work.

Environment

We tested the code in the following environment.

  • OS: Ubuntu 22.04.3 LTS
  • Python: 3.12
  • CUDA: 12.2
  • GPU: NVIDIA A100 (40GB)

Setup

Python and Packages

We used uv to manage Python and its packages. ```bash git clone https://github.com/CyberAgentAILab/x2-icl.git cd x2-icl

(Optional) If this version of Python is not installed

uv python pin 3.12 uv python install

PyTorch needs to be installed separately

uv venv --python 3.12 --python-preference managed uv pip install --no-cache --force-reinstall -r requirements.txt uv pip install --no-cache --force-reinstall torch==2.5.1 --index-url https://download.pytorch.org/whl/cu121 ```

API Keys

The code assumes that the API keys are stored as environment variables. Fill in the .envrc file and load it.

```bash cp .envrc_example .envrc

Fill in the .envrc file with your API keys

If you are using direnv

direnv allow

Otherwise

source .envrc ```

Data

Download the test data from the repository of X-ICL and place them under data/testset. bash git clone https://github.com/xlhex/acl2024_xicl.git cp -r acl2024_xicl/data/testset ./data rm -rf acl2024_xicl

The demonstration files under data/prompt are named as follows: * xx.txt: Demonstrations for vanilla ICL. xx corresponds to one of {anli_v1, esnli_no, qqp_no}. * xx_one_reason.txt: Demonstrations for X-ICL. _no omitted. * xx_all_reason.txt: Demonstrations for our X^2-ICL. _no omitted.

Run

Below are sample commands for running the experiments. See script for more examples.

NOTE: * We used Azure OpenAI API for GPT-4o. * We used the specific version gpt-4o-2024-08-06, and the code assumes that the deployment name is the same. - If you want to use a different deployment name, modify model_libs in code/utils_api.py. * We set the content filters to the least restrictive setting.

```bash MODEL="gpt-4o-2024-08-06" TASK="ANLI" TEST="data/testset/anliv3hard.jsonl" SEED=1000

Vanilla ICL

uv run code/rungpt.py \ --modelname $MODEL \ --trainfile data/prompt/anli/seed$SEED/anliv1.txt \ --test_file $TEST \ --task $TASK \ --seed $SEED

X-ICL

uv run code/rungpt.py \ --modelname $MODEL \ --trainfile data/prompt/anli/seed$SEED/anliv1onereason.txt \ --test_file $TEST \ --task $TASK \ --seed $SEED

X^2-ICL

uv run code/rungpt.py \ --modelname $MODEL \ --trainfile data/prompt/anli/seed$SEED/anliv1allreason.txt \ --test_file $TEST \ --task $TASK \ --seed $SEED ```

Citation

```bibtex @inproceedings{honda-oka-2025-exploring, title = "Exploring Explanations Improves the Robustness of In-Context Learning", author = "Honda, Ukyo and Oka, Tatsushi", editor = "Che, Wanxiang and Nabende, Joyce and Shutova, Ekaterina and Pilehvar, Mohammad Taher", booktitle = "Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)", month = jul, year = "2025", address = "Vienna, Austria", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2025.acl-long.1155/", doi = "10.18653/v1/2025.acl-long.1155", pages = "23693--23714", ISBN = "979-8-89176-251-0", }

@inproceedings{he-etal-2024-using, title = "Using Natural Language Explanations to Improve Robustness of In-context Learning", author = "He, Xuanli and Wu, Yuxiang and Camburu, Oana-Maria and Minervini, Pasquale and Stenetorp, Pontus", editor = "Ku, Lun-Wei and Martins, Andre and Srikumar, Vivek", booktitle = "Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)", month = aug, year = "2024", address = "Bangkok, Thailand", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2024.acl-long.728/", doi = "10.18653/v1/2024.acl-long.728", pages = "13477--13499", } ```

Owner

  • Name: CyberAgent AI Lab
  • Login: CyberAgentAILab
  • Kind: organization
  • Location: Japan

GitHub Events

Total
  • Push event: 1
  • Public event: 1
Last Year
  • Push event: 1
  • Public event: 1

Dependencies

requirements.txt pypi
  • accelerate ==1.2.1
  • annotated-types ==0.7.0
  • anyio ==4.9.0
  • bitsandbytes ==0.45.0
  • cachetools ==5.5.2
  • certifi ==2025.4.26
  • charset-normalizer ==3.4.2
  • distro ==1.9.0
  • filelock ==3.18.0
  • fsspec ==2025.5.1
  • google-ai-generativelanguage ==0.6.15
  • google-api-core ==2.24.2
  • google-api-python-client ==2.170.0
  • google-auth ==2.40.2
  • google-auth-httplib2 ==0.2.0
  • google-generativeai ==0.8.4
  • googleapis-common-protos ==1.70.0
  • grpcio ==1.67.1
  • grpcio-status ==1.67.1
  • h11 ==0.16.0
  • hf-xet ==1.1.2
  • httpcore ==1.0.9
  • httplib2 ==0.22.0
  • httpx ==0.28.1
  • huggingface-hub ==0.32.0
  • idna ==3.10
  • jinja2 ==3.1.6
  • jiter ==0.10.0
  • markupsafe ==3.0.2
  • mpmath ==1.3.0
  • networkx ==3.4.2
  • numpy ==2.2.2
  • openai ==1.58.1
  • packaging ==25.0
  • proto-plus ==1.26.1
  • protobuf ==5.29.4
  • psutil ==7.0.0
  • pyasn1 ==0.6.1
  • pyasn1-modules ==0.4.2
  • pydantic ==2.11.5
  • pydantic-core ==2.33.2
  • pyparsing ==3.2.3
  • pyyaml ==6.0.2
  • regex ==2024.11.6
  • requests ==2.32.3
  • rsa ==4.9.1
  • safetensors ==0.5.3
  • scipy ==1.15.1
  • setuptools ==80.8.0
  • sniffio ==1.3.1
  • sympy ==1.13.1
  • tiktoken ==0.9.0
  • tokenizers ==0.21.1
  • tqdm ==4.67.1
  • transformers ==4.48.0
  • triton ==3.1.0
  • typing-extensions ==4.13.2
  • typing-inspection ==0.4.1
  • uritemplate ==4.1.1
  • urllib3 ==2.4.0