/POSIX

POSIX: A Prompt Sensitivity Index for Language Models

Primary LanguagePythonMIT LicenseMIT


            

PrOmpt Sensitivity IndeX

(Companion Software for our EMNLP 2024 Paper)

GitHub GitHub Stars GitHub Forks

About POSIX

POSIX is a simple and easy-to-use Python Library to evaluate prompt sensitivity of Language Models.

Installation

The simplest way to install POSIX is via pip:

pip install prompt-sensitivity-index

You can also install POSIX from source:

git clone https://github.com/kowndinya-renduchintala/POSIX.git
cd POSIX
pip install .

Example Usage

from prompt_sensitivity_index.models import HFModel
from prompt_sensitivity_index.posix import (
    PosixConfig, 
    PosixTrace, 
    get_prompt_sensitivity, 
    write_trace_to_json
)

intent_aligned_prompts=[
    [
        "Q: What is the capital of France?\nA: ",
        "Q: WHat is te capital city of France?\nA: ",
        "Q: what is teh cpital of france??\nA: "
    ],
    [
        "Q: What is the national animal of India?\nA: ",
        "Q: What's the national animl of India?\nA: ",
        "Q: WHat is teh national animal of India?\nA: "
    ],
    [
        "Q: Tell me the meaning of rendezvous?\nA: ",
        "Q: WHat is the meaning of rendezvous?\nA: ",
        "Q: What does rendezvous mean?\nA: "
    ]
]
model=HFModel("openai-community/gpt2")
config=PosixConfig(max_new_tokens=5, batched=False)
posix, trace=get_prompt_sensitivity(model, intent_aligned_prompts, config, verbose=True)
print(f"Prompt Sensitivity Index: {posix}")
write_trace_to_json(trace, "posix_trace.json")

How does POSIX work?

Preliminaries

Definition-1 (Intent-Aligned Prompts) Any two prompts $x_1$ and $x_2$ are said to be intent-aligned despite variations in their wording or template or inclusion of minor spelling errors, if they are designed to elicit responses from a language model based on the same underlying goal, intent or meaning.

Definition-2 (Intent-Aligned Prompt Set) A set of prompts $\boldsymbol{X}=\{x_i\}_{i=1}^{N}$ is said to be an intent-aligned prompt set if and only if for all $1\le i\ne j\le 1$, $x_i\in\boldsymbol{X}$ and $x_j\in\boldsymbol{X}$ are intent-aligned.

Defining PrOmpt Sensitivity IndeX ($\texttt{POSIX}$)

Definition-3 (Prompt Sensitivity) Let $\boldsymbol{X}=\{x_i\}_{i=1}^{N}$ be an intent-aligned prompt set and $\boldsymbol{Y}= \{y_i\}_{i=1}^{N}$ be the corresponding responses generated by a language model $\mathcal{M}$, i.e., $y_i$ is the response generated by $\mathcal{M}$ when prompted using $x_i$. The prompt sensitivity of $\mathcal{M}$ on $\boldsymbol{X}$ is defined as

$$\psi_{\mathcal{M}, \boldsymbol{X}}=\frac{1}{N(N-1)}\sum_{i=1}^{N}\sum_{j=1}^{N}\frac{1}{L_{y_j}}\left|\log\frac{\mathbb{P}_{\mathcal{M}}(y_j\mid x_i)}{\mathbb{P}_{\mathcal{M}}(y_j\mid x_j)}\right|$$

where $N$ is the cardinality of $\boldsymbol{X}$, $L_{y_i}$ is the number of tokens in $y_i$, $\mathbb{P}_{\mathcal{M}}(y_j\mid x_i)$ is the probability of generating $y_j$ when prompted using $x_i$ and $\mathbb{P}_{\mathcal{M}}(y_j\mid x_j)$ is the probability of generating $y_j$ when prompted using $x_j$.

Definition-4 ($\texttt{POSIX}$) Given a language model $\mathcal{M}$ and a dataset $\mathcal{D}=\{\boldsymbol{X}_i\}_{i=1}^{M}$ intent-aligned prompt sets ($\boldsymbol{X}_i$ 's), the PrOmpt Sensitivity IndeX ($\texttt{POSIX}$) for the language model $\mathcal{M}$ on the dataset $\mathcal{D}$ is defined as

$$\texttt{POSIX}_{\mathcal{D},\mathcal{M}}=\frac{1}{M}\sum_{i=1}^{M}\psi_{\mathcal{M}, \boldsymbol{X}_i}$$

Data

Please download the intent-aligned prompts used in our experiments from here.

Citation

If you use POSIX in your research, please cite our EMNLP 2024 paper 😊 -

POSIX: A Prompt Sensitivity Index For Large Language Models (Chatterjee et al., Findings 2024)

@inproceedings{chatterjee-etal-2024-posix,
    title = "{POSIX}: A Prompt Sensitivity Index For Large Language Models",
    author = "Chatterjee, Anwoy  and
      Renduchintala, H S V N S Kowndinya  and
      Bhatia, Sumit  and
      Chakraborty, Tanmoy",
    editor = "Al-Onaizan, Yaser  and
      Bansal, Mohit  and
      Chen, Yun-Nung",
    booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2024",
    month = nov,
    year = "2024",
    address = "Miami, Florida, USA",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2024.findings-emnlp.852",
    pages = "14550--14565",
    abstract = "Despite their remarkable capabilities, Large Language Models (LLMs) are found to be surprisingly sensitive to minor variations in prompts, often generating significantly divergent outputs in response to minor variations in the prompts, such as spelling errors, alteration of wording or the prompt template. However, while assessing the quality of an LLM, the focus often tends to be solely on its performance on downstream tasks, while very little to no attention is paid to prompt sensitivity. To fill this gap, we propose POSIX {--} a novel PrOmpt Sensitivity IndeX as a reliable measure of prompt sensitivity, thereby offering a more comprehensive evaluation of LLM performance. The key idea behind POSIX is to capture the relative change in loglikelihood of a given response upon replacing the corresponding prompt with a different intent-preserving prompt. We provide thorough empirical evidence demonstrating the efficacy of POSIX in capturing prompt sensitivity and subsequently use it to measure and thereby compare prompt sensitivity of various open source LLMs. We find that merely increasing the parameter count or instruction tuning does not necessarily reduce prompt sensitivity whereas adding some few-shot exemplars, even just one, almost always leads to significant decrease in prompt sensitivity. We also find that alterations to prompt template lead to the highest sensitivity in the case of MCQ type tasks, whereas paraphrasing results in the highest sensitivity in open-ended generation tasks. The code for reproducing our results is open-sourced at https://github.com/kowndinya-renduchintala/POSIX.",
}

License

POSIX is licensed under the MIT License. See LICENSE for more information.