Observed since 20 Oct, 19:06 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Library for running AdapativeConsistency based Inference on large language models.
Pranjal Aggarwal, Aman Madaan, Yiming Yang, Mausam
A popular approach for improving the correctness of output from large language models (LLMs) is Self-Consistency - poll the LLM multiple times and output the most frequent solution. Existing Self-Consistency techniques always draw a constant number of samples per question, where a better approach will be to non-uniformly distribute the available budget based on the amount of agreement in the samples drawn so far. In response, we introduce Adaptive-Consistency, a cost-efficient, model-agnostic technique that dynamically adjusts the number of samples per question using a lightweight stopping criterion. Our experiments over 13 datasets and two LLMs demonstrate that Adaptive-Consistency reduces sample budget by up to 6.0 times with an average accuracy drop of less than 0.1%.
This repository contains code for:
pip install AdaptiveConsistency
First, clone the repo:
git clone https://github.com/Pranjal2041/AdaptiveConsistency.git
Next install the package using:
python setup.py install
Using Adaptive Consistency in your code requires only 2-3 lines of changes in your existing framework.
from adaptive_consistency import AC, BetaStoppingCriteria
ac = AC(model, stopping_criteria=BetaStoppingCriteria(0.95), max_gens = 40)
You can directly run a whole loop of evaluation using:
ac.eval_loop(sampling_function, *args, **kwargs)
For example, if using Openai api for sampling, you can use:
import openai
ac.eval_loop(openai.Completion.create, engine="text-davinci-003", prompt="Solve the questions ahead", max_tokens=5)
Or you can check for consistency of answers at each step:
answers = []
for i in range(40):
answers.append(generate_answer_from_model()) # Example openai.Completion.create
if ac.should_stop(answers):
break
You can use one of the following Stopping Criterias:
BetaStoppingCriteria (beta): Uses the Beta Distribution to guide the stopping criteria. This is the default stopping criteria.DirichletStoppingCriteria (dirichlet): Uses the Dirichlet Distribution to guide the stopping criteria.EntropyStoppingCriteria (entropy): Uses the Entropy of the distribution to guide the stopping criteria.MajorityStoppingCriteria (majority): Uses the Majority ratio of the top element in the distribution to guide the stopping criteria.RandomStoppingCriteria (random): Randomly stops the sampling process with a pre-defined probability.CRPStoppingCriteria (crp): Uses the Chinese Restaurant Process to guide the stopping criteria.Check out the paper for more details.
Run,
bash download_data.sh
We provide the model outputs for all the models used in the paper. You can download them using:
bash download_outputs.sh
These model outputs will work for all experiments in the paper.
If you decide to skip the previous step, you can run your generations on your own. You can use the following command:
bash scripts/run_self_consistency.sh
bash scripts/run_adaptive_consistency.sh
By default, beta function will be used for stopping criteria. You can change it by passing the stopping_criteria and corresponding Confidence Threshold as arguments. For example, to use entropy stopping criteria, with a Confidence Threshold of 0.75, you can use:
bash scripts/run_adaptive_consistency.sh entropy 0.75
This step will print the final accuracy on the terminal.
You can skip Step 3, and directly run eval on the model outputs. You can use the following command:
python eval_outputs.py --output_file <path_to_output_file> --stop_criteria <stop_criteria> --stop_criteria_thresh <stop_criteria_thresh>
This will print the average generations and accuracy on the terminal.
@misc{aggarwal2023lets,
title={Let's Sample Step by Step: Adaptive-Consistency for Efficient Reasoning with LLMs},
author={Pranjal Aggarwal and Aman Madaan and Yiming Yang and Mausam},
year={2023},
eprint={2305.11860},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
Adaptive-Consistency is MIT licensed, as found in the LICENSE file.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 1.0.0 | 22 May 2023 | 0 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 19:06 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:ba25dc2cb49e25879eac338d216242b7b70b16563b7dec00c3a93e53421e67cb