> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/jp/ji-chu/continued-pretraining.md).

# 継続事前学習

別名、継続ファインチューニング。Unsloth では継続的に事前学習できるため、モデルに新しい言語を学習させられます。

* その [テキスト補完ノートブック](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_\(7B\)-Text_Completion.ipynb) は継続事前学習/生テキスト用です。
* その [継続事前学習ノートブック](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_v0.3_\(7B\)-CPT.ipynb) は別の言語を学習するためのものです。

継続事前学習と私たちのリリースについては、さらに詳しく [ブログ記事をご覧ください](https://unsloth.ai/blog/contpretraining).

## 継続事前学習とは何ですか？

継続事前学習（CPT）は、言語モデルを「誘導」して新しい知識領域や分布外の領域を理解させるために必要です。Llama-3 8b や Mistral 7b のようなベースモデルは、まず数兆トークン規模の巨大なデータセットで事前学習されます（たとえば Llama-3 は 15 兆）。

しかし、これらのモデルは、他の言語や、法律、医療などの特定分野のテキストについて十分に学習されていないことがあります。そのため、言語モデルに新しいトークンやデータセットを学習させるには、継続事前学習（CPT）が必要です。

## 高度な機能:

### 継続ファインチューニング用の LoRA アダプターを読み込む

Unsloth を通じて LoRA アダプターを保存している場合は、LoRA 重みを使って学習を継続することもできます。オプティマイザの状態もリセットされます。オプティマイザの状態まで読み込んでファインチューニングを継続するには、次のセクションを参照してください。

```python
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "LORA_MODEL_NAME",
    max_seq_length = max_seq_length,
    dtype = dtype,
    load_in_4bit = load_in_4bit,
)
trainer = Trainer(...)
trainer.train()
```

### 継続事前学習とファインチューニングの `lm_head` そして `embed_tokens` 行列

次を追加します `lm_head` そして `embed_tokens`。Colab では、Llama-3 8b でメモリ不足になることがあります。その場合は、次を追加するだけでOKです。 `lm_head`.

```python
model = FastLanguageModel.get_peft_model(
    model,
    r = 16,
    target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                      "gate_proj", "up_proj", "down_proj",
                      "lm_head", "embed_tokens",],
    lora_alpha = 16,
)
```

その後、2つの異なる学習率を使います。- そのうち1つは、 `lm_head` または `embed_tokens` 次のように:

```python
from unsloth import UnslothTrainer, UnslothTrainingArguments

trainer = UnslothTrainer(
    ....
    args = UnslothTrainingArguments(
        ....
        learning_rate = 5e-5,
        embedding_learning_rate = 5e-6, # learning_rate より 2〜10 倍小さい
    ),
)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/jp/ji-chu/continued-pretraining.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
