Wanfq/Explore_Instruct_Rewriting_32k
收藏数据集概述
Explore-Instruct 是一种增强特定领域指令覆盖率的新方法。该方法假设领域空间本质上类似于树状结构,借鉴经典搜索算法的精髓并结合大型语言模型(LLMs)的能力,主动遍历领域空间并生成指令调优数据,无需预定义的树结构。具体操作包括:
- 前瞻:深入探索多个潜在的细粒度子任务,从而绘制出复杂的任务网络。
- 回溯:寻找替代分支以扩大搜索边界,从而扩展领域范围。
数据发布
Explore-Instruct 数据集在 brainstorming、rewriting 和 math 领域发布于 🤗 Huggingface Datasets。每个领域包含两个版本的数据集:基础版和扩展版。基础版包含 10k 指令调优数据,扩展版包含 16k、32k 和 64k 指令调优数据。每个数据集是 JSON 格式的结构化文件,包含以下字段:
instruction:str, 描述模型应执行的任务。input:str, 任务的可选上下文或输入。output:str, 任务和输入文本的地面真实输出文本。
模型发布
Explore-LM 模型在 brainstorming、rewriting 和 math 领域发布于 🤗 Huggingface Models。每个领域包含两个版本的模型:基础版和扩展版,分别使用相应版本的数据集进行训练。
数据生成过程
生成领域特定指令调优数据的步骤如下:
领域空间探索
bash python3 generate_instruction.py --action extend --save_dir ./en_data/demo_domain --out_dir ./en_data/demo_domain_exploration --lang en --domain demo_domain --extend_nums <TASK_NUMBER_DEPTH_0>,...,<TASK_NUMBER_DEPTH_MAX_DEPTH-1> --max_depth <MAX_DEPTH> --assistant_name openai
指令调优数据生成
bash python3 generate_instruction.py --action enrich --save_dir ./en_data/demo_domain_exploration --out_dir ./en_data/demo_domain_generation --lang en --domain demo_domain --enrich_nums <DATA_NUMBER_DEPTH_0>,...,<DATA_NUMBER_DEPTH_MAX_DEPTH> --enrich_batch_size <BATCH_SIZE> --assistant_name openai
任务修剪
bash python3 generate_instruction.py --action prune --save_dir ./en_data/demo_domain_generation --out_dir ./en_data/demo_domain_pruning --lang en --domain demo_domain --pruned_file ./en_data/demo_domain_pruning/pruned_subtasks_name.json --prune_threshold <PRUNE_THRESHOLD> --assistant_name openai
数据过滤
bash python3 generate_instruction.py --action filter --save_dir ./en_data/demo_domain_pruning --out_dir ./en_data/demo_domain_filtering --lang en --domain demo_domain --pruned_file ./en_data/demo_domain_pruning/pruned_subtasks_name.json --filter_threshold <FILTER_THRESHOLD> --assistant_name openai
数据采样
bash python3 generate_instruction.py --action sample --save_dir ./en_data/demo_domain_filtering --out_dir ./en_data/demo_domain_sampling --lang en --domain demo_domain --pruned_file ./en_data/demo_domain_filtering/pruned_subtasks_name.json --sample_example_num <SAMPLE_EXAMPLES_NUM> --sample_max_depth <SAMPLE_MAX_DEPTH> --sample_use_pruned --assistant_name openai
微调
使用以下超参数对 LLaMA-7B 进行微调:
| 超参数 | 全局批量大小 | 学习率 | 轮数 | 最大长度 | 权重衰减 |
|---|---|---|---|---|---|
| LLaMA 7B | 128 | 2e-5 | 3 | 512 | 0 |
微调命令如下: bash deepspeed --num_gpus=8 ./train/train.py --deepspeed ./deepspeed_config/deepspeed_zero3_offload_config.json --model_name_or_path decapoda-research/llama-7b-hf --data_path ./en_data/demo_domain_sampling --fp16 True --output_dir ./training_results/explore-lm-7b-demo-domain --num_train_epochs 3 --per_device_train_batch_size 2 --per_device_eval_batch_size 2 --gradient_accumulation_steps 8 --evaluation_strategy "no" --model_max_length 512 --save_strategy "steps" --save_steps 2000 --save_total_limit 1 --learning_rate 2e-5 --weight_decay 0. --warmup_ratio 0.03 --lr_scheduler_type "cosine" --logging_steps 1 --prompt_type alpaca 2>&1 | tee ./training_logs/explore-lm-7b-demo-domain.log
python3 ./train/zero_to_fp32.py --checkpoint_dir ./training_results/explore-lm-7b-demo-domain --output_file ./training_results/explore-lm-7b-demo-domain/pytorch_model.bin
评估
不同领域的评估数据集如下:
- Brainstorming 和 Rewriting:来自 BELLE 翻译测试集的相应类别。
- Math:从 MATH 测试集中随机选择的 500 个问题。
评估指标如下:
- Brainstorming 和 Rewriting:自动和人工评估遵循 Vicuna。
- Math:解决数学问题的准确率。
自动评估命令如下:
Brainstorming 和 Rewriting 领域
bash
1. 推理
python3 ./eval/generate.py --model_id <MODEL_ID> --model_path <MODEL_PATH> --question_file ./eval/question/en_eval_set.jsonl --answer_file ./eval/answer/<MODEL_ID>.jsonl --num_gpus 8 --num_beams 1 --temperature 0.7 --max_new_tokens 512 --prompt_type alpaca --do_sample
2. 评估
python3 ./eval/chatgpt_score.py --baseline_file ./eval/answer/<MODEL_1>.jsonl --answer_file ./eval/answer/<MODEL_2>.jsonl --review_file ./eval/review/<MODEL_1>cp<MODEL_2>_<DOMAIN>.jsonl --prompt_file ./eval/prompt/en_review_prompt_compare.jsonl --target_classes <DOMAIN> --batch_size <BATCH_SIZE> --review_model "gpt-3.5-turbo-0301"
Math 领域
bash
1. 推理
python3 ./eval/generate.py --model_id <MODEL_ID> --model_path <MODEL_PATH> --question_file ./eval/question/MATH_eval_set_sample.jsonl --answer_file ./eval/answer/<MODEL_ID>.jsonl --num_gpus 8 --num_beams 10 --temperature 1.0 --max_new_tokens 512 --prompt_type alpaca
2. 评估
python3 ./eval/auto_eval.py --question_file ./eval/question/MATH_eval_set_sample.jsonl --answer_file ./eval/answer/<MODEL_ID>.jsonl
限制
Explore-Instruct 仍在开发中,需要大量改进。该工作主要关注增强特定领域指令覆盖率,未涉及其他方面,如生成复杂和挑战性指令或减轻有毒和有害指令。未来工作需要探索这些领域。
许可证
Explore-Instruct 仅用于研究目的,数据集和模型训练结果仅允许非商业使用。
引用
如果您的工作与本研究相关,请引用:
@misc{wan2023explore, title={Explore-Instruct: Enhancing Domain-Specific Instruction Coverage through Active Exploration}, author={Fanqi, Wan and Xinting, Huang and Tao, Yang and Xiaojun, Quan and Wei, Bi and Shuming, Shi}, year={2023}, eprint={2310.09168}, archivePrefix={arXiv}, primaryClass={cs.CL} }



