This repository is the code base for the paper: Exploiting Primacy Effect to Improve Large Language Models.
Clone the repository and install the requirements:
git clone https://github.com/biancaraimondi/PrimacyEffect.git
cd PrimacyEffect
pip install -r requirements.txtThe preprocessed datasets can be found in the Dataset folder.
If you want to do your own preprocessing, use the src/dataset_preprocessing.ipynb file.
For the HWU dataset, you can find the relative base version here. For the BANKING dataset, you can find the relative base version here. For the CLINC dataset, you can find the relative base version here.
Use the scripts/pretrained_finetuned.sh script to test the models on the datasets comparing pre-trained and fine-tuned versions.
Insert the following informations in the script variables:
modelvariants: the list of models you want to test.datasets: the list of datasets you want to use.
./scripts/pretrained_finetuned.shThe results will be saved in the results/pretrained_finetuned folder.
Use the scripts/reordering.sh script to test our technique over the models on the same datasets used in the latter section to compare accuracy.
Insert the following informations in the script variables:
modelvariants: the list of models you want to test.reorder_labels: indicateTrueif you want to reorder the labels using our technique,Falseotherwise.descending_order: indicate1if you want to reorder the labels in descending order,0if you want to reorder the labels in ascending order.labels_query_order: indicate1if you want first the labels and then the question in the prompt,0if you want first the question and then the labels in the prompt.similarities: choose betweencosine_similarity,euclidean_distance, andmanhattan_distanceas the similarity metric you want to use for reordering the labels.datasets: the list of datasets you want to use.
./scripts/reordering.shThe results will be saved in the results/reordering folder.
Use the src/plot_pretrained_finetuned.ipynb file to create the plots for the Pre-trained vs Fine-tuned work.
Use the src/plot_reordering.ipynb file to create the plots for the Reordering work.
This repository is released under the Apache 2.0 license.
If you use this code in your research, please cite the following paper:
@misc{raimondi2025exploitingprimacyeffectimprove,
title={Exploiting Primacy Effect To Improve Large Language Models},
author={Bianca Raimondi and Maurizio Gabbrielli},
year={2025},
eprint={2507.13949},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2507.13949},
}