lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese
Deepseek's R1 models are excellent, state-of-the-art reasoning models which have been trained to work bilingually, with English and Chinese.
However, these models are inconsistent in the language that they produce - often outputting Chinese or English when prompted in Japanese.
For this reason, we developed
lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese as a Japanese version of R1.
This model is a Japanese fine-tuned version of
deepseek-ai/DeepSeek-R1-Distill-Qwen-7B on our
lightblue/distilabel-reasoning-R1-Llama-70B dataset which reliably and accurately outputs Japanese in response to prompts.
This model was trained was trained for <10 minutes on the 8 x L20 instance (
ecs.gn8is-8x.32xlarge ) on
Alibaba Cloud .
How to use
When using these models, we recommend using a sampling temperature of between 0.5-0.7,
as per the original distilled R1 models .
Additionally, we have observed that the model sometimes tends to repeat itself more than the original R1 model, so we also recommend setting repetition_penalty to 1.1, or higher if the model repeats itself when processing your prompts.
We include scripts to use this model in vLLM:
vLLM
Install
vLLM using
pip install vllm.
Show vLLM code
1 from vllm import LLM , SamplingParams
2
3 llm = LLM (
4 model = "lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese" ,
5 max_model_len = 8_000
6 )
7
8 sampling_params = SamplingParams (
9 temperature = 0.5 ,
10 max_tokens = 8_000 ,
11 repetition_penalty = 1.1
12 )
13
14 prompts = [
15 """学校には1クラスにつき20人の生徒がおり、クラスは合計3つあります。
16 学校全体では男子と女子がそれぞれ50%ずついます。
17 1つ目のクラスには女子が15人、2つ目のクラスには女子が12人います。
18 3つ目のクラスには何人の男子がいますか?"""
19 ]
20
21 conversations = [
22 [ { "role" : "user" , "content" : x } ] for x in prompts
23 ]
24
25 outputs = llm . chat ( conversations , sampling_params = sampling_params )
26
27 for output in outputs :
28 print ( output . outputs [ 0 ] . text )
29
30 < think >
31 # まず、学校の総生徒数を算出します。各クラスに20人の生徒があり、クラスは3つあるため、総生徒数は60人です。
32
33 # 次に、学校全体で男子と女子は同じ人数で分布しています。したがって、男子と女子各有30人。
34 . . .
35 # したがって、3つ目のクラスの男子数は20 - 3 = 17人です。
36 # </think>
37
38 # **解答:**
39
40 # 学校の総生徒数を算出します。
41 . . .
42 # **最終的な答え:**
43 # \[
44 # \boxed{17}
45 # \]
Evaluation
We evaluated this model for output accuracy and the percentage of valid Japanese
<think> sections using the first 50 rows of the
SakanaAI/gsm8k-ja-test_250-1319 dataset.
We compare this to the original R1 model and test in both regimes where repetition penalty is 1.0 and 1.1:
Repetition Penalty Answer accuracy (%) Valid Japanese <think> (%) deepseek-ai/DeepSeek-R1-Distill-Qwen-7B 1.0 60 94 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B 1.1 62 96 lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese 1.0 66 92 lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese 1.1 70 98
Code for the SakanaAI/gsm8k-ja-test_250-1319 evaluation can be found
here .
We further use the first 50 prompts from
DeL-TaiseiOzaki/Tengentoppa-sft-reasoning-ja to evaluate the percentage of valid Japanese
<think> sections in model responses.
This benchmark contains more varied and complex prompts, meaning this is a more realistic evaluation of how reliably this model can output Japanese.
Repetition Penalty Valid Japanese <think> (%) deepseek-ai/DeepSeek-R1-Distill-Qwen-7B 1.0 48 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B 1.1 48 lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese 1.0 84 lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese 1.1 94
Code for the DeL-TaiseiOzaki/Tengentoppa-sft-reasoning-ja evaluation can be found
here .
How this model was made
We made the data for this model using the following steps:
Sample English reasoning-style prompts from argilla/distilabel-reasoning-prompts .
Remove similar prompts using text similarity based on BAAI/bge-m3 embeddings.
Translate English prompts to Japanese using gpt-4o-mini-2024-07-18 .
Generate answers to prompts using deepseek-ai/DeepSeek-R1-Distill-Llama-70B .
Filter out responses which did not:
Finish within 2048 tokens
Contain a valid <think> section
Have the <think> section written in Japanese
We used this data to train our model using supervised fine tuning on
LLaMA-Factory with the
ecs.gn8is-8x.32xlarge instance.
日本語
DeepseekのR1モデル は優れた、最先端の推論モデルであり、英語と中国語のバイリンガルで動作するように訓練されています。しかし、これらのモデルは出力される言語が一貫していないことがあり、日本語でプロンプトを与えると中国語や英語を出力することがあります。そこで、我々はR1の日本語版として
lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese を開発しました。
このモデルは、
Alibaba Cloud の8 x L20インスタンス(
ecs.gn8is-8x.32xlarge )で<10分間訓練されました。
使用方法
これらのモデルを使用する際は、元の蒸留R1モデルで推奨されているように、サンプリング温度を0.5から0.7の間で使用することをお勧めします。
また、モデルが元のR1モデルよりも繰り返しがちな傾向があるため、プロンプトを処理する際にモデルが自分を繰り返す場合は、repetition_penaltyを1.1またはそれ以上に設定することをお勧めします。
このモデルをvLLMで使用するためのスクリプトを含めています:
vLLM
vLLM をインストールするには、
pip install vllmを使用します。
vLLMコードを表示
1 from vllm import LLM , SamplingParams
2
3 llm = LLM (
4 model = "lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese" ,
5 max_model_len = 8_000
6 )
7
8 sampling_params = SamplingParams (
9 temperature = 0.5 ,
10 max_tokens = 8_000 ,
11 repetition_penalty = 1.1
12 )
13
14 prompts = [
15 """学校には1クラスにつき20人の生徒がおり、クラスは合計3つあります。
16 学校全体では男子と女子がそれぞれ50%ずついます。
17 1つ目のクラスには女子が15人、2つ目のクラスには女子が12人います。
18 3つ目のクラスには何人の男子がいますか?"""
19 ]
20
21 conversations = [
22 [ { "role" : "user" , "content" : x } ] for x in prompts
23 ]
24
25 outputs = llm . chat ( conversations , sampling_params = sampling_params )
26
27 for output in outputs :
28 print ( output . outputs [ 0 ] . text )
29
30 < think >
31 # まず、学校の総生徒数を算出します。各クラスに20人の生徒があり、クラスは3つあるため、総生徒数は60人です。
32
33 # 次に、学校全体で男子と女子は同じ人数で分布しています。したがって、男子と女子各有30人。
34 . . .
35 # したがって、3つ目のクラスの男子数は20 - 3 = 17人です。
36 # </think>
37
38 # **解答:**
39
40 # 学校の総生徒数を算出します。
41 . . .
42 # **最終的な答え:**
43 # \[
44 # \boxed{17}
45 # \]
評価
これは元のR1モデルと比較し、繰り返しペナルティが1.0と1.1の両方の条件でテストを行いました:
Repetition Penalty Answer accuracy (%) Valid Japanese <think> (%) deepseek-ai/DeepSeek-R1-Distill-Qwen-7B 1.0 60 94 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B 1.1 62 96 lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese 1.0 66 92 lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese 1.1 70 98
SakanaAI/gsm8k-ja-test_250-1319の評価コードは
こちら にあります。
さらに、(DeL-TaiseiOzaki/Tengentoppa-sft-reasoning-ja)[
https://huggingface.co/datasets/DeL-TaiseiOzaki/Tengentoppa-sft-reasoning-ja]の最初の50プロンプトを使用して、モデル応答における有効な日本語の <think>セクションの割合を評価します。このベンチマークにはより多様で複雑なプロンプトが含まれており、モデルが日本語を信頼性高く出力できるかどうかを、より現実的に評価します。
Repetition Penalty Valid Japanese <think> (%) deepseek-ai/DeepSeek-R1-Distill-Qwen-7B 1.0 48 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B 1.1 48 lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese 1.0 84 lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese 1.1 94
DeL-TaiseiOzaki/Tengentoppa-sft-reasoning-ja評価コードは
こちら にあります。
作成方法
このモデルのデータは以下の手順で作成されました:
argilla/distilabel-reasoning-prompts から英語の推論スタイルのプロンプトをサンプルします。
BAAI/bge-m3 埋め込みに基づくテキスト類似度を使用して、類似したプロンプトを削除します。
gpt-4o-mini-2024-07-18 を使用して、英語のプロンプトを日本語に翻訳します。
deepseek-ai/DeepSeek-R1-Distill-Llama-70B を使用して、プロンプトに対する回答を生成します。
以下の条件を満たさない応答をフィルタリングします:
2048トークン以内に終了すること
有効な<think>セクションを含んでいること
<think>セクションが日本語で書かれていること
Training details
Full training config
Training config yaml
1 ### model
2 model_name_or_path : deepseek - ai/DeepSeek - R1 - Distill - Qwen - 7B
3
4 ### method
5 stage : sft
6 do_train : true
7 finetuning_type : full
8 deepspeed : /root/LLaMA - Factory/examples/deepspeed/ds_z2_config.json
9
10 ### dataset
11 dataset : distilabel - reasoning - R1 - Llama - 70B - ja - train
12 template : qwen
13 cutoff_len : 4500
14 overwrite_cache : true
15 preprocessing_num_workers : 16
16 packing : true
17
18 ### output
19 output_dir : /root/train_outputs/DeepSeek - R1 - Distill - Qwen - 7B/distilabel - reasoning - R1 - Llama - 70B - ja - train
20 logging_steps : 1
21 save_steps : 0.99999
22 plot_loss : true
23 overwrite_output_dir : true
24
25 ### train
26 per_device_train_batch_size : 1
27 gradient_accumulation_steps : 1
28 learning_rate : 1.0e-5
29 num_train_epochs : 1.0
30 lr_scheduler_type : cosine
31 warmup_ratio : 0.01
32 bf16 : true
33 ddp_timeout : 180000000
34
35 ### eval
36 val_size : 0.01
37 per_device_eval_batch_size : 1
38 eval_strategy : steps
39 eval_steps : 0.1
Training run script
1 echo '{
2 "distilabel-reasoning-R1-Llama-70B-ja-train": {
3 "hf_hub_url": "lightblue/distilabel-reasoning-R1-Llama-70B-ja-train",
4 "formatting": "sharegpt"
5 }
6 }' > /root/LLaMA-Factory/data/dataset_info.json
7
8 cd /root/LLaMA-Factory && llamafactory-cli train /root/reasoning_train.yaml
9
10 rm -r /root/train_outputs/DeepSeek-R1-Distill-Qwen-7B/distilabel-reasoning-R1-Llama-70B-ja-train/checkpoint*
11 huggingface-cli upload lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese /root/train_outputs/DeepSeek-R1-Distill-Qwen-7B/distilabel-reasoning-R1-Llama-70B-ja-train
Training hyperparameters
The following hyperparameters were used during training:
learning_rate: 1e-05
train_batch_size: 1
eval_batch_size: 1
seed: 42
distributed_type: multi-GPU
num_devices: 8
total_train_batch_size: 8
total_eval_batch_size: 8
optimizer: Use adamw_torch with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
lr_scheduler_type: cosine
lr_scheduler_warmup_ratio: 0.01
num_epochs: 1.0
Training results
Training Loss Epoch Step Validation Loss 0.766 0.1087 5 0.5912 0.5873 0.2174 10 0.5282 0.3868 0.3261 15 0.4958 0.5101 0.4348 20 0.4761 0.4085 0.5435 25 0.4644 0.5561 0.6522 30 0.4578 0.4683 0.7609 35 0.4542 0.5055 0.8696 40 0.4526 0.5359 0.9783 45 0.4519
Framework versions
Transformers 4.46.1
Pytorch 2.5.1+cu124
Datasets 3.1.0
Tokenizers 0.20.3
License
We share this model under an Apache 2.0 license.
Developed by
Lightblue technology logo
This model was trained by Peter Devine (
ptrdvn ) for Lightblue