From 61c08e911275bf6848ebe4f3743aed8d99496b7f Mon Sep 17 00:00:00 2001 From: shizidushu Date: Fri, 19 Jul 2024 22:08:26 +0800 Subject: [PATCH] Update examples.zh.mdx to keep it update and make it more readable --- pages/introduction/examples.zh.mdx | 134 ++++++++++++++--------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/pages/introduction/examples.zh.mdx b/pages/introduction/examples.zh.mdx index ee30175..d9636e1 100644 --- a/pages/introduction/examples.zh.mdx +++ b/pages/introduction/examples.zh.mdx @@ -3,9 +3,9 @@ import {Cards, Card} from 'nextra-theme-docs' import {CodeIcon} from 'components/icons' -在上一节中,我们介绍并给出了如何赋能大语言模型的基本示例。 +上一节介绍了如何提示大语言模型的基本示例。 -在本节中,我们会提供更多示例,介绍如何使用提示词来完成不同的任务,并介绍其中涉及的重要概念。通常,学习概念的最佳方法是通过示例进行学习。下面,我们将通过示例介绍说明如何使用精细的提示词来执行不同类型的任务。 +在本节中,我们会提供更多示例,介绍如何使用提示词来完成不同的任务,并介绍其中涉及的重要概念。通常,学习概念的最佳方式是通过例子。下面几个例子展示了如何使用精心制作的提示词来执行不同类型的任务。 主题: @@ -21,11 +21,9 @@ import {CodeIcon} from 'components/icons' ## 文本概括 -自然语言生成的标准任务之一是文本概括。文本概括可能涉及到不同的风格和领域。事实上,语言模型最前景的应用场景之一就是能够快速概括出易于理解的文章大意和相关概念。 我们可以使用提示词尝试一个简单的概括任务。 +自然语言生成中的一个标准任务是文本摘要。文本摘要可以涵盖许多不同的风格和领域。事实上,语言模型最有前景的应用之一就是将文章和概念概括成简洁易读的摘要。让我们尝试使用提示进行一个基本的摘要任务。 -假设我想了解抗生素的相关信息,我可以给出这样的提示: - -_提示词_ +*提示词:* ``` Explain antibiotics @@ -33,68 +31,70 @@ 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. ``` -在问答形式中,“A:” 是一种明确的提示格式。 在这个示例中,我用它去提示模型,我想要该概念的进一步解释。 在这个例子中,我们可能还不清楚使用它是否有用,我们会在之后的示例中探讨这一点。 现在假设我们感觉模型给了太多的信息,想要进一步提炼它。 我们可以指导模型帮我们用一句话总结相关内容: - -_提示词_ +"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. -Explain the above in one sentence: // 用一句话解释上面的信息: +Explain the above in one sentence: ``` -_输出结果_ +> 译注:`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. ``` -本示例是模型在没有过多关注上文输出内容的准确性的情况下,尝试用一个句子来总结段落内容。 关于上文准确性,我们可以通过指令或说明进一步改善它,这一点我们会在后续指南中进行探讨。 读到这里,您可以暂时停住并进行实验,看看是否能获得更好的结果。 +在不过多关注上面输出的准确性的情况下(这是我们将在后续指南中讨论的内容),模型尝试将段落总结成一句话。你可以对指令进行巧妙的设计,但我们将留到后面的章节再讨论。你可以暂时停住并进行实验,看看是否能获得更好的结果。 * * * ## 信息提取 -语言模型通过训练不仅可以用于执行自然语言生成相关任务,还可以用于执行文本分类和其他一系列自然语言处理 (NLP) 任务。 +虽然语言模型是被训练用于执行自然语言生成及相关任务,但它同样非常擅长执行分类和一系列其他自然语言处理(NLP)任务。 -使用以下示例提示词从指定段落中提取信息: +这是一个从给定段落中提取信息的提示词示例。 -_提示词_ +*提示词:* ``` 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: // 指出上文中提到的大语言模型: +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. ``` -我们可以通过许多方式改进以上结果,但当前方式已经非常有用。 +你可以通过许多方法来改进上述结果,但这已经非常有用了。 -现在应该很明显,您可以通过简单地指示语言模型去执行不同的任务。 AI 研发人员也利用这种能力来构建强大的产品和体验。 +现在应该很明显,你可以通过简单地指示模型做什么来让它执行不同的任务。这是一个强大的能力,AI产品开发人员已经在利用它来构建强大的产品和体验。 -Paragraph source: [ChatGPT: five priorities for research](https://www.nature.com/articles/d41586-023-00288-7) +段落来源: [ChatGPT: five priorities for research](https://www.nature.com/articles/d41586-023-00288-7) * * * ## 问答 -提高模型响应精确度的最佳方法之一是改进提示词的格式。 如前所述,提示词可以通过指令、上下文、输入和输出指示以改进响应结果。 虽然这些要素不是必需的,但如果您的指示越明确,响应的结果就会越好。 以下示例可以说明结构化提示词的重要性。 +让模型给出具体回答的最佳方法之一是改善提示的格式。如前所述,一个提示可以结合指令、上下文、输入和输出指示(output indicators)来获得更好的结果。虽然这些组成部分不是必需的,但随着你给出的指令越具体,你将获得越好的结果,这成为了一种良好的实践。下面是一个例子,展示了按照更结构化的提示词来会是什么样子的。 -_提示词_ +*提示词:* ``` -Answer the question based on the context below. Keep the answer short and concise. Respond "Unsure about answer" if not sure about the answer. // 基于以下语境回答问题。如果不知道答案的话,请回答“不确定答案”。 +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. @@ -103,40 +103,40 @@ Question: What was OKT3 originally sourced from? Answer: ``` -_输出结果_ +*输出:* ``` Mice. ``` -语境参考至 [Nature](https://www.nature.com/articles/d41586-023-00400-x)。 +上下文获取自 [Nature](https://www.nature.com/articles/d41586-023-00400-x)。 * * * ## 文本分类 -目前,我们已经会使用简单的指令来执行任务。 作为提示工程师,您需要提供更好的指令。 此外, 您也会发现,对于更负责的使用场景,仅提供指令是远远不够的。 所以,您需要思考如何在提示词中包含相关语境和其他不同要素。 同样,你还可以提供其他的信息,如`输入数据`和`示例`。 +到目前为止,你已经使用了简单的指令来执行任务。作为提示词工程师,你需要更擅长提供更好的指令。但这还不是全部!你还会发现,在更困难的用例中,仅仅提供指令是不够的。这就是你需要更多考虑上下文和其他元素(在提示词中使用)的地方。你可以提供的其他元素包括`输入数据`或`示例`。 -可以通过以下示例体验文本分类: +让我们通过一个文本分类的示例来演示这一点。 -_提示词_ +*提示词:* ``` -Classify the text into neutral, negative or positive. // 将文本按中立、负面或正面进行分类 +Classify the text into neutral, negative or positive. Text: I think the food was okay. Sentiment: ``` -_输出结果_ +*输出:* ``` Neutral ``` -我们给出了对文本进行分类的指令,语言模型做出了正确响应,判断文本类型为 `'Neutral'`。 如果我们想要语言模型以指定格式做出响应, 比如,我们想要它返回 `neutral` 而不是 `Neutral`, 那我们要如何做呢? 我们有多种方法可以实现这一点。 此例中,我们主要是关注绝对特性,因此,我们提示词中包含的信息越多,响应结果就会越好。 我们可以使用以下示例来校正响应结果: +你给出了对文本进行分类的指令,模型以`'Neutral'`回应,这是正确的。这没有问题,但假设你真正需要的是让模型以你希望的确切格式给出标签。因此,你希望它返回的是`neutral`而不是`Neutral`。你如何实现这一点呢?有几种不同的方法可以做到这一点。在这里,你关心的是具体性,所以你给提示词提供的信息越多,结果就越好。你可以尝试提供示例来指定正确的行为。让我们再试一次: -_提示词_ +*提示词:* ``` Classify the text into neutral, negative or positive. @@ -148,15 +148,17 @@ Text: I think the food was okay. Sentiment: ``` -_输出结果_ +*输出:* ``` neutral ``` -完美! 这次模型返回了 `neutral`,这正是我们想要的特定标签。 提示词中的示例使得模型可以给出更具体的响应。 有时给出具体的指令十分重要,可以通过以下示例感受这一点: +完美!这次模型返回了`neutral`,这是你所寻找的具体标签。看起来,提示中提供的示例帮助模型在其输出中保持了具体性。 + +为了强调有时具体性为什么很重要,请查看下面的例子并找出问题所在: -_提示词_ +*提示词:* ``` Classify the text into nutral, negative or positive. @@ -165,26 +167,26 @@ Text: I think the vacation is okay. Sentiment: ``` -_输出结果_ +*输出:* ``` Neutral ``` -这时候你知道给出具体指令的重要性了吧? +这里的问题是什么?作为提示,模型完全忽略了虚构的`nutral`标签。相反,模型输出了`Neutral`,因为它对这个标签有一定的偏好。但假设你真正想要的是`nutral`。你怎么解决这个问题?也许你可以尝试为标签添加描述或在提示中增加更多示例?如果你不确定,我们将在接下来的部分讨论一些想法。 * * * ## 对话 -你可以通过提示工程进行更有趣的实验,比如指导大语言模型系统如何表现,指定它的行为意图和身份。 如果你正在构建客服聊天机器人之类的对话系统时,这项功能尤其有用。 +你可以通过提示工程进行更有趣的实验,比如指导大语言模型系统如何表现,指定它的行为意图和身份。 当你在构建对话系统,如客户服务聊天机器人时,这尤其有用。 -比如,可以通过以下示例创建一个对话系统,该系统能够基于问题给出技术性和科学的回答。 你可以关注我们是如何通过指令明确地告诉模型应该如何表现。 这种应用场景有时也被称为 _角色提示(Role Prompting)_。 +比如,可以通过以下示例创建一个对话系统,该系统能够基于问题给出技术性和科学的回答。 你可以关注我们是如何通过指令明确地告诉模型应该如何表现。 这种应用场景有时也被称为*角色提示(Role Prompting)*。 -_提示词_ +*提示词:* ``` -The following is a conversation with an AI research assistant. The assistant tone is technical and scientific. // 以下是与 AI 助理的对话,语气应该专业、技术性强。 +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? @@ -192,18 +194,18 @@ 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. ``` -我们的 AI 助理给出的回答非常技术对吧? 下面,我们让它给出更易于理解的答案。 +我们的AI研究助手听起来有点太技术性了,对吗?好的,让我们改变这种行为,并指示系统给出更易于理解的回答。 -_提示词_ +*提示词:* ``` -The following is a conversation with an AI research assistant. The assistant answers should be easy to understand even by primary school students. // 以下是与 AI 助理的对话。请给出易于理解的答案,最好是小学生都能看懂的那种。 +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? @@ -211,31 +213,31 @@ 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. ``` -我想我们应该取得了一些进展, 你也可以继续改进它。 如果你再添加更多的示例,可能会得到更好的结果。 +我想我们应该取得了一些进展, 你也可以继续改进它。 如果你再添加更多的示例,可能会得到更好的结果。 * * * ## 代码生成 -大语言模型另外一个有效的应用场景是代码生成。 在此方面,Copilot 就是一个很好的示例。 你可以通过一些有效的提示词执行代码生成任务。 让我们来看一下下面的例子。 +大语言模型(LLMs)在代码生成方面非常有效。 在此方面,Copilot 就是一个很好的示例。通过巧妙的提示,你可以执行大量的代码生成任务。下面我们来看几个示例。 我们先用它写个简单的用户欢迎程序: -_提示词_ +*提示词:* ``` /* -询问用户的姓名并说“ Hello” +Ask the user for their name and say "Hello" */ ``` -_输出结果_ +*输出:* ``` let name = prompt("What is your name?"); @@ -244,9 +246,9 @@ console.log(`Hello, ${name}!`); 你看,我们甚至都不需要指定要使用的编程语言。 -来,我们再稍微升级一下。 下面的例子会向你展示提示词会让大语言模型变得多么强大。 +来,我们再稍微升级一下。 下面的示例展示了通过稍微多一点的提示词设计工作,LLMs可以变得多么强大。 -_提示词_ +*提示词:* ``` """ @@ -256,7 +258,7 @@ Create a MySQL query for all students in the Computer Science Department """ ``` -_输出结果_ +*输出:* ``` SELECT StudentId, StudentName @@ -264,31 +266,31 @@ FROM students WHERE DepartmentId IN (SELECT DepartmentId FROM departments WHERE DepartmentName = 'Computer Science'); ``` -挺厉害的嘛。 本例中,我们提供了有关数据库架构并要求它生成有效的 MySQL 查询。 +这非常令人印象深刻。在这种情况下,你提供了关于数据库模式的数据,并要求它生成一个有效的 MySQL 查询。 * * * ## 推理 -目前对于大语言模型来说,推理任务算是最具有挑战性的了。 推理任务最让人兴奋的地方就是可以促使各种复杂的应用程序从大语言模型中诞生。 +也许,当今大型语言模型(LLM)面临的最困难任务之一是需要某种形式的推理的任务。推理是最具吸引力的领域之一,因为有了推理,就可以从LLM中涌现出各种复杂的应用类型。 目前,涉及数学能力的推理任务已经有了一些改进。 对于当前的大型语言模型来说,执行推理任务可能会有一些难度,因此就需要更高级的提示词工程技术。 我们会在后面的指南中介绍这些高级技术。 现在,我们将介绍几个基本示例来展示算术功能。 -_提示词_ +*提示词:* ``` 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. @@ -296,7 +298,7 @@ The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. A: ``` -_输出结果_ +*输出:* ``` No, the odd numbers in this group add up to an odd number: 119. @@ -304,7 +306,7 @@ No, the odd numbers in this group add up to an odd number: 119. 这不对! 我们试着用提示词去改进它: -_提示词_ +*提示词:* ``` The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. @@ -312,7 +314,7 @@ 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 @@ -320,9 +322,7 @@ Sum: 41 41 is an odd number. ``` -好多了吧? 顺便说一句,我试过几次,有时还是会失败。 如果你可以用示例给模型说明一下,可能会获得更准确的结果。 - -我们后面还会在本章节中介绍更多常见应用示例。 +效果好多了,对吧?顺便提一下,我们尝试了几次这个任务,模型有时会失败。如果你提供更好的指令并结合示例,这可能有助于获得更准确的结果。 在后面的章节,我们将介绍更高级的提示工程概念和技术,以完成更困难任务。