# 継続事前学習

* その [テキスト補完ノートブック](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 ではメモリ不足になることがあります。その場合は、単に `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 つの異なる学習率を使用します — `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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
