PrintedImprimé le·aylart.github.io/learn·
CC BY-NC 4.0
Written in English. The French version was automatically generated
and I have not revised it.
Rédigé en anglais. La version française a été
générée automatiquement et je ne l'ai pas révisée.
In-context learningApprentissage en contexte
Adapting to what is in the prompt
When you give a chatbot a few lines that follow a pattern and leave the last
one unfinished, it usually completes the pattern without being told what to
do. In Figure 1figure 1,
each input sentence is followed by the same sentence in capital letters, and
Gemini writes the last one in capitals, although nothing in the prompt asks for
capitals.
Figure 1. Gemini 2.5 Flash completing a pattern it was shown, in 2025.
de Wynter, A. (2026). Is In-Context Learning Learning?. The Fourteenth International Conference on Learning Representations (ICLR 2026). https://arxiv.org/abs/2509.10414
Jurafsky, D., & Martin, J. H. (2026). Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. Online draft, 3rd edition. https://web.stanford.edu/~jurafsky/slp3/
S’adapter à ce que contient la requête
Quand vous donnez à un agent conversationnel quelques lignes qui suivent un même
schéma et laissez la dernière inachevée, il complète généralement le schéma sans
qu’on lui dise quoi faire. Dans la
Figure 1figure 1,
chaque phrase d’entrée est suivie de la même phrase en majuscules, et Gemini
écrit la dernière en majuscules, alors que rien dans la requête ne demande de
majuscules.
Figure 1. Gemini 2.5 Flash complète un schéma qu'on lui a montré, en 2025. La conversation est en anglais.
de Wynter, A. (2026). Is In-Context Learning Learning?. The Fourteenth International Conference on Learning Representations (ICLR 2026). https://arxiv.org/abs/2509.10414
Jurafsky, D., & Martin, J. H. (2026). Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. Online draft, 3rd edition. https://web.stanford.edu/~jurafsky/slp3/
A system prompt can look like a set of settings that the model then applies, and
so can the custom instructions you add yourself. ChatGPT, for instance, presents custom instructions as a form, with
fields to fill in, a personality to choose and traits to add
(Figure 2figure 2).
The model receives these instructions as text in its context window, though,
processed like the rest of the
conversation (see also the Custom instructions, memory, projects and skills page, in the Using LLMs module) (voir aussi la page Instructions personnalisées, mémoire, projets et compétences, dans le module Utiliser les GML).
Figure 2. ChatGPT's form for custom instructions, in August 2025. The interface has changed since.
A setting is applied every time. A system prompt is followed because the model
was trained to follow instructions (see also the Instruction tuning: learning from examples page) (voir aussi la page L'affinage par instructions : apprendre à partir d'exemples),
and to give the system prompt priority over later messages, an order known as
the instruction hierarchy (Zhang et al., 2025b). This usually works, but not
always, and two situations make it less reliable:
Long conversations. Instructions at the start are followed less reliably
as the conversation goes on (Li et al., 2024; Qin et al., 2025).
Anthropic’s own system prompt takes both situations into account: it mentions a
reminder that the service adds to long conversations to help Claude keep its
instructions, and warns that text in a user’s message may falsely claim to come
from Anthropic.
Sources
Jurafsky, D., & Martin, J. H. (2026). Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. Online draft, 3rd edition. https://web.stanford.edu/~jurafsky/slp3/
Li, K., Liu, T., Bashkansky, N., Bau, D., Viégas, F., Pfister, H., & Wattenberg, M. (2024). Measuring and Controlling Instruction (In)Stability in Language Model Dialogs. First Conference on Language Modeling (COLM 2024). https://openreview.net/forum?id=60a1SAtH4e
Qin, Y., Zhang, T., Zhang, T., Shen, Y., Luo, W., Sun, H., et al. (2025). SysBench: Can LLMs Follow System Message?. The Thirteenth International Conference on Learning Representations (ICLR 2025). https://mlanthology.org/iclr/2025/qin2025iclr-sysbench/
Zhang, Z., Li, S., Zhang, Z., Liu, X., Jiang, H., Tang, X., et al. (2025b). IHEval: Evaluating Language Models on Following the Instruction Hierarchy. Proceedings of the 2025 Conference of the Nations of the Americas Chapter of the Association for Computational Linguistics (NAACL 2025), 8374–8398. https://doi.org/10.18653/v1/2025.naacl-long.425
des informations sur lui-même et sur les produits du fournisseur, comme
les autres modèles et applications Claude ;
les demandes à refuser, et la manière de les refuser ;
des instructions sur le ton et la mise en forme, comme « Claude keeps
responses focused, brief, and concise » (des réponses ciblées, brèves et
concises) ;
Une requête générative système peut ressembler à un ensemble de réglages que le
modèle appliquerait ensuite, tout comme les instructions personnalisées que vous
ajoutez vous-même. ChatGPT, par exemple, présente les instructions
personnalisées sous la forme d’un formulaire, avec des champs à remplir, une
personnalité à choisir et des traits à ajouter
(Figure 2figure 2).
Le modèle reçoit pourtant ces instructions sous forme de texte dans sa fenêtre
contextuelle, et les traite comme le reste de la
conversation (see also the Custom instructions, memory, projects and skills page, in the Using LLMs module) (voir aussi la page Instructions personnalisées, mémoire, projets et compétences, dans le module Utiliser les GML).
Figure 2. Le formulaire d'instructions personnalisées de ChatGPT, en anglais, en août 2025. L'interface a changé depuis.
Un réglage s’applique chaque fois. Une requête générative système est suivie
parce que le modèle a été entraîné à suivre des
instructions (see also the Instruction tuning: learning from examples page) (voir aussi la page L'affinage par instructions : apprendre à partir d'exemples), et
à donner la priorité à la requête générative système sur les messages suivants,
un ordre appelé hiérarchie des instructions (Zhang et al., 2025b). Cela
fonctionne généralement, mais pas toujours, et deux situations le rendent moins
fiable :
Les longues conversations. Les instructions données au début sont suivies
de moins en moins fidèlement à mesure que la conversation avance (Li et al.,
2024 ; Qin et al., 2025).
La requête système d’Anthropic elle-même tient compte de ces deux situations :
elle mentionne un rappel que le service ajoute aux longues conversations pour
aider Claude à respecter ses instructions, et avertit que du texte figurant dans
le message d’une personne peut prétendre à tort venir d’Anthropic.
Sources
Jurafsky, D., & Martin, J. H. (2026). Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. Online draft, 3rd edition. https://web.stanford.edu/~jurafsky/slp3/
Li, K., Liu, T., Bashkansky, N., Bau, D., Viégas, F., Pfister, H., & Wattenberg, M. (2024). Measuring and Controlling Instruction (In)Stability in Language Model Dialogs. First Conference on Language Modeling (COLM 2024). https://openreview.net/forum?id=60a1SAtH4e
Qin, Y., Zhang, T., Zhang, T., Shen, Y., Luo, W., Sun, H., et al. (2025). SysBench: Can LLMs Follow System Message?. The Thirteenth International Conference on Learning Representations (ICLR 2025). https://mlanthology.org/iclr/2025/qin2025iclr-sysbench/
Zhang, Z., Li, S., Zhang, Z., Liu, X., Jiang, H., Tang, X., et al. (2025b). IHEval: Evaluating Language Models on Following the Instruction Hierarchy. Proceedings of the 2025 Conference of the Nations of the Americas Chapter of the Association for Computational Linguistics (NAACL 2025), 8374–8398. https://doi.org/10.18653/v1/2025.naacl-long.425
Zero-shot and few-shot promptingRequêtes sans exemple et avec quelques exemples
Describing a task or showing it
You can describe a task in your prompt and let the model carry it out, which is
called zero-shot prompting, or first show it a few examples of what you want,
which is called few-shot prompting. With a single example, it is sometimes
called one-shot prompting.
In Figure 3figure 3,
ChatGPT is first asked, in French, for a few phrases of five words with
exemple as the middle word. None of its five answers fits. In the same
conversation, after being told that the answers were wrong and given one
example, four of its five answers fit, although one simply repeats the example.
After four examples, seven of its eight answers fit. Because everything
happened in one conversation, part of the improvement may come from the
correction rather than from the examples
alone (see also the Giving examples page, in the Using LLMs module) (voir aussi la page Donner des exemples, dans le module Utiliser les GML).
Figure 3. ChatGPT (GPT-4o) asked, in French, for five-word phrases with exemple as the middle word: without an example, then with one, then with four, in one conversation on 17 January 2025.
What examples show the model
Examples show a model more than the answer to each case: what an input looks
like, which answers are possible and what format an answer takes. With older,
smaller models, these could matter more than whether the answers in the
examples were right (Min et al., 2022), but larger models follow the answers in
the examples more closely, so wrong examples are more likely to mislead them
(Wei et al., 2023b; Shi et al., 2024).
Jurafsky, D., & Martin, J. H. (2026). Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. Online draft, 3rd edition. https://web.stanford.edu/~jurafsky/slp3/
Min, S., Lyu, X., Holtzman, A., Artetxe, M., Lewis, M., Hajishirzi, H., & Zettlemoyer, L. (2022). Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?. Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, 11048–11064. https://aclanthology.org/2022.emnlp-main.759/
Shi, Z., Wei, J., Xu, Z., & Liang, Y. (2024). Why Larger Language Models Do In-context Learning Differently?. Proceedings of the 41st International Conference on Machine Learning (ICML 2024), PMLR 235, 44991–45013. https://proceedings.mlr.press/v235/shi24f.html
Wei, J., Wei, J., Tay, Y., Tran, D., Webson, A., Lu, Y., et al. (2023b). Larger language models do in-context learning differently. Preprint, arXiv:2303.03846 (submitted to ICLR 2024). https://openreview.net/forum?id=DRGnEkbiQZ
Décrire une tâche ou la montrer
Vous pouvez décrire une tâche dans votre requête et laisser le modèle
l’exécuter, ce qu’on appelle la formulation de requête sans exemple (angl.
zero-shot prompting), ou lui montrer d’abord quelques exemples de ce que vous
voulez, ce qu’on appelle la formulation de requête avec quelques exemples (angl.
few-shot prompting). Avec un seul exemple, on parle parfois en anglais de
one-shot prompting.
Dans la
Figure 3figure 3,
on demande d’abord à ChatGPT quelques phrases de cinq mots dont le mot central
est exemple. Aucune de ses cinq réponses ne convient. Dans la même
conversation, après s’être fait dire que les réponses étaient fausses et avoir
reçu un exemple, il en donne cinq dont quatre conviennent, même si l’une se
contente de répéter l’exemple. Après quatre exemples, sept de ses huit réponses
conviennent. Comme tout s’est passé dans une seule conversation, une partie de
l’amélioration peut venir de la correction plutôt que des seuls
exemples (see also the Giving examples page, in the Using LLMs module) (voir aussi la page Donner des exemples, dans le module Utiliser les GML).
Figure 3. ChatGPT (GPT-4o), à qui l'on demande des phrases de cinq mots dont le mot central est exemple : sans exemple, puis avec un exemple, puis avec quatre, dans une même conversation, le 17 janvier 2025.
Ce que les exemples montrent au modèle
Les exemples montrent au modèle davantage que la réponse à chaque cas : à quoi
ressemble une entrée, quelles réponses sont possibles et quelle forme prend une
réponse. Avec des modèles plus anciens et plus petits, ces éléments pouvaient
compter davantage que l’exactitude des réponses données en exemple (Min et
coll., 2022), mais les modèles plus grands suivent de plus près les réponses des
exemples, si bien que des exemples erronés risquent davantage de les induire en
erreur (Wei et al., 2023b ; Shi et al., 2024).
Jurafsky, D., & Martin, J. H. (2026). Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. Online draft, 3rd edition. https://web.stanford.edu/~jurafsky/slp3/
Min, S., Lyu, X., Holtzman, A., Artetxe, M., Lewis, M., Hajishirzi, H., & Zettlemoyer, L. (2022). Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?. Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, 11048–11064. https://aclanthology.org/2022.emnlp-main.759/
Shi, Z., Wei, J., Xu, Z., & Liang, Y. (2024). Why Larger Language Models Do In-context Learning Differently?. Proceedings of the 41st International Conference on Machine Learning (ICML 2024), PMLR 235, 44991–45013. https://proceedings.mlr.press/v235/shi24f.html
Wei, J., Wei, J., Tay, Y., Tran, D., Webson, A., Lu, Y., et al. (2023b). Larger language models do in-context learning differently. Preprint, arXiv:2303.03846 (submitted to ICLR 2024). https://openreview.net/forum?id=DRGnEkbiQZ
What context can and cannot doCe que le contexte peut faire, et ce qu'il ne peut pas faire
It supplies information the model can use, such as your terminology or the
content of a document you
attach (see also the context window page) (voir aussi la page La fenêtre contextuelle).
It fades in long conversations. Instructions given at the start are
followed less reliably as the conversation goes
on (see also the System prompts page) (voir aussi la page Requêtes génératives système).
Context is therefore well suited to adapting a model to one document, client or
conversation. Behaviour that has to be the same across thousands of requests
calls for changing the model itself, or for a check outside the model.
Bertsch, A., Ivgi, M., Xiao, E., Alon, U., Berant, J., Gormley, M. R., & Neubig, G. (2025). In-Context Learning with Long-Context Models: An In-Depth Exploration. Proceedings of the 2025 Conference of the Nations of the Americas Chapter of the Association for Computational Linguistics (NAACL 2025), 12119–12149. https://doi.org/10.18653/v1/2025.naacl-long.605
Goyal, S., Baek, C., Kolter, J. Z., & Raghunathan, A. (2025). Context-Parametric Inversion: Why Instruction Finetuning May Not Actually Improve Context Reliance. The Thirteenth International Conference on Learning Representations (ICLR 2025). https://arxiv.org/abs/2410.10796
Zou, K., Khalifa, M., & Wang, L. (2025). On Many-Shot In-Context Learning for Long-Context Evaluation. Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (ACL 2025), 25605–25639. https://doi.org/10.18653/v1/2025.acl-long.1245
Il fournit des informations que le modèle peut utiliser, comme votre
terminologie ou le contenu d’un document que vous
joignez (see also the context window page) (voir aussi la page La fenêtre contextuelle).
Il ne donne pas de bons résultats là où le modèle n’a aucune base, dans un
domaine ou une langue qu’il connaît mal, même avec tout un livre de
documentation.
Il s’estompe dans les longues conversations. Les instructions données au
début sont suivies de moins en moins fidèlement à mesure que la conversation
avance (see also the System prompts page) (voir aussi la page Requêtes génératives système).
Le contexte convient donc bien pour adapter un modèle à un document, à un client
ou à une conversation. Un comportement qui doit être identique sur des milliers
de requêtes exige de modifier le modèle lui-même, ou d’ajouter une vérification
en dehors du modèle.
Bertsch, A., Ivgi, M., Xiao, E., Alon, U., Berant, J., Gormley, M. R., & Neubig, G. (2025). In-Context Learning with Long-Context Models: An In-Depth Exploration. Proceedings of the 2025 Conference of the Nations of the Americas Chapter of the Association for Computational Linguistics (NAACL 2025), 12119–12149. https://doi.org/10.18653/v1/2025.naacl-long.605
Goyal, S., Baek, C., Kolter, J. Z., & Raghunathan, A. (2025). Context-Parametric Inversion: Why Instruction Finetuning May Not Actually Improve Context Reliance. The Thirteenth International Conference on Learning Representations (ICLR 2025). https://arxiv.org/abs/2410.10796
Zou, K., Khalifa, M., & Wang, L. (2025). On Many-Shot In-Context Learning for Long-Context Evaluation. Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (ACL 2025), 25605–25639. https://doi.org/10.18653/v1/2025.acl-long.1245