File size: 17,433 Bytes
b3ee0d4
 
faabbfb
b3ee0d4
 
 
 
 
 
 
 
faabbfb
 
 
 
b3ee0d4
 
faabbfb
b3ee0d4
faabbfb
b3ee0d4
faabbfb
 
 
b3ee0d4
f5f4970
b3ee0d4
faabbfb
b3ee0d4
faabbfb
b3ee0d4
faabbfb
b3ee0d4
faabbfb
b3ee0d4
faabbfb
b3ee0d4
faabbfb
 
b3ee0d4
faabbfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56633c4
faabbfb
 
 
 
 
 
 
 
29d69ec
faabbfb
cef295c
faabbfb
 
adedb66
faabbfb
 
 
 
 
 
 
29d69ec
faabbfb
cef295c
faabbfb
 
 
 
 
 
 
 
 
 
 
adedb66
 
faabbfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cef295c
faabbfb
 
 
 
 
 
 
 
 
 
cef295c
faabbfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d605834
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
faabbfb
 
d605834
 
 
 
 
 
 
 
 
 
 
 
 
 
b3ee0d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
faabbfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
---
library_name: transformers
license: apache-2.0
base_model: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
tags:
- llama-factory
- full
- generated_from_trainer
model-index:
- name: distilabel-reasoning-R1-Llama-70B-ja-train
  results: []
datasets:
- lightblue/distilabel-reasoning-R1-Llama-70B
language:
- ja
---

