Part04:提示词示例

提示词实战:从基础到进阶的七大应用场景

上一节我们介绍了提示词的基本概念,本节将通过七个具体的应用场景,展示如何通过精心设计的提示词来执行不同类型的任务。学习概念的最佳方式往往是通过实例,以下示例将带你深入了解提示工程的实际应用。

文本概括

文本摘要是自然语言生成的标准任务之一。语言模型最有前景的应用之一,就是将复杂的文章和概念概括成简洁易读的摘要。

基础摘要任务

我们可以尝试使用提示词进行一个基本的摘要任务。注意这里使用了"A:"作为显式提示格式,告诉模型接下来期望有一个答案。

提示词:

Explain antibiotics

A:

输出:

Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body's immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance.

进阶控制:一句话总结

如果你觉得模型提供的信息过多,可以指导模型用一句话总结相关内容,从而进一步提炼信息。

提示词:

Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body's immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance.

Explain the above in one sentence:

输出:

Antibiotics are medications used to treat bacterial infections by either killing the bacteria or stopping them from reproducing, but they are not effective against viruses and overuse can lead to antibiotic resistance.

信息提取

虽然语言模型主要用于自然语言生成,但它们在分类和信息提取等自然语言处理任务上同样表现出色。

示例:提取特定产品名

这是一个从给定段落中提取特定信息的提示词示例。

提示词:

Author-contribution statements and acknowledgements in research papers should state clearly and specifically whether, and to what extent, the authors used AI technologies such as ChatGPT in the preparation of their manuscript and analysis. They should also indicate which LLMs were used. This will alert editors and reviewers to scrutinize manuscripts more carefully for potential biases, inaccuracies and improper source crediting. Likewise, scientific journals should be transparent about their use of LLMs, for example when selecting submitted manuscripts.

Mention the large language model based product mentioned in the paragraph above:

输出:

The large language model based product mentioned in the paragraph above is ChatGPT.

你可以通过多种方法改进上述结果,但这已经展示了通过简单指示让模型执行不同任务的强大能力。

问答

让模型给出具体回答的最佳方法之一是改善提示词的格式。结合指令、上下文、输入和输出指示,通常能获得更好的结果。

结构化提示词示例

以下示例展示了更结构化的提示词格式,包含明确的上下文和约束条件。

提示词:

Answer the question based on the context below. Keep the answer short and concise. Respond "Unsure about answer" if not sure about the answer.

Context: Teplizumab traces its roots to a New Jersey drug company called Ortho Pharmaceutical. There, scientists generated an early version of the antibody, dubbed OKT3. Originally sourced from mice, the molecule was able to bind to the surface of T cells and limit their cell-killing potential. In 1986, it was approved to help prevent organ rejection after kidney transplants, making it the first therapeutic antibody allowed for human use.

Question: What was OKT3 originally sourced from?

Answer:

输出:

Mice.

文本分类

作为提示词工程师,你需要擅长提供清晰的指令。但在更困难的用例中,仅仅提供指令是不够的,这时你需要考虑提供示例(Few-Shot Prompting)来指定正确的行为。

基础分类

提示词:

Classify the text into neutral, negative or positive.

Text: I think the food was okay.

Sentiment:

输出:

Neutral

进阶分类:指定格式

如果你希望模型返回特定的标签格式(例如小写的"neutral"而不是首字母大写的"Neutral"),可以通过提供示例来引导模型。

提示词:

Classify the text into neutral, negative or positive.

Text: I think the vacation is okay.

Sentiment: neutral

Text: I think the food was okay.

Sentiment:

输出:

neutral

注意:具体性的重要性

如果在提示词中拼写错误(如将"neutral"写成"nutral"),模型可能会忽略你的虚构标签而输出它认为正确的标签。这强调了在提示词中提供准确信息和示例的重要性。

对话

你可以通过提示工程指导大语言模型扮演特定角色,指定其行为意图和身份。这在构建客户服务聊天机器人等对话系统时非常有用,也被称为"角色提示"。

技术性回答风格

提示词:

The following is a conversation with an AI research assistant. The assistant tone is technical and scientific.

