How does in-context learning improve the output of a transformer?

Including examples in the prompt can improve the completion. This is stated in the lecture on in-context learning and we see it play out in practice in lab1. But what is happening at the transformer level when an example is included? It seems to be something more than how the lecture describes training and using an LLM.

Here’s what I’ve reasoned through so far. But it feels incomplete. Any additional information or help from the community is welcome!

I know that in one-shot or few-shot, or even in zero-shot with context about the form of the prompt, the user is providing context to an LLM that has already been trained. So I am guessing context has no effect on the transformer architecture. I also know that context – since it’s part of the prompt – will become part of the embedding and position vectors for the prompt. OK. But what happens next? Are the examples processed in a special way that goes beyond predicting the completion to the whole prompt based on self-attention, vector-embedding, and normalization/regularization? Is the prompt itself first segmented into “examples” and “main question”? Is the transformer capable of analogical problem solving and not just outputting next-word probabilities?

Help me whether you have an answer or whether you just feel like you can brainstorm an answer. I feel like I am missing a big piece of the picture.

When an example is included in the prompt for a language model, it provides additional context and information for the model to generate more accurate and relevant completions. This additional context allows the model to better understand the what the user expects from it and generate responses that align with the given examples.

Here’s a breakdown of what happens at the transformer level when an example is included in the prompt:

Context Inclusion: The examples provided in the prompt become part of the context in which the model operates. This context is used to guide the generation of completions.

Embedding and Positional Encoding: The examples, along with the main question or prompt, are encoded as part of the input using embedding and positional encoding techniques. This allows the model to represent the input in a format that the transformer can process.

Self-Attention and Processing: The transformer model processes the input using self-attention mechanisms, which allow it to attend to different parts of the input sequence and capture dependencies between tokens. The examples and main question are processed together in this manner.

Analogical Problem Solving: The transformer model is capable of analogical problem solving, as it can use the provided examples to infer patterns, relationships, and similarities in the input data. This capability allows the model to generate completions that are consistent with the examples and the main question.

Next-Word Prediction: The model generates completions based on its learned representations, self-attention mechanisms, and training on a diverse range of language data. It predicts the most likely next words or tokens based on the input context, including the examples and main question.

Overall, including examples in the prompt enhances the model’s ability to understand and generate relevant completions by providing it with additional context and information. The transformer’s architecture and capabilities allow it to leverage this context to produce more accurate and contextually relevant outputs.