[日本語はこちら](#japanese)

# lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese

[Deepseek's R1 models](https://huggingface.co./collections/deepseek-ai/deepseek-r1-678e1e131c0169c0bc89728d) 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](https://huggingface.co./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](https://huggingface.co./deepseek-ai/DeepSeek-R1-Distill-Qwen-7B) on our [lightblue/distilabel-reasoning-R1-Llama-70B](https://huggingface.co./datasets/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](https://www.alibabacloud.com/help/en/ecs/user-guide/gpu-accelerated-compute-optimized-and-vgpu-accelerated-instance-families-1)) on [Alibaba Cloud](https://www.alibabacloud.com/).

# 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](https://huggingface.co./deepseek-ai/DeepSeek-R1-Distill-Qwen-7B#usage-recommendations).

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:

<ul>
  <li><b>vLLM</b>

Install [vLLM](https://github.com/vllm-project/vllm/) using `pip install vllm`.

<details open>
  <summary>Show vLLM code</summary>
  
```python
from vllm import LLM, SamplingParams

llm = LLM(
    model="lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese",
    max_model_len=8_000
)

sampling_params = SamplingParams(
    temperature=0.5, 
    max_tokens=8_000,
    repetition_penalty=1.1
)

prompts = [
    """学校には1クラスにつき20人の生徒がおり、クラスは合計3つあります。
学校全体では男子と女子がそれぞれ50%ずついます。
1つ目のクラスには女子が15人、2つ目のクラスには女子が12人います。
3つ目のクラスには何人の男子がいますか?"""
]

conversations = [
    [{"role": "user", "content": x}] for x in prompts
]

outputs = llm.chat(conversations, sampling_params=sampling_params)

for output in outputs:
    print(output.outputs[0].text)

<think>
# まず、学校の総生徒数を算出します。各クラスに20人の生徒があり、クラスは3つあるため、総生徒数は60人です。

# 次に、学校全体で男子と女子は同じ人数で分布しています。したがって、男子と女子各有30人。
...
# したがって、3つ目のクラスの男子数は20 - 3 = 17人です。
# </think>

# **解答:**

# 学校の総生徒数を算出します。
...
# **最終的な答え:**
# \[
# \boxed{17}
# \]
```

</details></li>
</ul>	

# 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](https://huggingface.co./datasets/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](https://drive.google.com/file/d/1gCzCJv5vasw8R3KVQimfoIDFyfxwxNvC/view?usp=sharing).


We further use the first 50 prompts from [DeL-TaiseiOzaki/Tengentoppa-sft-reasoning-ja](https://huggingface.co./datasets/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](https://drive.google.com/file/d/1f75IM5x1SZrb300odkEsLMfKsfibrxvR/view?usp=sharing).

# How this model was made

We made the data for this model using the following steps:

1. Sample English reasoning-style prompts from [argilla/distilabel-reasoning-prompts](https://huggingface.co./datasets/argilla/distilabel-reasoning-prompts).
2. Remove similar prompts using text similarity based on [BAAI/bge-m3](https://huggingface.co./BAAI/bge-m3) embeddings.
3. Translate English prompts to Japanese using [gpt-4o-mini-2024-07-18](https://openai.com/index/gpt-4o-mini-advancing-cost-efficient-intelligence/).
4. Generate answers to prompts using [deepseek-ai/DeepSeek-R1-Distill-Llama-70B](https://huggingface.co./deepseek-ai/DeepSeek-R1-Distill-Llama-70B).
5. 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](https://github.com/hiyouga/LLaMA-Factory) with the [ecs.gn8is-8x.32xlarge](https://www.alibabacloud.com/help/en/ecs/user-guide/gpu-accelerated-compute-optimized-and-vgpu-accelerated-instance-families-1) instance.


<br/>
<br/>
<h1 style="font-size: 48px;" id="japanese">日本語</h3>

[DeepseekのR1モデル](https://huggingface.co./collections/deepseek-ai/deepseek-r1-678e1e131c0169c0bc89728d)は優れた、最先端の推論モデルであり、英語と中国語のバイリンガルで動作するように訓練されています。しかし、これらのモデルは出力される言語が一貫していないことがあり、日本語でプロンプトを与えると中国語や英語を出力することがあります。そこで、我々はR1の日本語版として[lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese](https://huggingface.co./lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese)を開発しました。

このモデルは、我々の[lightblue/distilabel-reasoning-R1-Llama-70B](https://huggingface.co./datasets/lightblue/distilabel-reasoning-R1-Llama-70B) データセットを使用して、[deepseek-ai/DeepSeek-R1-Distill-Qwen-7B](https://huggingface.co./deepseek-ai/DeepSeek-R1-Distill-Qwen-7B)の日本語版として微調整されています。

このモデルは、[Alibaba Cloud](https://www.alibabacloud.com/)の8 x L20インスタンス([ecs.gn8is-8x.32xlarge](https://www.alibabacloud.com/help/en/ecs/user-guide/gpu-accelerated-compute-optimized-and-vgpu-accelerated-instance-families-1))で\<10分間訓練されました。

# 使用方法

これらのモデルを使用する際は、元の蒸留R1モデルで推奨されているように、サンプリング温度を0.5から0.7の間で使用することをお勧めします。

また、モデルが元のR1モデルよりも繰り返しがちな傾向があるため、プロンプトを処理する際にモデルが自分を繰り返す場合は、`repetition_penalty`を1.1またはそれ以上に設定することをお勧めします。

このモデルをvLLMで使用するためのスクリプトを含めています:

<ul>
  <li><b>vLLM</b>

[vLLM](https://github.com/vllm-project/vllm/)をインストールするには、 `pip install vllm`を使用します。

<details open>
  <summary>vLLMコードを表示</summary>
  
```python
from vllm import LLM, SamplingParams

llm = LLM(
    model="lightblue/DeepSeek-R1-Distill-Qwen-7B-Japanese",
    max_model_len=8_000
)

sampling_params = SamplingParams(
    temperature=0.5, 
    max_tokens=8_000,
    repetition_penalty=1.1
)

prompts = [
    """学校には1クラスにつき20人の生徒がおり、クラスは合計3つあります。
学校全体では男子と女子がそれぞれ50%ずついます。
1つ目のクラスには女子が15人、2つ目のクラスには女子が12人います。
3つ目のクラスには何人の男子がいますか?"""
]

conversations = [
    [{"role": "user", "content": x}] for x in prompts
]

outputs = llm.chat(conversations, sampling_params=sampling_params)

for output in outputs:
    print(output.outputs[0].text)

<think>
# まず、学校の総生徒数を算出します。各クラスに20人の生徒があり、クラスは3つあるため、総生徒数は60人です。

# 次に、学校全体で男子と女子は同じ人数で分布しています。したがって、男子と女子各有30人。
...
# したがって、3つ目のクラスの男子数は20 - 3 = 17人です。
# </think>

# **解答:**

# 学校の総生徒数を算出します。
...
# **最終的な答え:**
# \[
# \boxed{17}
# \]
```

</details></li>
</ul>

# 評価

このモデルは、(SakanaAI/gsm8k-ja-test_250-1319)[https://huggingface.co./datasets/SakanaAI/gsm8k-ja-test_250-1319]データセットの最初の50行を使用して、出力の正確性と有効な日本語の`<think>`セクションの割合を評価しました。

これは元の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の評価コードは[こちら](https://drive.google.com/file/d/1gCzCJv5vasw8R3KVQimfoIDFyfxwxNvC/view?usp=sharing)にあります。

さらに、(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評価コードは[こちら](https://drive.google.com/file/d/1f75IM5x1SZrb300odkEsLMfKsfibrxvR/view?usp=sharing)にあります。

# 作成方法

このモデルのデータは以下の手順で作成されました:

1. [argilla/distilabel-reasoning-prompts](https://huggingface.co./datasets/argilla/distilabel-reasoning-prompts)から英語の推論スタイルのプロンプトをサンプルします。
2. [BAAI/bge-m3](https://huggingface.co./BAAI/bge-m3)埋め込みに基づくテキスト類似度を使用して、類似したプロンプトを削除します。
3. [gpt-4o-mini-2024-07-18](https://openai.com/index/gpt-4o-mini-advancing-cost-efficient-intelligence/)を使用して、英語のプロンプトを日本語に翻訳します。
4. [deepseek-ai/DeepSeek-R1-Distill-Llama-70B](https://huggingface.co./deepseek-ai/DeepSeek-R1-Distill-Llama-70B)を使用して、プロンプトに対する回答を生成します。
5. 以下の条件を満たさない応答をフィルタリングします:
   * 2048トークン以内に終了すること
   * 有効な`<think>`セクションを含んでいること
   * `<think>`セクションが日本語で書かれていること


# Training details
<details>
  <summary>Full training config</summary>

  ### Training config yaml
  
  ```yaml
### model
model_name_or_path: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B

### method
stage: sft
do_train: true
finetuning_type: full
deepspeed: /root/LLaMA-Factory/examples/deepspeed/ds_z2_config.json

### dataset
dataset: distilabel-reasoning-R1-Llama-70B-ja-train
template: qwen
cutoff_len: 4500
overwrite_cache: true
preprocessing_num_workers: 16
packing: true

### output
output_dir: /root/train_outputs/DeepSeek-R1-Distill-Qwen-7B/distilabel-reasoning-R1-Llama-70B-ja-train
logging_steps: 1
save_steps: 0.99999
plot_loss: true
overwrite_output_dir: true

### train
per_device_train_batch_size: 1
gradient_accumulation_steps: 1
learning_rate: 1.0e-5
num_train_epochs: 1.0
lr_scheduler_type: cosine
warmup_ratio: 0.01
bf16: true
ddp_timeout: 180000000

### eval
val_size: 0.01
per_device_eval_batch_size: 1
eval_strategy: steps
eval_steps: 0.1
```

### Training run script

```shell
echo '{
  "distilabel-reasoning-R1-Llama-70B-ja-train": {
    "hf_hub_url": "lightblue/distilabel-reasoning-R1-Llama-70B-ja-train",
    "formatting": "sharegpt"
  }
}' > /root/LLaMA-Factory/data/dataset_info.json

cd /root/LLaMA-Factory && llamafactory-cli train /root/reasoning_train.yaml

rm -r /root/train_outputs/DeepSeek-R1-Distill-Qwen-7B/distilabel-reasoning-R1-Llama-70B-ja-train/checkpoint*
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
</details>

<br/>

# License

We share this model under an Apache 2.0 license.

# Developed by

<a href="https://www.lightblue-tech.com">
<img src="https://www.lightblue-tech.com/wp-content/uploads/2023/08/color_%E6%A8%AA%E5%9E%8B-1536x469.png" alt="Lightblue technology logo" width="400"/>
</a>

This model was trained by Peter Devine ([ptrdvn](https://huggingface.co./ptrdvn)) for Lightblue