Skip to content

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

ChemReason-Bench

ChemReason-Bench is a chemistry reasoning benchmark and training/inference toolkit for multi-task evaluation on experimental procedure understanding.

This upload package includes:

  • benchmark test prompts and answers
  • SFT and RL training data
  • training code for SFT and GRPO
  • local and API-based prediction scripts
  • evaluation code and metric configuration

Repository Layout

ChemReason_Bench_Upload/
├── .gitignore
├── DATA_LICENSE
├── LICENSE
├── README.md
├── requirements.txt
├── benchmark_data/
│   ├── answers.jsonl
│   └── prompts.jsonl
├── chemreason/
│   ├── __init__.py
│   ├── config.py
│   ├── data_rl.py
│   ├── data_sft.py
│   ├── grpo_unified.py
│   ├── main.py
│   ├── modeling.py
│   ├── rewards.py
│   ├── sft_unified.py
│   ├── trainer_grpo.py
│   └── trainer_sft.py
├── config/
│   ├── ds_zero3_bf16.json
│   └── train_chemreason.yaml
├── eval/
│   ├── eval.py
│   └── eval_config.yaml
├── predict/
│   ├── predict.py
│   ├── predict_claude_api.py
│   ├── predict_ds_api.py
│   ├── predict_grpo.py
│   └── predict_qwen_api.py
├── train_data/
│   ├── rl_dev.jsonl
│   ├── rl_train.jsonl
│   ├── sft_dev.jsonl
│   └── sft_train.jsonl

Tasks

The benchmark contains six task types:

  • ordering
  • step_validation
  • condition_validation
  • step_completion
  • contrastive_choice
  • rationalization

Benchmark test inputs are stored in benchmark_data/prompts.jsonl, and reference answers are stored in benchmark_data/answers.jsonl.

Training data is stored in train_data/.

Installation

Use Python 3.10+.

pip install -r requirements.txt

If you plan to train with GPUs, install a torch build that matches your CUDA environment.

Training

The main training entry point is chemreason/main.py.

Example commands from the repository root:

python -m chemreason.main --config config/train_chemreason.yaml --mode sft
python -m chemreason.main --config config/train_chemreason.yaml --mode grpo
python -m chemreason.main --config config/train_chemreason.yaml --mode sft_grpo

The default training config is config/train_chemreason.yaml.

Important notes:

  • model.base_model_name and model.tokenizer_name should point to a valid Hugging Face model name or local path.
  • Training data paths in the config are relative to the repository root.
  • resume_from_checkpoint is null by default and should be set explicitly only when resuming.

Useful CLI overrides:

python -m chemreason.main \
  --config config/train_chemreason.yaml \
  --mode sft \
  --output-dir outputs/chemreason_demo \
  --set model.base_model_name=Qwen/Qwen2.5-7B-Instruct \
  --set model.tokenizer_name=Qwen/Qwen2.5-7B-Instruct

Local Prediction

Base model or SFT adapter

Use predict/predict.py:

python predict/predict.py \
  --prompts benchmark_data/prompts.jsonl \
  --out outputs/predictions.jsonl \
  --base_model Qwen/Qwen2.5-7B-Instruct \
  --adapter /path/to/sft_adapter \
  --device cuda \
  --dtype bf16 \
  --prompt_style json \
  --probs_mode lm \
  --binary_mode lm

Key options:

  • --prompt_style {json,sft} selects JSON-only prompting or SFT-style prompting.
  • --probs_mode lm is recommended for contrastive_choice if you want comparable log-loss style probabilities.
  • --binary_mode lm is recommended for binary tasks if you want score-based metrics such as Brier, ECE, AUROC, and AUPRC.

SFT + GRPO stacked adapters

Use predict/predict_grpo.py:

python predict/predict_grpo.py \
  --prompts benchmark_data/prompts.jsonl \
  --out outputs/predictions_grpo.jsonl \
  --base_model Qwen/Qwen2.5-7B-Instruct \
  --adapter_sft /path/to/sft_adapter \
  --adapter_grpo /path/to/grpo_adapter \
  --device cuda \
  --dtype bf16 \
  --probs_mode lm \
  --binary_mode lm

API-Based Prediction

The repository also includes API-based inference scripts:

  • predict/predict_qwen_api.py
  • predict/predict_ds_api.py
  • predict/predict_claude_api.py

These scripts expect an API key either through CLI flags or environment variables such as:

  • DASHSCOPE_API_KEY
  • QWEN_API_KEY
  • DEEPSEEK_API_KEY
  • OPENAI_API_KEY
  • ANTHROPIC_API_KEY

Example:

python predict/predict_claude_api.py \
  --prompts benchmark_data/prompts.jsonl \
  --out outputs/predictions_claude.jsonl \
  --base_model claude-sonnet-4-20250514 \
  --prompt_style json

Evaluation

Use eval/eval.py with eval/eval_config.yaml:

python eval/eval.py \
  --pred outputs/predictions.jsonl \
  --gt benchmark_data/answers.jsonl \
  --config eval/eval_config.yaml \
  --out outputs/report.json

The evaluation report includes:

  • per-task metrics
  • macro-style overall metrics
  • segmented results for benchmark IDs 1-400, 401-500, and overall

Note on unit normalization:

  • eval.py contains a built-in default unit normalization map.
  • The CLI supports --ucum /path/to/ucum_map.yaml if you want to override it.
  • The current evaluator does not automatically read tasks.step_completion.unit_system.ucum_map from eval_config.yaml; only --ucum affects the external map path.

Data Format

All benchmark and training files use JSONL.

Typical fields include:

  • task_id
  • task_type
  • context
  • question
  • legend
  • task-specific fields such as steps_to_order, options, ground_truth, and prediction

Prediction files should contain one JSON object per line with:

  • task_id
  • task_type
  • prediction

Reproducibility Notes

  • Run commands from the repository root so relative paths resolve correctly.
  • Check model availability and tokenizer compatibility before training or inference.
  • bert-score is required for the full rationalization evaluation path.
  • GPU memory requirements depend strongly on the base model, sequence length, and batch size.

License

The source code, documentation, and configuration files in this repository are licensed under the Apache License 2.0. See LICENSE.

The benchmark and training data under benchmark_data/ and train_data/ are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). See DATA_LICENSE.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages