---
title: "In-Context Learning — インコンテキスト学習"
source: "https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92"
wiki: "systems-analysis.info/int"
article: "In-Context_Learning_—_インコンテキスト学習"
language: "ja"
categories:
  - "Category:Japanese"
  - "Category:Large language models"
  - "Category:Machine learning"
  - "Category:Prompt engineering"
revision_id: 3219
wiki_created_at: 2026-09-06T23:17:28Z
wiki_modified_at: 2026-09-06T23:17:28Z
downloaded_at: 2026-09-07T22:55:49Z
---

# In-Context Learning — インコンテキスト学習

**インコンテキスト学習**（英語: **In-Context Learning**、**ICL**）は、大規模言語モデル（LLM）が、プロンプトとして与えられた文脈内の例（デモンストレーション）だけを用いて、新しいタスクを「その場で」学習する基本的な能力である。この適応は、モデルの重み（パラメータ）を更新することなく、すなわち従来のファインチューニング（fine-tuning）なしで行われる点が最大の特徴である<sup>[\[1\]](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_note-lakera-1)[\[2\]](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_note-hopsworks-2)</sup>。

このメカニズムにより、モデルは特別に訓練されていないタスクを解く際にも、驚くほどの柔軟性を示せる。ICLは、大規模言語モデルをこれほど強力で汎用的なものにした主要なブレークスルーの一つである<sup>[\[3\]](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_note-gradient_pub-3)</sup>。

## 動作メカニズム

ICLがどのように機能するのかの正確な理解は、今なお活発な研究分野であるが、この現象を説明するいくつかの主要な理論が存在する。

### メタオプティマイザとしてのTransformer

有力な説の一つは、Transformerアーキテクチャが事前学習の段階で、順伝播（forward pass）の中で学習アルゴリズムを実装する方法を獲得する、というものである。モデルが例を含むプロンプトを受け取ると、重みではなく内部状態（活性化）を調整することで、提示されたタスクを解くための一種の最適化を暗黙的に実行する<sup>[\[4\]](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_note-arxiv_grad-4)</sup>。

### ベイズ推論

別の説では、ICLをベイズ推論の一形態とみなす。膨大なデータで事前学習されたモデルは、多数の概念に関する事前知識を備えている。コンテキスト内の例は、モデルが隠れた概念についての事後分布を精緻化するための証拠として働く。言い換えれば、例は、モデルが既知の何千ものタスクの中から、今どのタスクを解くべきかを「特定する」のに役立つ<sup>[\[5\]](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_note-stanford-5)</sup>。

## インコンテキスト学習の種類

与える例の数に応じて、ICLは主に3つのタイプに分けられる。

- **Few-shot Learning（少数ショット学習）**: 最も一般的でバランスのとれた方式である。モデルには複数（通常は2〜10個）のデモンストレーション例が与えられる。

*例（センチメント分類）:*

    テキスト: 「なんて素晴らしい日なんだ！」
    センチメント: ポジティブ

    テキスト: 「渋滞にはまるのは大嫌いだ。」
    センチメント: ネガティブ

    テキスト: 「この映画はかなり平凡だった。」
    センチメント:

*期待される回答:*

    ニュートラル

- **One-shot Learning（ワンショット学習）**: モデルには例が1つだけ与えられる。これだけでも応答の形式を指定でき、ゼロショットと比べて性能を大きく高めるのに十分な場合が多い。

<!-- -->

- **Zero-shot Learning（ゼロショット学習）**: モデルには例が与えられず、タスクの指示や説明だけが渡される。この場合、モデルは事前学習で得た知識だけに頼る。

## 実用的な応用

ICLを適切に使えば、コストのかかる開発やファインチューニングなしに、幅広いタスクを解ける。

- **創造的・文体的なタスク**（特定のスタイルでのコード生成、特定の著者の文体での文章作成）:
  - Few-shot Learningが推奨される。
  - 例は、モデルが必要なスタイル・フォーマット・出力構造を捉えるのに役立つ。

<!-- -->

- **明確な指示を持つ単純なタスク**（翻訳、要約、簡単な質問への回答）:
  - 多くの場合、Zero-shot Learningで十分である。
  - 現代のモデルは、そのタスクが事前学習に含まれていれば、十分にうまく処理できる。

<!-- -->

- **出力形式が重要なタスク**（JSON生成、固有表現抽出）:
  - One-shotまたはFew-shot Learningが推奨される。
  - たった1つの例でも、必要な応答構造を明確に定め、フォーマットの誤りを防げる。

## 長所と短所

<table class="wikitable">
<caption>ICLの長所と短所の比較</caption>
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="header">
<th>長所</th>
<th>短所</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><ul>
<li><strong>柔軟性と速度:</strong> 再学習なしに、新しいタスクへ即座に適応できる。</li>
<li><strong>リソースの節約:</strong> データ収集・ラベリングやファインチューニングのための計算資源が不要。</li>
<li><strong>アクセシビリティ:</strong> MLの専門知識がないユーザーでも、簡単なテキスト例でモデルを調整できる。</li>
</ul></td>
<td><ul>
<li><strong>コンテキストウィンドウの制限:</strong> 例の数は、モデルの最大コンテキスト長によって制限される。</li>
<li><strong>例への感受性:</strong> 結果は、与えるデモンストレーションの品質・順序・フォーマットに大きく左右される。</li>
<li><strong>推論時の高コスト:</strong> 多くの例を含む長いプロンプトは、生成のコストと時間を増やす。</li>
<li><strong>セキュリティリスク:</strong> 機密情報を例として渡すのは安全でない場合がある。</li>
</ul></td>
</tr>
</tbody>
</table>

ICLの長所と短所の比較

## 他のパラダイムとの比較

### ICL vs. Fine-tuning - ICLとファインチューニングの比較

ファインチューニング（fine-tuning）は、モデルの重みを変更し、新しい知識を「刻み込む」。これによりモデルは特定分野の専門家になるが、全体的な柔軟性は下がる。対照的に、ICLは重みを変えず、より柔軟である一方、深いドメイン知識を要する特化タスクでは性能が劣ることがある。

### ICL vs. RAG (Retrieval-Augmented Generation) - ICLとRAGの比較

どちらの方法もモデルのコンテキストを拡張するが、目的が異なる。

- **ICL**は、例を用いてモデルにタスクの実行方法を教える（スキルの提示）。
- **RAG**は、検索した情報を用いて、回答に必要な事実をモデルに伝える（知識の提供）。

実際には、最良の結果を得るために、ICLとRAGはしばしば組み合わせて使われる。

## 参考文献

- Brown, T. B. et al. (2020). *Language Models are Few-Shot Learners*. <a href="https://arxiv.org/abs/2005.14165" class="external text" rel="nofollow">arXiv:2005.14165</a>.
- Dai, D. et al. (2022). *Why Can GPT Learn In-Context? Language Models Implicitly Perform Gradient Descent as Meta-Optimizers*. <a href="https://arxiv.org/abs/2212.10559" class="external text" rel="nofollow">arXiv:2212.10559</a>.
- Panwar, M.; Ahuja, K.; Goyal, N. (2024). *In-Context Learning through the Bayesian Prism*. <a href="https://arxiv.org/abs/2306.04891" class="external text" rel="nofollow">arXiv:2306.04891</a>.
- Müller, S. et al. (2021). *Transformers Can Do Bayesian Inference*. <a href="https://arxiv.org/abs/2112.10510" class="external text" rel="nofollow">arXiv:2112.10510</a>.
- Garg, S. et al. (2022). *What Can Transformers Learn In-Context? A Case Study of Simple Function Classes*. <a href="https://arxiv.org/abs/2208.01066" class="external text" rel="nofollow">arXiv:2208.01066</a>.
- Min, S. et al. (2022). *Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?*. <a href="https://arxiv.org/abs/2202.12837" class="external text" rel="nofollow">arXiv:2202.12837</a>.
- Wang, X.; Zhu, W.; Wang, W. Y. (2023). *Large Language Models are Implicitly Topic Models: Explaining and Finding Good Demonstrations for In-Context Learning*. <a href="https://arxiv.org/abs/2301.11916" class="external text" rel="nofollow">arXiv:2301.11916</a>.
- Dong, Q. et al. (2024). *A Survey on In-Context Learning*. <a href="https://arxiv.org/abs/2301.00234" class="external text" rel="nofollow">arXiv:2301.00234</a>.
- Yu, Z.; Ananiadou, S. (2024). *How Do Large Language Models Learn In-Context? Query and Key Matrices of In-Context Heads Are Two Towers for Metric Learning*. <a href="https://arxiv.org/abs/2402.02872" class="external text" rel="nofollow">arXiv:2402.02872</a>.
- Wibisono, K. C.; Wang, Y. (2024). *From Unstructured Data to In-Context Learning: Exploring What Tasks Can Be Learned and When*. <a href="https://arxiv.org/abs/2406.00131" class="external text" rel="nofollow">arXiv:2406.00131</a>.
- Chan, S. et al. (2022). *Data Distributional Properties Drive Emergent In-Context Learning in Transformers*. <a href="https://arxiv.org/abs/2205.05055" class="external text" rel="nofollow">arXiv:2205.05055</a>.
- Hahn, M.; Goyal, N. (2023). *A Theory of Emergent In-Context Learning as Implicit Structure Induction*. <a href="https://arxiv.org/abs/2303.07971" class="external text" rel="nofollow">arXiv:2303.07971</a>.

## 脚注

1.  <span id="cite_note-lakera-1">[↑](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_ref-lakera_1-0) "What is In-Context Learning (ICL)?". *Lakera*. <a href="https://www.lakera.ai/blog/what-is-in-context-learning" class="external autonumber" rel="nofollow">[1]</a></span>
2.  <span id="cite_note-hopsworks-2">[↑](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_ref-hopsworks_2-0) "In-Context Learning (ICL)". *Hopsworks*. <a href="https://www.hopsworks.ai/dictionary/in-context-learning-icl" class="external autonumber" rel="nofollow">[2]</a></span>
3.  <span id="cite_note-gradient_pub-3">[↑](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_ref-gradient_pub_3-0) "In-Context Learning, In Context". *The Gradient*. <a href="https://thegradient.pub/in-context-learning-in-context/" class="external autonumber" rel="nofollow">[3]</a></span>
4.  <span id="cite_note-arxiv_grad-4">[↑](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_ref-arxiv_grad_4-0) Dai, D. et al. "Why Can GPT Learn In-Context? Language Models Implicitly Perform Gradient Descent as Meta-Optimizers". *arXiv:2212.10559*, 2022. <a href="https://arxiv.org/abs/2212.10559" class="external autonumber" rel="nofollow">[4]</a></span>
5.  <span id="cite_note-stanford-5">[↑](https://systems-analysis.info/int/In-Context_Learning_%E2%80%94_%E3%82%A4%E3%83%B3%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%AD%A6%E7%BF%92#cite_ref-stanford_5-0) "Understanding In-Context Learning". *Stanford HAI*, 2023. <a href="https://ai.stanford.edu/blog/understanding-incontext/" class="external autonumber" rel="nofollow">[5]</a></span>
