📋 Legal Disclaimer and Terms of Use - Click to Read
Legal Disclaimer and Terms of Use
Disclaimer
This material contains analysis and commentary created independently by the author. The content is:
- Based on publicly available information and community discussions
- Not affiliated with, endorsed by, or authorized by Oracle Corporation
- Not representative of official examination content
- Provided for educational purposes only
Terms of Use
Personal Use Only
- This material is intended solely for personal, non-commercial educational use
- Commercial use, including sale, rental, or incorporation into paid services, is strictly prohibited
Academic Integrity
- This material is designed to enhance understanding, not to facilitate cheating
- Users are responsible for complying with all applicable examination rules and policies
- The author does not condone or support any form of academic misconduct
Distribution Restrictions
- Redistribution, copying, or uploading to public platforms without written authorization is prohibited
- To share this content, please share the original link rather than copying the material
Legal Notice
The author reserves all rights to this original work. Unauthorized use may result in legal action.
Limitation of Liability
This material is provided "as is" without warranties of any kind. The author assumes no responsibility for:
- Accuracy or completeness of information
- Any damages resulting from use of this material
- Actions taken by users based on this content
By using this material, you acknowledge that you have read, understood, and agree to comply with these terms.
Section 1: Core Generative AI Concepts
1.1 In-Context Learning (Q1, Q9, Q141)
In-context learning is a powerful capability of Large Language Models (LLMs) that allows them to learn and execute new tasks without updating their weights (i.e., without training or fine-tuning). This process relies solely on the contextual information provided within the prompt.
• Mechanism: It leverages the LLM's "pattern matching" ability. By observing input-output examples or instructions in the prompt, the model infers the task's underlying pattern and applies it to new inputs. The entire process does not involve updating the model's parameters.
• Types:
- Zero-Shot Learning: No examples are provided in the prompt; the model relies solely on instructions and its pre-trained knowledge.
- One-Shot Learning: The prompt includes one example.
- Few-Shot Learning (K-Shot Prompting): The prompt contains a small number of examples (typically 2 to 5), which is often the most effective way to utilize in-context learning.
• Key Advantage: Provides examples in the prompt to guide the LLM to better performance with no training cost. As stated in Q9, "In the prompt, it provides examples to guide the LLM to better performance, without training costs."
• Disadvantage (Q100): It can increase latency for each model request because longer prompts with examples require more computational resources and time for the LLM to process.
• Distinction from Fine-tuning: Unlike fine-tuning, which updates model parameters and is costly, in-context learning is parameter-agnostic, flexible, and has lower costs.
• Relationship with Prompt Engineering: In-context learning is a core technique within prompt engineering, where the goal is to find the most effective prompts to elicit desired model capabilities.
Q1. What does in-context learning in Large Language Models involve?
A. Training the model using reinforcement learning
B. Conditioning the model with task-specific instructions or demonstrations
C. Pretraining the model on a specific domain
D. Adding more layers to the model
Click to check the correct answer
Correct Answer: B. This involves guiding the model at inference time with examples, without updating its parameters.
Here is a detailed explanation of the concept and the distinctions from the other options:
Explanation in Chinese
上下文学习(In-context Learning)
- 核心:在推理阶段,通过在输入提示(Prompt)中提供任务相关的指令或几个示例(demonstrations),引导一个已经预训练好的大语言模型(LLM)去执行新的、未见过的任务,而不更新模型的任何参数。
- 实现方式:用户在向模型提问时,会构造一个包含“上下文”的提示。这个上下文通常包含一到多个“输入-输出”的完整示例,模型会从中“领悟”任务的模式和要求,并对用户真正想解决的问题给出相应格式和内容的回答。
- 可以理解为:给一个博学的专家(预训练好的LLM)看几个例题和答案,然后让他照着样子去解一道新题。专家并没有通过这几个例题去“重新学习”知识改变自己的大脑结构(参数),只是利用自己已有的知识储备,理解了当前任务的“游戏规则”。
一个简单的上下文学习示例:
# 示例:将动物翻译成表情符号
# --- 上下文中的示例 ---
# 示例1
输入:牛
输出:🐄
# 示例2
输入:老虎
输出:🐅
# --- 用户的实际问题 ---
输入:青蛙
输出:
# 模型的输出:
# 🐸
在这个示例中:模型在没有经过专门的“动物-表情符号”数据训练的情况下,依靠提示中提供的两个示例,"学会"了这项新任务,并正确输出了 🐸
。同样,也可以在提示中提供明确的指令(如 "请将以下动物名称转换为表情符号"),让模型"理解任务"。
为什么其它选项是错误的
-
A. 使用强化学习进行训练
这是一种通过奖励和惩罚机制来优化模型行为的训练方法,它会直接修改模型的参数。而上下文学习发生在推理阶段,不涉及任何参数更新。 -
C. 在特定领域上预训练模型
这属于模型训练的范畴,通常是在通用预训练之后,使用特定领域(如医学、法律)的大量数据继续训练模型,使其成为领域专家。这与上下文学习在推理时即时、临时地适应任务的特性不同。 -
D. 为模型增加更多的层
这是改变模型架构的行为,目的是提升模型的容量和表达能力,属于模型设计和开发阶段的工作,与"上下文学习"这一在推理时利用模型能力的概念无关。
上下文学习的常见形式与要点
- 零样本学习(Zero-shot Learning):只提供任务指令,不提供任何示例。
- 单样本学习(One-shot Learning):提供任务指令和一个示例。
- 少样本学习(Few-shot Learning):提供任务指令和多个示例,这是最常见的形式。
- 局限性:效果受限于模型的规模和预训练质量;对示例的选择和顺序非常敏感;如果提示过长,可能会超出模型的上下文窗口限制,导致信息丢失。
一句话总结:
上下文学习 = 不训练,只提示,通过在输入中提供示例或指令让模型即时地学会新任务。
Explanation in English
What is In-Context Learning?
- Core Idea: During the inference phase, In-Context Learning (ICL) guides a pre-trained Large Language Model (LLM) to perform novel tasks by providing it with task-specific instructions or a few examples (demonstrations) in the input prompt, all without updating the model's internal parameters.
- How it Works: A user constructs a prompt that includes a "context" before the actual query. This context, typically a few input-output pairs, allows the model to infer the underlying pattern of the task and apply it to the new input.
- Think of it as: Giving a highly knowledgeable expert a few solved examples of a new type of problem and then asking them to solve a new one. The expert doesn't relearn their knowledge (update parameters); they simply use their existing expertise to understand the "rules of the game" for the current task.
A simple example of in-context learning:
# Example for a sentiment classification task.
# --- Demonstrations in the context ---
# Example 1
Text: "This movie was fantastic, I loved it!"
Sentiment: Positive
# Example 2
Text: "A complete waste of time."
Sentiment: Negative
# --- The actual query ---
Text: "The acting was superb, but the plot was predictable."
Sentiment:
# Model's expected output:
# Mixed
Without any fine-tuning, the model "learns" the sentiment classification task from the two demonstrations provided in the prompt and outputs Mixed
.
Similarly, you can provide explicit instructions (e.g., "Classify the sentiment of the following text as Positive, Negative, or Mixed.") to make the model perform the task.
Why the Other Options Are Incorrect
-
A. Training the model using reinforcement learning
This is a training method that updates model weights based on a system of rewards and penalties to optimize behavior. In contrast, In-Context Learning is a form of learning that happens at inference time via prompting and involves no parameter updates. -
C. Pretraining the model on a specific domain
This falls under the training category. It is an optional step after initial pre-training where the model is further trained on a large, domain-specific dataset (e.g., medical texts) to become a specialist. This is different from the temporary, on-the-fly adaptation nature of In-Context Learning. -
D. Adding more layers to the model
This refers to altering the model's architecture to increase its capacity. It is part of the model's design and development, entirely unrelated to the concept of using a pre-trained model to perform new tasks at inference time.
Common Forms and Key Points of In-Context Learning
- Zero-shot Learning: Providing only a task description with no examples.
- One-shot Learning: Providing one demonstration.
- Few-shot Learning: Providing multiple demonstrations, which is the most common and effective form of ICL.
- Limitations: The effectiveness of ICL is constrained by the model's scale and the quality of its pre-training data. It is also sensitive to the choice and ordering of the examples in the prompt. If the prompt exceeds the model's context window, performance degrades.
Summary in one sentence:
In-Context Learning = No training, only prompting; using demonstrations or instructions in the input to make the model perform a new task on the fly.
Q9. What is the main advantage of using few-shot model prompting to customize a Large Language Model (LLM)?
A. It eliminates the need for any training or computational resources.
B. It allows the LLM to access a larger dataset.
C. It provides examples in the prompt to guide the LLM to better performance with no training cost.
D. It significantly reduces the latency for each model request.
Click to check the correct answer
Correct Answer: C. It guides the model with examples at inference time, avoiding costly fine-tuning.
Here is a detailed explanation of the concept and the distinctions from the other options:
Explanation in Chinese
少样本提示(Few-shot Prompting)
- 核心:在推理阶段,通过在输入提示(Prompt)中提供几个("少样本")完整的“输入-输出”示例,来引导一个预训练好的大语言模型(LLM)执行特定的、可能未见过的任务,而无需对模型进行任何参数微调。
- 实现方式:用户在构造提示时,首先给出几个清晰的范例,然后附上自己真正要解决的问题。模型会从这些范例中“领悟”任务的模式、期望的输出格式以及内在逻辑。
- 可以理解为:教一个经验丰富的员工处理一种新格式的报告。你不会送他去重新培训(微调),而是直接给他看几份已经完成的合格报告作为模板,然后让他照着样子处理新的数据。
一个简单的少样本提示示例:
# 示例说明:从非结构化文本中提取关键信息为JSON格式。
# --- 示例 1 ---
文本:张三,年龄30岁,是北京的一名工程师。
JSON:{"name": "张三", "age": 30, "city": "北京", "occupation": "工程师"}
# --- 示例 2 ---
文本:来自上海的律师李四,今年45岁。
JSON:{"name": "李四", "age": 45, "city": "上海", "occupation": "律师"}
# --- 实际问题 ---
文本:王五是一位来自深圳的25岁设计师。
JSON:
# 模型输出:
# {"name": "王五", "age": 25, "city": "深圳", "occupation": "设计师"}
在这个示例中:模型在没有经过专门的JSON提取微调的情况下,依靠提示中提供的两个示例,"学会"了如何将句子转换为结构化的JSON对象,并正确输出了结果。
为什么其它选项是错误的
-
A. 它消除了对任何训练或计算资源的需求。
这种说法是错误的。虽然它避免了训练所需的计算资源,但模型推理本身(即处理提示并生成答案)仍然需要大量的计算资源。 -
B. 它允许LLM访问更大的数据集。
这是一种误解。少样本提示是在模型的输入窗口内提供信息,并没有让模型去访问或连接任何外部的、更大的数据集。模型依赖的仍然是其预训练时学到的知识。 -
D. 它显著降低了每个模型请求的延迟。
这通常是相反的。因为少样本提示包含了额外的示例,使得整个输入文本(Prompt)变得更长,模型需要处理更多的Token,这往往会增加而不是降低请求的延迟。
少样本提示的常见形式与要点
- 上下文学习(In-Context Learning):少样本提示是上下文学习最典型的应用形式。
- 示例质量是关键:示例的质量、多样性和相关性直接决定了模型表现的好坏。
- 对比零样本和单样本:零样本(Zero-shot)只给指令,单样本(One-shot)给一个例子,少样本(Few-shot)给多个例子,效果通常随示例数量增加而提升(在一定范围内)。
- 局限性:受限于模型的上下文窗口长度;对于复杂任务,仅仅几个示例可能不足以让模型完全理解。
一句话总结:
少样本提示 = 不微调,只示范,通过在提示中加入几个相关例子让模型即时理解并执行特定格式或逻辑的任务。
Explanation in English
What is Few-Shot Prompting?
- Core Idea: During the inference phase, few-shot prompting is a technique to customize an LLM's output for a specific task by including a few complete demonstrations (the "shots") of the desired input-output format directly in the prompt, all without any costly model fine-tuning.
- How it Works: The user engineers a prompt that contains several examples before presenting the final query. The model uses its vast pre-trained knowledge to recognize the pattern, format, and intent from these examples and applies that understanding to the query.
- Think of it as: Giving a seasoned consultant a quick briefing for a new client report. You don't send them to a training course (fine-tuning); you just show them 2-3 examples of past successful reports, and they adapt their approach accordingly for the new task.
A simple example of few-shot prompting:
# Comment: Classify customer feedback with custom labels.
# --- Example 1 ---
Feedback: "The app keeps crashing, it's so frustrating."
Classification: Bug Report
# --- Example 2 ---
Feedback: "How do I change my password?"
Classification: User Inquiry
# --- Example 3 ---
Feedback: "It would be great if you could add a dark mode."
Classification: Feature Request
# --- Actual Query ---
Feedback: "The payment button isn't working."
Classification:
# Model Output:
# Bug Report
Without any fine-tuning on these specific labels, the model "learns" from the three provided shots what "Bug Report", "User Inquiry", and "Feature Request" mean in this context and correctly classifies the new feedback.
Why the Other Options Are Incorrect
-
A. It eliminates the need for any training or computational resources.
This is incorrect. While it bypasses the need for training computations, the inference step itself is computationally expensive, requiring significant GPU resources to process the prompt and generate a response. -
B. It allows the LLM to access a larger dataset.
This is a misconception. Few-shot prompting operates entirely within the model's context window. It doesn't grant the model access to any external or larger datasets; it only uses the data provided in the prompt. -
D. It significantly reduces the latency for each model request.
This is generally the opposite of what happens. Because few-shot prompts are longer (they contain extra examples), they increase the number of tokens the model must process, which typically increases the response latency.
Common Forms and Key Points of Few-shot Prompting
- In-Context Learning (ICL): Few-shot prompting is the most prominent application of ICL.
- Example Quality is Crucial: The performance of the model is highly dependent on the relevance, clarity, and quality of the examples provided.
- Spectrum of "Shots": It sits between Zero-shot (instruction only) and One-shot (one example). Performance generally improves with more shots, up to a certain point.
- Limitations: The technique is fundamentally constrained by the model's maximum context window length. For highly complex tasks, a few examples may not be sufficient to provide the necessary guidance.
Summary in one sentence:
Few-Shot Prompting = No fine-tuning, only demonstration; using a handful of examples in the prompt to make the model perform a specific, customized task correctly at inference time.
Q141. What does "k-shot prompting" refer to when using Large Language Models for task-specific applications?
A. Providing the exact k words in the prompt to guide the model's response
B. Explicitly providing k examples of the intended task in the prompt to guide the model’s output
C. The process of training the model on k different tasks simultaneously to improve its versatility
D. Limiting the model to only k possible outcomes or answers for a given task
Click to check the correct answer
Correct Answer: B. It refers to including 'k' number of demonstrations in the prompt to condition the model.
Here is a detailed explanation of the concept and the distinctions from the other options:
Explanation in Chinese
K-样本提示(K-shot Prompting)
- 核心:在推理阶段,通过在输入提示(Prompt)中包含
k
个完整的任务示例(“样本”或“shots”),来引导一个预训练好的大语言模型(LLM)理解并执行一项新任务,整个过程不涉及任何模型参数的更新。 - 实现方式:用户构造一个提示,其中包含
k
组“输入-期望输出”的配对,然后紧跟着一个只有“输入”的新问题。模型通过分析这k
个示例,推断出任务的模式、格式和要求,并为新问题生成一个符合该模式的输出。k
是一个变量,代表示例的数量。 - 可以理解为:给一个学生做应用题,你先给他讲了
k
道例题,每道例题都有题目和完整解法。然后,你再给他一道新题让他解答。他会模仿例题的解题思路和格式来解决新问题。
一个简单的 K-样本提示示例 (k=2,即2-shot):
# 这是一个2-shot示例,用于将自然语言转换为SQL查询。
# --- 示例 1 (Shot 1) ---
问题:显示所有用户的名字。
SQL:SELECT name FROM users;
# --- 示例 2 (Shot 2) ---
问题:计算总共有多少个产品。
SQL:SELECT COUNT(*) FROM products;
# --- 实际问题 ---
问题:找出所有来自北京的用户。
SQL:
# 模型输出:
# SELECT * FROM users WHERE city = '北京';
在这个示例中:模型通过分析前面提供的两个示例,"学会"了如何将一个自然语言问题转换成一句SQL查询,并为新问题生成了正确的SQL语句。
为什么其它选项是错误的
-
A. 在提示中提供 k 个确切的词来引导模型的响应
这是对“shot”一词的误解。“shot”在这里指的是一个完整的示例(通常是输入和输出对),而不是单个的词。 -
C. 同时在 k 个不同任务上训练模型以提高其通用性
这描述的是多任务学习(Multi-task Learning),是一种训练方法,它会更新模型的权重。而K-shot提示是一种在推理时使用的技术,不涉及训练。 -
D. 将模型的可能输出或答案限制为 k 种
这描述的是输出约束(Output Constraining),例如通过设置logit bias或使用特定解码策略来实现。它控制的是输出的范围,而不是通过示例来引导模型的行为。
K-样本提示的常见形式与要点
- 零样本(Zero-shot, k=0):不提供任何示例,只提供任务的描述或指令。
- 单样本(One-shot, k=1):在提示中提供一个完整的示例。
- 少样本(Few-shot, k>1):在提示中提供多个(通常是2到5个)示例。这是最常见的形式,因为它在效果和提示长度之间取得了很好的平衡。
- 关键点:
k
的值越大,通常效果越好,但也会增加提示的长度,可能消耗更多计算资源并增加延迟。同时,k
的值受限于模型的最大上下文窗口。
一句话总结:
K-样本提示 = 不训练,只示范,通过在提示中给出 k
个完整示例让模型在推理时即时学会并执行特定任务。
Explanation in English
What is K-shot Prompting?
- Core Idea: During the inference phase, k-shot prompting is the technique of including
k
complete examples, or "shots," of a task within the input prompt to guide a pre-trained Large Language Model's output, all done without updating any of the model's parameters. - How it Works: The user engineers a prompt containing
k
input-output pairs that demonstrate the task. This is followed by a new input for which the model must generate the output. The model leverages its pattern-recognition capabilities to understand the task from the examples and produce a response that follows the same logic and format. - Think of it as: A form of in-context learning where
k
is a variable for the number of demonstrations. If you setk=3
, you are showing the model three solved problems before asking it to tackle a new one.
A simple example of k-shot prompting (where k=2, i.e., 2-shot):
# A 2-shot prompt for generating Python docstrings.
# --- Example 1 (Shot 1) ---
# Code:
def add(a, b):
return a + b
# Docstring:
"""Adds two numbers together.
Args:
a (int): The first number.
b (int): The second number.
Returns:
int: The sum of the two numbers.
"""
# --- Example 2 (Shot 2) ---
# Code:
def subtract(a, b):
return a - b
# Docstring:
"""Subtracts the second number from the first.
Args:
a (int): The number to subtract from.
b (int): The number to subtract.
Returns:
int: The difference between the two numbers.
"""
# --- Actual Query ---
# Code:
def multiply(a, b):
return a * b
# Docstring:
# Model's Expected Output:
"""Multiplies two numbers.
Args:
a (int): The first number.
b (int): The second number.
Returns:
int: The product of the two numbers.
"""
In this example, by seeing two demonstrations, the model learns the specific format for the docstring and applies it correctly to the new multiply
function.
Why the Other Options Are Incorrect
-
A. Providing the exact k words in the prompt to guide the model's response
This misunderstands the term "shot." A shot refers to a complete example or demonstration, not an individual word. -
C. The process of training the model on k different tasks simultaneously to improve its versatility
This describes multi-task learning, which is a training paradigm that modifies the model's weights. K-shot prompting is an inference technique. -
D. Limiting the model to only k possible outcomes or answers for a given task
This refers to constraining the output space, for instance, by using techniques like logit biasing. This is different from providing examples to teach the model a behavior pattern.
Common Forms and Key Points of K-shot Prompting
- Zero-shot (k=0): Provides only the task instruction with no examples. Relies entirely on the model's prior knowledge.
- One-shot (k=1): Provides a single example to guide the model.
- Few-shot (k>1): Provides two or more examples. This is often the most effective approach, balancing guidance with prompt length.
- Key Consideration: Increasing
k
can improve performance but also increases prompt length, leading to higher computational cost, latency, and the risk of exceeding the model's context window.
Summary in one sentence:
K-shot Prompting = No training, just demonstration; it involves using k
examples within a prompt to guide a model's behavior at inference time.