Official implementation for NeurIPS 2025 paper "SemCoT: Accelerating Chain-of-Thought Reasoning through Semantically-Aligned Implicit Tokens"
Python
22
20 commits
updated Nov 7, 2025
Official PyTorch implementation of the NeurIPS 2025 paper: "SemCoT: Accelerating Chain-of-Thought Reasoning through Semantically-Aligned Implicit Tokens" View Paper (PDF)
SemCoT is a novel framework that accelerates Chain-of-Thought (CoT) reasoning in Large Language Models (LLMs) by replacing verbose explicit reasoning with compact, semantically-aligned implicit tokens. Unlike existing methods, SemCoT jointly optimizes both token-level generation speed and semantic alignment with ground-truth reasoning.
# Clone the repository
git clone https://github.com/YinhanHe123/SemCoT.git
cd SemCoT
# Install dependencies
pip install -r requirements.txt
transformers==4.57.0
peft==0.17.1
datasets==4.0.0
tensorboardX==2.6.2.2
First, generate the reasoning pairs dataset:
python main.py \
--mode generate_data \
--dataset gsm8k \
--config small \
--device 0
Note: You'll need to add your OpenAI API key in data/gpt4pair.py:
def __init__(self, model_name: str = "gpt-4o-mini", api_key: str = "your-api-key-here"):
python main.py \
--mode semcot \
--dataset gsm8k \
--config small \
--use_best_params \
--num_exps 3 \
--device 0
python main.py \
--mode baseline \
--baseline pause \
--dataset gsm8k \
--config small \
--num_exps 3 \
--device 0
SemCoT supports five reasoning datasets:
Datasets are automatically downloaded and preprocessed on first use.
Three LLM configurations are available:
| Config | Teacher Model | Student Model | Use Case |
|---|---|---|---|
small | Llama-2-7B | Sheared-LLaMA-1.3B | Default |
mistral | Mistral-7B | mistral-1.1b | Alternative |
qwen | Qwen2.5-7B | Qwen2.5-0.5B | Experimental |
--mode: Operation mode (semcot, baseline, generate_data)--config: Model configuration (small, mistral, qwen)--dataset: Dataset name (gsm8k, svamp, multiarith, commonsense_qa, coin_flip)--baseline: Baseline method (pause, icot_si, codi, softcot, coconut)--device: GPU device ID--num_exps: Number of experimental runs (default: 3)--use_best_params: Use pre-tuned hyperparametersSentence Transformer:
--st_linear_lr: Linear layer learning rate (default: 1e-4)--st_linear_wd: Linear layer weight decay (default: 1e-3)--st_linear_epochs: Linear layer epochs (default: 7)--st_llm_lr: LLM learning rate (default: 1e-7)--st_llm_wd: LLM weight decay (default: 1e-5)--st_llm_epochs: LLM epochs (default: 3)Contemplation Generator:
--cg_linear_lr: Linear layer learning rate (default: 1e-4)--cg_linear_wd: Linear layer weight decay (default: 1e-3)--cg_linear_epochs: Linear layer epochs (default: 7)--cg_llm_lr: LLM learning rate (default: 1e-7)--cg_llm_wd: LLM weight decay (default: 1e-5)--cg_llm_epochs: LLM epochs (default: 3)--alpha: Balance between semantic alignment and answer accuracy (default: 0)--train_max_contemp_tokens: Number of implicit tokens during training (default: 5)--eval_max_contemp_tokens: Number of implicit tokens during evaluation (default: 1)--batch_size: Training batch size (default: 4)--seed: Random seed (default: 42)SemCoT includes several ablation variants:
# Without sentence transformer
python main.py --mode semcot --variation no_sentence_transformer
# Without semantic alignment loss
python main.py --mode semcot --variation no_l_reason
# Without warmup training
python main.py --mode semcot --variation no_warmup
# Using full LLM instead of lightweight model
python main.py --mode semcot --variation no_small_contemp_gen
Results are saved in results/{mode}/{variation}/{config}/{dataset}/:
{
"numerical_accuracy": 0.983,
"ave_sample_time": 1.02,
"dataset": "gsm8k",
"eval_temp": 0.7,
"exp_num": 0
}
SemCoT/
├── data/ # Dataset handling
│ ├── cot_datasets.py # Dataset loaders
│ └── gpt4pair.py # GPT-4 reasoning generation
├── models/ # Model implementations
│ ├── semcot.py # SemCoT components
│ ├── pause.py # Baseline: Pause tokens
│ ├── icot_si.py # Baseline: ICoT-SI
│ ├── codi.py # Baseline: CODI
│ ├── softcot.py # Baseline: SoftCoT
│ └── coconut.py # Baseline: COCONUT
├── training/ # Training scripts
│ ├── train_semcot.py # SemCoT training
│ └── train_*.py # Baseline training
├── utils/ # Utilities
│ ├── logging.py # TensorBoard logging
│ └── utils.py # Helper functions
├── main.py # Main entry point
└── requirements.txt # Dependencies
If you find this work useful, please cite our paper:
@inproceedings{he2025semcot,
title={SemCoT: Accelerating Chain-of-Thought Reasoning through Semantically-Aligned Implicit Tokens},
author={He, Yinhan and Zheng, Wendy and Zhu, Yaochen and Zheng, Zaiyi and Su, Lin and Vasudevan, Sriram and Guo, Qi and Hong, Liangjie and Li, Jundong},
booktitle={39th Conference on Neural Information Processing Systems (NeurIPS 2025)},
year={2025}
}
This project is licensed under the MIT License - see the LICENSE file for details.
The models used in this project have their own licenses:
Please ensure compliance with the respective model licenses when using this code.
This work was supported by the National Science Foundation (NSF), Office of Naval Research (ONR), and Commonwealth Cyber Initiative (CCI). We thank the authors of the baseline methods for their open-source implementations.
For questions or issues, please open an issue on GitHub or contact:
Official implementation for NeurIPS 2025 paper "SemCoT: Accelerating Chain-of-Thought Reasoning through Semantically-Aligned Implicit Tokens"
Python
22
20 commits
updated Nov 7, 2025
Official PyTorch implementation of the NeurIPS 2025 paper: "SemCoT: Accelerating Chain-of-Thought Reasoning through Semantically-Aligned Implicit Tokens" View Paper (PDF)
SemCoT is a novel framework that accelerates Chain-of-Thought (CoT) reasoning in Large Language Models (LLMs) by replacing verbose explicit reasoning with compact, semantically-aligned implicit tokens. Unlike existing methods, SemCoT jointly optimizes both token-level generation speed and semantic alignment with ground-truth reasoning.
# Clone the repository
git clone https://github.com/YinhanHe123/SemCoT.git
cd SemCoT
# Install dependencies
pip install -r requirements.txt
transformers==4.57.0
peft==0.17.1
datasets==4.0.0
tensorboardX==2.6.2.2
First, generate the reasoning pairs dataset:
python main.py \
--mode generate_data \
--dataset gsm8k \
--config small \
--device 0
Note: You'll need to add your OpenAI API key in data/gpt4pair.py:
def __init__(self, model_name: str = "gpt-4o-mini", api_key: str = "your-api-key-here"):
python main.py \
--mode semcot \
--dataset gsm8k \
--config small \
--use_best_params \
--num_exps 3 \
--device 0
python main.py \
--mode baseline \
--baseline pause \
--dataset gsm8k \
--config small \
--num_exps 3 \
--device 0
SemCoT supports five reasoning datasets:
Datasets are automatically downloaded and preprocessed on first use.
Three LLM configurations are available:
| Config | Teacher Model | Student Model | Use Case |
|---|---|---|---|
small | Llama-2-7B | Sheared-LLaMA-1.3B | Default |
mistral | Mistral-7B | mistral-1.1b | Alternative |
qwen | Qwen2.5-7B | Qwen2.5-0.5B | Experimental |
--mode: Operation mode (semcot, baseline, generate_data)--config: Model configuration (small, mistral, qwen)--dataset: Dataset name (gsm8k, svamp, multiarith, commonsense_qa, coin_flip)--baseline: Baseline method (pause, icot_si, codi, softcot, coconut)--device: GPU device ID--num_exps: Number of experimental runs (default: 3)--use_best_params: Use pre-tuned hyperparametersSentence Transformer:
--st_linear_lr: Linear layer learning rate (default: 1e-4)--st_linear_wd: Linear layer weight decay (default: 1e-3)--st_linear_epochs: Linear layer epochs (default: 7)--st_llm_lr: LLM learning rate (default: 1e-7)--st_llm_wd: LLM weight decay (default: 1e-5)--st_llm_epochs: LLM epochs (default: 3)Contemplation Generator:
--cg_linear_lr: Linear layer learning rate (default: 1e-4)--cg_linear_wd: Linear layer weight decay (default: 1e-3)--cg_linear_epochs: Linear layer epochs (default: 7)--cg_llm_lr: LLM learning rate (default: 1e-7)--cg_llm_wd: LLM weight decay (default: 1e-5)--cg_llm_epochs: LLM epochs (default: 3)--alpha: Balance between semantic alignment and answer accuracy (default: 0)--train_max_contemp_tokens: Number of implicit tokens during training (default: 5)--eval_max_contemp_tokens: Number of implicit tokens during evaluation (default: 1)--batch_size: Training batch size (default: 4)--seed: Random seed (default: 42)SemCoT includes several ablation variants:
# Without sentence transformer
python main.py --mode semcot --variation no_sentence_transformer
# Without semantic alignment loss
python main.py --mode semcot --variation no_l_reason
# Without warmup training
python main.py --mode semcot --variation no_warmup
# Using full LLM instead of lightweight model
python main.py --mode semcot --variation no_small_contemp_gen
Results are saved in results/{mode}/{variation}/{config}/{dataset}/:
{
"numerical_accuracy": 0.983,
"ave_sample_time": 1.02,
"dataset": "gsm8k",
"eval_temp": 0.7,
"exp_num": 0
}
SemCoT/
├── data/ # Dataset handling
│ ├── cot_datasets.py # Dataset loaders
│ └── gpt4pair.py # GPT-4 reasoning generation
├── models/ # Model implementations
│ ├── semcot.py # SemCoT components
│ ├── pause.py # Baseline: Pause tokens
│ ├── icot_si.py # Baseline: ICoT-SI
│ ├── codi.py # Baseline: CODI
│ ├── softcot.py # Baseline: SoftCoT
│ └── coconut.py # Baseline: COCONUT
├── training/ # Training scripts
│ ├── train_semcot.py # SemCoT training
│ └── train_*.py # Baseline training
├── utils/ # Utilities
│ ├── logging.py # TensorBoard logging
│ └── utils.py # Helper functions
├── main.py # Main entry point
└── requirements.txt # Dependencies
If you find this work useful, please cite our paper:
@inproceedings{he2025semcot,
title={SemCoT: Accelerating Chain-of-Thought Reasoning through Semantically-Aligned Implicit Tokens},
author={He, Yinhan and Zheng, Wendy and Zhu, Yaochen and Zheng, Zaiyi and Su, Lin and Vasudevan, Sriram and Guo, Qi and Hong, Liangjie and Li, Jundong},
booktitle={39th Conference on Neural Information Processing Systems (NeurIPS 2025)},
year={2025}
}
This project is licensed under the MIT License - see the LICENSE file for details.
The models used in this project have their own licenses:
Please ensure compliance with the respective model licenses when using this code.
This work was supported by the National Science Foundation (NSF), Office of Naval Research (ONR), and Commonwealth Cyber Initiative (CCI). We thank the authors of the baseline methods for their open-source implementations.
For questions or issues, please open an issue on GitHub or contact: