CoTranslator-4B / README.md
Word2Li's picture
Update README.md
a0ed48e verified
|
Raw History Blame Contribute Delete
5.34 kB
---
library_name: transformers
license: apache-2.0
base_model: Qwen/Qwen3-4B-Thinking-2507
base_model_relation: finetune
pipeline_tag: text-generation
language:
- en
datasets:
- Word2Li/CoTranslator-Nemotron-SFT-Math-v4-Pairs
tags:
- cotranslator
- reasoning-distillation
- chain-of-thought
- math
- qwen3
- supervised-fine-tuning
---
# CoTranslator-4B
Main translator trained on the 1/8 paired-data subset, introduced in **[CoTranslator: Reverse to Forward Chain-of-Thought Translator for Reasoning Distillation](https://arxiv.org/abs/2508.21589)**.
CoTranslator learns to convert answer-conditioned reverse chain-of-thought (CoT) trajectories into trajectories resembling verified forward solutions. Its translations provide supervision for downstream student models.
![Overview of CoTranslator](assets/main.png)
*Overview of CoTranslator. The translator learns from paired reverse and verified forward trajectories, then translates reverse trajectories at scale to construct student training data.*
## Released checkpoint
| Item | Value |
| --- | --- |
| Base model | [Qwen/Qwen3-4B-Thinking-2507](https://huggingface.co/Qwen/Qwen3-4B-Thinking-2507) |
| Parameters stored | 4,022,468,096 |
| Training | Full-parameter supervised fine-tuning |
| Source pair configuration | [`subset_1_8`](https://huggingface.co/datasets/Word2Li/CoTranslator-Nemotron-SFT-Math-v4-Pairs) |
| Rows in the source JSONL | 33,286, before training preprocessing and packing |
| Checkpoint step | 616 |
| Weights | BF16, two Safetensors shards |
The companion translator is [CoTranslator-4B-Full](https://huggingface.co/Word2Li/CoTranslator-4B-Full).
## Translation task
The teacher generates a reverse trajectory with access to the reference answer, using the semantic suppression prompt described in the manuscript. The translator receives that trajectory, including its reasoning and final response. During training, its target is the corresponding question-only forward response from the original Nemotron dataset, accepted by answer verification.
The translation input consists of the following system instruction and a user message containing the reverse trajectory:
```text
You are a reasoning trajectory refiner. Given a teacher-generated solution trajectory, produce a more natural reasoning trajectory. Preserve the mathematical conclusion and answer format.
```
```text
<think>
{{reasoning_content}}
</think>
{{content}}
```
At inference, supply the teacher trajectory in this format. The manuscript conditions the translator on the trajectory alone; the problem and reference answer are used for pairing and verification.
## Training configuration
The settings below are recorded in this checkpoint's `args.json` and match the manuscript's translator configuration.
| Setting | Value |
| --- | --- |
| Framework | Megatron-Swift |
| Epochs | 3 |
| Learning rate | 5e-5 |
| LR schedule / warmup fraction | Cosine / 0.1 |
| Weight decay | 0.1 |
| Global / micro batch size | 32 / 2 |
| Sequence length | 65,536 tokens |
| Packing / precision | Enabled / BF16 |
| Adam beta1 / beta2 | 0.9 / 0.95 |
| Gradient clipping | 1.0 |
| Seed | 42 |
| Chat template | `qwen3_thinking` |
Training preprocessing drops examples exceeding the 65,536-token limit; the source JSONL row count precedes that preprocessing.
## Usage
Use a recent Transformers release. The checkpoint configuration was saved with Transformers 5.12.1; local configuration and tokenizer loading were checked with that version.
```bash
pip install -U transformers accelerate torch datasets
```
This example translates the input trajectory from one released training pair:
```python
import torch
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "Word2Li/CoTranslator-4B"
data = load_dataset(
"Word2Li/CoTranslator-Nemotron-SFT-Math-v4-Pairs", "subset_1_8",
split="train", streaming=True,
)
example = next(iter(data))
messages = example["messages"][:2]
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id, dtype="auto", device_map="auto",
)
prompt = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True,
)
inputs = tokenizer(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
with torch.inference_mode():
output = model.generate(
**inputs, max_new_tokens=32768, do_sample=True,
temperature=0.6, top_p=0.95, top_k=20,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id,
)
continuation = tokenizer.decode(
output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True,
)
# The bundled chat template already places the opening <think> in the prompt.
translated_trajectory = "<think>\n" + continuation
print(translated_trajectory)
```
The manuscript uses temperature 0.6, top-p 0.95, top-k 20, min-p 0, and a maximum of 32,768 generated tokens for translator inference.
## License and attribution
This release uses Apache-2.0, matching the [base model license](https://huggingface.co/Qwen/Qwen3-4B-Thinking-2507/blob/main/LICENSE). Training data attribution and source-specific data licenses are described in the [paired dataset card](https://huggingface.co/datasets/Word2Li/CoTranslator-Nemotron-SFT-Math-v4-Pairs).