Home

Awesome

From Quantity to Quality: Boosting LLM Performance with Self-Guided Data Selection for Instruction Tuning (NAACL'24)

From Quantity to Quality: Boosting LLM Performance with Self-Guided Data Selection for Instruction Tuning<br>(NAACL'24)<br> Chinese Version: [知乎]

<p align="center" width="40%"> <a ><img src="images/cherry.jpeg" alt="overview" style="width: 40%; min-width: 300px; display: block; margin: auto;"></a> </p>

This is the repo for the Cherry Data Selection project, which introduces a self-guided methodology for LLMs to autonomously discern and select cherry samples from vast open-source datasets, effectively minimizing manual curation and potential cost for instruction tuning an LLM.

The repo contains:

(Feel free to email Ming (Homepage, Email) for any questions or feedback.)

News

Contents

Overview

Our study puts forth a method for autonomously sifting through expansive open-source datasets to discover the most impactful training samples. We coin these samples as "cherry data", designating those data fragments that hold the potential to exponentially enhance LLM instruction tuning. At the heart of our research is the hypothesis that during their preliminary training stages with carefully chosen instruction data, LLMs can develop an intrinsic capability to discern instructions. This foundational understanding equips them with the discernment to assess the quality of broader datasets thus making it possible to estimate the instruction-following difficulty in a self-guided manner.

<p align="center" width="70%"> <a ><img src="images/method_overview.png" alt="overview" style="width: 50%; min-width: 300px; display: block; margin: auto;"></a> </p>

Initially, the model is familiarized with a fraction of the target dataset during the "Learning from Brief Experience" phase. This preliminary knowledge paves the way for the subsequent "Evaluating Based on Experience" phase, where we meticulously evaluate the model's response generation. To estimate the difficulty of a given example, we propose a novel metric called Instruction-Following Difficulty (IFD) score in which both models' capability to generate a response to a given instruction and the models' capability to generate a response directly are measured and compared. By calculating Instruction-Following Difficulty (IFD) scores, we quantify the challenge each sample presents to the model. Harnessing these insights, the "Retraining from Self-Guided Experience" phase utilizes cherry data with standout IFD scores to hone the model, culminating in our superior cherry models. The net result is a model that aligns more adeptly with instructions, ensuring enhanced performance.

Highlights

Install

Install the dependencies with pip install -r requirements.txt

Note: This requirements.txt is originated from the Stanford Alpaca. If you are using a different code base with PyTorch installed, we recommend you manually install the below packages and do not need to install from requirements.txt

pip install tqdm

pip install scikit-learn

Run Code

  1. Select Pre-Experienced Data
python cherry_seletion/data_analysis.py \
    --data_path data/alpaca_data.json \
    --save_path alpaca_data_pre.pt \
    --model_name_or_path <your_path_to_hf_converted_llama_ckpt_and_tokenizer> \
    --max_length 512 \
    --prompt alpaca \
    --mod pre

--data_path: The targeted dataset in the Alpaca format <br> --save_path: The path to save the .pt file containing embeddings or scores <br> --prompt: The prompt type used for training and selecting data, can choose between alpaca or wiz <br> --mod: pre used for getting needed embeddings or scores on selecting pre-experienced samples and cherry used for cherry <br>

python cherry_seletion/data_by_cluster.py \
    --pt_data_path alpaca_data_pre.pt \
    --json_data_path data/alpaca_data.json \
    --json_save_path alpaca_data_pre.json \
    --sample_num 10 \
    --kmeans_num_clusters 100 \
    --low_th 25 \
    --up_th 75

--pt_data_path: The .pt file from previous step containing needed embeddings or scores --json_data_path: The targeted dataset in the Alpaca format <br> --json_save_path: The path to save the selected pre-experienced samples <br> --sample_num: How many samples will be selected in each cluster <br> --kmeans_num_clusters: How many clusters will be generated by K-Means <br> --low_th and --up_th: The lower and Upper threshold for selecting samples within each cluster <br>

  1. Train Pre-Experienced Model

  2. Select Cherry Data

python cherry_seletion/data_analysis.py \
    --data_path data/alpaca_data.json \
    --save_path alpaca_data_cherry.pt \
    --model_name_or_path <your_path_pre_experienced_model> \
    --max_length 512 \
    --prompt alpaca \
    --mod cherry
python cherry_seletion/data_by_IFD.py \
    --pt_data_path alpaca_data_cherry.pt \
    --json_data_path data/alpaca_data.json \
    --json_save_path alpaca_data_cherry.json \
    --max_length 512 \
    --sample_rate 0.06 \
    --prompt alpaca

--sample_rate: How many cherry samples you would like to select? You can also use --sample_number to set the exact number of samples.

  1. Train Cherry Model

Data and Model Weights V1

llama 1 models

The following table provides a comparison between our cherry models and baseline models on the Huggingface Open LLM Leaderboard and AlpacaEval Leaderboard. <br> These results are based on cherry_data_v1. The prompt and training hyperparameters can be found in the Hyperparameters section. These results verify the effectiveness of our method, which can be used to select the most valuable data samples for instruction tuning. <br>

AvgARCHellaSwagMMLUTruthfulQAAlpacaEvalDataModel
Alpaca50.2142.6576.9141.7339.5526.46//
5% Alpaca52.0653.9279.4936.5138.3334.74[Link][hf-Link]
10% Alpaca//////[Link][hf-Link]
15% Alpaca//////[Link][hf-Link]
WizardLM54.1851.6077.7042.7044.7067.64//
WizardLM*52.7953.0777.4437.7542.9061.99[hf-Link][hf-Link]
10% WizardLM51.5952.9078.9533.0841.4161.44[Link][hf-Link]
20% WizardLM//////[Link][hf-Link]
20% WizardLM//////[Link][hf-Link]
40% WizardLM52.8353.0777.7935.2945.1765.09[Link][hf-Link]

Also, the WizardLM filter script is provided here: [Link]

llama 2 models

Thanks to the FastChat and flash-attention, we are able to run our experiments with longer length. <br> The above results are directly using cherry_data_v1 for finetuning the llama-2-7B model, with the length of 2048, and using original vicuna prompts.

AvgARCHellaSwagMMLUTruthfulQAAlpacaEvalDataModel
WizardLM57.0954.1879.2546.9248.0166.08/[Link]
10% WizardLM57.5754.8680.4645.7449.2071.36[Link][Link]
20% WizardLM//////[Link][Link]
20% WizardLM58.5055.9780.4046.8750.7672.57[Link][Link]
40% WizardLM58.0056.2380.2246.1549.3770.52[Link][Link]

Note: WizardLM in the above table is our implementation using FastChat code, prompt, and configuration. <br> Note: Due to the hardware limit, all our models are using the 7B model. <br> Note: For these llama2 models, we still use the cherry_data_v1 to ensure the effectiveness of our data. We will soon make the cherry_data_v2 which is based on llama2 available.

Data and Model Weights V2

In this section, all the IFD scores are calculated on llama2-7b or llama2-13b models by using Vicuna's prompt. The training of pre-experienced models is discarded for more efficient usage. The performances are promising in the llama2 model even without a pre-experienced model, indicating the proficiency of our proposed IFD scores.

AvgARCHellaSwagMMLUTruthfulQAAlpacaEvalDataModel
Alpaca-7b (llama2)55.2554.3578.6547.0240.9827.75//
5% Alpaca-7b (llama2)55.7857.9480.3744.9140.6236.78//
10% Alpaca-7b (llama2)56.3158.0280.4246.6440.18///
15% Alpaca-7b (llama2)56.3757.4280.6846.4040.95///
Alpaca-13b (llama2)58.7857.5981.9854.0541.4935.00//
5% Alpaca-13b (llama2)61.2162.3784.0055.6542.8246.82//
10% Alpaca-13b (llama2)61.0262.9783.8855.2941.93///
15% Alpaca-13b (llama2)61.2362.3783.4855.5643.42///

All the above models are trained using FastChat code and prompt. <br> Data with IFD scores will be released soon.

Evaluation

We release the codes and data for using GPT4 or chatGPT to evaluate and compare the performance between two LLMs. This method greatly eliminates the potential position bias of GPT4 and chatGPT. For details, please see AlpaGasus or our paper. We thank @Lichang-Chen and AlpaGasus repo for sharing the evaluation codes.

To use this code, please follow the below scripts:

bash scripts/do_eval_generation.sh: The model automatically generates the responses for a given instruction in test datasets. <br> bash scripts/do_eval_generation_wrap.sh: Wrap the response files of LLMs being compared. <br> bash scripts/do_eval.sh: Use GPT4 or chatGPT for the evaluation. <br> bash scripts/do_review_eval_score.sh: Parse the results and draw the figure. <be>

More detailed illustrations will be updated. Feel free to drop me an email if you are urgent about it.

Performance Comparison

Comparing our models trained on selected data with models trained on full data. (a) Comparison between our model with 5% Alpaca data and the official Alpaca model. (b) Comparison between our model with 10% WizardLM data and the reimplemented WizardLM model. (c) Comparison between our model with 40% WizardLM data and the official WizardLM model. All these experiments use GPT4 as the judge. Each horizontal bar represents a comparison in a specific test set.

<p align="center" width="100%"> <a ><img src="images/main_result_gpt4.png" alt="overview" style="width: 100%; min-width: 300px; display: block; margin: auto;"></a> </p>

Prompt

We used the following prompts for fine-tuning the cherry models with Alpaca data:

Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.

### Instruction:
{instruction}

### Input:
{input}

### Response:
Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Instruction:
{instruction}

### Response:

We used the following prompts for fine-tuning the cherry models with Wizard data:

{instruction}

### Response:

Hyperparameters

HyperparameterGlobal Batch SizeLearning rateEpochsMax lengthWeight decayWarmup Rate
Cherry Models V1 (Alpaca)1282e-5351200.03
Cherry Models V1 (WizardLM)1282e-53102400.03
------:---:---:---:---:---:
Cherry Models V2 7B1282e-53204800.03
Cherry Models V2 13B1281e-55204800.03

ToDo

Citation

Please consider citing our paper if you think our codes, data, or models are useful. Thank you!

@inproceedings{li-etal-2024-quantity,
    title = "From Quantity to Quality: Boosting {LLM} Performance with Self-Guided Data Selection for Instruction Tuning",
    author = "Li, Ming  and
      Zhang, Yong  and
      Li, Zhitao  and
      Chen, Jiuhai  and
      Chen, Lichang  and
      Cheng, Ning  and
      Wang, Jianzong  and
      Zhou, Tianyi  and
      Xiao, Jing",
    editor = "Duh, Kevin  and
      Gomez, Helena  and
      Bethard, Steven",
    booktitle = "Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers)",
    month = jun,
    year = "2024",
    address = "Mexico City, Mexico",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2024.naacl-long.421",
    pages = "7595--7628",
}

@inproceedings{li-etal-2024-superfiltering,
    title = "Superfiltering: Weak-to-Strong Data Filtering for Fast Instruction-Tuning",
    author = "Li, Ming  and
      Zhang, Yong  and
      He, Shwai  and
      Li, Zhitao  and
      Zhao, Hongyu  and
      Wang, Jianzong  and
      Cheng, Ning  and
      Zhou, Tianyi",
    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.769",
    pages = "14255--14273",
}

@inproceedings{li-etal-2024-selective,
    title = "Selective Reflection-Tuning: Student-Selected Data Recycling for {LLM} Instruction-Tuning",
    author = "Li, Ming  and
      Chen, Lichang  and
      Chen, Jiuhai  and
      He, Shwai  and
      Gu, Jiuxiang  and
      Zhou, Tianyi",
    editor = "Ku, Lun-Wei  and
      Martins, Andre  and
      Srikumar, Vivek",
    booktitle = "Findings of the Association for Computational Linguistics ACL 2024",
    month = aug,
    year = "2024",
    address = "Bangkok, Thailand and virtual meeting",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2024.findings-acl.958",
    pages = "16189--16211",
}

@inproceedings{li2023reflectiontuning,
  title={Reflection-Tuning: Recycling Data for Better Instruction-Tuning},
  author={Ming Li and Lichang Chen and Jiuhai Chen and Shwai He and Tianyi Zhou},
  booktitle={NeurIPS 2023 Workshop on Instruction Tuning and Instruction Following},
  year={2023},
  url={https://openreview.net/forum?id=xaqoZZqkPU}
}

Our Related Works

If you are interested in Data Selection for Instruction Tuning, please see Cherry_LLM and Superfiltering. <br> If you are interested in human/LLM-free Data Augmentation for Instruction Tuning, please see Mosaic-IT and RuleR. <br> If you are interested in Data Improvement for Instruction Tuning, please see Reflection_Tuning. <br> If you are interested in Knowledge Distillation in the LLM era, please see this Survey. <br>

Star History

Star History Chart