8000
Skip to content

Repository files navigation

CASE: Causal Alignment and Structural Enforcement for Improving Chain-of-Thought Faithfulness

Python License

Improving Chain-of-Thought faithfulness through training-time causal alignment and inference-time structural enforcement.

📖 Abstract🔬 Methodology⚙️ Installation🚀 Usage📊 Evaluation🧪 Experiments


📖 Abstract

Chain-of-Thought (CoT) reasoning may produce plausible explanations that do not faithfully support the final answer.

From a causal perspective, faithful reasoning should follow

$$ Z\rightarrow X\rightarrow Y, $$

where the instruction $Z$ influences the answer $Y$ only through the generated CoT $X$.

We propose CASE (Causal Alignment and Structural Enforcement), which combines:

  • Training-Time Causal Alignment (TCA): strengthens CoT-to-answer dependence using Mixed Training Datasets and Selective-Loss SFT.

  • Inference-Time Structural Enforcement (ISE): blocks direct attention from instruction tokens to answer tokens.

Faithfulness Metric
Figure 1: Overview of the proposed CASE framework.

Experiments on three LLMs and four reasoning benchmarks show that CASE improves overall CoT faithfulness by more than 24% on average over the strongest baselines while preserving competitive accuracy.


🔬 Methodology

1. Training-Time Causal Alignment

Dataset Name Purpose
$\mathcal{D}_A$ Standard Dataset Standard CoT and answer supervision
$\mathcal{D}_B$ Counterfactual-CoT Dataset Strengthen $X\rightarrow Y$
$\mathcal{D}_C$ Biased-Instruction Dataset Suppress $Z\rightarrow Y$ shortcuts
$\mathcal{D}_D$ Empty-Instruction Dataset Encourage prediction from the CoT alone

CASE applies Selective-Loss SFT:

  • Both CoT and answer tokens are supervised on $\mathcal{D}_A$.

  • Only answer tokens are supervised on $\mathcal{D}_B$, $\mathcal{D}_C$, and $\mathcal{D}_D$.

This objective strengthens the CoT-to-answer mechanism without forcing the model to imitate constructed auxiliary reasoning traces.

2. Inference-Time Structural Enforcement

During answer generation, CASE masks direct attention from instruction tokens to answer tokens.

The answer can still attend to the generated CoT and its computational states, preserving the mediated path

$$ Z\rightarrow X\rightarrow Y, $$

while blocking the direct shortcut $Z\rightarrow Y$.


⚙️ Installation

cd CASE
pip install -r requirements.txt

Prepare directories for datasets, models, generated data, and results:

mkdir datasets models generated_data results

🚀 Usage

1. Generate Standard CoT Data

python build_cot_answers.py \
  --dataset_path ai2_arc \
  --output_path generated_data/arc_cot.pkl \
  --deepseek_api_key YOUR_API_KEY

2. Generate Counterfactual-CoT Data

python build_counterfactual.py \
  --dataset_path ai2_arc \
  --cleaned_reasoning_path generated_data/arc_cot.pkl \
  --output_path generated_data/arc_counterfactual.pkl \
  --deepseek_api_key YOUR_API_KEY

3. Generate Biased-Instruction Data

python build_biased_questions.py \
  --dataset_path ai2_arc \
  --cleaned_reasoning_path generated_data/arc_cot.pkl \
  --output_path generated_data/arc_biased.pkl \
  --seed 42

4. Train CASE

python CASE_train.py \
  --model_path models/Llama-3.1-8B-Instruct \
  --dataset_path ai2_arc \
  --cleaned_reasoning_path generated_data/arc_cot.pkl \
  --counterfactual_path generated_data/arc_counterfactual.pkl \
  --biased_questions_path generated_data/arc_biased.pkl \
  --output_dir results/case_lora \
  --enable_stage1_answer_only_qbody_mask_data \
  --gradient_checkpointing \
  --use_4bit

5. Evaluate CASE

python CASE_test.py \
  --model_path models/Llama-3.1-8B-Instruct \
  --adapter_path results/case_lora \
  --dataset_path ai2_arc \
  --counterfactual_path generated_data/arc_counterfactual.pkl \
  --deepseek_api_key YOUR_API_KEY \
  --mask_question_on_answer \
  --use_few_shot \
  --use_4bit \
  --save_dir results/case_evaluation

📊 Evaluation

CASE uses four CoT faithfulness metrics:

Metric Description Better
Filler Tokens (FT) Replaces the CoT with filler tokens Higher
Early Answering (EA) Tests whether the model can answer before seeing the complete CoT Higher
Controlled Indirect Effect (CIE) Replaces the original CoT with a counterfactual CoT Higher
Controlled Direct Effect (CDE) Changes the instruction while keeping the CoT fixed Lower

The overall faithfulness score is

$$ \text{G-mean}_{Faith}=\sqrt[4]{FT \times EA \times CIE \times (1-CDE)}. $$

Evaluation results are saved as:

results/case_evaluation/
├── summary.json
├── predictions.pkl
├── outputs.pkl
├── questions.pkl
└── filler_predictions.pkl

🧪 Experiments

CASE is evaluated using:

  • Models Llama-3.1-8B, Qwen3-8B, and DeepSeek-R1-Distill-Qwen-7B.
  • Datasets: ARC-Easy, ARC-Challenge, StrategyQA, and LogiQA.
  • Cross-dataset settings: ARC-Challenge → OpenBookQA and StrategyQA → ARC-Easy.

CASE achieves the best $\text{G-mean}_{Faith}$ across all 12 main model-dataset settings while maintaining competitive task accuracy.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0