Human: Hello, who are you?

AI: Greeting! I am an AI research assistant. How can I help you today?

Human: Can you tell me about the creation of blackholes?

AI:

输出:

Sure! Black holes are regions of spacetime where the gravitational force is so strong that nothing, not even light, can escape from it. They are created when a very massive star dies and its core collapses in on itself, forming a singularity of infinite density. The intense gravity of the singularity pulls in all the matter and radiation around it, creating the black hole.

通俗易懂风格

如果你希望回答更易于理解,可以调整指令。

提示词:

The following is a conversation with an AI research assistant. The assistant answers should be easy to understand even by primary school students.

Human: Hello, who are you?

AI: Greeting! I am an AI research assistant. How can I help you today?

Human: Can you tell me about the creation of black holes?

AI:

输出:

Sure! Black holes are created when a very massive star runs out of fuel and collapses in on itself. The gravity of the star is so strong that nothing, not even light, can escape its pull. This creates a point in space-time with an intense gravitational force called a black hole.

代码生成

大语言模型在代码生成方面非常有效,通过巧妙的提示,你可以执行大量的代码生成任务,甚至不需要指定编程语言。

简单程序

提示词:

/*

Ask the user for their name and say "Hello"

*/

输出:

let name = prompt("What is your name?");

console.log(Hello, ${name}!);

数据库查询生成

通过提供更多上下文(如数据库模式),模型可以生成复杂的查询。

提示词:

"""

Table departments, columns = [DepartmentId, DepartmentName]

Table students, columns = [DepartmentId, StudentId, StudentName]

Create a MySQL query for all students in the Computer Science Department

"""

输出:

SELECT StudentId, StudentName

FROM students

WHERE DepartmentId IN (SELECT DepartmentId FROM departments WHERE DepartmentName = 'Computer Science');

推理

推理是大型语言模型面临的最困难任务之一,但对于复杂应用的涌现至关重要。对于涉及数学能力的推理任务,有时需要更高级的提示词工程技术。

基础算术

提示词:

What is 9,000 * 9,000?

输出:

81,000,000

复杂推理:分步思考

当模型直接回答出错时(例如判断奇偶数之和),可以通过指示模型"将问题分解为步骤"来提高准确率。

提示词:

The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.

Solve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.

输出:

Odd numbers: 15, 5, 13, 7, 1

Sum: 41

41 is an odd number.

通过提供更好的指令并结合示例,可以显著提高模型在推理任务上的准确性。在后续章节中,我们将介绍更高级的提示工程概念和技术。

相关推荐
甄心爱学习6 小时前
【项目实训】法律文书智能摘要系统3
前端·人工智能
TheRouter6 小时前
AI 不会消灭软件工程,它只会消灭低维的软件工程
人工智能·软件工程
冲浪中台6 小时前
从追逐技术到回归业务本质,吃互联网红利罢了
服务器·前端·人工智能·低代码
3DVisionary6 小时前
升维洞察:DIC全场视觉检测如何重塑力学测试的“时空秩序”
人工智能·计算机视觉·视觉检测·动态测量·dic技术·xtdic·结构疲劳演化
做个文艺程序员6 小时前
Claude Skill 进阶:多文件结构、脚本集成与触发优化
人工智能·python·开源
阿杰学AI6 小时前
AI核心知识125—大语言模型之 混合专家架构(简洁且通俗易懂版)
人工智能·ai·语言模型·智能路由器·aigc·moe·混合专家架构
m0_743106466 小时前
【浙大&南洋理工最新综述】Feed-Forward 3D Scene Modeling(一)
论文阅读·人工智能·计算机视觉·3d·几何学
hqyjzsb6 小时前
传统剪辑师升级AI视频生成师后接单效率与收入变化
人工智能·aigc·服务发现·音视频·学习方法·业界资讯·ai写作
星幻元宇VR6 小时前
VR动感电动车|以沉浸体验推动交通安全科普新方式
人工智能·科技·学习·安全·生活·vr
织_网6 小时前
SDD规范驱动开发全解析:核心理念、工作流、落地层级+多AI协同实战
人工智能·驱动开发