Other

项目介绍

xuyige/SoftCoT 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 Other 许可证,目前获得 96 个 Star、17 次 Fork。

仓库全名
xuyige/SoftCoT
开源许可证
Other
Star 数
96
Fork 数
17
未关闭 Issue
13

README 摘要

SoftCoT: Soft Chain-of-Thought for Efficient Reasoning with LLMs Authors: Yige Xu , Xu Guo , Zhiwei Zeng , Chunyan Miao . Updates 27-May-2025: We release the camera-ready version of SoftCoT [[Paper]](https://arxiv.org/abs/2502.12134v2). 19-May-2025: We release the official implementation of SoftCoT++. 17-May-2025: To help reproducing, we release some useful data as well as an official reproduce of SoftCoT, check the…

完整内容见 GitHub 原始 README 或本页 。

常见问题

SoftCoT 用什么语言开发?

主要使用 Python 编写,采用 Other 许可证,目前有 96 个 Star。

SoftCoT 可以免费商用吗?

仓库标注的许可证为 Other,商用前请先阅读仓库 LICENSE 文件确认授权范围。

如何获取 SoftCoT 的源码?

可以直接克隆仓库:git clone https://github.com/xuyige/SoftCoT.git,默认分支为 main;安装与运行步骤见仓库 README。

SoftCoT 最近还在维护吗?

仓库最近一次更新为 2025年5月31日,当前有 13 个未关闭 Issue;Star 数为 96,可作为社区活跃度的参考。

关于

ACL'2025: SoftCoT: Soft Chain-of-Thought for Efficient Reasoning with LLMs. and preprint: SoftCoT++: Test-Time Scaling with Soft Chain-of-Thought Reasoning

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
132
价值分
62
活跃状态
活跃

README

SoftCoT: Soft Chain-of-Thought for Efficient Reasoning with LLMs


Authors: Yige Xu, Xu Guo, Zhiwei Zeng, Chunyan Miao.

Updates

  • 27-May-2025: We release the camera-ready version of SoftCoT [Paper].
  • 19-May-2025: We release the official implementation of SoftCoT++.
  • 17-May-2025: To help reproducing, we release some useful data as well as an official reproduce of SoftCoT, check the data here, check the logs and checkpoints here.
  • 16-May-2025: We release the paper of SoftCoT++ [Paper].
  • 15-May-2025: Our SoftCoT is accepted by ACL’2025 (main conference).
  • 26-Mar-2025: We release the official implementation of SoftCoT.
  • 17-Feb-2025: We release the preprint version of our first SoftCoT [Paper].

Overview

SoftCoT

How can we apply CoT in continuous space with LLMs? —— We say SoftCoT!

We introduce SoftCoT, a simple yet effective approach that enables LLMs to perform reasoning in continuous space while simultaneously mitigating the issue of catastrophic forgetting.

SoftCoT operates by first employing a lightweight assistant language model to generate soft thoughts—intermediate representations that capture nuanced reasoning patterns. These soft thoughts are then projected into the embedding space of the target LLM via a dedicated projection module. This process not only supports reasoning in a continuous latent space but also preserves previously learned knowledge, thereby enhancing the robustness and adaptability of the LLM. softcot

SoftCoT++

How can we scale thinking in continuous space with LLMs? —— We say SoftCoT++!

Unlike discrete decoding, where repeated sampling enables exploring diverse reasoning paths, latent representations in continuous space are fixed for a given input, which limits diverse exploration. To tackle this limitation, we introduce SoftCoT++, an extended version of SoftCoT, to apply test-time scaling for thinking on continuous space. Specifically, we perturb latent thoughts via multiple specialized initial tokens and apply contrastive learning to promote diversity among soft thought representations

softcotpp

Quick Start

Setup and Dependencies

Requirements for SoftCoT:

  • fastNLP==0.7.0
  • torch==2.4.1
  • transformers==4.44.2

Requirements for SoftCoT++ (can also be used for SoftCoT):

  • fastNLP==0.7.0
  • torch==2.7.0
  • transformers==4.51.0

Prepare Data

Take math reasoning as example, we need to preprocess the data under the GSM8K-style, which is shown in ./data/gsm8k.

For better reproducing SoftCoT, you can find some useful data as well as checkpoints here.

Training

Train for SoftCoT

Here we use GSM8K as an example, for Llama, we have:

CUDA_VISIBLE_DEVICES=0 python train_softcot.py \
    --large_model_id meta-llama/Llama-3.1-8B-Instruct \
    --small_model_id meta-llama/Llama-3.2-1B-Instruct \
    --output_name [Output Name] \
    --batch_size 4 \
    --task_name gsm8k \
    --num_thought_tokens 32 \
    --n_epochs 10 \

For Qwen, we have:

CUDA_VISIBLE_DEVICES=0 python train_softcot.py \
    --large_model_id Qwen/Qwen2.5-7B-Instruct \
    --small_model_id Qwen/Qwen2.5-1.5B-Instruct \
    --output_name [Output Name] \
    --batch_size 4 \
    --task_name gsm8k \
    --num_thought_tokens 32 \
    --n_epochs 10 \

Tips:

  • The output_name argument is used to differentiate between various experimental settings.
  • The training script is under the single-GPU style, we do not adopt our code to multi-GPU training.
  • The argument num_thought_tokens is set to 32 during training for a more stable training. For evaluation, num_thought_tokens keeps to 4.
Train for SoftCoT++

Here we use GSM8K as an example, for Llama, we have:

CUDA_VISIBLE_DEVICES=0 python train_softcotpp.py \
    --large_model_id meta-llama/Llama-3.1-8B-Instruct \
    --small_model_id meta-llama/Llama-3.2-1B-Instruct \
    --output_name [Output Name] \
    --batch_size 4 \
    --model_name scaling-nce \
    --task_name gsm8k \
    --num_thought_tokens 32 \
    --num_scaling_times 10 \
    --n_epochs 10 \

For Qwen, we have:

CUDA_VISIBLE_DEVICES=0 python train_softcotpp.py \
    --large_model_id Qwen/Qwen3-8B \
    --small_model_id Qwen/Qwen3-0.6B \
    --output_name [Output Name] \
    --batch_size 4 \
    --model_name scaling-nce \
    --task_name gsm8k \
    --num_thought_tokens 32 \
    --num_scaling_times 10 \
    --n_epochs 10 \

Tips:

  • num_scaling_times shows how many thinking chains we want to scale.
  • model_name controls using Contrastive Learning Loss (scaling-nce) or not (scaling).

Evaluation

After the training stage, we will save to projection module, which can be used for evaluation.

Evaluation for SoftCoT
bash run_batch_softcot.sh \
    --base_model_id meta-llama/Llama-3.1-8B-Instruct \
    --assistant_model_id meta-llama/Llama-3.2-1B-Instruct \
    --params_file_name [Dir to Your Ckpt]/projectin.bin \
    --num_thought_tokens 4 \
    --num_return_sequences 1 \
    --task_name gsm8k \
    --seed_from 41 \
    --seed_to 45 \
    --print_input \
    --print_response \
    --log_dir [Dir to Your Log File] \
    --run_name [Experiment Running Name, Default is Empty]

In this script we conduct evaluation with 5 random seeds from 41 to 45 under the control of argument seed_from and seed_to. If you want to run only once, you can keep the two arguments same.

Evaluation for SoftCoT++
bash run_batch_softcotpp.sh \
    --base_model_id Qwen/Qwen3-8B \
    --assistant_model_id Qwen/Qwen3-0.6B \
    --params_file_name [Dir to Your Ckpt]/projectin.bin \
    --num_thought_tokens 4 \
    --num_return_sequences 1 \
    --num_scaling_times 10 \
    --task_name gsm8k \
    --seed_from 41 \
    --seed_to 45 \
    --print_input \
    --print_response \
    --log_dir [Dir to Your Log File] \
    --run_name [Experiment Running Name, Default is Empty]

If you want to combine SoftCoT++ with self-consistency, you can:

bash run_batch_softcotpp.sh \
    --base_model_id Qwen/Qwen3-8B \
    --assistant_model_id Qwen/Qwen3-0.6B \
    --params_file_name [Dir to Your Ckpt]/projectin.bin \
    --num_thought_tokens 4 \
    --num_return_sequences 10 \
    --num_scaling_times 10 \
    --task_name gsm8k \
    --seed_from 41 \
    --seed_to 45 \
    --print_input \
    --print_response \
    --log_dir [Dir to Your Log File] \
    --run_name [Experiment Running Name, Default is Empty]

Citation

If you find this work helpful, please cite:

@inproceedings{xu2025softcot,
  title={{SoftCoT}: Soft Chain-of-Thought for Efficient Reasoning with LLMs},
  author={Xu, Yige and Guo, Xu and Zeng, Zhiwei and Miao, Chunyan},
  booktitle={Proceedings of {ACL}},
  year={2025}
}
@article{xu2025softcotpp,
  title={{SoftCoT++}: Test-Time Scaling with Soft Chain-of-Thought Reasoning},
  author={Xu, Yige and Guo, Xu and Zeng, Zhiwei and Miao, Chunyan},
  journal={arXiv preprint arXiv:2505.11484},
  year={2025}
}

评论

暂无评论