This repository releases the core pipeline of Answer Divergence-Guided Selection (ADG) for instruction data selection. ADG scores each instruction by the geometric structure of multiple sampled answers, rather than relying on a single reference response. In the paper, ADG consistently improves instruction tuning under a fixed 10K budget across two backbones, three public instruction pools, and six benchmarks spanning reasoning, knowledge, and coding. The method combines dispersion magnitude and shape anisotropy, then performs bin-wise selection for semantic coverage.
🌟 Overview
Instruction tuning quality depends heavily on which examples are selected under a fixed data budget. ADG addresses this by examining how a base model responds to the same instruction under stochastic decoding.
For each instruction, ADG:
samples multiple answers with relatively high-temperature decoding,
maps answers into a representation space,
computes geometry-aware scores from the sampled answers,
ranks examples by the combined score,
performs proportional selection within semantic bins.
This repository provides the practical pipeline for:
multi-sample answer generation,
instruction embedding and clustering,
ADG scoring and subset selection,
model training,
benchmark evaluation,
optional task-type analysis.
Use this model ,you need clone follow repository
git clone https://github.com/WisdomShell/ADG.git
📦 What Is Released
This repository includes the following components:
Core selection code
ADG/ADG_llama.py
ADG scoring and selection for the LLaMA backbone.
ADG/ADG_qwen.py
ADG scoring and selection for the Qwen backbone.
Answer generation and instruction embedding
generation/generation.py
Generates multiple sampled answers for each instruction.
generation/embedding/embed.py
Builds instruction embeddings and performs clustering for bin-wise selection.
Training and evaluation
train/train_llama.sh
Training entry script for LLaMA.
train/train_qwen.sh
Training entry script for Qwen.
train/training/stanford_alpaca/
Training utilities and backbone-specific training scripts.
eval/eval.sh
Evaluation script based on lm-evaluation-harness.
Analysis
analysis/analyse.py
Optional task-type classification script for analyzing selected data.
Environment
requirements.txt
Required Python packages for this repository.
Depending on your environment, you may also need to install GPU-specific packages separately.
🧾 Data Format
ADG expects instruction datasets in JSON or JSONL format. Each example should follow the schema below:
json
1{2"id":0,3"instruction":"Write a short explanation of transformers.",4"input":"",5"output":"Transformers are neural networks based on self-attention..."6}
Notes:
id should uniquely identify each example.
instruction is required.
input is optional and can be empty or omitted.
output is the reference response in the original instruction dataset.
Other instruction datasets can be used as long as they are converted into this format.
After answer generation, the intermediate JSONL file contains records like:
json
1{2"id":0,3"instruction":"Write a short explanation of transformers.",4"output":"Transformers are neural networks based on self-attention...",5"generated_answers":[6"...",7"...",8"...",9"...",10"..."11]12}
Then configure MODEL_PATH and output paths in eval/eval.sh, and run:
bash
1cdeval2bash eval.sh
The evaluation script currently includes:
BBH
GSM8K
MMLU
TruthfulQA
MBPP
HumanEval
📊 ADG Scoring Intuition
ADG is built around two complementary signals derived from multiple sampled answers:
Dispersion magnitude
Measures how widely the sampled answers spread in representation space.
Shape anisotropy
Measures whether the spread is multi-directional rather than dominated by a single direction.
The final ADG score combines these two parts, and the selected subset is obtained through semantic bin-wise ranking. This design helps avoid collapsing selection into only a few dense instruction regions.
🛠️ Script Notes
generation/generation.py
Main functionality:
load the base model,
sample multiple answers for each instruction,
save generated answers in JSONL format,
support distributed generation.
generation/embedding/embed.py
Main functionality:
build instruction embeddings,
run clustering,
save instruction embeddings and cluster labels,
provide the semantic bins used by ADG selection.
ADG/ADG_llama.py
Main functionality:
read the generated-answer JSONL file,
compute answer-geometry metrics,
combine metrics into the ADG score,
perform proportional cluster-based selection,
save top.json, middle.json, and bottom.json.
ADG/ADG_qwen.py
Main functionality:
compute ADG metrics for Qwen-generated answers,
support checkpoint-based resumption,
perform the same top / middle / bottom selection pipeline.
analysis/analyse.py
Main functionality:
classify instructions into coarse task categories,
support optional data-level analysis of selected subsets.
train/train_llama.sh and train/train_qwen.sh
Main functionality:
launch distributed full fine-tuning,
use the selected subset for instruction tuning.
eval/eval.sh
Main functionality:
run benchmark evaluation with lm-evaluation-harness,
support reasoning, knowledge, and coding tasks.
❓ Common Issues
1. Path configuration is not updated
Most scripts use placeholder paths. Update all required paths before running.
2. Inconsistent model and intermediate files
Make sure the generation backbone, embedding backbone, ADG scoring script, and training script are aligned.
3. Missing intermediate files
The selector depends on:
generated answer JSONL,
instruction embeddings,
clustering results.
Run the previous stages before starting ADG selection.
4. GPU memory pressure
Generation, embedding, and scoring all use hidden-state-based processing. You may need to reduce batch size or adjust GPU allocation depending on your hardware.
5. Evaluation dependency is not installed
eval/eval.sh depends on lm-evaluation-harness. Install it separately before running evaluation.
📖 Citation
If you use this repository, please cite the paper.