吴恩达 GPT Prompting 课程

这篇具有很好参考价值的文章主要介绍了吴恩达 GPT Prompting 课程。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Guidelines for Prompting

In this lesson, you’ll practice two prompting principles and their related tactics in order to write effective prompts for large language models.

Prompting Principles

  • Principle 1: Write clear and specific instructions
  1. Use delimiters to clearly indicate distinct parts of the input
  2. Ask for a structured output
  3. Ask the model to check whether conditions are satisfied
  4. “Few-shot” prompting
  • Principle 2: Give the model time to “think”
  1. Specify the steps required to complete a task
  2. Ask for output in a specified format
  3. Instruct the model to work out its own solution before rushing to a conclusion

Principle 1: Write clear and specific instructions

1.1: Use delimiters to clearly indicate distinct parts of the input

  • Delimiters can be anything like: ```, """, < >, <tag> </tag>, :
text = f"""
You should express what you want a model to do by \ 
providing instructions that are as clear and \ 
specific as you can possibly make them. \ 
This will guide the model towards the desired output, \ 
and reduce the chances of receiving irrelevant \ 
or incorrect responses. Don't confuse writing a \ 
clear prompt with writing a short prompt. \ 
In many cases, longer prompts provide more clarity \ 
and context for the model, which can lead to \ 
more detailed and relevant outputs.
"""
prompt = f"""
Summarize the text delimited by triple backticks \ 
into a single sentence.
```{text}```
"""
response = get_completion(prompt)
print(response)

GPT 返回结果:

To guide a model towards the desired output and reduce irrelevant or incorrect responses, it is important to provide clear and specific instructions, which can be achieved through longer prompts that offer more clarity and context.

1.2: Ask for a structured output

  • JSON, HTML
prompt = f"""
Generate a list of three made-up book titles along \ 
with their authors and genres. 
Provide them in JSON format with the following keys: 
book_id, title, author, genre.
"""
response = get_completion(prompt)
print(response)

GPT 返回结果:

{
  "books": [
    {
      "book_id": 1,
      "title": "The Enigma of Elysium",
      "author": "Evelyn Sinclair",
      "genre": "Mystery"
    },
    {
      "book_id": 2,
      "title": "Whispers in the Wind",
      "author": "Nathaniel Blackwood",
      "genre": "Fantasy"
    },
    {
      "book_id": 3,
      "title": "Echoes of the Past",
      "author": "Amelia Hart",
      "genre": "Romance"
    }
  ]
}

1.3: Ask the model to check whether conditions are satisfied

text_1 = f"""
Making a cup of tea is easy! First, you need to get some \ 
water boiling. While that's happening, \ 
grab a cup and put a tea bag in it. Once the water is \ 
hot enough, just pour it over the tea bag. \ 
Let it sit for a bit so the tea can steep. After a \ 
few minutes, take out the tea bag. If you \ 
like, you can add some sugar or milk to taste. \ 
And that's it! You've got yourself a delicious \ 
cup of tea to enjoy.
"""
prompt = f"""
You will be provided with text delimited by triple quotes. 
If it contains a sequence of instructions, \ 
re-write those instructions in the following format:

Step 1 - ...
Step 2 - …
…
Step N - …

If the text does not contain a sequence of instructions, \ 
then simply write \"No steps provided.\"

\"\"\"{text_1}\"\"\"
"""
response = get_completion(prompt)
print("Completion for Text 1:")
print(response)

GPT 返回结果:
Completion for Text 1:
Step 1 - Get some water boiling.
Step 2 - Grab a cup and put a tea bag in it.
Step 3 - Once the water is hot enough, pour it over the tea bag.
Step 4 - Let it sit for a bit so the tea can steep.
Step 5 - After a few minutes, take out the tea bag.
Step 6 - If you like, add some sugar or milk to taste.
Step 7 - Enjoy your delicious cup of tea.

text_2 = f"""
The sun is shining brightly today, and the birds are \
singing. It's a beautiful day to go for a \ 
walk in the park. The flowers are blooming, and the \ 
trees are swaying gently in the breeze. People \ 
are out and about, enjoying the lovely weather. \ 
Some are having picnics, while others are playing \ 
games or simply relaxing on the grass. It's a \ 
perfect day to spend time outdoors and appreciate the \ 
beauty of nature.
"""
prompt = f"""
You will be provided with text delimited by triple quotes. 
If it contains a sequence of instructions, \ 
re-write those instructions in the following format:

Step 1 - ...
Step 2 - …
…
Step N - …

If the text does not contain a sequence of instructions, \ 
then simply write \"No steps provided.\"

\"\"\"{text_2}\"\"\"
"""
response = get_completion(prompt)
print("Completion for Text 2:")
print(response)

GPT 返回结果:
Completion for Text 2:
No steps provided.

1.4: “Few-shot” prompting

prompt = f"""
Your task is to answer in a consistent style.

<child>: Teach me about patience.

<grandparent>: The river that carves the deepest \ 
valley flows from a modest spring; the \ 
grandest symphony originates from a single note; \ 
the most intricate tapestry begins with a solitary thread.

<child>: Teach me about resilience.
"""
response = get_completion(prompt)
print(response)

GPT 返回结果:
: Resilience is like a mighty oak tree that withstands the strongest storms, bending but never breaking. It is the unwavering determination to rise again after every fall, and the ability to find strength in the face of adversity. Just as a diamond is formed under immense pressure, resilience is forged through challenges and hardships, making us stronger and more resilient in the process.

Principle 2: Give the model time to “think”

2.1.1: Specify the steps required to complete a task

text = f"""
In a charming village, siblings Jack and Jill set out on \ 
a quest to fetch water from a hilltop \ 
well. As they climbed, singing joyfully, misfortune \ 
struck—Jack tripped on a stone and tumbled \ 
down the hill, with Jill following suit. \ 
Though slightly battered, the pair returned home to \ 
comforting embraces. Despite the mishap, \ 
their adventurous spirits remained undimmed, and they \ 
continued exploring with delight.
"""

prompt_1 = f"""
Perform the following actions: 
1 - Summarize the following text delimited by triple \
backticks with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the following \
keys: french_summary, num_names.

Separate your answers with line breaks.

Text:
```{text}```
"""
response = get_completion(prompt_1)
print("Completion for prompt 1:")
print(response)

GPT 返回结果:

Completion for prompt 1:
1 - Jack and Jill, siblings, go on a quest to fetch water from a hilltop well, but encounter misfortune when Jack trips on a stone and tumbles down the hill, with Jill following suit, yet they return home and remain undeterred in their adventurous spirits.

2 - Jack et Jill, frère et sœur, partent en quête d'eau d'un puits au sommet d'une colline, mais rencontrent un malheur lorsque Jack trébuche sur une pierre et dévale la colline, suivi de Jill, pourtant ils rentrent chez eux et restent déterminés dans leur esprit d'aventure.

3 - Jack, Jill

4 - {
  "french_summary": "Jack et Jill, frère et sœur, partent en quête d'eau d'un puits au sommet d'une colline, mais rencontrent un malheur lorsque Jack trébuche sur une pierre et dévale la colline, suivi de Jill, pourtant ils rentrent chez eux et restent déterminés dans leur esprit d'aventure.",
  "num_names": 2
}

2.1.2 Ask for output in a specified format

prompt_2 = f"""
Your task is to perform the following actions: 
1 - Summarize the following text delimited by 
  <> with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the 
  following keys: french_summary, num_names.

Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>
Names: <list of names in Italian summary>
Output JSON: <json with summary and num_names>

Text: <{text}>
"""
response = get_completion(prompt_2)
print("\nCompletion for prompt 2:")
print(response)

GPT 返回结果:

Completion for prompt 2:
Summary: Jack and Jill, siblings, go on a quest to fetch water from a hilltop well but encounter misfortune along the way. 
Translation: Jack et Jill, frère et sœur, partent en quête d'eau d'un puits au sommet d'une colline mais rencontrent des malheurs en chemin.
Names: Jack, Jill
Output JSON: {"french_summary": "Jack et Jill, frère et sœur, partent en quête d'eau d'un puits au sommet d'une colline mais rencontrent des malheurs en chemin.", "num_names": 2}

2.2: Instruct the model to work out its own solution before rushing to a conclusion

prompt = f"""
Determine if the student's solution is correct or not.

Question:
I'm building a solar power installation and I need \
 help working out the financials. 
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \ 
me a flat $100k per year, and an additional $10 / square \
foot
What is the total cost for the first year of operations 
as a function of the number of square feet.

Student's Solution:
Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
"""
response = get_completion(prompt)
print(response)

GPT 返回结果:

The student's solution is correct. They correctly identified the costs for land, solar panels, and maintenance, and calculated the total cost as a function of the number of square feet.

Note that the student’s solution is actually not correct.
We can fix this by instructing the model to work out its own solution first (or not).

prompt = f"""
Your task is to determine if the student's solution \
is correct or not.
To solve the problem do the following:
- First, work out your own solution to the problem. 
- Then compare your solution to the student's solution \ 
and evaluate if the student's solution is correct or not. 
Don't decide if the student's solution is correct until 
you have done the problem yourself.

Use the following format:
Question:

question here

Student's solution:
student's solution here

Actual solution:

steps to work out the solution and your solution here

Is the student's solution the same as actual solution \
just calculated:

yes or no

Student grade:

correct or incorrect


Question:

I'm building a solar power installation and I need help \
working out the financials. 
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \
me a flat $100k per year, and an additional $10 / square \
foot
What is the total cost for the first year of operations \
as a function of the number of square feet.


Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000

Actual solution:

response = get_completion(prompt)
print(response)

GPT 返回结果:

To calculate the total cost for the first year of operations, we need to add up the costs of land, solar panels, and maintenance.

Let x be the size of the installation in square feet.

Costs:
1. Land cost: $100 * x
2. Solar panel cost: $250 * x
3. Maintenance cost: $100,000 + $10 * x

Total cost: $100 * x + $250 * x + $100,000 + $10 * x = $360 * x + $100,000

Is the student's solution the same as the actual solution just calculated:
No

Student grade:
Incorrect

Model Limitations: Hallucinations

  • Boie is a real company, the product name is not real.
prompt = f"""
Tell me about AeroGlide UltraSlim Smart Toothbrush by Boie
"""
response = get_completion(prompt)
print(response)

GPT 返回结果:文章来源地址https://www.toymoban.com/news/detail-667336.html

The AeroGlide UltraSlim Smart Toothbrush by Boie is a technologically advanced toothbrush designed to provide a superior brushing experience. Boie is a company known for its innovative oral care products, and the AeroGlide UltraSlim Smart Toothbrush is no exception.

One of the standout features of this toothbrush is its ultra-slim design. The brush head is only 2mm thick, making it much thinner than traditional toothbrushes. This slim profile allows for better access to hard-to-reach areas of the mouth, ensuring a thorough and effective clean.

The AeroGlide UltraSlim Smart Toothbrush also incorporates smart technology. It connects to a mobile app via Bluetooth, allowing users to track their brushing habits and receive personalized recommendations for improving their oral hygiene routine. The app provides real-time feedback on brushing technique, ensuring that users are brushing for the recommended two minutes and covering all areas of their mouth.

The toothbrush itself is made from a durable and hygienic material called thermoplastic elastomer. This material is non-porous, meaning it doesn't harbor bacteria or mold, making it more hygienic than traditional toothbrush bristles. The bristles are also ultra-soft, providing a gentle yet effective clean without causing any damage to the gums or enamel.

In addition to its technological features, the AeroGlide UltraSlim Smart Toothbrush is also eco-friendly. It is designed to last for up to six months, reducing the need for frequent replacements. The brush head is also replaceable, further reducing waste.

Overall, the AeroGlide UltraSlim Smart Toothbrush by Boie offers a combination of advanced technology, slim design, and eco-friendly features. It aims to provide users with a superior brushing experience, helping them maintain optimal oral health.

到了这里,关于吴恩达 GPT Prompting 课程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【AI提示】ChatGPT提示工程课程(吴恩达&OpenAI)推理文本(中文chatgpt版)

    设置 Setup 产品评论文本 情感(正面/负面)Sentiment (positive/negative) 识别情绪类型 从客户评论中提取产品和公司名称 一次完成多项任务 Inferring topics 推断主题 为某些主题制作新闻提醒 Inferring 推理 在本课中,您将从产品评论和新闻文章中推断情绪和主题。 设置 Setup 产品评论

    2024年02月07日
    浏览(85)
  • “AI 程序员”席卷而来,吴恩达四步设计让 Agent 提前超越 GPT-5

    作者 | 王启隆 出品 | AI 科技大本营(ID:rgznai100) 有不少科幻片描绘了这样的世界:数字实体执行一座城市的所有任务,人工智能可以与数字世界甚至物理世界的一切事物进行交互,不断学习和适应新环境,周围的人对此司空见惯,仿佛一切都理应如此…… 现在,随着 AI

    2024年04月08日
    浏览(61)
  • 吴恩达+Open AI 《面向开发者的ChatGPT Prompt 工程》课程学习1——课程介绍

    许多人都体验过ChatGPT的Web用户界面来完成特定而且通常是一次性的任务。但是从开发者的角度来说,通过API调用LLM(large language model大语言模型)来快速构建应用程序这个强大的功能被严重低估了。 学习到一些软件开发提示词的最佳实践; 学习到一些常见的用例、总结、推

    2024年02月06日
    浏览(68)
  • Azure Machine Learning - Azure OpenAI 服务使用 GPT-35-Turbo and GPT-4

    通过 Azure OpenAI 服务使用 GPT-35-Turbo and GPT-4 Azure 订阅 - 免费创建订阅 已在所需的 Azure 订阅中授予对 Azure OpenAI 服务的访问权限。 目前,仅应用程序授予对此服务的访问权限。 可以填写 https://aka.ms/oai/access 处的表单来申请对 Azure OpenAI 服务的访问权限。 Python 3.7.1 或更高版本。

    2024年02月05日
    浏览(47)
  • Azure Machine Learning - Azure OpenAI GPT 3.5 Turbo 微调教程

    本教程将引导你在Azure平台完成对 gpt-35-turbo-0613 模型的微调。 关注TechLead,分享AI全维度知识。作者拥有10+年互联网服务架构、AI产品研发经验、团队管理经验,同济本复旦硕,复旦机器人智能实验室成员,阿里云认证的资深架构师,项目管理专业人士,上亿营收AI产品研发负

    2024年02月04日
    浏览(57)
  • 吴恩达+Open AI 《面向开发者的ChatGPT Prompt 工程》课程学习2——prompt指导原则1

    吴恩达+Open AI 《面向开发者的ChatGPT Prompt 工程》课程学习1——课程介绍 吴恩达+Open AI 《面向开发者的ChatGPT Prompt 工程》课程学习2——prompt指导原则1(本博文) prompt编写指导原则1:写出清晰而具体的指示。 本节课讲述方式:理论+代码实践。 1 在整个课程中,我们将使用

    2024年02月07日
    浏览(41)
  • 【机器学习】吴恩达课程1-Introduction

    计算机程序从经验E中学习,解决某一任务T,进行某一性能P,通过P测定在T上的表现因经验E而提高。 跳棋程序 E:程序自身下的上万盘棋局 T:下跳棋 P:与新对手下跳棋时赢的概率 给算法一个数据集,其中包含了正确答案,算法的目的是给出更多的正确答案。 (1)预测房价

    2024年02月16日
    浏览(39)
  • 吴恩达llama课程笔记:第七课llama安全工具

     羊驼Llama是当前最流行的开源大模型,其卓越的性能和广泛的应用领域使其成为业界瞩目的焦点。作为一款由Meta AI发布的开放且高效的大型基础语言模型,Llama拥有7B、13B和70B(700亿)三种版本,满足不同场景和需求。 吴恩达教授推出了全新的Llama课程,旨在帮助学习者全面

    2024年04月25日
    浏览(34)
  • 吴恩达471机器学习入门课程1第3周——逻辑回归

    实施逻辑回归并将其应用于两个不同的数据集。 在这一部分中,你将建立一个逻辑回归模型来预测学生是否被大学录取。 2.1、问题描述 假设你是一所大学部门的管理员,并且想要根据每个申请人在两次考试中的成绩来确定他们被录取的机会。 你有先前申请者的历史数据,可

    2024年02月09日
    浏览(39)
  • 吴恩达ChatGPT课爆火

    点上方 计算机视觉联盟 获取更多干货 没想到时至今日,ChatGPT竟还会犯低级错误? 吴恩达大神最新开课就指出来了: ChatGPT不会反转单词! 比如让它反转下lollipop这个词,输出是pilollol,完全混乱。 哦豁,这确实有点大跌眼镜啊。 以至于听课网友在Reddit上发帖后,立马引来

    2024年02月09日
    浏览(44)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包