This directory contains various scripts used in the xFinder project for robust and pinpoint answer extraction from LLMs.
- Operating System: Ubuntu
- Package Manager: Anaconda
- GPU: NVIDIA A100, 80GB
- Prepare the Conda Environment
conda create --name xtuner-env python=3.10 -y
conda activate xtuner-env
- Install XTuner via pip
pip install -U 'xtuner[deepspeed]'
The fine-tuning dataset for xFinder was derived by converting the training set of the KAF dataset into a format supported by xtuner. The final fine-tuning data is structured as follows:
{
"system": "You are a help assistant tasked with extracting the precise key answer from given output sentences. You must only provide the extracted key answer without including any additional text.",
"input": "I will provide you with a question, output sentences along with an answer range. The output sentences are the response of the question provided. The answer range could either describe the type of answer expected or list all possible valid answers. Using the information provided, you must accurately and precisely determine and extract the intended key answer from the output sentences. Please don't have your subjective thoughts about the question.\nFirst, you need to determine whether the content of the output sentences is relevant to the given question. If the entire output sentences are unrelated to the question (meaning the output sentences are not addressing the question), then output [No valid answer].\nOtherwise, ignore the parts of the output sentences that have no relevance to the question and then extract the key answer that matches the answer range.\nBelow are some special cases you need to be aware of: \n (1) If the output sentences present multiple different answers, carefully determine if the later provided answer is a correction or modification of a previous one. If so, extract this corrected or modified answer as the final response. Conversely, if the output sentences fluctuate between multiple answers without a clear final answer, you should output [No valid answer].\n (2) If the answer range is a list and the key answer in the output sentences is not explicitly listed among the candidate options in the answer range, also output [No valid answer].\n\nQuestion: \"\"\"Which statement correctly describes a physical characteristic of the Moon? Answer Choices: (A) The Moon is made of hot gases. (B) The Moon is covered with many craters. (C) The Moon has many bodies of liquid water. (D) The Moon has the ability to give off its own light.\"\"\"\n\nOutput sentences: \"\"\"\n\nStep 1: Analyze the question and the given options.\nThe question is asking for a physical characteristic of the Moon.\n\nStep 2: Evaluate each option.\nOption (A) states that the Moon is made of hot gases, which is not a physical characteristic.\nOption (B) states that the Moon is covered with many craters, which is a physical characteristic.\nOption (C) states that the Moon has many bodies of liquid water, which is not a physical characteristic.\nOption (D) states that the Moon has the ability to give off its own light, which is not a physical characteristic.\n\nStep 3: Choose the correct option based on the evaluation.\nThe correct option is (B) The Moon is covered with many craters.\n\nFinal Answer: B. The Moon is covered with many craters.\"\"\"\n\nAnswer range: [['D', 'The Moon has the ability to give off its own light.'], ['C', 'The Moon has many bodies of liquid water.'], ['B', 'The Moon is covered with many craters.'], ['A', 'The Moon is made of hot gases.']]\n\nKey extracted answer: ",
"output": "B"
}
The configuration files used to fine-tune different models to obtain xFinder are shown in the table below:
Use the xtuner train
command to start training.
CUDA_VISIBLE_DEVICES=0 xtuner train path/to/scripts/xtuner_config/xFinder-qwen1518_qlora.py --deepspeed deepspeed_zero2
Parameter conversion and merging after fine-tuning.
./xtuner_merge.sh -l /path/to/llm -a /path/to/adapter -m /path/to/merge/save