├── subtitle_split.py
├── chinese_subtitles
├── prompt_eng_09_conclusion_chinese.srt
├── prompt_eng_04_summarizing_chinese.srt
├── prompt_eng_01_intro_chinese.srt
├── prompt_eng_07_expanding_chinese.srt
├── prompt_eng_06_transforming_chinese.srt
├── prompt_eng_05_inferring_chinese.srt
└── prompt_eng_08_chatbot_chinese.srt
├── README.md
├── english_subtitles
├── prompt_eng_09_conclusion_english.srt
├── prompt_eng_04_summarizing_english.srt
├── prompt_eng_01_intro_english.srt
└── prompt_eng_07_expanding_english.srt
├── subtitles
├── raw
│ ├── prompt_eng_09_conclusion.srt
│ ├── prompt_eng_04_summarizing.srt
│ └── prompt_eng_01_intro.srt
└── styled
│ └── prompt_eng_09_conclusion.ass
└── course_notebooks
├── l7-expanding.ipynb
├── l8-chatbot.ipynb
├── l3-iterative-prompt-development.ipynb
├── l5-inferring.ipynb
├── l6-transforming.ipynb
└── l4-summarizing.ipynb
/subtitle_split.py:
--------------------------------------------------------------------------------
1 | import os
2 | import re
3 |
4 | subs_path = 'subtitles/raw'
5 | cn_subs_path = 'chinese_subtitles'
6 | en_subs_path = 'english_subtitles'
7 |
8 | def extract_timeline_and_content(input_file):
9 | # Read the input file and create a dictionary of subtitles with timeline keys
10 | with open(input_file, "r", encoding="utf-8") as f:
11 | lines = f.readlines()
12 |
13 | subtitles_dict = {}
14 | for i, line in enumerate(lines):
15 | line = line.strip()
16 | if re.match(r'\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}', line):
17 | timeline = line
18 | chinese = lines[i + 1].strip()
19 | english = lines[i + 2].strip()
20 | subtitles_dict[timeline] = {"chinese": chinese, "english": english}
21 |
22 | return subtitles_dict
23 |
24 | def write_chinese_subtitles(subtitles_dict, output_file):
25 | # Write Chinese subtitles to output_file
26 | with open(output_file, "w", encoding="utf-8") as f:
27 | for idx, (timeline, content) in enumerate(subtitles_dict.items()):
28 | f.write(f"{idx + 1}\n{timeline}\n{content['chinese']}\n\n")
29 |
30 | def write_english_subtitles(subtitles_dict, output_file):
31 | # Write English subtitles to output_file
32 | with open(output_file, "w", encoding="utf-8") as f:
33 | for idx, (timeline, content) in enumerate(subtitles_dict.items()):
34 | f.write(f"{idx + 1}\n{timeline}\n{content['english']}\n\n")
35 |
36 | def process_filename(filename):
37 | # Generate Chinese and English output filenames
38 | basename, ext = os.path.splitext(filename)
39 | return basename + "_chinese" + ext, basename + "_english" + ext
40 |
41 | def process_files():
42 | # Create output directories if they don't exist
43 | os.makedirs(cn_subs_path, exist_ok=True)
44 | os.makedirs(en_subs_path, exist_ok=True)
45 |
46 | # Iterate through all SRT files in the subtitles directory
47 | for filename in os.listdir(subs_path):
48 | if filename.endswith(".srt") and not filename.endswith("_chinese.srt") and not filename.endswith("_english.srt"):
49 | print(f"Processing {filename}")
50 | input_file = os.path.join(subs_path, filename)
51 | subtitles_dict = extract_timeline_and_content(input_file)
52 | chinese_output, english_output = process_filename(filename)
53 | write_chinese_subtitles(subtitles_dict, os.path.join(cn_subs_path, chinese_output))
54 | write_english_subtitles(subtitles_dict, os.path.join(en_subs_path, english_output))
55 | print(f"Generated {chinese_output} and {english_output}\n")
56 |
57 | # Traverse all subtitle files under current directory and generate Chinese and English subtitles.
58 | process_files()
--------------------------------------------------------------------------------
/chinese_subtitles/prompt_eng_09_conclusion_chinese.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:08,840
3 | 祝贺你在这个短期课程中走到了最后
4 |
5 | 2
6 | 00:00:08,840 --> 00:00:11,280
7 | 综上所述,在这个短课程中
8 |
9 | 3
10 | 00:00:11,280 --> 00:00:14,380
11 | 你已经了解了提示的两个关键原则
12 |
13 | 4
14 | 00:00:14,380 --> 00:00:17,480
15 | 正确且清晰的描述具体指示,以及知道什么时候使用
16 |
17 | 5
18 | 00:00:17,480 --> 00:00:19,160
19 | 给予模型思考的时间
20 |
21 | 6
22 | 00:00:19,160 --> 00:00:22,080
23 | 你还了解了迭代提示的发展以及如何
24 |
25 | 7
26 | 00:00:22,080 --> 00:00:26,200
27 | 有一个过程来获得适合你的应用的提示是关键
28 |
29 | 8
30 | 00:00:26,200 --> 00:00:28,800
31 | 我们还学习了一些大语言模型的功能
32 |
33 | 9
34 | 00:00:28,800 --> 00:00:31,640
35 | 这些功能对许多应用是有用的
36 |
37 | 10
38 | 00:00:31,640 --> 00:00:36,320
39 | 特别是总结、推理、转换和扩展
40 |
41 | 11
42 | 00:00:36,320 --> 00:00:39,880
43 | 你还看到了如何建立一个定制的聊天机器人
44 |
45 | 12
46 | 00:00:39,880 --> 00:00:43,320
47 | 在短短的课程中,你学到了很多东西
48 |
49 | 13
50 | 00:00:43,320 --> 00:00:46,240
51 | 我希望你喜欢阅读这些材料
52 |
53 | 14
54 | 00:00:46,240 --> 00:00:47,920
55 | 我们希望你能想出一些想法
56 |
57 | 15
58 | 00:00:47,920 --> 00:00:50,120
59 | 我们希望你能想出一些可以自己构建的应用
60 |
61 | 16
62 | 00:00:50,120 --> 00:00:53,120
63 | 并请你去尝试一下,让我们知道你想出了什么
64 |
65 | 17
66 | 00:00:53,120 --> 00:00:54,720
67 | 任何应用都不小
68 |
69 | 18
70 | 00:00:54,720 --> 00:00:57,000
71 | 从一些很小的项目开始也是可以的
72 |
73 | 19
74 | 00:00:57,000 --> 00:00:59,800
75 | 一个非常小的项目,也许实用
76 |
77 | 20
78 | 00:00:59,800 --> 00:01:01,800
79 | 也可能毫无用处
80 |
81 | 21
82 | 00:01:01,800 --> 00:01:03,320
83 | 这只是一些有趣的东西
84 |
85 | 22
86 | 00:01:03,320 --> 00:01:06,200
87 | 是的。我发现玩这些模型非常有趣
88 |
89 | 23
90 | 00:01:06,200 --> 00:01:07,440
91 | 所以放心去玩吧
92 |
93 | 24
94 | 00:01:07,440 --> 00:01:08,640
95 | 是的,我同意。从我的经验来看
96 |
97 | 25
98 | 00:01:08,640 --> 00:01:11,080
99 | 这是一个很好的周末活动
100 |
101 | 26
102 | 00:01:11,080 --> 00:01:14,960
103 | 而且,你可以通过第一个项目获得的经验教训
104 |
105 | 27
106 | 00:01:14,960 --> 00:01:18,520
107 | 来构建第二个更好的项目
108 |
109 | 28
110 | 00:01:18,520 --> 00:01:21,360
111 | 甚至可能是更好的第三个项目,等等
112 |
113 | 29
114 | 00:01:21,360 --> 00:01:26,960
115 | 这就是我自己使用这些模型逐渐成长的方式
116 |
117 | 30
118 | 00:01:26,960 --> 00:01:31,360
119 | 或者如果你已经有了一个更大的项目想法,就去做吧
120 |
121 | 31
122 | 00:01:31,360 --> 00:01:33,960
123 | 作为一个提醒
124 |
125 | 32
126 | 00:01:33,960 --> 00:01:37,200
127 | 这些大语言模型是一种非常强大的技术
128 |
129 | 33
130 | 00:01:37,200 --> 00:01:41,120
131 | 所以不言而喻,我们要求你负责任地使用它们
132 |
133 | 34
134 | 00:01:41,120 --> 00:01:43,960
135 | 请只建立会产生积极影响的东西
136 |
137 | 35
138 | 00:01:43,960 --> 00:01:46,240
139 | 是的,完全同意。我认为在这个时代
140 |
141 | 36
142 | 00:01:46,240 --> 00:01:49,480
143 | 建立AI系统的人可以对其他人产生巨大的影响
144 |
145 | 37
146 | 00:01:49,480 --> 00:01:54,960
147 | 因此,我们所有人都要负责任地使用这些工具,这一点比以往任何时候都重要
148 |
149 | 38
150 | 00:01:54,960 --> 00:01:59,720
151 | 我认为建立基于大语言模型的应用程序
152 |
153 | 39
154 | 00:01:59,720 --> 00:02:02,880
155 | 是一个非常令人兴奋和不断增长的领域
156 |
157 | 40
158 | 00:02:02,880 --> 00:02:05,160
159 | 现在你已经完成了这个课程
160 |
161 | 41
162 | 00:02:05,160 --> 00:02:08,240
163 | 我想你现在已经有了丰富的知识
164 |
165 | 42
166 | 00:02:08,240 --> 00:02:11,320
167 | 可以让你构建少数人知道如何构建的东西
168 |
169 | 43
170 | 00:02:11,320 --> 00:02:17,280
171 | 与此同时,我希望你也能帮助我们传播信息,鼓励其他人也参加这个课程
172 |
173 | 44
174 | 00:02:17,280 --> 00:02:20,520
175 | 最后,我希望你在做这个课程时很开心
176 |
177 | 45
178 | 00:02:20,520 --> 00:02:23,280
179 | 同时也感谢你能完成这个课程
180 |
181 | 46
182 | 00:02:23,280 --> 00:02:27,120
183 | Isa和我都期待着听到你所建立的惊人的东西
184 |
185 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # 《ChatGPT Prompt Engineering for Developers》中英双语字幕
4 |
5 | 该项目主要用于存放《面向开发者的 ChatGPT 提示词工程》非官方版中英双语字幕。
6 |
7 | - **中文视频地址:[面向开发者的 ChatGPT 提示词工程](https://www.bilibili.com/video/BV1s24y1F7eq/)**
8 | - **英文原视频地址:[ChatGPT Prompt Engineering for Developers](https://learn.deeplearning.ai/)**
9 | - **配套代码与笔记:[《ChatGPT Prompt Engineering for Developers》课程中文版 Datawhale](https://github.com/datawhalechina/prompt-engineering-for-developers)**
10 |
11 | 如果你在观看视频的过程中,发现翻译出现错漏、错别字、病句等情况,欢迎向我们提交 Pull Request 以改进字幕翻译质量。
12 |
13 | 本项目文件夹说明:
14 |
15 | - `subtitles`:核心字幕,里面放置了「中英双语字幕」;
16 | - `english_subtitles`:从双语字幕中分离出来的「英文字幕」;
17 | - `chinese_subtitles`:从双语字幕中分离出来的「中文字幕」;
18 | - `course_notebooks`: 从课程中复制至本地的 Notebook。
19 |
20 | 字幕效果展示:
21 |
22 | 
23 |
24 | ## 课程介绍
25 |
26 | ChatGPT 上线至今,已经快 5 个月了,但是不少人还没真正掌握它的使用技巧。
27 |
28 | 其实,ChatGPT 的难点,在于 Prompt(提示词)的编写,OpenAI 创始人在今年 2 月时,在 Twitter 上说:「能够出色编写 Prompt 跟聊天机器人对话,是一项能令人惊艳的高杠杆技能」。
29 |
30 | 因为从 ChatGPT 发布之后,如何写好 Prompt 已经成为了一个分水岭。熟练掌握 Prompt 编写的人,能够很快让 ChatGPT 理解需求,并很好的执行任务。
31 |
32 | 目前你在网上看到的所有 AI 助理、智能翻译、角色扮演,本质上还是通过编写 Prompt 来实现。
33 |
34 | 只要你的 Prompt 写的足够好,ChatGPT 可以帮你快速完成很多工作,包括写爬虫脚本、金融数据分析、文案润色与翻译等等,并且这些工作还做的比一般人出色。
35 |
36 | 为了帮助大家能更好的掌握 Prompt 工程,DeepLearning.ai 创始人吴恩达与 OpenAI 开发者 Iza Fulford 联手推出了一门面向开发者的技术教程:《**ChatGPT 提示工程**》。
37 |
38 |
39 |
40 |
41 |
42 | 吴恩达老师相信大家都有所耳闻,作为人工智能界的重量级大佬,我们经常能在 AI 技术界看到他活跃的身影。
43 |
44 | 另一位讲师 Iza Fulford,大家可能不太熟悉,这里重点介绍下。
45 |
46 | 她是斯坦福本硕高材生,ChatGPT 之前在 GitHub 开源的那个文档搜索插件:**Retrieval**,就是出自她之手。
47 |
48 | 另外,她还是 OpenAI Cookbook(官方手册)的编撰者,如果你最近有深入了解过 GPT 相关的技术,那这本手册于你而言应该不会陌生。
49 |
50 | 该手册里面提供了大量 GPT 相关的使用案例,能帮助你快速上手并掌握 GPT 模型的开发与应用。
51 |
52 | 可以说,这两位大佬联手,推出的教程绝对不会差。更令人振奋的是,这个教程完全对外开放,所有人均可免费学习!
53 |
54 | 那么,这个教程里面主要讲了什么内容呢?
55 |
56 | 该教程总共分为 9 个章节,总一个多小时,里面主要涵盖:**提示词最佳实践、评论情感分类、文本总结、邮件撰写、文本翻译、快速搭建一个聊天机器人**等等。
57 |
58 | 
59 |
60 | 所有当下 ChatGPT 的流行案例,你都能在这个教程里面找到,十分全面!
61 |
62 | 除了能在这个教程里面学到如何使用 Prompt,你还能学到 GPT 接口调用开发知识。有需要的话,你甚至能在这个教程之上去延伸扩展,搭建出一款令人惊艳的应用。
63 |
64 | 目前该教程已经在 DeepLearning.ai 正式上线,官网上线提供了可交互式的 Notebook,让你可以一边学习,一边跟着编写代码实践。
65 |
66 | 不过当下这个教程只有英文版,为了让看不懂英文的同学也能第一时间学习并掌握这项技术。
67 |
68 | 我花了一天时间,完整翻译了所有英文字幕,并且[将所有视频与字幕同步上传到了 B 站](https://www.bilibili.com/video/BV1s24y1F7eq/)。
69 |
70 | 大家有时间的话,可以多学一下这个教程,相信整个学习下来,绝对能让你受益匪浅!
71 |
72 | ## 贡献者
73 |
74 | 查看 [贡献列表](https://github.com/GitHubDaily/ChatGPT-Prompt-Engineering-for-Developers-in-Chinese/graphs/contributors) 获取更多信息,感谢所有为项目作为贡献的人!
75 |
76 |
77 |
78 |
79 |
80 | ## 开源协议
81 |
82 | 项目基于 [CC BY-NC-SA 4.0 协议](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh) 发布。
83 |
84 | [![CC BY-NC-SA 4.0][cc-by-nc-sa-image]][cc-by-nc-sa]
85 |
86 | [cc-by-nc-sa]: http://creativecommons.org/licenses/by-nc-sa/4.0/
87 | [cc-by-nc-sa-image]: https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png
88 | [cc-by-nc-sa-shield]: https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg
89 |
--------------------------------------------------------------------------------
/english_subtitles/prompt_eng_09_conclusion_english.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:08,840
3 | Congratulations on making it to the end of this short course
4 |
5 | 2
6 | 00:00:08,840 --> 00:00:11,280
7 | In summary, in this short course
8 |
9 | 3
10 | 00:00:11,280 --> 00:00:14,380
11 | you've learned about two key principles for prompting
12 |
13 | 4
14 | 00:00:14,380 --> 00:00:17,480
15 | right clearance for specific instructions and when it's appropriate
16 |
17 | 5
18 | 00:00:17,480 --> 00:00:19,160
19 | give the model time to think
20 |
21 | 6
22 | 00:00:19,160 --> 00:00:22,080
23 | You also learned about iterative prompt development and how
24 |
25 | 7
26 | 00:00:22,080 --> 00:00:26,200
27 | having a process to get to the prompt is right for your application is key
28 |
29 | 8
30 | 00:00:26,200 --> 00:00:28,800
31 | And we went through a few capabilities of
32 |
33 | 9
34 | 00:00:28,800 --> 00:00:31,640
35 | large language models that are useful for many applications
36 |
37 | 10
38 | 00:00:31,640 --> 00:00:36,320
39 | specifically summarizing, inferring, transforming, and expanding
40 |
41 | 11
42 | 00:00:36,320 --> 00:00:39,880
43 | And you also saw how to build a custom chatbot
44 |
45 | 12
46 | 00:00:39,880 --> 00:00:43,320
47 | That was a lot that you learned in just one short course
48 |
49 | 13
50 | 00:00:43,320 --> 00:00:46,240
51 | and I hope you enjoyed going through these materials
52 |
53 | 14
54 | 00:00:46,240 --> 00:00:47,920
55 | We hope you'll come up with some ideas for
56 |
57 | 15
58 | 00:00:47,920 --> 00:00:50,120
59 | applications that you can build yourself now
60 |
61 | 16
62 | 00:00:50,120 --> 00:00:53,120
63 | And please go try this out and let us know what you come up with
64 |
65 | 17
66 | 00:00:53,120 --> 00:00:54,720
67 | No application is too small
68 |
69 | 18
70 | 00:00:54,720 --> 00:00:57,000
71 | It's fine to start with something that's kind of
72 |
73 | 19
74 | 00:00:57,000 --> 00:00:59,800
75 | a very small project with maybe a little bit of utility
76 |
77 | 20
78 | 00:00:59,800 --> 00:01:01,800
79 | or maybe it's not even useful at all
80 |
81 | 21
82 | 00:01:01,800 --> 00:01:03,320
83 | It's just something fun
84 |
85 | 22
86 | 00:01:03,320 --> 00:01:06,200
87 | Yeah. And I find playing with these models actually really fun
88 |
89 | 23
90 | 00:01:06,200 --> 00:01:07,440
91 | So go play with it
92 |
93 | 24
94 | 00:01:07,440 --> 00:01:08,640
95 | Yeah, I agree. It's a good
96 |
97 | 25
98 | 00:01:08,640 --> 00:01:11,080
99 | a good weekend activity, speaking from experience
100 |
101 | 26
102 | 00:01:11,080 --> 00:01:14,960
103 | And just, you know
104 |
105 | 27
106 | 00:01:14,960 --> 00:01:18,520
107 | please use the learnings from your first project to build a better second project
108 |
109 | 28
110 | 00:01:18,520 --> 00:01:21,360
111 | and you know, maybe even a better third project, so on
112 |
113 | 29
114 | 00:01:21,360 --> 00:01:26,960
115 | That's kind of how I have kind of grown over time using these models myself as well
116 |
117 | 30
118 | 00:01:26,960 --> 00:01:31,360
119 | Or if you have an idea for a bigger project already, just, just go for it
120 |
121 | 31
122 | 00:01:31,360 --> 00:01:33,960
123 | And, you know, as a reminder
124 |
125 | 32
126 | 00:01:33,960 --> 00:01:37,200
127 | these kind of large language models are a very powerful technology
128 |
129 | 33
130 | 00:01:37,200 --> 00:01:41,120
131 | So it kind of goes without saying that we ask you to use them responsibly
132 |
133 | 34
134 | 00:01:41,120 --> 00:01:43,960
135 | and please only build things that will have a positive impact
136 |
137 | 35
138 | 00:01:43,960 --> 00:01:46,240
139 | Yeah, fully agree. I think in this age
140 |
141 | 36
142 | 00:01:46,240 --> 00:01:49,480
143 | people that build AI systems can have a huge impact on others
144 |
145 | 37
146 | 00:01:49,480 --> 00:01:54,960
147 | So it's more important than ever that all of us only use these tools responsibly
148 |
149 | 38
150 | 00:01:54,960 --> 00:01:59,720
151 | And I think building large language model-based applications
152 |
153 | 39
154 | 00:01:59,720 --> 00:02:02,880
155 | is just a very exciting and growing field right now
156 |
157 | 40
158 | 00:02:02,880 --> 00:02:05,160
159 | And now that you've finished this course
160 |
161 | 41
162 | 00:02:05,160 --> 00:02:08,240
163 | I think you now have a wealth of knowledge to let
164 |
165 | 42
166 | 00:02:08,240 --> 00:02:11,320
167 | you build things that few people today know how to
168 |
169 | 43
170 | 00:02:11,320 --> 00:02:17,280
171 | So I hope you also help us to spread the word and encourage others to take this course too
172 |
173 | 44
174 | 00:02:17,280 --> 00:02:20,520
175 | In closing, I hope you had fun doing this course
176 |
177 | 45
178 | 00:02:20,520 --> 00:02:23,280
179 | and I want to thank you for finishing this course
180 |
181 | 46
182 | 00:02:23,280 --> 00:02:27,120
183 | and both Isa and I look forward to hearing about the amazing things that you've built
184 |
185 |
--------------------------------------------------------------------------------
/subtitles/raw/prompt_eng_09_conclusion.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:08,840
3 | 祝贺你在这个短期课程中走到了最后
4 | Congratulations on making it to the end of this short course
5 |
6 | 2
7 | 00:00:08,840 --> 00:00:11,280
8 | 综上所述,在这个短课程中
9 | In summary, in this short course
10 |
11 | 3
12 | 00:00:11,280 --> 00:00:14,380
13 | 你已经了解了提示的两个关键原则
14 | you've learned about two key principles for prompting
15 |
16 | 4
17 | 00:00:14,380 --> 00:00:17,480
18 | 正确且清晰的描述具体指示,以及知道什么时候使用
19 | right clearance for specific instructions and when it's appropriate
20 |
21 | 5
22 | 00:00:17,480 --> 00:00:19,160
23 | 给予模型思考的时间
24 | give the model time to think
25 |
26 | 6
27 | 00:00:19,160 --> 00:00:22,080
28 | 你还了解了迭代提示的发展以及如何
29 | You also learned about iterative prompt development and how
30 |
31 | 7
32 | 00:00:22,080 --> 00:00:26,200
33 | 有一个过程来获得适合你的应用的提示是关键
34 | having a process to get to the prompt is right for your application is key
35 |
36 | 8
37 | 00:00:26,200 --> 00:00:28,800
38 | 我们还学习了一些大语言模型的功能
39 | And we went through a few capabilities of
40 |
41 | 9
42 | 00:00:28,800 --> 00:00:31,640
43 | 这些功能对许多应用是有用的
44 | large language models that are useful for many applications
45 |
46 | 10
47 | 00:00:31,640 --> 00:00:36,320
48 | 特别是总结、推理、转换和扩展
49 | specifically summarizing, inferring, transforming, and expanding
50 |
51 | 11
52 | 00:00:36,320 --> 00:00:39,880
53 | 你还看到了如何建立一个定制的聊天机器人
54 | And you also saw how to build a custom chatbot
55 |
56 | 12
57 | 00:00:39,880 --> 00:00:43,320
58 | 在短短的课程中,你学到了很多东西
59 | That was a lot that you learned in just one short course
60 |
61 | 13
62 | 00:00:43,320 --> 00:00:46,240
63 | 我希望你喜欢阅读这些材料
64 | and I hope you enjoyed going through these materials
65 |
66 | 14
67 | 00:00:46,240 --> 00:00:47,920
68 | 我们希望你能想出一些想法
69 | We hope you'll come up with some ideas for
70 |
71 | 15
72 | 00:00:47,920 --> 00:00:50,120
73 | 我们希望你能想出一些可以自己构建的应用
74 | applications that you can build yourself now
75 |
76 | 16
77 | 00:00:50,120 --> 00:00:53,120
78 | 并请你去尝试一下,让我们知道你想出了什么
79 | And please go try this out and let us know what you come up with
80 |
81 | 17
82 | 00:00:53,120 --> 00:00:54,720
83 | 任何应用都不小
84 | No application is too small
85 |
86 | 18
87 | 00:00:54,720 --> 00:00:57,000
88 | 从一些很小的项目开始也是可以的
89 | It's fine to start with something that's kind of
90 |
91 | 19
92 | 00:00:57,000 --> 00:00:59,800
93 | 一个非常小的项目,也许实用
94 | a very small project with maybe a little bit of utility
95 |
96 | 20
97 | 00:00:59,800 --> 00:01:01,800
98 | 也可能毫无用处
99 | or maybe it's not even useful at all
100 |
101 | 21
102 | 00:01:01,800 --> 00:01:03,320
103 | 这只是一些有趣的东西
104 | It's just something fun
105 |
106 | 22
107 | 00:01:03,320 --> 00:01:06,200
108 | 是的。我发现玩这些模型非常有趣
109 | Yeah. And I find playing with these models actually really fun
110 |
111 | 23
112 | 00:01:06,200 --> 00:01:07,440
113 | 所以放心去玩吧
114 | So go play with it
115 |
116 | 24
117 | 00:01:07,440 --> 00:01:08,640
118 | 是的,我同意。从我的经验来看
119 | Yeah, I agree. It's a good
120 |
121 | 25
122 | 00:01:08,640 --> 00:01:11,080
123 | 这是一个很好的周末活动
124 | a good weekend activity, speaking from experience
125 |
126 | 26
127 | 00:01:11,080 --> 00:01:14,960
128 | 而且,你可以通过第一个项目获得的经验教训
129 | And just, you know
130 |
131 | 27
132 | 00:01:14,960 --> 00:01:18,520
133 | 来构建第二个更好的项目
134 | please use the learnings from your first project to build a better second project
135 |
136 | 28
137 | 00:01:18,520 --> 00:01:21,360
138 | 甚至可能是更好的第三个项目,等等
139 | and you know, maybe even a better third project, so on
140 |
141 | 29
142 | 00:01:21,360 --> 00:01:26,960
143 | 这就是我自己使用这些模型逐渐成长的方式
144 | That's kind of how I have kind of grown over time using these models myself as well
145 |
146 | 30
147 | 00:01:26,960 --> 00:01:31,360
148 | 或者如果你已经有了一个更大的项目想法,就去做吧
149 | Or if you have an idea for a bigger project already, just, just go for it
150 |
151 | 31
152 | 00:01:31,360 --> 00:01:33,960
153 | 作为一个提醒
154 | And, you know, as a reminder
155 |
156 | 32
157 | 00:01:33,960 --> 00:01:37,200
158 | 这些大语言模型是一种非常强大的技术
159 | these kind of large language models are a very powerful technology
160 |
161 | 33
162 | 00:01:37,200 --> 00:01:41,120
163 | 所以不言而喻,我们要求你负责任地使用它们
164 | So it kind of goes without saying that we ask you to use them responsibly
165 |
166 | 34
167 | 00:01:41,120 --> 00:01:43,960
168 | 请只建立会产生积极影响的东西
169 | and please only build things that will have a positive impact
170 |
171 | 35
172 | 00:01:43,960 --> 00:01:46,240
173 | 是的,完全同意。我认为在这个时代
174 | Yeah, fully agree. I think in this age
175 |
176 | 36
177 | 00:01:46,240 --> 00:01:49,480
178 | 建立AI系统的人可以对其他人产生巨大的影响
179 | people that build AI systems can have a huge impact on others
180 |
181 | 37
182 | 00:01:49,480 --> 00:01:54,960
183 | 因此,我们所有人都要负责任地使用这些工具,这一点比以往任何时候都重要
184 | So it's more important than ever that all of us only use these tools responsibly
185 |
186 | 38
187 | 00:01:54,960 --> 00:01:59,720
188 | 我认为建立基于大语言模型的应用程序
189 | And I think building large language model-based applications
190 |
191 | 39
192 | 00:01:59,720 --> 00:02:02,880
193 | 是一个非常令人兴奋和不断增长的领域
194 | is just a very exciting and growing field right now
195 |
196 | 40
197 | 00:02:02,880 --> 00:02:05,160
198 | 现在你已经完成了这个课程
199 | And now that you've finished this course
200 |
201 | 41
202 | 00:02:05,160 --> 00:02:08,240
203 | 我想你现在已经有了丰富的知识
204 | I think you now have a wealth of knowledge to let
205 |
206 | 42
207 | 00:02:08,240 --> 00:02:11,320
208 | 可以让你构建少数人知道如何构建的东西
209 | you build things that few people today know how to
210 |
211 | 43
212 | 00:02:11,320 --> 00:02:17,280
213 | 与此同时,我希望你也能帮助我们传播信息,鼓励其他人也参加这个课程
214 | So I hope you also help us to spread the word and encourage others to take this course too
215 |
216 | 44
217 | 00:02:17,280 --> 00:02:20,520
218 | 最后,我希望你在做这个课程时很开心
219 | In closing, I hope you had fun doing this course
220 |
221 | 45
222 | 00:02:20,520 --> 00:02:23,280
223 | 同时也感谢你能完成这个课程
224 | and I want to thank you for finishing this course
225 |
226 | 46
227 | 00:02:23,280 --> 00:02:27,120
228 | Isa和我都期待着听到你所建立的惊人的东西
229 | and both Isa and I look forward to hearing about the amazing things that you've built
230 |
231 |
--------------------------------------------------------------------------------
/course_notebooks/l7-expanding.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "attachments": {},
5 | "cell_type": "markdown",
6 | "metadata": {},
7 | "source": [
8 | "[](https://colab.research.google.com/github/GitHubDaily/ChatGPT-Prompt-Engineering-for-Developers-in-Chinese/blob/master/assets/7-Expanding/l7-expanding.ipynb)\n",
9 | "# Expanding\n",
10 | "In this lesson, you will generate customer service emails that are tailored to each customer's review.\n",
11 | "\n",
12 | "## Setup"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": null,
18 | "metadata": {},
19 | "outputs": [],
20 | "source": [
21 | "# Basic congfig \n",
22 | "# Install basic package and set key\n",
23 | "!pip install openai\n",
24 | "!export OPENAI_API_KEY='sk-...'"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": null,
30 | "metadata": {},
31 | "outputs": [],
32 | "source": [
33 | "import openai\n",
34 | "import os\n",
35 | "\n",
36 | "from dotenv import load_dotenv, find_dotenv\n",
37 | "_ = load_dotenv(find_dotenv()) # read local .env file\n",
38 | "\n",
39 | "openai.api_key = os.getenv('OPENAI_API_KEY')"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "def get_completion(prompt, model=\"gpt-3.5-turbo\",temperature=0): # Andrew mentioned that the prompt/ completion paradigm is preferable for this class\n",
49 | " messages = [{\"role\": \"user\", \"content\": prompt}]\n",
50 | " response = openai.ChatCompletion.create(\n",
51 | " model=model,\n",
52 | " messages=messages,\n",
53 | " temperature=temperature, # this is the degree of randomness of the model's output\n",
54 | " )\n",
55 | " return response.choices[0].message[\"content\"]"
56 | ]
57 | },
58 | {
59 | "attachments": {},
60 | "cell_type": "markdown",
61 | "metadata": {},
62 | "source": [
63 | "## Customize the automated reply to a customer email"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "# given the sentiment from the lesson on \"inferring\",\n",
73 | "# and the original customer message, customize the email\n",
74 | "sentiment = \"negative\"\n",
75 | "\n",
76 | "# review for a blender\n",
77 | "review = f\"\"\"\n",
78 | "So, they still had the 17 piece system on seasonal \\\n",
79 | "sale for around $49 in the month of November, about \\\n",
80 | "half off, but for some reason (call it price gouging) \\\n",
81 | "around the second week of December the prices all went \\\n",
82 | "up to about anywhere from between $70-$89 for the same \\\n",
83 | "system. And the 11 piece system went up around $10 or \\\n",
84 | "so in price also from the earlier sale price of $29. \\\n",
85 | "So it looks okay, but if you look at the base, the part \\\n",
86 | "where the blade locks into place doesn’t look as good \\\n",
87 | "as in previous editions from a few years ago, but I \\\n",
88 | "plan to be very gentle with it (example, I crush \\\n",
89 | "very hard items like beans, ice, rice, etc. in the \\ \n",
90 | "blender first then pulverize them in the serving size \\\n",
91 | "I want in the blender then switch to the whipping \\\n",
92 | "blade for a finer flour, and use the cross cutting blade \\\n",
93 | "first when making smoothies, then use the flat blade \\\n",
94 | "if I need them finer/less pulpy). Special tip when making \\\n",
95 | "smoothies, finely cut and freeze the fruits and \\\n",
96 | "vegetables (if using spinach-lightly stew soften the \\ \n",
97 | "spinach then freeze until ready for use-and if making \\\n",
98 | "sorbet, use a small to medium sized food processor) \\ \n",
99 | "that you plan to use that way you can avoid adding so \\\n",
100 | "much ice if at all-when making your smoothie. \\\n",
101 | "After about a year, the motor was making a funny noise. \\\n",
102 | "I called customer service but the warranty expired \\\n",
103 | "already, so I had to buy another one. FYI: The overall \\\n",
104 | "quality has gone done in these types of products, so \\\n",
105 | "they are kind of counting on brand recognition and \\\n",
106 | "consumer loyalty to maintain sales. Got it in about \\\n",
107 | "two days.\n",
108 | "\"\"\""
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": null,
114 | "metadata": {},
115 | "outputs": [],
116 | "source": [
117 | "prompt = f\"\"\"\n",
118 | "You are a customer service AI assistant.\n",
119 | "Your task is to send an email reply to a valued customer.\n",
120 | "Given the customer email delimited by ```, \\\n",
121 | "Generate a reply to thank the customer for their review.\n",
122 | "If the sentiment is positive or neutral, thank them for \\\n",
123 | "their review.\n",
124 | "If the sentiment is negative, apologize and suggest that \\\n",
125 | "they can reach out to customer service. \n",
126 | "Make sure to use specific details from the review.\n",
127 | "Write in a concise and professional tone.\n",
128 | "Sign the email as `AI customer agent`.\n",
129 | "Customer review: ```{review}```\n",
130 | "Review sentiment: {sentiment}\n",
131 | "\"\"\"\n",
132 | "response = get_completion(prompt)\n",
133 | "print(response)"
134 | ]
135 | },
136 | {
137 | "cell_type": "markdown",
138 | "metadata": {},
139 | "source": []
140 | }
141 | ],
142 | "metadata": {
143 | "kernelspec": {
144 | "display_name": "gpt_index",
145 | "language": "python",
146 | "name": "python3"
147 | },
148 | "language_info": {
149 | "codemirror_mode": {
150 | "name": "ipython",
151 | "version": 3
152 | },
153 | "file_extension": ".py",
154 | "mimetype": "text/x-python",
155 | "name": "python",
156 | "nbconvert_exporter": "python",
157 | "pygments_lexer": "ipython3",
158 | "version": "3.8.16"
159 | },
160 | "orig_nbformat": 4
161 | },
162 | "nbformat": 4,
163 | "nbformat_minor": 2
164 | }
165 |
--------------------------------------------------------------------------------
/chinese_subtitles/prompt_eng_04_summarizing_chinese.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:09,680
3 | 当今世界有如此多的文字,但我们几乎没有人有足够的时间
4 |
5 | 2
6 | 00:00:09,680 --> 00:00:12,760
7 | 来阅读这些文字
8 |
9 | 3
10 | 00:00:12,760 --> 00:00:16,920
11 | 因此,我认为,大语言模型最令人兴奋的应用之一
12 |
13 | 4
14 | 00:00:16,920 --> 00:00:18,660
15 | 是用它来对文本进行总结
16 |
17 | 5
18 | 00:00:18,660 --> 00:00:24,480
19 | 这也是我看到多个团队在不同软件应用中构建的东西
20 |
21 | 6
22 | 00:00:24,480 --> 00:00:26,880
23 | 你可以在ChatGPT网站上这样做
24 |
25 | 7
26 | 00:00:26,880 --> 00:00:31,000
27 | 我经常用这种方式来总结文章
28 |
29 | 8
30 | 00:00:31,000 --> 00:00:33,000
31 | 这样我就可以比以前多读很多文章
32 |
33 | 9
34 | 00:00:33,000 --> 00:00:37,880
35 | 你将在本课程中,学习如何以编程方式来实现这个任务
36 |
37 | 10
38 | 00:00:37,880 --> 00:00:43,520
39 | 因此,让我们深入研究代码,看看你如何使用它来总结文本
40 |
41 | 11
42 | 00:00:43,520 --> 00:00:48,280
43 | 让我们从之前的初始代码开始,导入openai,加载
44 |
45 | 12
46 | 00:00:48,280 --> 00:00:52,620
47 | API Key,这里是get_completion辅助函数
48 |
49 | 13
50 | 00:00:52,620 --> 00:01:00,640
51 | 我将以“总结此产品评价”的任务作为运行示例
52 |
53 | 14
54 | 00:01:00,640 --> 00:01:04,640
55 | 我为女儿的生日买了这只熊猫毛绒玩具,女儿非常喜欢
56 |
57 | 15
58 | 00:01:04,640 --> 00:01:06,320
59 | 无论去哪儿都要带上它,诸如此类
60 |
61 | 16
62 | 00:01:06,320 --> 00:01:13,640
63 | 如果你正在建立一个电子商务网站,并且有大量的评论
64 |
65 | 17
66 | 00:01:13,640 --> 00:01:18,680
67 | 有一个工具可以用来总结冗长的评论,给你提供一种方式
68 |
69 | 18
70 | 00:01:18,680 --> 00:01:24,200
71 | 让你可以浏览更多评论,更好地了解所有客户的想法
72 |
73 | 19
74 | 00:01:24,200 --> 00:01:27,280
75 | 因此,这里有一个生成摘要的提示
76 |
77 | 20
78 | 00:01:27,280 --> 00:01:30,600
79 | 你的任务是对电子商务网站上的产品评论生成一个简短的总结,总结如下
80 |
81 | 21
82 | 00:01:30,600 --> 00:01:36,800
83 | 下面的评论等等,最多只能用30个字
84 |
85 | 22
86 | 00:01:36,800 --> 00:01:42,400
87 | 因此,这个柔软可爱的熊猫毛绒玩具受到女儿的喜爱,但价格有点小贵
88 |
89 | 23
90 | 00:01:42,400 --> 00:01:43,400
91 | 提前到货
92 |
93 | 24
94 | 00:01:43,400 --> 00:01:44,400
95 | 还不错
96 |
97 | 25
98 | 00:01:44,400 --> 00:01:45,400
99 | 这是个相当好的总结
100 |
101 | 26
102 | 00:01:45,400 --> 00:01:49,760
103 | 正如你在前面的视频中看到的,你还可以玩一些东西,比如控制
104 |
105 | 27
106 | 00:01:49,760 --> 00:01:55,720
107 | 字符数或句子数来影响这个摘要的长度
108 |
109 | 28
110 | 00:01:55,720 --> 00:01:59,920
111 | 现在,有时在创建一个摘要时,如果你有一个非常具体的目的
112 |
113 | 29
114 | 00:01:59,920 --> 00:02:05,600
115 | 例如,你想给运输部门提供反馈
116 |
117 | 30
118 | 00:02:05,600 --> 00:02:11,200
119 | 你也可以修改提示来突出这点,这样他们就可以生成一个更好的总结
120 |
121 | 31
122 | 00:02:11,200 --> 00:02:15,600
123 | 适用于你业务中的一个特定群体
124 |
125 | 32
126 | 00:02:15,600 --> 00:02:26,880
127 | 例如,如果我想要给运输部门反馈
128 |
129 | 33
130 | 00:02:26,880 --> 00:02:35,800
131 | 那么我会将关注点集中在商品的运输和交付等方面
132 |
133 | 34
134 | 00:02:35,800 --> 00:02:42,560
135 | 如果我运行这个指令,那么你会得到一个新的摘要
136 |
137 | 35
138 | 00:02:42,560 --> 00:02:49,120
139 | 这次不是以“柔软可爱的熊猫毛绒玩具”开始,而是强调它比预期提前了一天送达
140 |
141 | 36
142 | 00:02:49,120 --> 00:02:53,600
143 | 然后它仍然有其他细节
144 |
145 | 37
146 | 00:02:53,600 --> 00:02:59,640
147 | 或者作为另一个例子,如果我们不是想给运输部门提供反馈
148 |
149 | 38
150 | 00:02:59,640 --> 00:03:09,520
151 | 而是给定价部门提供反馈
152 |
153 | 39
154 | 00:03:09,520 --> 00:03:15,760
155 | 定价部门负责确定产品的价格
156 |
157 | 40
158 | 00:03:15,760 --> 00:03:22,960
159 | 我会告诉它专注于与产品价格和感知价值相关的任何方面
160 |
161 | 41
162 | 00:03:22,960 --> 00:03:25,240
163 | 价值
164 |
165 | 42
166 | 00:03:25,240 --> 00:03:31,520
167 | 那么这将生成一个不同的总结,它说
168 |
169 | 43
170 | 00:03:31,520 --> 00:03:33,480
171 | 也许这个尺寸的价格可能太高了
172 |
173 | 44
174 | 00:03:33,480 --> 00:03:38,640
175 | 现在,在我为运输部门或定价部门生成的摘要中
176 |
177 | 45
178 | 00:03:38,640 --> 00:03:44,400
179 | 它更侧重于与这些特定部门有关的信息
180 |
181 | 46
182 | 00:03:44,400 --> 00:03:50,000
183 | 事实上,你可以随时暂停视频
184 |
185 | 47
186 | 00:03:50,000 --> 00:03:55,360
187 | 然后让它为负责产品客户体验的部门提供有关产品的信息
188 |
189 | 48
190 | 00:03:55,360 --> 00:04:01,920
191 | 或者为你认为对电子商务站点有趣的其他某些方面提供信息
192 |
193 | 49
194 | 00:04:01,920 --> 00:04:07,000
195 | 但在这些摘要中,尽管它生成了与运输有关的信息
196 |
197 | 50
198 | 00:04:07,000 --> 00:04:12,240
199 | 但也有一些其他信息,你可以决定这些信息是否有帮助
200 |
201 | 51
202 | 00:04:12,240 --> 00:04:20,120
203 | 因此,根据你想要总结的方式,你也可以要求它提取信息
204 |
205 | 52
206 | 00:04:20,120 --> 00:04:22,960
207 | 而不是对其进行总结
208 |
209 | 53
210 | 00:04:22,960 --> 00:04:27,920
211 | 因此,这里有一个提示,说你的任务是
212 |
213 | 54
214 | 00:04:27,920 --> 00:04:29,200
215 | 提取相关的信息来反馈给给运输部门
216 |
217 | 55
218 | 00:04:29,200 --> 00:04:35,440
219 | 现在它只是说,产品比预期早到了一天,没有其他的信息
220 |
221 | 56
222 | 00:04:35,440 --> 00:04:41,240
223 | 这在一般的总结中也是有帮助的,但如果想知道运输方面发生了什么
224 |
225 | 57
226 | 00:04:41,240 --> 00:04:45,000
227 | 就不那么具体了
228 |
229 | 58
230 | 00:04:45,000 --> 00:04:50,600
231 | 最后,让我与你分享一个具体的例子,说明如何在工作流程中使用这个方法
232 |
233 | 59
234 | 00:04:50,600 --> 00:04:56,760
235 | 来帮助总结多个评论,使其更容易阅读
236 |
237 | 60
238 | 00:04:56,760 --> 00:04:59,920
239 | 因此,这里有几条评论
240 |
241 | 61
242 | 00:04:59,920 --> 00:05:03,920
243 | 这有点长,但这是对落地灯的第二个评论
244 |
245 | 62
246 | 00:05:03,920 --> 00:05:04,920
247 | 需要一盏灯放在卧室里
248 |
249 | 63
250 | 00:05:04,920 --> 00:05:07,280
251 | 这是关于电动牙刷的第三条评论
252 |
253 | 64
254 | 00:05:07,280 --> 00:05:09,600
255 | 我的牙科保健师推荐的
256 |
257 | 65
258 | 00:05:09,600 --> 00:05:12,640
259 | 关于电动牙刷的评论有点长
260 |
261 | 66
262 | 00:05:12,640 --> 00:05:17,920
263 | 这是关于搅拌机的评论,当时它说是季节性销售的17件套装系统
264 |
265 | 67
266 | 00:05:17,920 --> 00:05:18,920
267 | 诸如此类
268 |
269 | 68
270 | 00:05:18,920 --> 00:05:20,280
271 | 这实际上是很多的文字
272 |
273 | 69
274 | 00:05:20,280 --> 00:05:23,280
275 | 如果你愿意,可以随意暂停视频,读完这些文字
276 |
277 | 70
278 | 00:05:23,280 --> 00:05:28,480
279 | 但是,如果你想知道这些评论者写了什么,而不必停下来阅读所有的
280 |
281 | 71
282 | 00:05:28,480 --> 00:05:29,480
283 | 这方面的细节呢?
284 |
285 | 72
286 | 00:05:29,480 --> 00:05:41,600
287 | 所以我要把 review_1 设为我们之前展示的那个产品评论
288 |
289 | 73
290 | 00:05:41,600 --> 00:05:45,320
291 | 我将把所有这些评论放到一个列表中
292 |
293 | 74
294 | 00:05:45,320 --> 00:05:53,800
295 | 现在,如果我对这些评论实施一个for循环
296 |
297 | 75
298 | 00:05:53,800 --> 00:06:01,240
299 | 这是我的提示,我要求它最多用20个字来总结它
300 |
301 | 76
302 | 00:06:01,240 --> 00:06:07,320
303 | 然后让它得到响应并打印出来
304 |
305 | 77
306 | 00:06:07,320 --> 00:06:10,760
307 | 让我们运行这个程序
308 |
309 | 78
310 | 00:06:10,760 --> 00:06:16,360
311 | 它打印出的第一条评论是熊猫玩具的评论,灯的总结评论
312 |
313 | 79
314 | 00:06:16,360 --> 00:06:21,880
315 | 牙刷的摘要评论,然后是搅拌器
316 |
317 | 80
318 | 00:06:21,880 --> 00:06:29,800
319 | 因此,如果你有一个网站,你有数百条评论,你可以想象你如何
320 |
321 | 81
322 | 00:06:29,800 --> 00:06:35,360
323 | 使用它来建立一个控制面板,为大量的评论,生成简短的摘要
324 |
325 | 82
326 | 00:06:35,360 --> 00:06:40,760
327 | 这样你或其他人就可以更快地浏览这些评论
328 |
329 | 83
330 | 00:06:40,760 --> 00:06:46,200
331 | 然后,如果他们愿意,可以点击查看原始的长篇评论
332 |
333 | 84
334 | 00:06:46,200 --> 00:06:51,640
335 | 这可以帮助你更高效地了解所有客户的想法
336 |
337 | 85
338 | 00:06:51,640 --> 00:06:55,640
339 | 好了,总结就到这里
340 |
341 | 86
342 | 00:06:55,640 --> 00:07:00,960
343 | 我希望你能想象一下,如果你有任何有许多文本的应用
344 |
345 | 87
346 | 00:07:00,960 --> 00:07:05,680
347 | 你可以使用这样的提示来总结,帮助人们快速了解文字中的内容和各种文本
348 |
349 | 88
350 | 00:07:05,680 --> 00:07:10,240
351 | 可以选择进一步深入挖掘
352 |
353 | 89
354 | 00:07:10,240 --> 00:07:12,520
355 | 如果有需要的话
356 |
357 | 90
358 | 00:07:12,520 --> 00:07:17,640
359 | 在下一个视频中,我们将看到大语言模型的另一个能力,即
360 |
361 | 91
362 | 00:07:17,640 --> 00:07:19,880
363 | 推断的能力
364 |
365 | 92
366 | 00:07:19,880 --> 00:07:24,280
367 | 例如,如果你有一些产品评论数据
368 |
369 | 93
370 | 00:07:24,280 --> 00:07:29,680
371 | 你希望快速了解哪些评论具有积极或消极情感,该怎么办?
372 |
373 | 94
374 | 00:07:29,680 --> 00:07:49,840
375 | 让我们在下一个视频中看看如何实现这个功能
376 |
377 |
--------------------------------------------------------------------------------
/chinese_subtitles/prompt_eng_01_intro_chinese.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:09,000
3 | 欢迎学习《面向开发者的 ChatGPT Prompt 工程》课程
4 |
5 | 2
6 | 00:00:09,000 --> 00:00:14,000
7 | 很高兴能邀请到 Isa Fulford 和我一起授课
8 |
9 | 3
10 | 00:00:14,000 --> 00:00:18,000
11 | 她是 OpenAI 的技术人员之一,曾建立了流行的
12 |
13 | 4
14 | 00:00:18,000 --> 00:00:23,000
15 | ChatGPT 检索插件,她大部分工作是教人们
16 |
17 | 5
18 | 00:00:23,000 --> 00:00:27,000
19 | 如何在产品中使用LLM或大语言模型技术
20 |
21 | 6
22 | 00:00:27,000 --> 00:00:31,000
23 | 她还为OpenAI手册做出了贡献,教会人们如何使用提示
24 |
25 | 7
26 | 00:00:31,000 --> 00:00:32,000
27 | 所以,很高兴有你参与
28 |
29 | 8
30 | 00:00:32,000 --> 00:00:37,000
31 | 我也很高兴能在这里与大家分享一些提示的最佳实践
32 |
33 | 9
34 | 00:00:37,000 --> 00:00:42,000
35 | 在互联网上有很多关于提示资料以及一些文章
36 |
37 | 10
38 | 00:00:42,000 --> 00:00:45,000
39 | 比如,每个人都必须知道的30个提示
40 |
41 | 11
42 | 00:00:45,000 --> 00:00:50,000
43 | 许多人正在使用 ChatGPT 的 Web 用户界面
44 |
45 | 12
46 | 00:00:50,000 --> 00:00:54,000
47 | 来完成特定而且通常是一次性的任务
48 |
49 | 13
50 | 00:00:54,000 --> 00:01:00,000
51 | 但作为一名开发者,我认为LLMs和大语言模型的强大也是不可忽视的
52 |
53 | 14
54 | 00:01:00,000 --> 00:01:04,000
55 | 那就是通过API调用LLM来快速构建软件应用程序
56 |
57 | 15
58 | 00:01:04,000 --> 00:01:08,000
59 | 我认为这仍然被严重低估
60 |
61 | 16
62 | 00:01:08,000 --> 00:01:12,000
63 | 事实上,我在AI Fund的团队,也就是Deep Learning.AI的姐妹公司
64 |
65 | 17
66 | 00:01:12,000 --> 00:01:16,000
67 | 一直在与许多初创公司、不同项目合作
68 |
69 | 18
70 | 00:01:16,000 --> 00:01:18,000
71 | 来应用这些技术
72 |
73 | 19
74 | 00:01:18,000 --> 00:01:23,000
75 | 看到LLM API能够让开发者快速建立一些东西
76 |
77 | 20
78 | 00:01:23,000 --> 00:01:25,000
79 | 这很令人兴奋
80 |
81 | 21
82 | 00:01:25,000 --> 00:01:29,000
83 | 所以在这个课程中,我们将与你分享一些可能性
84 |
85 | 22
86 | 00:01:29,000 --> 00:01:34,000
87 | 你可以做什么,以及如何做的最佳实践
88 |
89 | 23
90 | 00:01:34,000 --> 00:01:36,000
91 | 这里会覆盖很多资料
92 |
93 | 24
94 | 00:01:36,000 --> 00:01:41,000
95 | 首先,你将学习一些软件开发的提示词最佳实践
96 |
97 | 25
98 | 00:01:41,000 --> 00:01:45,000
99 | 然后,我们将涵盖一些常见的用例、总结、推断
100 |
101 | 26
102 | 00:01:45,000 --> 00:01:50,000
103 | 转化、扩展,然后使用LLM建立一个聊天机器人
104 |
105 | 27
106 | 00:01:50,000 --> 00:01:53,000
107 | 我们希望这将激发你
108 |
109 | 28
110 | 00:01:53,000 --> 00:01:55,000
111 | 开发新应用的想象力
112 |
113 | 29
114 | 00:01:55,000 --> 00:01:58,000
115 | 因此,在大型语言模型或LLM的发展中
116 |
117 | 30
118 | 00:01:58,000 --> 00:02:02,000
119 | 大体上有两种类型的LLM,我把它们称为
120 |
121 | 31
122 | 00:02:02,000 --> 00:02:06,000
123 | 基础LLM和指令学习LLM
124 |
125 | 32
126 | 00:02:06,000 --> 00:02:11,000
127 | 基础LLM已经被训练成基于文本训练数据来预测下一个单词
128 |
129 | 33
130 | 00:02:11,000 --> 00:02:15,000
131 | 通常通过互联网和其他来源训练大量数据
132 |
133 | 34
134 | 00:02:15,000 --> 00:02:19,000
135 | 并计算出下一个最可能出现的词是什么
136 |
137 | 35
138 | 00:02:19,000 --> 00:02:24,000
139 | 比如,你输入这个提示:"从前有一只独角兽"
140 |
141 | 36
142 | 00:02:24,000 --> 00:02:28,000
143 | 它会进行补全,并预测接下来的几个词是
144 |
145 | 37
146 | 00:02:28,000 --> 00:02:31,000
147 | "和所有独角兽朋友一起生活在一个神奇的森林里"
148 |
149 | 38
150 | 00:02:31,000 --> 00:02:35,000
151 | 但是如果你是用"法国的首都是什么"作为提示
152 |
153 | 39
154 | 00:02:35,000 --> 00:02:40,000
155 | 那么根据互联网上的文章
156 |
157 | 40
158 | 00:02:40,000 --> 00:02:44,000
159 | 很有可能是,基础LLM会以下列方式完成这个任务
160 |
161 | 41
162 | 00:02:44,000 --> 00:02:48,000
163 | 什么是法国最大的城市,什么是法国的人口,等等
164 |
165 | 42
166 | 00:02:48,000 --> 00:02:52,000
167 | 因为互联网上的文章,可能会列出
168 |
169 | 43
170 | 00:02:52,000 --> 00:02:55,000
171 | 关于法国的小测验问题列表
172 |
173 | 44
174 | 00:02:55,000 --> 00:03:00,000
175 | 与此相反,指令学习LLM,发展势头较猛
176 |
177 | 45
178 | 00:03:00,000 --> 00:03:04,000
179 | LLM的研究和实践一直在进行
180 |
181 | 46
182 | 00:03:04,000 --> 00:03:08,000
183 | 一个经过指令学习的LLM已经被训练得能够遵循指令
184 |
185 | 47
186 | 00:03:08,000 --> 00:03:11,000
187 | 因此,如果你问它,法国的首都是什么?
188 |
189 | 48
190 | 00:03:11,000 --> 00:03:15,000
191 | 它很可能输出法国的首都是巴黎
192 |
193 | 49
194 | 00:03:15,000 --> 00:03:19,000
195 | 因此,指令学习的LLM的典型训练方式是
196 |
197 | 50
198 | 00:03:19,000 --> 00:03:23,000
199 | 从一个在大量文本数据上训练过的基础LLM开始
200 |
201 | 51
202 | 00:03:23,000 --> 00:03:28,000
203 | 然后进一步训练它,用输入和输出来进一步微调它
204 |
205 | 52
206 | 00:03:28,000 --> 00:03:32,000
207 | 这些输入和输出都是指令,也是遵循这些指令的良好尝试
208 |
209 | 53
210 | 00:03:32,000 --> 00:03:36,000
211 | 然后经常使用一种叫做RLHF的技术进一步完善
212 |
213 | 54
214 | 00:03:36,000 --> 00:03:41,000
215 | 从人类反馈中进行强化学习,以使系统能够更好地
216 |
217 | 55
218 | 00:03:41,000 --> 00:03:43,000
219 | 提供帮助并遵循指令
220 |
221 | 56
222 | 00:03:43,000 --> 00:03:47,000
223 | 因为经过指令学习的LLM已经被训练得很有帮助
224 |
225 | 57
226 | 00:03:47,000 --> 00:03:51,000
227 | 诚实且无害,因此,举例来说,它们不太可能输出
228 |
229 | 58
230 | 00:03:51,000 --> 00:03:55,000
231 | 那些与基础LLM相比,会出问题的文本,如有害的输出
232 |
233 | 59
234 | 00:03:55,000 --> 00:03:59,000
235 | 很多实际应用场景已经开始向
236 |
237 | 60
238 | 00:03:59,000 --> 00:04:01,000
239 | 指令学习LLM转移
240 |
241 | 61
242 | 00:04:01,000 --> 00:04:04,000
243 | 你在互联网上找到的一些最佳实践可能更适用于基础LLM
244 |
245 | 62
246 | 00:04:04,000 --> 00:04:08,000
247 | 但对于今天的大多数实际应用情况来说,它们可能不太合适
248 |
249 | 63
250 | 00:04:08,000 --> 00:04:13,000
251 | 我们建议大多数人多关注指令学习LLM
252 |
253 | 64
254 | 00:04:13,000 --> 00:04:17,000
255 | 它们更容易使用,而且由于OpenAI
256 |
257 | 65
258 | 00:04:17,000 --> 00:04:22,000
259 | 和其他LLM公司的工作,也将变得更加安全和一致
260 |
261 | 66
262 | 00:04:22,000 --> 00:04:27,000
263 | 因此,本课程将重点介绍指令学习LLM的最佳实践
264 |
265 | 67
266 | 00:04:27,000 --> 00:04:32,000
267 | 这也是我们建议你在大多数应用中使用的
268 |
269 | 68
270 | 00:04:32,000 --> 00:04:36,000
271 | 在继续之前,我想感谢来自OpenAI
272 |
273 | 69
274 | 00:04:36,000 --> 00:04:39,000
275 | 和DeepLearning.ai的团队
276 |
277 | 70
278 | 00:04:39,000 --> 00:04:42,000
279 | 他们为我和Isa将要介绍的资料做出了贡献
280 |
281 | 71
282 | 00:04:42,000 --> 00:04:45,000
283 | 我非常感谢Andrew Main, Joe Palermo, Boris Power
284 |
285 | 72
286 | 00:04:45,000 --> 00:04:49,000
287 | Ted Sanders,以及来自OpenAI的Lilian Wang
288 |
289 | 73
290 | 00:04:49,000 --> 00:04:53,000
291 | 与我们一起集思广益,审核资料
292 |
293 | 74
294 | 00:04:53,000 --> 00:04:55,000
295 | 并做成这个简短的课程
296 |
297 | 75
298 | 00:04:55,000 --> 00:04:58,000
299 | 我也很感谢DeepLearning方面的工作
300 |
301 | 76
302 | 00:04:58,000 --> 00:05:01,000
303 | Jeff Ludwig、Eddie Hsu和Tommy Nelson的工作
304 |
305 | 77
306 | 00:05:01,000 --> 00:05:06,000
307 | 因此,当你使用一个指令学习LLM时,可以将其看作是
308 |
309 | 78
310 | 00:05:06,000 --> 00:05:10,000
311 | 向另一个人发出指令,比如一个聪明但不知道
312 |
313 | 79
314 | 00:05:10,000 --> 00:05:12,000
315 | 任务细节的人
316 |
317 | 80
318 | 00:05:12,000 --> 00:05:16,000
319 | 因此,当一个LLM不工作时,有时是因为指令
320 |
321 | 81
322 | 00:05:16,000 --> 00:05:17,000
323 | 不够清楚
324 |
325 | 82
326 | 00:05:17,000 --> 00:05:20,000
327 | 例如,如果你说,请给我写一些
328 |
329 | 83
330 | 00:05:20,000 --> 00:05:22,000
331 | 关于艾伦-图灵的东西
332 |
333 | 84
334 | 00:05:22,000 --> 00:05:26,000
335 | 那么,除此之外,明确以下几点也会有所帮助
336 |
337 | 85
338 | 00:05:26,000 --> 00:05:30,000
339 | 你想让文章侧重于他的科学工作
340 |
341 | 86
342 | 00:05:30,000 --> 00:05:34,000
343 | 他的个人生活、他在历史上的作用或其他方向
344 |
345 | 87
346 | 00:05:34,000 --> 00:05:39,000
347 | 如果你指定了想要文本的语调
348 |
349 | 88
350 | 00:05:39,000 --> 00:05:43,000
351 | 它是否会根据指定的语调来写,比如像专业记者写的那样
352 |
353 | 89
354 | 00:05:43,000 --> 00:05:46,000
355 | 还是更像随手写给朋友的轻松语气?
356 |
357 | 90
358 | 00:05:46,000 --> 00:05:47,000
359 | 这一点是成立的
360 |
361 | 91
362 | 00:05:47,000 --> 00:05:49,000
363 | LLM会产生你想要的东西
364 |
365 | 92
366 | 00:05:49,000 --> 00:05:52,000
367 | 当然,如果你想象是自己在问,比如
368 |
369 | 93
370 | 00:05:52,000 --> 00:05:56,000
371 | 一个刚毕业的大学生为你完成这项任务
372 |
373 | 94
374 | 00:05:56,000 --> 00:05:59,000
375 | 如果你甚至可以指定他们应该阅读哪些文本片段
376 |
377 | 95
378 | 00:05:59,000 --> 00:06:02,000
379 | 提前写出这篇关于艾伦-图灵的文章
380 |
381 | 96
382 | 00:06:02,000 --> 00:06:06,000
383 | 那么,这能成功让那个刚毕业的大学生
384 |
385 | 97
386 | 00:06:06,000 --> 00:06:09,000
387 | 更好的为你完成这项任务
388 |
389 | 98
390 | 00:06:09,000 --> 00:06:13,000
391 | 因此,在接下来的视频中,你会看到如何清晰且明确
392 |
393 | 99
394 | 00:06:13,000 --> 00:06:17,000
395 | 描述提示,这是一个重要的LLM提示准则
396 |
397 | 100
398 | 00:06:17,000 --> 00:06:21,000
399 | 而且你还将从Isa那里学到了第二个提示词准则
400 |
401 | 101
402 | 00:06:21,000 --> 00:06:24,000
403 | 那就是给LLM时间来思考
404 |
405 | 102
406 | 00:06:24,000 --> 00:06:29,000
407 | 因此,让我们继续观看下一个视频
408 |
409 |
--------------------------------------------------------------------------------
/subtitles/styled/prompt_eng_09_conclusion.ass:
--------------------------------------------------------------------------------
1 | [Script Info]
2 | ; Script generated by Aegisub 3.3.3
3 | ; http://www.aegisub.org/
4 | Title: Default Aegisub file
5 | ScriptType: v4.00+
6 | WrapStyle: 0
7 | ScaledBorderAndShadow: yes
8 | YCbCr Matrix: TV.709
9 | PlayResX: 1920
10 | PlayResY: 1080
11 |
12 | [Aegisub Project Garbage]
13 | Active Line: 5
14 |
15 | [V4+ Styles]
16 | Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
17 | Style: Default,Arial,48,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1
18 | Style: 蓝中字,FZHei-B01,60,&H00FFFFFF,&H000000FF,&H0ABD631D,&H64000000,0,0,0,0,100,100,0,0,1,3,1,2,10,10,10,1
19 | Style: 灰英字,Helvetica Neue,40,&H00FFFFFF,&H000000FF,&H0A3C3C3C,&H64000000,0,0,0,0,100,100,0,0,1,3,1,2,10,10,10,1
20 |
21 | [Events]
22 | Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
23 | Dialogue: 0,0:00:05.00,0:00:08.84,灰英字,,0,0,0,,Congratulations on making it to the end of this short course
24 | Dialogue: 0,0:00:08.84,0:00:11.28,灰英字,,0,0,0,,In summary, in this short course
25 | Dialogue: 0,0:00:11.28,0:00:14.38,灰英字,,0,0,0,,you've learned about two key principles for prompting
26 | Dialogue: 0,0:00:14.38,0:00:17.48,灰英字,,0,0,0,,right clearance for specific instructions and when it's appropriate
27 | Dialogue: 0,0:00:17.48,0:00:19.16,灰英字,,0,0,0,,give the model time to think
28 | Dialogue: 0,0:00:19.16,0:00:22.08,灰英字,,0,0,0,,You also learned about iterative prompt development and how
29 | Dialogue: 0,0:00:22.08,0:00:26.20,灰英字,,0,0,0,,having a process to get to the prompt is right for your application is key
30 | Dialogue: 0,0:00:26.20,0:00:28.80,灰英字,,0,0,0,,And we went through a few capabilities of
31 | Dialogue: 0,0:00:28.80,0:00:31.64,灰英字,,0,0,0,,large language models that are useful for many applications
32 | Dialogue: 0,0:00:31.64,0:00:36.32,灰英字,,0,0,0,,specifically summarizing, inferring, transforming, and expanding
33 | Dialogue: 0,0:00:36.32,0:00:39.88,灰英字,,0,0,0,,And you also saw how to build a custom chatbot
34 | Dialogue: 0,0:00:39.88,0:00:43.32,灰英字,,0,0,0,,That was a lot that you learned in just one short course
35 | Dialogue: 0,0:00:43.32,0:00:46.24,灰英字,,0,0,0,,and I hope you enjoyed going through these materials
36 | Dialogue: 0,0:00:46.24,0:00:47.92,灰英字,,0,0,0,,We hope you'll come up with some ideas for
37 | Dialogue: 0,0:00:47.92,0:00:50.12,灰英字,,0,0,0,,applications that you can build yourself now
38 | Dialogue: 0,0:00:50.12,0:00:53.12,灰英字,,0,0,0,,And please go try this out and let us know what you come up with
39 | Dialogue: 0,0:00:53.12,0:00:54.72,灰英字,,0,0,0,,No application is too small
40 | Dialogue: 0,0:00:54.72,0:00:57.00,灰英字,,0,0,0,,It's fine to start with something that's kind of
41 | Dialogue: 0,0:00:57.00,0:00:59.80,灰英字,,0,0,0,,a very small project with maybe a little bit of utility
42 | Dialogue: 0,0:00:59.80,0:01:01.80,灰英字,,0,0,0,,or maybe it's not even useful at all
43 | Dialogue: 0,0:01:01.80,0:01:03.32,灰英字,,0,0,0,,It's just something fun
44 | Dialogue: 0,0:01:03.32,0:01:06.20,灰英字,,0,0,0,,Yeah. And I find playing with these models actually really fun
45 | Dialogue: 0,0:01:06.20,0:01:07.44,灰英字,,0,0,0,,So go play with it
46 | Dialogue: 0,0:01:07.44,0:01:08.64,灰英字,,0,0,0,,Yeah, I agree. It's a good
47 | Dialogue: 0,0:01:08.64,0:01:11.08,灰英字,,0,0,0,,a good weekend activity, speaking from experience
48 | Dialogue: 0,0:01:11.08,0:01:14.96,灰英字,,0,0,0,,And just, you know
49 | Dialogue: 0,0:01:14.96,0:01:18.52,灰英字,,0,0,0,,please use the learnings from your first project to build a better second project
50 | Dialogue: 0,0:01:18.52,0:01:21.36,灰英字,,0,0,0,,and you know, maybe even a better third project, so on
51 | Dialogue: 0,0:01:21.36,0:01:26.96,灰英字,,0,0,0,,That's kind of how I have kind of grown over time using these models myself as well
52 | Dialogue: 0,0:01:26.96,0:01:31.36,灰英字,,0,0,0,,Or if you have an idea for a bigger project already, just, just go for it
53 | Dialogue: 0,0:01:31.36,0:01:33.96,灰英字,,0,0,0,,And, you know, as a reminder
54 | Dialogue: 0,0:01:33.96,0:01:37.20,灰英字,,0,0,0,,these kind of large language models are a very powerful technology
55 | Dialogue: 0,0:01:37.20,0:01:41.12,灰英字,,0,0,0,,So it kind of goes without saying that we ask you to use them responsibly
56 | Dialogue: 0,0:01:41.12,0:01:43.96,灰英字,,0,0,0,,and please only build things that will have a positive impact
57 | Dialogue: 0,0:01:43.96,0:01:46.24,灰英字,,0,0,0,,Yeah, fully agree. I think in this age
58 | Dialogue: 0,0:01:46.24,0:01:49.48,灰英字,,0,0,0,,people that build AI systems can have a huge impact on others
59 | Dialogue: 0,0:01:49.48,0:01:54.96,灰英字,,0,0,0,,So it's more important than ever that all of us only use these tools responsibly
60 | Dialogue: 0,0:01:54.96,0:01:59.72,灰英字,,0,0,0,,And I think building large language model-based applications
61 | Dialogue: 0,0:01:59.72,0:02:02.88,灰英字,,0,0,0,,is just a very exciting and growing field right now
62 | Dialogue: 0,0:02:02.88,0:02:05.16,灰英字,,0,0,0,,And now that you've finished this course
63 | Dialogue: 0,0:02:05.16,0:02:08.24,灰英字,,0,0,0,,I think you now have a wealth of knowledge to let
64 | Dialogue: 0,0:02:08.24,0:02:11.32,灰英字,,0,0,0,,you build things that few people today know how to
65 | Dialogue: 0,0:02:11.32,0:02:17.28,灰英字,,0,0,0,,So I hope you also help us to spread the word and encourage others to take this course too
66 | Dialogue: 0,0:02:17.28,0:02:20.52,灰英字,,0,0,0,,In closing, I hope you had fun doing this course
67 | Dialogue: 0,0:02:20.52,0:02:23.28,灰英字,,0,0,0,,and I want to thank you for finishing this course
68 | Dialogue: 0,0:02:23.28,0:02:27.12,灰英字,,0,0,0,,and both Isa and I look forward to hearing about the amazing things that you've built
69 | Dialogue: 0,0:00:05.00,0:00:08.84,蓝中字,,0,0,0,,祝贺你在这个短期课程中走到了最后
70 | Dialogue: 0,0:00:08.84,0:00:11.28,蓝中字,,0,0,0,,综上所述,在这个短课程中
71 | Dialogue: 0,0:00:11.28,0:00:14.38,蓝中字,,0,0,0,,你已经了解了提示的两个关键原则
72 | Dialogue: 0,0:00:14.38,0:00:17.48,蓝中字,,0,0,0,,正确且清晰的描述具体指示,以及知道什么时候使用
73 | Dialogue: 0,0:00:17.48,0:00:19.16,蓝中字,,0,0,0,,给予模型思考的时间
74 | Dialogue: 0,0:00:19.16,0:00:22.08,蓝中字,,0,0,0,,你还了解了迭代提示的发展以及如何
75 | Dialogue: 0,0:00:22.08,0:00:26.20,蓝中字,,0,0,0,,有一个过程来获得适合你的应用的提示是关键
76 | Dialogue: 0,0:00:26.20,0:00:28.80,蓝中字,,0,0,0,,我们还学习了一些大语言模型的功能
77 | Dialogue: 0,0:00:28.80,0:00:31.64,蓝中字,,0,0,0,,这些功能对许多应用是有用的
78 | Dialogue: 0,0:00:31.64,0:00:36.32,蓝中字,,0,0,0,,特别是总结、推理、转换和扩展
79 | Dialogue: 0,0:00:36.32,0:00:39.88,蓝中字,,0,0,0,,你还看到了如何建立一个定制的聊天机器人
80 | Dialogue: 0,0:00:39.88,0:00:43.32,蓝中字,,0,0,0,,在短短的课程中,你学到了很多东西
81 | Dialogue: 0,0:00:43.32,0:00:46.24,蓝中字,,0,0,0,,我希望你喜欢阅读这些材料
82 | Dialogue: 0,0:00:46.24,0:00:47.92,蓝中字,,0,0,0,,我们希望你能想出一些想法
83 | Dialogue: 0,0:00:47.92,0:00:50.12,蓝中字,,0,0,0,,我们希望你能想出一些可以自己构建的应用
84 | Dialogue: 0,0:00:50.12,0:00:53.12,蓝中字,,0,0,0,,并请你去尝试一下,让我们知道你想出了什么
85 | Dialogue: 0,0:00:53.12,0:00:54.72,蓝中字,,0,0,0,,任何应用都不小
86 | Dialogue: 0,0:00:54.72,0:00:57.00,蓝中字,,0,0,0,,从一些很小的项目开始也是可以的
87 | Dialogue: 0,0:00:57.00,0:00:59.80,蓝中字,,0,0,0,,一个非常小的项目,也许实用
88 | Dialogue: 0,0:00:59.80,0:01:01.80,蓝中字,,0,0,0,,也可能毫无用处
89 | Dialogue: 0,0:01:01.80,0:01:03.32,蓝中字,,0,0,0,,这只是一些有趣的东西
90 | Dialogue: 0,0:01:03.32,0:01:06.20,蓝中字,,0,0,0,,是的。我发现玩这些模型非常有趣
91 | Dialogue: 0,0:01:06.20,0:01:07.44,蓝中字,,0,0,0,,所以放心去玩吧
92 | Dialogue: 0,0:01:07.44,0:01:08.64,蓝中字,,0,0,0,,是的,我同意。从我的经验来看
93 | Dialogue: 0,0:01:08.64,0:01:11.08,蓝中字,,0,0,0,,这是一个很好的周末活动
94 | Dialogue: 0,0:01:11.08,0:01:14.96,蓝中字,,0,0,0,,而且,你可以通过第一个项目获得的经验教训
95 | Dialogue: 0,0:01:14.96,0:01:18.52,蓝中字,,0,0,0,,来构建第二个更好的项目
96 | Dialogue: 0,0:01:18.52,0:01:21.36,蓝中字,,0,0,0,,甚至可能是更好的第三个项目,等等
97 | Dialogue: 0,0:01:21.36,0:01:26.96,蓝中字,,0,0,0,,这就是我自己使用这些模型逐渐成长的方式
98 | Dialogue: 0,0:01:26.96,0:01:31.36,蓝中字,,0,0,0,,或者如果你已经有了一个更大的项目想法,就去做吧
99 | Dialogue: 0,0:01:31.36,0:01:33.96,蓝中字,,0,0,0,,作为一个提醒
100 | Dialogue: 0,0:01:33.96,0:01:37.20,蓝中字,,0,0,0,,这些大语言模型是一种非常强大的技术
101 | Dialogue: 0,0:01:37.20,0:01:41.12,蓝中字,,0,0,0,,所以不言而喻,我们要求你负责任地使用它们
102 | Dialogue: 0,0:01:41.12,0:01:43.96,蓝中字,,0,0,0,,请只建立会产生积极影响的东西
103 | Dialogue: 0,0:01:43.96,0:01:46.24,蓝中字,,0,0,0,,是的,完全同意。我认为在这个时代
104 | Dialogue: 0,0:01:46.24,0:01:49.48,蓝中字,,0,0,0,,建立AI系统的人可以对其他人产生巨大的影响
105 | Dialogue: 0,0:01:49.48,0:01:54.96,蓝中字,,0,0,0,,因此,我们所有人都要负责任地使用这些工具,这一点比以往任何时候都重要
106 | Dialogue: 0,0:01:54.96,0:01:59.72,蓝中字,,0,0,0,,我认为建立基于大语言模型的应用程序
107 | Dialogue: 0,0:01:59.72,0:02:02.88,蓝中字,,0,0,0,,是一个非常令人兴奋和不断增长的领域
108 | Dialogue: 0,0:02:02.88,0:02:05.16,蓝中字,,0,0,0,,现在你已经完成了这个课程
109 | Dialogue: 0,0:02:05.16,0:02:08.24,蓝中字,,0,0,0,,我想你现在已经有了丰富的知识
110 | Dialogue: 0,0:02:08.24,0:02:11.32,蓝中字,,0,0,0,,可以让你构建少数人知道如何构建的东西
111 | Dialogue: 0,0:02:11.32,0:02:17.28,蓝中字,,0,0,0,,与此同时,我希望你也能帮助我们传播信息,鼓励其他人也参加这个课程
112 | Dialogue: 0,0:02:17.28,0:02:20.52,蓝中字,,0,0,0,,最后,我希望你在做这个课程时很开心
113 | Dialogue: 0,0:02:20.52,0:02:23.28,蓝中字,,0,0,0,,同时也感谢你能完成这个课程
114 | Dialogue: 0,0:02:23.28,0:02:27.12,蓝中字,,0,0,0,,Isa和我都期待着听到你所建立的惊人的东西
--------------------------------------------------------------------------------
/chinese_subtitles/prompt_eng_07_expanding_chinese.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:08,200
3 | 扩写是指将一篇较短的文本进行扩写的工作
4 |
5 | 2
6 | 00:00:08,200 --> 00:00:11,140
7 | 如一套指示或一个主题列表
8 |
9 | 3
10 | 00:00:11,140 --> 00:00:14,900
11 | 并让大语言模型生成一个较长的文本
12 |
13 | 4
14 | 00:00:14,900 --> 00:00:18,260
15 | 例如一封电子邮件或一篇关于某些主题的文章
16 |
17 | 5
18 | 00:00:18,260 --> 00:00:20,100
19 | 这方面有一些很好的用途
20 |
21 | 6
22 | 00:00:20,100 --> 00:00:23,960
23 | 例如,如果你使用一个大语言模型作为头脑风暴的伙伴
24 |
25 | 7
26 | 00:00:23,960 --> 00:00:26,300
27 | 但是,我也想承认,有一些
28 |
29 | 8
30 | 00:00:26,300 --> 00:00:28,500
31 | 有问题的使用案例
32 |
33 | 9
34 | 00:00:28,500 --> 00:00:32,500
35 | 例如,如果有人用它来产生大量的垃圾邮件
36 |
37 | 10
38 | 00:00:32,500 --> 00:00:36,100
39 | 因此,当你使用大语言模型的这些能力时
40 |
41 | 11
42 | 00:00:36,100 --> 00:00:41,340
43 | 请以负责任的方式和帮助人们的方式来使用它
44 |
45 | 12
46 | 00:00:41,340 --> 00:00:45,280
47 | 在这个视频中,我们将通过一个例子来说明
48 |
49 | 13
50 | 00:00:45,280 --> 00:00:49,900
51 | 如何使用语言模型,生成一个基于某些信息的个性化电子邮件
52 |
53 | 14
54 | 00:00:49,900 --> 00:00:53,260
55 | 这封邮件自称是来自一个AI机器人
56 |
57 | 15
58 | 00:00:53,260 --> 00:00:56,140
59 | 正如恩达提到的,这一点非常重要
60 |
61 | 16
62 | 00:00:56,140 --> 00:00:58,500
63 | 我们还将使用另一个
64 |
65 | 17
66 | 00:00:58,500 --> 00:01:01,260
67 | 该模型的另一个输入参数,叫做temperature(温度)
68 |
69 | 18
70 | 00:01:01,260 --> 00:01:04,780
71 | 这允许你改变模型的探索和多样性的程度
72 |
73 | 19
74 | 00:01:04,780 --> 00:01:08,760
75 | 这允许你改变模型响应的探索和多样性
76 |
77 | 20
78 | 00:01:08,760 --> 00:01:10,980
79 | 因此,让我们开始吧
80 |
81 | 21
82 | 00:01:10,980 --> 00:01:12,740
83 | 在我们开始之前
84 |
85 | 22
86 | 00:01:12,740 --> 00:01:15,780
87 | 我们要做一些常规的设置
88 |
89 | 23
90 | 00:01:15,780 --> 00:01:18,400
91 | 所以要设置OpenAI Python软件包
92 |
93 | 24
94 | 00:01:18,400 --> 00:01:22,060
95 | 然后定义我们的辅助函数,get_completion
96 |
97 | 25
98 | 00:01:22,060 --> 00:01:26,460
99 | 现在我们要为客户的评论写一个自定义的电子邮件回复
100 |
101 | 26
102 | 00:01:26,460 --> 00:01:29,940
103 | 所以给定一个客户评论和情绪
104 |
105 | 27
106 | 00:01:29,940 --> 00:01:32,680
107 | 我们将生成一个自定义的回复
108 |
109 | 28
110 | 00:01:32,680 --> 00:01:37,100
111 | 现在我们要使用语言模型来生成
112 |
113 | 29
114 | 00:01:37,100 --> 00:01:41,900
115 | 根据客户的评论,给客户发送一封定制的电子邮件
116 |
117 | 30
118 | 00:01:41,900 --> 00:01:44,020
119 | 和评论的情绪
120 |
121 | 31
122 | 00:01:44,020 --> 00:01:47,100
123 | 所以我们已经提取了情绪
124 |
125 | 32
126 | 00:01:47,100 --> 00:01:52,740
127 | 使用我们在推理视频中看到的那种提示
128 |
129 | 33
130 | 00:01:52,740 --> 00:01:57,020
131 | 然后这就是客户对搅拌机的评论
132 |
133 | 34
134 | 00:01:57,100 --> 00:02:02,740
135 | 现在我们要根据情感来定制回复
136 |
137 | 35
138 | 00:02:02,740 --> 00:02:05,180
139 | 所以这里的指令是
140 |
141 | 36
142 | 00:02:05,180 --> 00:02:08,260
143 | 你是一个客户服务的AI助理
144 |
145 | 37
146 | 00:02:08,260 --> 00:02:11,180
147 | 你的任务是给一个有价值的客户发送电子邮件回复
148 |
149 | 38
150 | 00:02:11,180 --> 00:02:14,540
151 | 给出客户的电子邮件,以三个`符号分割
152 |
153 | 39
154 | 00:02:14,540 --> 00:02:16,860
155 | 产生一个回复,以感谢客户的评论
156 |
157 | 40
158 | 00:02:16,860 --> 00:02:18,780
159 | 如果情绪是积极的或中性的
160 |
161 | 41
162 | 00:02:18,780 --> 00:02:20,460
163 | 感谢他们的评论
164 |
165 | 42
166 | 00:02:20,460 --> 00:02:21,980
167 | 如果情绪是负面的
168 |
169 | 43
170 | 00:02:21,980 --> 00:02:25,260
171 | 道歉,并建议他们可以联系客户服务部
172 |
173 | 44
174 | 00:02:25,260 --> 00:02:27,820
175 | 确保使用评论中的具体细节
176 |
177 | 45
178 | 00:02:27,820 --> 00:02:29,820
179 | 用简明和专业的语气来写
180 |
181 | 46
182 | 00:02:29,820 --> 00:02:32,460
183 | 并以AI客户代理的身份在邮件中签名
184 |
185 | 47
186 | 00:02:32,460 --> 00:02:34,820
187 | 当你使用一个语言模型
188 |
189 | 48
190 | 00:02:34,820 --> 00:02:37,500
191 | 来生成你要展示给用户的文本
192 |
193 | 49
194 | 00:02:37,500 --> 00:02:40,860
195 | 有这样的透明度是非常重要的
196 |
197 | 50
198 | 00:02:40,860 --> 00:02:45,700
199 | 并让用户知道他们看到的文本是由AI生成的
200 |
201 | 51
202 | 00:02:45,700 --> 00:02:49,780
203 | 然后我们就输入客户的评论和评论的情绪
204 |
205 | 52
206 | 00:02:49,780 --> 00:02:53,220
207 | 还要注意,这部分不一定很重要
208 |
209 | 53
210 | 00:02:53,220 --> 00:02:57,180
211 | 因为我们实际上也可以使用这个提示来提取评论的情绪
212 |
213 | 54
214 | 00:02:57,180 --> 00:02:59,300
215 | 然后在后续步骤中,编写电子邮件
216 |
217 | 55
218 | 00:02:59,300 --> 00:03:01,140
219 | 但是,只是为了这个例子的目的
220 |
221 | 56
222 | 00:03:01,140 --> 00:03:04,300
223 | 好吧,我们已经从评论中提取了情感
224 |
225 | 57
226 | 00:03:04,300 --> 00:03:08,500
227 | 所以在这里我们有一个给客户的回复
228 |
229 | 58
230 | 00:03:08,500 --> 00:03:13,580
231 | 它涉及客户在评论中提到的细节
232 |
233 | 59
234 | 00:03:13,580 --> 00:03:16,620
235 | 并且按照我们的指示
236 |
237 | 60
238 | 00:03:16,620 --> 00:03:19,100
239 | 建议他们与客户服务部联系
240 |
241 | 61
242 | 00:03:19,100 --> 00:03:23,100
243 | 因为这只是一个AI客户服务代理
244 |
245 | 62
246 | 00:03:23,740 --> 00:03:30,420
247 | 接下来,我们将使用语言模型的一个参数,叫做temperature
248 |
249 | 63
250 | 00:03:30,420 --> 00:03:36,460
251 | 这将使我们能够改变模型响应的多样性
252 |
253 | 64
254 | 00:03:36,460 --> 00:03:38,900
255 | 所以你可以把temperature看成
256 |
257 | 65
258 | 00:03:38,900 --> 00:03:43,380
259 | 模型的探索或随机性的程度
260 |
261 | 66
262 | 00:03:43,380 --> 00:03:46,060
263 | 因此,对于这个特定的短语
264 |
265 | 67
266 | 00:03:46,060 --> 00:03:47,500
267 | 我最喜欢的食物是
268 |
269 | 68
270 | 00:03:47,500 --> 00:03:51,820
271 | 模型预测的最有可能的下一个词是披萨
272 |
273 | 69
274 | 00:03:51,820 --> 00:03:53,580
275 | 而接下来的两个最可能的
276 |
277 | 70
278 | 00:03:53,580 --> 00:03:55,900
279 | 它建议是寿司和玉米饼
280 |
281 | 71
282 | 00:03:55,900 --> 00:03:57,660
283 | 因此,在temperature为零的情况下
284 |
285 | 72
286 | 00:03:57,660 --> 00:04:00,060
287 | 模型总是会选择最可能的下一个词
288 |
289 | 73
290 | 00:04:00,060 --> 00:04:01,460
291 | 在这个例子中是比萨
292 |
293 | 74
294 | 00:04:01,460 --> 00:04:03,260
295 | 而在更高的temperature下
296 |
297 | 75
298 | 00:04:03,260 --> 00:04:07,100
299 | 它也会选择一个不太可能的词
300 |
301 | 76
302 | 00:04:07,100 --> 00:04:09,340
303 | 甚至在更高的temperature下
304 |
305 | 77
306 | 00:04:09,340 --> 00:04:10,700
307 | 它有可能选择玉米饼
308 |
309 | 78
310 | 00:04:10,700 --> 00:04:15,380
311 | 虽然这只有5%的机率被选中
312 |
313 | 79
314 | 00:04:15,380 --> 00:04:21,660
315 | 你可以想象,当模型继续这个最后的响应
316 |
317 | 80
318 | 00:04:21,660 --> 00:04:23,300
319 | 所以我最喜欢的食物是比萨饼
320 |
321 | 81
322 | 00:04:23,300 --> 00:04:25,420
323 | 而且它继续产生更多的词
324 |
325 | 82
326 | 00:04:25,420 --> 00:04:30,580
327 | 这个响应会与第一个响应发生分歧
328 |
329 | 83
330 | 00:04:30,580 --> 00:04:32,340
331 | 也就是我最喜欢的食物是玉米饼
332 |
333 | 84
334 | 00:04:32,340 --> 00:04:34,100
335 | 所以随着模型的继续
336 |
337 | 85
338 | 00:04:34,100 --> 00:04:37,060
339 | 这两个响应将变得越来越不同
340 |
341 | 86
342 | 00:04:37,060 --> 00:04:40,500
343 | 一般来说,在构建你想要的应用程序时
344 |
345 | 87
346 | 00:04:40,500 --> 00:04:43,420
347 | 一个可预测的响应
348 |
349 | 88
350 | 00:04:43,420 --> 00:04:45,420
351 | 我建议使用temperature=0
352 |
353 | 89
354 | 00:04:45,420 --> 00:04:46,780
355 | 在所有这些视频中
356 |
357 | 90
358 | 00:04:46,780 --> 00:04:48,900
359 | 我们一直在使用temperature=0
360 |
361 | 91
362 | 00:04:48,900 --> 00:04:51,380
363 | 我认为,如果你试图建立一个系统
364 |
365 | 92
366 | 00:04:51,380 --> 00:04:54,660
367 | 可靠和可预测的系统,你应该使用这个
368 |
369 | 93
370 | 00:04:54,660 --> 00:04:58,780
371 | 如果你想以更有创意的方式使用这个模型
372 |
373 | 94
374 | 00:04:58,780 --> 00:05:04,220
375 | 你可能希望有更多不同的输出
376 |
377 | 95
378 | 00:05:04,220 --> 00:05:06,860
379 | 你可能想用更高的temperature
380 |
381 | 96
382 | 00:05:06,860 --> 00:05:11,620
383 | 那么,现在让我们把刚才的提示也拿出来
384 |
385 | 97
386 | 00:05:11,620 --> 00:05:14,220
387 | 让我们试着生成一封电子邮件
388 |
389 | 98
390 | 00:05:14,220 --> 00:05:16,140
391 | 但让我们使用一个更高的temperature
392 |
393 | 99
394 | 00:05:16,140 --> 00:05:21,540
395 | 所以在我们的get_completion函数中,我们在整个视频中一直在使用
396 |
397 | 100
398 | 00:05:21,540 --> 00:05:25,100
399 | 我们已经指定了一个模型和一个temperature
400 |
401 | 101
402 | 00:05:25,100 --> 00:05:26,540
403 | 但我们已经把它们设置为默认值
404 |
405 | 102
406 | 00:05:26,540 --> 00:05:29,420
407 | 所以现在让我们试着改变temperature
408 |
409 | 103
410 | 00:05:30,140 --> 00:05:32,860
411 | 所以我们使用提示
412 |
413 | 104
414 | 00:05:32,860 --> 00:05:39,340
415 | 然后让我们试试temperature=0.7
416 |
417 | 105
418 | 00:05:43,620 --> 00:05:45,340
419 | 于是用temperature=0
420 |
421 | 106
422 | 00:05:45,340 --> 00:05:47,220
423 | 每次你执行同样的提示时
424 |
425 | 107
426 | 00:05:47,220 --> 00:05:50,580
427 | 你应该期待同样的完成
428 |
429 | 108
430 | 00:05:50,580 --> 00:05:52,580
431 | 而在temperature为0.7时
432 |
433 | 109
434 | 00:05:52,580 --> 00:05:55,060
435 | 你每次都会得到一个不同的输出
436 |
437 | 110
438 | 00:05:55,060 --> 00:05:58,100
439 | 所以这里我们有我们的电子邮件
440 |
441 | 111
442 | 00:05:58,100 --> 00:06:00,980
443 | 正如你所看到的,它与我们之前收到的电子邮件
444 |
445 | 112
446 | 00:06:00,980 --> 00:06:02,900
447 | 不同
448 |
449 | 113
450 | 00:06:02,900 --> 00:06:08,060
451 | 让我们再执行一次,以显示我们将再次得到一个不同的电子邮件
452 |
453 | 114
454 | 00:06:08,060 --> 00:06:11,340
455 | 这里我们有另一封不同的电子邮件
456 |
457 | 115
458 | 00:06:11,340 --> 00:06:16,780
459 | 所以我建议你自己玩一下temperature
460 |
461 | 116
462 | 00:06:16,780 --> 00:06:20,820
463 | 也许你现在可以暂停视频,并尝试这个提示
464 |
465 | 117
466 | 00:06:20,820 --> 00:06:22,620
467 | 用各种不同的temperature
468 |
469 | 118
470 | 00:06:22,620 --> 00:06:25,100
471 | 只是为了看看输出是如何变化的
472 |
473 | 119
474 | 00:06:25,100 --> 00:06:28,500
475 | 因此,总结一下,在较高的temperature下
476 |
477 | 120
478 | 00:06:28,500 --> 00:06:31,700
479 | 模型的输出更加随机
480 |
481 | 121
482 | 00:06:31,700 --> 00:06:34,500
483 | 你几乎可以认为,在较高temperature下
484 |
485 | 122
486 | 00:06:34,500 --> 00:06:36,500
487 | 助理更容易分心
488 |
489 | 123
490 | 00:06:36,500 --> 00:06:38,220
491 | 但也许更有创造力
492 |
493 | 124
494 | 00:06:39,620 --> 00:06:42,260
495 | 在下一个视频中,我们将进一步讨论
496 |
497 | 125
498 | 00:06:42,260 --> 00:06:44,540
499 | 对话补全终端格式
500 |
501 | 126
502 | 00:06:44,540 --> 00:07:00,060
503 | 以及你如何使用这种格式创建一个自定义的聊天机器人
504 |
505 |
--------------------------------------------------------------------------------
/course_notebooks/l8-chatbot.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "attachments": {},
5 | "cell_type": "markdown",
6 | "metadata": {},
7 | "source": [
8 | "[](https://colab.research.google.com/github/GitHubDaily/ChatGPT-Prompt-Engineering-for-Developers-in-Chinese/blob/master/assets/8-Chatbot/l8-chatbot.ipynb)\n",
9 | "# The Chat Format\n",
10 | "\n",
11 | "In this notebook, you will explore how you can utilize the chat format to have extended conversations with chatbots personalized or specialized for specific tasks or behaviors.\n",
12 | "\n",
13 | "## Setup"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": null,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "# Basic congfig \n",
23 | "# Install basic package and set key\n",
24 | "!pip install openai\n",
25 | "!export OPENAI_API_KEY='sk-...'"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": null,
31 | "metadata": {},
32 | "outputs": [],
33 | "source": [
34 | "import os\n",
35 | "import openai\n",
36 | "from dotenv import load_dotenv, find_dotenv\n",
37 | "_ = load_dotenv(find_dotenv()) # read local .env file\n",
38 | "\n",
39 | "openai.api_key = os.getenv('OPENAI_API_KEY')"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "def get_completion(prompt, model=\"gpt-3.5-turbo\"):\n",
49 | " messages = [{\"role\": \"user\", \"content\": prompt}]\n",
50 | " response = openai.ChatCompletion.create(\n",
51 | " model=model,\n",
52 | " messages=messages,\n",
53 | " temperature=0, # this is the degree of randomness of the model's output\n",
54 | " )\n",
55 | " return response.choices[0].message[\"content\"]\n",
56 | "\n",
57 | "def get_completion_from_messages(messages, model=\"gpt-3.5-turbo\", temperature=0):\n",
58 | " response = openai.ChatCompletion.create(\n",
59 | " model=model,\n",
60 | " messages=messages,\n",
61 | " temperature=temperature, # this is the degree of randomness of the model's output\n",
62 | " )\n",
63 | "# print(str(response.choices[0].message))\n",
64 | " return response.choices[0].message[\"content\"]"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": null,
70 | "metadata": {},
71 | "outputs": [],
72 | "source": [
73 | "messages = [ \n",
74 | "{'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'}, \n",
75 | "{'role':'user', 'content':'tell me a joke'}, \n",
76 | "{'role':'assistant', 'content':'Why did the chicken cross the road'}, \n",
77 | "{'role':'user', 'content':'I don\\'t know'} ]"
78 | ]
79 | },
80 | {
81 | "cell_type": "code",
82 | "execution_count": null,
83 | "metadata": {},
84 | "outputs": [],
85 | "source": [
86 | "response = get_completion_from_messages(messages, temperature=1)\n",
87 | "print(response)"
88 | ]
89 | },
90 | {
91 | "cell_type": "code",
92 | "execution_count": null,
93 | "metadata": {},
94 | "outputs": [],
95 | "source": [
96 | "messages = [ \n",
97 | "{'role':'system', 'content':'You are friendly chatbot.'}, \n",
98 | "{'role':'user', 'content':'Hi, my name is Isa'} ]\n",
99 | "response = get_completion_from_messages(messages, temperature=1)\n",
100 | "print(response)"
101 | ]
102 | },
103 | {
104 | "cell_type": "code",
105 | "execution_count": null,
106 | "metadata": {},
107 | "outputs": [],
108 | "source": [
109 | "messages = [ \n",
110 | "{'role':'system', 'content':'You are friendly chatbot.'}, \n",
111 | "{'role':'user', 'content':'Yes, can you remind me, What is my name?'} ]\n",
112 | "response = get_completion_from_messages(messages, temperature=1)\n",
113 | "print(response)"
114 | ]
115 | },
116 | {
117 | "cell_type": "code",
118 | "execution_count": null,
119 | "metadata": {},
120 | "outputs": [],
121 | "source": [
122 | "messages = [ \n",
123 | "{'role':'system', 'content':'You are friendly chatbot.'},\n",
124 | "{'role':'user', 'content':'Hi, my name is Isa'},\n",
125 | "{'role':'assistant', 'content': \"Hi Isa! It's nice to meet you. \\\n",
126 | "Is there anything I can help you with today?\"},\n",
127 | "{'role':'user', 'content':'Yes, you can remind me, What is my name?'} ]\n",
128 | "response = get_completion_from_messages(messages, temperature=1)\n",
129 | "print(response)"
130 | ]
131 | },
132 | {
133 | "attachments": {},
134 | "cell_type": "markdown",
135 | "metadata": {},
136 | "source": [
137 | "# OrderBot\n",
138 | "We can automate the collection of user prompts and assistant responses to build a OrderBot. The OrderBot will take orders at a pizza restaurant. "
139 | ]
140 | },
141 | {
142 | "cell_type": "code",
143 | "execution_count": null,
144 | "metadata": {},
145 | "outputs": [],
146 | "source": [
147 | "!pip install panel jupyter_bokeh"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": null,
153 | "metadata": {},
154 | "outputs": [],
155 | "source": [
156 | "def collect_messages(_):\n",
157 | " prompt = inp.value_input\n",
158 | " inp.value = ''\n",
159 | " context.append({'role':'user', 'content':f\"{prompt}\"})\n",
160 | " response = get_completion_from_messages(context) \n",
161 | " context.append({'role':'assistant', 'content':f\"{response}\"})\n",
162 | " panels.append(\n",
163 | " pn.Row('User:', pn.pane.Markdown(prompt, width=600)))\n",
164 | " panels.append(\n",
165 | " pn.Row('Assistant:', pn.pane.Markdown(response, width=600, style={'background-color': '#F6F6F6'})))\n",
166 | " \n",
167 | " return pn.Column(*panels)"
168 | ]
169 | },
170 | {
171 | "cell_type": "code",
172 | "execution_count": null,
173 | "metadata": {},
174 | "outputs": [],
175 | "source": [
176 | "import panel as pn # GUI\n",
177 | "pn.extension()\n",
178 | "\n",
179 | "panels = [] # collect display \n",
180 | "\n",
181 | "context = [ {'role':'system', 'content':\"\"\"\n",
182 | "You are OrderBot, an automated service to collect orders for a pizza restaurant. \\\n",
183 | "You first greet the customer, then collects the order, \\\n",
184 | "and then asks if it's a pickup or delivery. \\\n",
185 | "You wait to collect the entire order, then summarize it and check for a final \\\n",
186 | "time if the customer wants to add anything else. \\\n",
187 | "If it's a delivery, you ask for an address. \\\n",
188 | "Finally you collect the payment.\\\n",
189 | "Make sure to clarify all options, extras and sizes to uniquely \\\n",
190 | "identify the item from the menu.\\\n",
191 | "You respond in a short, very conversational friendly style. \\\n",
192 | "The menu includes \\\n",
193 | "pepperoni pizza 12.95, 10.00, 7.00 \\\n",
194 | "cheese pizza 10.95, 9.25, 6.50 \\\n",
195 | "eggplant pizza 11.95, 9.75, 6.75 \\\n",
196 | "fries 4.50, 3.50 \\\n",
197 | "greek salad 7.25 \\\n",
198 | "Toppings: \\\n",
199 | "extra cheese 2.00, \\\n",
200 | "mushrooms 1.50 \\\n",
201 | "sausage 3.00 \\\n",
202 | "canadian bacon 3.50 \\\n",
203 | "AI sauce 1.50 \\\n",
204 | "peppers 1.00 \\\n",
205 | "Drinks: \\\n",
206 | "coke 3.00, 2.00, 1.00 \\\n",
207 | "sprite 3.00, 2.00, 1.00 \\\n",
208 | "bottled water 5.00 \\\n",
209 | "\"\"\"} ] # accumulate messages\n",
210 | "\n",
211 | "\n",
212 | "inp = pn.widgets.TextInput(value=\"Hi\", placeholder='Enter text here…')\n",
213 | "button_conversation = pn.widgets.Button(name=\"Chat!\")\n",
214 | "\n",
215 | "interactive_conversation = pn.bind(collect_messages, button_conversation)\n",
216 | "\n",
217 | "dashboard = pn.Column(\n",
218 | " inp,\n",
219 | " pn.Row(button_conversation),\n",
220 | " pn.panel(interactive_conversation, loading_indicator=True, height=300),\n",
221 | ")\n",
222 | "\n",
223 | "dashboard"
224 | ]
225 | },
226 | {
227 | "cell_type": "code",
228 | "execution_count": null,
229 | "metadata": {},
230 | "outputs": [],
231 | "source": [
232 | "messages = context.copy()\n",
233 | "messages.append(\n",
234 | "{'role':'system', 'content':'create a json summary of the previous food order. Itemize the price for each item\\\n",
235 | " The fields should be 1) pizza, include size 2) list of toppings 3) list of drinks, include size 4) list of sides include size 5)total price '}, \n",
236 | ")\n",
237 | " #The fields should be 1) pizza, price 2) list of toppings 3) list of drinks, include size include price 4) list of sides include size include price, 5)total price '}, \n",
238 | "\n",
239 | "response = get_completion_from_messages(messages, temperature=0)\n",
240 | "print(response)"
241 | ]
242 | },
243 | {
244 | "cell_type": "code",
245 | "execution_count": null,
246 | "metadata": {},
247 | "outputs": [],
248 | "source": []
249 | },
250 | {
251 | "cell_type": "markdown",
252 | "metadata": {},
253 | "source": []
254 | }
255 | ],
256 | "metadata": {
257 | "kernelspec": {
258 | "display_name": "gpt_index",
259 | "language": "python",
260 | "name": "python3"
261 | },
262 | "language_info": {
263 | "codemirror_mode": {
264 | "name": "ipython",
265 | "version": 3
266 | },
267 | "file_extension": ".py",
268 | "mimetype": "text/x-python",
269 | "name": "python",
270 | "nbconvert_exporter": "python",
271 | "pygments_lexer": "ipython3",
272 | "version": "3.8.16"
273 | },
274 | "orig_nbformat": 4
275 | },
276 | "nbformat": 4,
277 | "nbformat_minor": 2
278 | }
279 |
--------------------------------------------------------------------------------
/english_subtitles/prompt_eng_04_summarizing_english.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:09,680
3 | There's so much text in today's world, pretty much none of us have enough time to read all
4 |
5 | 2
6 | 00:00:09,680 --> 00:00:12,760
7 | the things we wish we had time to
8 |
9 | 3
10 | 00:00:12,760 --> 00:00:16,920
11 | So one of the most exciting applications I've seen of large language models is to use it
12 |
13 | 4
14 | 00:00:16,920 --> 00:00:18,660
15 | to summarize text
16 |
17 | 5
18 | 00:00:18,660 --> 00:00:24,480
19 | And this is something that I'm seeing multiple teams build into multiple software applications
20 |
21 | 6
22 | 00:00:24,480 --> 00:00:26,880
23 | You can do this in the ChatGPT web interface
24 |
25 | 7
26 | 00:00:26,880 --> 00:00:31,000
27 | I do this all the time to summarize articles so I can just kind of read the content of
28 |
29 | 8
30 | 00:00:31,000 --> 00:00:33,000
31 | many more articles than I previously could
32 |
33 | 9
34 | 00:00:33,000 --> 00:00:37,880
35 | And if you want to do this more programmatically, you'll see how to in this lesson
36 |
37 | 10
38 | 00:00:37,880 --> 00:00:43,520
39 | So that's let's dig into the code to see how you could use this yourself to summarize text
40 |
41 | 11
42 | 00:00:43,520 --> 00:00:48,280
43 | So let's start off with the same starter code as you saw before of import openai, load the
44 |
45 | 12
46 | 00:00:48,280 --> 00:00:52,620
47 | API key and here's that get_completion helper function
48 |
49 | 13
50 | 00:00:52,620 --> 00:01:00,640
51 | I'm going to use as the running example, the task of summarizing this product review
52 |
53 | 14
54 | 00:01:00,640 --> 00:01:04,640
55 | Got this panda plush toy for my daughter's birthday
56 |
57 | 15
58 | 00:01:04,640 --> 00:01:06,320
59 | and so on and so on
60 |
61 | 16
62 | 00:01:06,320 --> 00:01:13,640
63 | If you're building an e commerce website, and there's just a large volume of reviews
64 |
65 | 17
66 | 00:01:13,640 --> 00:01:18,680
67 | having a tool to summarize the lengthy reviews could give you a way to very quickly glance
68 |
69 | 18
70 | 00:01:18,680 --> 00:01:24,200
71 | over more reviews to get a better sense of what all your customers are thinking
72 |
73 | 19
74 | 00:01:24,200 --> 00:01:27,280
75 | So here's a prompt for generating a summary
76 |
77 | 20
78 | 00:01:27,280 --> 00:01:30,600
79 | Your task is generate a short summary of a product review from e commerce website, summarize
80 |
81 | 21
82 | 00:01:30,600 --> 00:01:36,800
83 | review below, and so on, in at most 30 words
84 |
85 | 22
86 | 00:01:36,800 --> 00:01:42,400
87 | And so this is soft and cute panda plush toy loved by daughter, but small for the price
88 |
89 | 23
90 | 00:01:42,400 --> 00:01:43,400
91 | arrived early
92 |
93 | 24
94 | 00:01:43,400 --> 00:01:44,400
95 | Not bad
96 |
97 | 25
98 | 00:01:44,400 --> 00:01:45,400
99 | It's a pretty good summary
100 |
101 | 26
102 | 00:01:45,400 --> 00:01:49,760
103 | And as you saw in the previous video, you can also play with things like controlling
104 |
105 | 27
106 | 00:01:49,760 --> 00:01:55,720
107 | the character count or the number of sentences to affect the length of this summary
108 |
109 | 28
110 | 00:01:55,720 --> 00:01:59,920
111 | Now sometimes when creating a summary, if you have a very specific purpose in mind for
112 |
113 | 29
114 | 00:01:59,920 --> 00:02:05,600
115 | the summary, for example, if you want to give feedback to the shipping department, you can
116 |
117 | 30
118 | 00:02:05,600 --> 00:02:11,200
119 | also modify the prompt to reflect that so that they can generate a summary that is more
120 |
121 | 31
122 | 00:02:11,200 --> 00:02:15,600
123 | applicable to one particular group in your business
124 |
125 | 32
126 | 00:02:15,600 --> 00:02:26,880
127 | So for example, if I add to give feedback to the shipping department, let's say I change
128 |
129 | 33
130 | 00:02:26,880 --> 00:02:35,800
131 | this to start to focus on any aspects that mention shipping and delivery of the product
132 |
133 | 34
134 | 00:02:35,800 --> 00:02:42,560
135 | And if I run this, then again, you get a summary, but instead of starting off with soft and
136 |
137 | 35
138 | 00:02:42,560 --> 00:02:49,120
139 | cute panda plush toy, it now focuses on the fact that it arrived a day earlier than expected
140 |
141 | 36
142 | 00:02:49,120 --> 00:02:53,600
143 | And then it still has, you know, other details
144 |
145 | 37
146 | 00:02:53,600 --> 00:02:59,640
147 | Or as another example, if we aren't trying to give feedback to the shipping department
148 |
149 | 38
150 | 00:02:59,640 --> 00:03:09,520
151 | but let's say we want to give feedback to the pricing department
152 |
153 | 39
154 | 00:03:09,520 --> 00:03:15,760
155 | So the pricing department is responsible for determining the price of the product
156 |
157 | 40
158 | 00:03:15,760 --> 00:03:22,960
159 | And I'm going to tell it to focus on any aspects that are relevant to the price and perceived
160 |
161 | 41
162 | 00:03:22,960 --> 00:03:25,240
163 | value
164 |
165 | 42
166 | 00:03:25,240 --> 00:03:31,520
167 | Then this generates a different summary that it says
168 |
169 | 43
170 | 00:03:31,520 --> 00:03:33,480
171 | maybe the price may be too high for a size
172 |
173 | 44
174 | 00:03:33,480 --> 00:03:38,640
175 | Now in the summaries that I've generated for the shipping department or the pricing department
176 |
177 | 45
178 | 00:03:38,640 --> 00:03:44,400
179 | it focuses a bit more on information relevant to those specific departments
180 |
181 | 46
182 | 00:03:44,400 --> 00:03:50,000
183 | And in fact, feel free to pause the video now and maybe ask it to generate information
184 |
185 | 47
186 | 00:03:50,000 --> 00:03:55,360
187 | for the product department responsible for the customer experience of the product or
188 |
189 | 48
190 | 00:03:55,360 --> 00:04:01,920
191 | for something else that you think might be interesting to an e-commerce site
192 |
193 | 49
194 | 00:04:01,920 --> 00:04:07,000
195 | But in these summaries, even though it generated the information relevant to shipping, it had
196 |
197 | 50
198 | 00:04:07,000 --> 00:04:12,240
199 | some other information too, which you could decide may or may not be helpful
200 |
201 | 51
202 | 00:04:12,240 --> 00:04:20,120
203 | So depending on how you want to summarize it, you can also ask it to extract information
204 |
205 | 52
206 | 00:04:20,120 --> 00:04:22,960
207 | rather than summarize it
208 |
209 | 53
210 | 00:04:22,960 --> 00:04:27,920
211 | So here's a prompt that says you're tasked to extract relevant information to give feedback
212 |
213 | 54
214 | 00:04:27,920 --> 00:04:29,200
215 | to the shipping department
216 |
217 | 55
218 | 00:04:29,200 --> 00:04:35,440
219 | And now it just says, product arrived a day earlier than expected without all of the other
220 |
221 | 56
222 | 00:04:35,440 --> 00:04:41,240
223 | information, which was also helpful in a general summary, but less specific to the shipping
224 |
225 | 57
226 | 00:04:41,240 --> 00:04:45,000
227 | department if all it wants to know is what happened with the shipping
228 |
229 | 58
230 | 00:04:45,000 --> 00:04:50,600
231 | Lastly, let me just share with you a concrete example for how to use this in a workflow
232 |
233 | 59
234 | 00:04:50,600 --> 00:04:56,760
235 | to help summarize multiple reviews to make them easier to read
236 |
237 | 60
238 | 00:04:56,760 --> 00:04:59,920
239 | So here are a few reviews
240 |
241 | 61
242 | 00:04:59,920 --> 00:05:03,920
243 | This is kind of long, but here's a second review for a standing lamp
244 |
245 | 62
246 | 00:05:03,920 --> 00:05:04,920
247 | need a lamp on a bedroom
248 |
249 | 63
250 | 00:05:04,920 --> 00:05:07,280
251 | Here's a third review for an electric toothbrush
252 |
253 | 64
254 | 00:05:07,280 --> 00:05:09,600
255 | My dental hygienist recommended
256 |
257 | 65
258 | 00:05:09,600 --> 00:05:12,640
259 | Kind of a long review about the electric toothbrush
260 |
261 | 66
262 | 00:05:12,640 --> 00:05:17,920
263 | This is a review for a blender when it said, so said 17 piece system on seasonal sale and
264 |
265 | 67
266 | 00:05:17,920 --> 00:05:18,920
267 | so on and so on
268 |
269 | 68
270 | 00:05:18,920 --> 00:05:20,280
271 | This is actually a lot of text
272 |
273 | 69
274 | 00:05:20,280 --> 00:05:23,280
275 | If you want, feel free to pause the video and read through all this text
276 |
277 | 70
278 | 00:05:23,280 --> 00:05:28,480
279 | But what if you want to know what these reviewers wrote without having to stop and read all
280 |
281 | 71
282 | 00:05:28,480 --> 00:05:29,480
283 | this in detail?
284 |
285 | 72
286 | 00:05:29,480 --> 00:05:41,600
287 | So I'm going to set review_1 to be just the product review that we had up there
288 |
289 | 73
290 | 00:05:41,600 --> 00:05:45,320
291 | I'm going to put all of these reviews into a list
292 |
293 | 74
294 | 00:05:45,320 --> 00:05:53,800
295 | And now if I implement a for loop over the reviews
296 |
297 | 75
298 | 00:05:53,800 --> 00:06:01,240
299 | So here's my prompt and here I've asked it to summarize it in at most 20 words
300 |
301 | 76
302 | 00:06:01,240 --> 00:06:07,320
303 | Then let's have it get the response and print it out
304 |
305 | 77
306 | 00:06:07,320 --> 00:06:10,760
307 | And let's run that
308 |
309 | 78
310 | 00:06:10,760 --> 00:06:16,360
311 | And it prints out the first review is that PandaToy review, summary review of the lamp
312 |
313 | 79
314 | 00:06:16,360 --> 00:06:21,880
315 | summary review of the toothbrush, and then the blender
316 |
317 | 80
318 | 00:06:21,880 --> 00:06:29,800
319 | And so if you have a website where you have hundreds of reviews, you can imagine how you
320 |
321 | 81
322 | 00:06:29,800 --> 00:06:35,360
323 | might use this to build a dashboard, to take huge numbers of reviews, generate short summaries
324 |
325 | 82
326 | 00:06:35,360 --> 00:06:40,760
327 | of them so that you or someone else can browse the reviews much more quickly
328 |
329 | 83
330 | 00:06:40,760 --> 00:06:46,200
331 | And then if they wish, maybe click in to see the original longer review
332 |
333 | 84
334 | 00:06:46,200 --> 00:06:51,640
335 | And this can help you efficiently get a better sense of what all of your customers are thinking
336 |
337 | 85
338 | 00:06:51,640 --> 00:06:55,640
339 | All right, so that's it for summarizing
340 |
341 | 86
342 | 00:06:55,640 --> 00:07:00,960
343 | And I hope that you can picture if you have any applications with many pieces of text
344 |
345 | 87
346 | 00:07:00,960 --> 00:07:05,680
347 | how you can use prompts like these to summarize them to help people quickly get a sense of
348 |
349 | 88
350 | 00:07:05,680 --> 00:07:10,240
351 | what's in the text, the many pieces of text, and perhaps optionally dig in more
352 |
353 | 89
354 | 00:07:10,240 --> 00:07:12,520
355 | if they wish
356 |
357 | 90
358 | 00:07:12,520 --> 00:07:17,640
359 | In the next video, we'll look at another capability of large language models, which is to make
360 |
361 | 91
362 | 00:07:17,640 --> 00:07:19,880
363 | inferences using text
364 |
365 | 92
366 | 00:07:19,880 --> 00:07:24,280
367 | For example, what if you had, again, product reviews, and you wanted to very quickly get
368 |
369 | 93
370 | 00:07:24,280 --> 00:07:29,680
371 | a sense of which product reviews have a positive or a negative sentiment?
372 |
373 | 94
374 | 00:07:29,680 --> 00:07:49,840
375 | Let's take a look at how to do that in the next video
376 |
377 |
--------------------------------------------------------------------------------
/course_notebooks/l3-iterative-prompt-development.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "attachments": {},
5 | "cell_type": "markdown",
6 | "metadata": {},
7 | "source": [
8 | "[](https://colab.research.google.com/github/GitHubDaily/ChatGPT-Prompt-Engineering-for-Developers-in-Chinese/blob/master/assets/3-Iterative/l3-iterative-prompt-development.ipynb)\n",
9 | "# Iterative Prompt Develelopment\n",
10 | "In this lesson, you'll iteratively analyze and refine your prompts to generate marketing copy from a product fact sheet.\n",
11 | "\n",
12 | "## Setup"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": null,
18 | "metadata": {},
19 | "outputs": [],
20 | "source": [
21 | "# Basic congfig \n",
22 | "# Install basic package and set key\n",
23 | "!pip install openai\n",
24 | "!export OPENAI_API_KEY='sk-...'"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": null,
30 | "metadata": {},
31 | "outputs": [],
32 | "source": [
33 | "import openai\n",
34 | "import os\n",
35 | "\n",
36 | "from dotenv import load_dotenv, find_dotenv\n",
37 | "_ = load_dotenv(find_dotenv()) # read local .env file\n",
38 | "\n",
39 | "openai.api_key = os.getenv('OPENAI_API_KEY')"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "def get_completion(prompt, model=\"gpt-3.5-turbo\"):\n",
49 | " messages = [{\"role\": \"user\", \"content\": prompt}]\n",
50 | " response = openai.ChatCompletion.create(\n",
51 | " model=model,\n",
52 | " messages=messages,\n",
53 | " temperature=0, # this is the degree of randomness of the model's output\n",
54 | " )\n",
55 | " return response.choices[0].message[\"content\"]"
56 | ]
57 | },
58 | {
59 | "attachments": {},
60 | "cell_type": "markdown",
61 | "metadata": {},
62 | "source": [
63 | "Generate a marketing product description from a product fact sheet"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "fact_sheet_chair = \"\"\"\n",
73 | "OVERVIEW\n",
74 | "- Part of a beautiful family of mid-century inspired office furniture, \n",
75 | "including filing cabinets, desks, bookcases, meeting tables, and more.\n",
76 | "- Several options of shell color and base finishes.\n",
77 | "- Available with plastic back and front upholstery (SWC-100) \n",
78 | "or full upholstery (SWC-110) in 10 fabric and 6 leather options.\n",
79 | "- Base finish options are: stainless steel, matte black, \n",
80 | "gloss white, or chrome.\n",
81 | "- Chair is available with or without armrests.\n",
82 | "- Suitable for home or business settings.\n",
83 | "- Qualified for contract use.\n",
84 | "\n",
85 | "CONSTRUCTION\n",
86 | "- 5-wheel plastic coated aluminum base.\n",
87 | "- Pneumatic chair adjust for easy raise/lower action.\n",
88 | "\n",
89 | "DIMENSIONS\n",
90 | "- WIDTH 53 CM | 20.87”\n",
91 | "- DEPTH 51 CM | 20.08”\n",
92 | "- HEIGHT 80 CM | 31.50”\n",
93 | "- SEAT HEIGHT 44 CM | 17.32”\n",
94 | "- SEAT DEPTH 41 CM | 16.14”\n",
95 | "\n",
96 | "OPTIONS\n",
97 | "- Soft or hard-floor caster options.\n",
98 | "- Two choices of seat foam densities: \n",
99 | " medium (1.8 lb/ft3) or high (2.8 lb/ft3)\n",
100 | "- Armless or 8 position PU armrests \n",
101 | "\n",
102 | "MATERIALS\n",
103 | "SHELL BASE GLIDER\n",
104 | "- Cast Aluminum with modified nylon PA6/PA66 coating.\n",
105 | "- Shell thickness: 10 mm.\n",
106 | "SEAT\n",
107 | "- HD36 foam\n",
108 | "\n",
109 | "COUNTRY OF ORIGIN\n",
110 | "- Italy\n",
111 | "\"\"\""
112 | ]
113 | },
114 | {
115 | "cell_type": "code",
116 | "execution_count": null,
117 | "metadata": {},
118 | "outputs": [],
119 | "source": [
120 | "prompt = f\"\"\"\n",
121 | "Your task is to help a marketing team create a \n",
122 | "description for a retail website of a product based \n",
123 | "on a technical fact sheet.\n",
124 | "\n",
125 | "Write a product description based on the information \n",
126 | "provided in the technical specifications delimited by \n",
127 | "triple backticks.\n",
128 | "\n",
129 | "Technical specifications: ```{fact_sheet_chair}```\n",
130 | "\"\"\"\n",
131 | "response = get_completion(prompt)\n",
132 | "print(response)\n"
133 | ]
134 | },
135 | {
136 | "attachments": {},
137 | "cell_type": "markdown",
138 | "metadata": {},
139 | "source": [
140 | "## Issue 1: The text is too long \n",
141 | "- Limit the number of words/sentences/characters."
142 | ]
143 | },
144 | {
145 | "cell_type": "code",
146 | "execution_count": null,
147 | "metadata": {},
148 | "outputs": [],
149 | "source": [
150 | "prompt = f\"\"\"\n",
151 | "Your task is to help a marketing team create a \n",
152 | "description for a retail website of a product based \n",
153 | "on a technical fact sheet.\n",
154 | "\n",
155 | "Write a product description based on the information \n",
156 | "provided in the technical specifications delimited by \n",
157 | "triple backticks.\n",
158 | "\n",
159 | "Use at most 50 words.\n",
160 | "\n",
161 | "Technical specifications: ```{fact_sheet_chair}```\n",
162 | "\"\"\"\n",
163 | "response = get_completion(prompt)\n",
164 | "print(response)"
165 | ]
166 | },
167 | {
168 | "cell_type": "code",
169 | "execution_count": null,
170 | "metadata": {},
171 | "outputs": [],
172 | "source": [
173 | "len(response)"
174 | ]
175 | },
176 | {
177 | "attachments": {},
178 | "cell_type": "markdown",
179 | "metadata": {},
180 | "source": [
181 | "## Issue 2. Text focuses on the wrong details\n",
182 | "- Ask it to focus on the aspects that are relevant to the intended audience."
183 | ]
184 | },
185 | {
186 | "cell_type": "code",
187 | "execution_count": null,
188 | "metadata": {},
189 | "outputs": [],
190 | "source": [
191 | "prompt = f\"\"\"\n",
192 | "Your task is to help a marketing team create a \n",
193 | "description for a retail website of a product based \n",
194 | "on a technical fact sheet.\n",
195 | "\n",
196 | "Write a product description based on the information \n",
197 | "provided in the technical specifications delimited by \n",
198 | "triple backticks.\n",
199 | "\n",
200 | "The description is intended for furniture retailers, \n",
201 | "so should be technical in nature and focus on the \n",
202 | "materials the product is constructed from.\n",
203 | "\n",
204 | "Use at most 50 words.\n",
205 | "\n",
206 | "Technical specifications: ```{fact_sheet_chair}```\n",
207 | "\"\"\"\n",
208 | "response = get_completion(prompt)\n",
209 | "print(response) "
210 | ]
211 | },
212 | {
213 | "cell_type": "code",
214 | "execution_count": null,
215 | "metadata": {},
216 | "outputs": [],
217 | "source": [
218 | "prompt = f\"\"\"\n",
219 | "Your task is to help a marketing team create a \n",
220 | "description for a retail website of a product based \n",
221 | "on a technical fact sheet.\n",
222 | "\n",
223 | "Write a product description based on the information \n",
224 | "provided in the technical specifications delimited by \n",
225 | "triple backticks.\n",
226 | "\n",
227 | "The description is intended for furniture retailers, \n",
228 | "so should be technical in nature and focus on the \n",
229 | "materials the product is constructed from.\n",
230 | "\n",
231 | "At the end of the description, include every 7-character \n",
232 | "Product ID in the technical specification.\n",
233 | "\n",
234 | "Use at most 50 words.\n",
235 | "\n",
236 | "Technical specifications: ```{fact_sheet_chair}```\n",
237 | "\"\"\"\n",
238 | "response = get_completion(prompt)\n",
239 | "print(response) "
240 | ]
241 | },
242 | {
243 | "attachments": {},
244 | "cell_type": "markdown",
245 | "metadata": {},
246 | "source": [
247 | "## Issue 3. Description needs a table of dimensions\n",
248 | "- Ask it to extract information and organize it in a table."
249 | ]
250 | },
251 | {
252 | "cell_type": "code",
253 | "execution_count": null,
254 | "metadata": {},
255 | "outputs": [],
256 | "source": [
257 | "prompt = f\"\"\"\n",
258 | "Your task is to help a marketing team create a \n",
259 | "description for a retail website of a product based \n",
260 | "on a technical fact sheet.\n",
261 | "\n",
262 | "Write a product description based on the information \n",
263 | "provided in the technical specifications delimited by \n",
264 | "triple backticks.\n",
265 | "\n",
266 | "The description is intended for furniture retailers, \n",
267 | "so should be technical in nature and focus on the \n",
268 | "materials the product is constructed from.\n",
269 | "\n",
270 | "At the end of the description, include every 7-character \n",
271 | "Product ID in the technical specification.\n",
272 | "\n",
273 | "After the description, include a table that gives the \n",
274 | "product's dimensions. The table should have two columns.\n",
275 | "In the first column include the name of the dimension. \n",
276 | "In the second column include the measurements in inches only.\n",
277 | "\n",
278 | "Give the table the title 'Product Dimensions'.\n",
279 | "\n",
280 | "Format everything as HTML that can be used in a website. \n",
281 | "Place the description in a element.\n",
282 | "\n",
283 | "Technical specifications: ```{fact_sheet_chair}```\n",
284 | "\"\"\"\n",
285 | "\n",
286 | "response = get_completion(prompt)\n",
287 | "print(response)"
288 | ]
289 | },
290 | {
291 | "attachments": {},
292 | "cell_type": "markdown",
293 | "metadata": {},
294 | "source": [
295 | "## Load Python libraries to view HTML"
296 | ]
297 | },
298 | {
299 | "cell_type": "code",
300 | "execution_count": null,
301 | "metadata": {},
302 | "outputs": [],
303 | "source": [
304 | "from IPython.display import display, HTML"
305 | ]
306 | },
307 | {
308 | "cell_type": "code",
309 | "execution_count": null,
310 | "metadata": {},
311 | "outputs": [],
312 | "source": [
313 | "display(HTML(response))"
314 | ]
315 | }
316 | ],
317 | "metadata": {
318 | "kernelspec": {
319 | "display_name": "gpt_index",
320 | "language": "python",
321 | "name": "python3"
322 | },
323 | "language_info": {
324 | "codemirror_mode": {
325 | "name": "ipython",
326 | "version": 3
327 | },
328 | "file_extension": ".py",
329 | "mimetype": "text/x-python",
330 | "name": "python",
331 | "nbconvert_exporter": "python",
332 | "pygments_lexer": "ipython3",
333 | "version": "3.8.16"
334 | },
335 | "orig_nbformat": 4
336 | },
337 | "nbformat": 4,
338 | "nbformat_minor": 2
339 | }
340 |
--------------------------------------------------------------------------------
/english_subtitles/prompt_eng_01_intro_english.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:09,000
3 | Welcome to this course on ChatGPT Prompt Engineering for Developers
4 |
5 | 2
6 | 00:00:09,000 --> 00:00:14,000
7 | I'm thrilled to have with me Iza Fulford to teach this along with me
8 |
9 | 3
10 | 00:00:14,000 --> 00:00:18,000
11 | She is a member of the technical staff of OpenAI and had built the popular
12 |
13 | 4
14 | 00:00:18,000 --> 00:00:23,000
15 | ChatGPT Retrieval plugin and a large part of her work has been teaching people
16 |
17 | 5
18 | 00:00:23,000 --> 00:00:27,000
19 | how to use LLM or large language model technology in products
20 |
21 | 6
22 | 00:00:27,000 --> 00:00:31,000
23 | She's also contributed to the OpenAI cookbook that teaches people prompting
24 |
25 | 7
26 | 00:00:31,000 --> 00:00:32,000
27 | So thrilled to have you with you
28 |
29 | 8
30 | 00:00:32,000 --> 00:00:37,000
31 | And I'm thrilled to be here and share some prompting best practices with you all
32 |
33 | 9
34 | 00:00:37,000 --> 00:00:42,000
35 | So there's been a lot of material on the internet for prompting with articles
36 |
37 | 10
38 | 00:00:42,000 --> 00:00:45,000
39 | like 30 prompts everyone has to know
40 |
41 | 11
42 | 00:00:45,000 --> 00:00:50,000
43 | A lot of that has been focused on the ChatGPT web user interface
44 |
45 | 12
46 | 00:00:50,000 --> 00:00:54,000
47 | which many people are using to do specific and often one-off tasks
48 |
49 | 13
50 | 00:00:54,000 --> 00:01:00,000
51 | But I think the power of LLMs, large language models as a developer too
52 |
53 | 14
54 | 00:01:00,000 --> 00:01:04,000
55 | that is using API calls to LLMs to quickly build software applications
56 |
57 | 15
58 | 00:01:04,000 --> 00:01:08,000
59 | I think that is still very underappreciated
60 |
61 | 16
62 | 00:01:08,000 --> 00:01:12,000
63 | In fact, my team at AI Fund, which is a sister company to Deep Learning.AI
64 |
65 | 17
66 | 00:01:12,000 --> 00:01:16,000
67 | has been working with many startups on applying these technologies
68 |
69 | 18
70 | 00:01:16,000 --> 00:01:18,000
71 | to many different applications
72 |
73 | 19
74 | 00:01:18,000 --> 00:01:23,000
75 | And it's been exciting to see what LLM APIs can enable developers
76 |
77 | 20
78 | 00:01:23,000 --> 00:01:25,000
79 | to very quickly build
80 |
81 | 21
82 | 00:01:25,000 --> 00:01:29,000
83 | So in this course, we'll share with you some of the possibilities
84 |
85 | 22
86 | 00:01:29,000 --> 00:01:34,000
87 | for what you can do as well as best practices for how you can do them
88 |
89 | 23
90 | 00:01:34,000 --> 00:01:36,000
91 | There's a lot of material to cover
92 |
93 | 24
94 | 00:01:36,000 --> 00:01:41,000
95 | First, you'll learn some prompting best practices for software development
96 |
97 | 25
98 | 00:01:41,000 --> 00:01:45,000
99 | Then we'll cover some common use cases, summarizing, inferring
100 |
101 | 26
102 | 00:01:45,000 --> 00:01:50,000
103 | transforming, expanding, and then you'll build a chatbot using an LLM
104 |
105 | 27
106 | 00:01:50,000 --> 00:01:53,000
107 | We hope that this will spark your imagination about new applications
108 |
109 | 28
110 | 00:01:53,000 --> 00:01:55,000
111 | that you can build
112 |
113 | 29
114 | 00:01:55,000 --> 00:01:58,000
115 | So in the development of large language models or LLMs
116 |
117 | 30
118 | 00:01:58,000 --> 00:02:02,000
119 | there have been broadly two types of LLMs, which I'm going to refer to
120 |
121 | 31
122 | 00:02:02,000 --> 00:02:06,000
123 | as base LLMs and instruction-tuned LLMs
124 |
125 | 32
126 | 00:02:06,000 --> 00:02:11,000
127 | So base LLM has been trained to predict the next word based on text training data
128 |
129 | 33
130 | 00:02:11,000 --> 00:02:15,000
131 | often trained on a large amount of data from the internet and other sources
132 |
133 | 34
134 | 00:02:15,000 --> 00:02:19,000
135 | to figure out what's the next most likely word to follow
136 |
137 | 35
138 | 00:02:19,000 --> 00:02:24,000
139 | So for example, if you were to prompt this, once upon a time there was a unicorn
140 |
141 | 36
142 | 00:02:24,000 --> 00:02:28,000
143 | it may complete this, that is, it may predict the next several words are
144 |
145 | 37
146 | 00:02:28,000 --> 00:02:31,000
147 | that live in a magical forest with all unicorn friends
148 |
149 | 38
150 | 00:02:31,000 --> 00:02:35,000
151 | But if you were to prompt this with what is the capital of France
152 |
153 | 39
154 | 00:02:35,000 --> 00:02:40,000
155 | then based on what articles on the internet might have
156 |
157 | 40
158 | 00:02:40,000 --> 00:02:44,000
159 | it's quite possible that the base LLM will complete this with
160 |
161 | 41
162 | 00:02:44,000 --> 00:02:48,000
163 | what is France's largest city, what is France's population, and so on
164 |
165 | 42
166 | 00:02:48,000 --> 00:02:52,000
167 | because articles on the internet could quite plausibly be lists of quiz questions
168 |
169 | 43
170 | 00:02:52,000 --> 00:02:55,000
171 | about the country of France
172 |
173 | 44
174 | 00:02:55,000 --> 00:03:00,000
175 | In contrast, an instruction-tuned LLM, which is where a lot of momentum
176 |
177 | 45
178 | 00:03:00,000 --> 00:03:04,000
179 | of LLM research and practice has been going
180 |
181 | 46
182 | 00:03:04,000 --> 00:03:08,000
183 | an instruction-tuned LLM has been trained to follow instructions
184 |
185 | 47
186 | 00:03:08,000 --> 00:03:11,000
187 | So if you were to ask it, what is the capital of France
188 |
189 | 48
190 | 00:03:11,000 --> 00:03:15,000
191 | it's much more likely to output something like the capital of France is Paris
192 |
193 | 49
194 | 00:03:15,000 --> 00:03:19,000
195 | So the way that instruction-tuned LLMs are typically trained is
196 |
197 | 50
198 | 00:03:19,000 --> 00:03:23,000
199 | you start off with a base LLM that's been trained on a huge amount of text data
200 |
201 | 51
202 | 00:03:23,000 --> 00:03:28,000
203 | and further train it, further fine-tune it with inputs and outputs
204 |
205 | 52
206 | 00:03:28,000 --> 00:03:32,000
207 | that are instructions and good attempts to follow those instructions
208 |
209 | 53
210 | 00:03:32,000 --> 00:03:36,000
211 | and then often further refine using a technique called RLHF
212 |
213 | 54
214 | 00:03:36,000 --> 00:03:41,000
215 | reinforcement learning from human feedback, to make the system better able
216 |
217 | 55
218 | 00:03:41,000 --> 00:03:43,000
219 | to be helpful and follow instructions
220 |
221 | 56
222 | 00:03:43,000 --> 00:03:47,000
223 | Because instruction-tuned LLMs have been trained to be helpful
224 |
225 | 57
226 | 00:03:47,000 --> 00:03:51,000
227 | honest, and harmless, so for example, they're less likely to output
228 |
229 | 58
230 | 00:03:51,000 --> 00:03:55,000
231 | problematic text, such as toxic outputs, compared to base LLM
232 |
233 | 59
234 | 00:03:55,000 --> 00:03:59,000
235 | a lot of the practical usage scenarios have been shifting
236 |
237 | 60
238 | 00:03:59,000 --> 00:04:01,000
239 | toward instruction-tuned LLMs
240 |
241 | 61
242 | 00:04:01,000 --> 00:04:04,000
243 | Some of the best practices you find on the internet may be more suited
244 |
245 | 62
246 | 00:04:04,000 --> 00:04:08,000
247 | for a base LLM, but for most practical applications today
248 |
249 | 63
250 | 00:04:08,000 --> 00:04:13,000
251 | we would recommend most people instead focus on instruction-tuned LLMs
252 |
253 | 64
254 | 00:04:13,000 --> 00:04:17,000
255 | which are easier to use, and also because of the work of OpenAI
256 |
257 | 65
258 | 00:04:17,000 --> 00:04:22,000
259 | and other LLM companies, becoming safer and more aligned
260 |
261 | 66
262 | 00:04:22,000 --> 00:04:27,000
263 | So this course will focus on best practices for instruction-tuned LLMs
264 |
265 | 67
266 | 00:04:27,000 --> 00:04:32,000
267 | which is what we recommend you use for most of your applications
268 |
269 | 68
270 | 00:04:32,000 --> 00:04:36,000
271 | Before moving on, I just want to acknowledge the team from OpenAI
272 |
273 | 69
274 | 00:04:36,000 --> 00:04:39,000
275 | and DeepLearning.ai that had contributed to the materials
276 |
277 | 70
278 | 00:04:39,000 --> 00:04:42,000
279 | that Isa and I will be presenting
280 |
281 | 71
282 | 00:04:42,000 --> 00:04:45,000
283 | I'm very grateful to Andrew Main, Joe Palermo, Boris Power
284 |
285 | 72
286 | 00:04:45,000 --> 00:04:49,000
287 | Ted Sanders, and Lilian Wang from OpenAI that were very involved
288 |
289 | 73
290 | 00:04:49,000 --> 00:04:53,000
291 | with us brainstorming materials, vetting the materials to put together
292 |
293 | 74
294 | 00:04:53,000 --> 00:04:55,000
295 | the curriculum for this short course
296 |
297 | 75
298 | 00:04:55,000 --> 00:04:58,000
299 | And I'm also grateful on the DeepLearning side for the work
300 |
301 | 76
302 | 00:04:58,000 --> 00:05:01,000
303 | of Jeff Ludwig, Eddie Hsu, and Tommy Nelson
304 |
305 | 77
306 | 00:05:01,000 --> 00:05:06,000
307 | So when you use an instruction-tuned LLM, think of giving instructions
308 |
309 | 78
310 | 00:05:06,000 --> 00:05:10,000
311 | to another person, say someone that's smart but doesn't know
312 |
313 | 79
314 | 00:05:10,000 --> 00:05:12,000
315 | the specifics of your task
316 |
317 | 80
318 | 00:05:12,000 --> 00:05:16,000
319 | So when an LLM doesn't work, sometimes it's because the instructions
320 |
321 | 81
322 | 00:05:16,000 --> 00:05:17,000
323 | weren't clear enough
324 |
325 | 82
326 | 00:05:17,000 --> 00:05:20,000
327 | For example, if you were to say, please write me something
328 |
329 | 83
330 | 00:05:20,000 --> 00:05:22,000
331 | about Alan Turing
332 |
333 | 84
334 | 00:05:22,000 --> 00:05:26,000
335 | Well, in addition to that, it can be helpful to be clear about
336 |
337 | 85
338 | 00:05:26,000 --> 00:05:30,000
339 | whether you want the text to focus on his scientific work
340 |
341 | 86
342 | 00:05:30,000 --> 00:05:34,000
343 | or his personal life or his role in history or something else
344 |
345 | 87
346 | 00:05:34,000 --> 00:05:39,000
347 | And if you specify what you want the tone of the text to be
348 |
349 | 88
350 | 00:05:39,000 --> 00:05:43,000
351 | should it take on the tone like a professional journalist would write
352 |
353 | 89
354 | 00:05:43,000 --> 00:05:46,000
355 | or is it more of a casual note that you dash off to a friend?
356 |
357 | 90
358 | 00:05:46,000 --> 00:05:47,000
359 | That holds
360 |
361 | 91
362 | 00:05:47,000 --> 00:05:49,000
363 | The LLM generates what you want
364 |
365 | 92
366 | 00:05:49,000 --> 00:05:52,000
367 | And of course, if you picture yourself asking, say
368 |
369 | 93
370 | 00:05:52,000 --> 00:05:56,000
371 | a fresh college graduate to carry out this task for you
372 |
373 | 94
374 | 00:05:56,000 --> 00:05:59,000
375 | if you can even specify what snippets of text they should read
376 |
377 | 95
378 | 00:05:59,000 --> 00:06:02,000
379 | in advance to write this text about Alan Turing
380 |
381 | 96
382 | 00:06:02,000 --> 00:06:06,000
383 | then that even better sets up that fresh college grad for success
384 |
385 | 97
386 | 00:06:06,000 --> 00:06:09,000
387 | to carry out this task for you
388 |
389 | 98
390 | 00:06:09,000 --> 00:06:13,000
391 | So in the next video, you see examples of how to be clear
392 |
393 | 99
394 | 00:06:13,000 --> 00:06:17,000
395 | and specific, which is an important principle of prompting LLMs
396 |
397 | 100
398 | 00:06:17,000 --> 00:06:21,000
399 | And you also learn from Isa a second principle of prompting
400 |
401 | 101
402 | 00:06:21,000 --> 00:06:24,000
403 | that is giving a LLM time to think
404 |
405 | 102
406 | 00:06:24,000 --> 00:06:29,000
407 | So with that, let's go on to the next video
408 |
409 |
--------------------------------------------------------------------------------
/english_subtitles/prompt_eng_07_expanding_english.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:08,200
3 | Expanding is the task of taking a shorter piece of text
4 |
5 | 2
6 | 00:00:08,200 --> 00:00:11,140
7 | such as a set of instructions or a list of topics
8 |
9 | 3
10 | 00:00:11,140 --> 00:00:14,900
11 | and having the large language model generate a longer piece of text
12 |
13 | 4
14 | 00:00:14,900 --> 00:00:18,260
15 | such as an email or an essay about some topic
16 |
17 | 5
18 | 00:00:18,260 --> 00:00:20,100
19 | There are some great uses of this
20 |
21 | 6
22 | 00:00:20,100 --> 00:00:23,960
23 | such as if you use a large language model as a brainstorming partner
24 |
25 | 7
26 | 00:00:23,960 --> 00:00:26,300
27 | But I just also want to acknowledge that there's
28 |
29 | 8
30 | 00:00:26,300 --> 00:00:28,500
31 | some problematic use cases of this
32 |
33 | 9
34 | 00:00:28,500 --> 00:00:32,500
35 | such as if someone were to use it to generate a large amount of spam
36 |
37 | 10
38 | 00:00:32,500 --> 00:00:36,100
39 | So when you use these capabilities of a large language model
40 |
41 | 11
42 | 00:00:36,100 --> 00:00:41,340
43 | please use it only in a responsible way and in a way that helps people
44 |
45 | 12
46 | 00:00:41,340 --> 00:00:45,280
47 | In this video, we'll go through an example of how you can use
48 |
49 | 13
50 | 00:00:45,280 --> 00:00:49,900
51 | a language model to generate a personalized email based on some information
52 |
53 | 14
54 | 00:00:49,900 --> 00:00:53,260
55 | The email is kind of self-proclaimed to be from an AI bot
56 |
57 | 15
58 | 00:00:53,260 --> 00:00:56,140
59 | which as Andrew mentioned, is very important
60 |
61 | 16
62 | 00:00:56,140 --> 00:00:58,500
63 | We're also going to use another one of
64 |
65 | 17
66 | 00:00:58,500 --> 00:01:01,260
67 | the model's input parameters called temperature
68 |
69 | 18
70 | 00:01:01,260 --> 00:01:04,780
71 | and this allows you to vary the degree of
72 |
73 | 19
74 | 00:01:04,780 --> 00:01:08,760
75 | exploration and variety in the model's responses
76 |
77 | 20
78 | 00:01:08,760 --> 00:01:10,980
79 | So let's get into it
80 |
81 | 21
82 | 00:01:10,980 --> 00:01:12,740
83 | So before we get started
84 |
85 | 22
86 | 00:01:12,740 --> 00:01:15,780
87 | we're going to do the usual setup
88 |
89 | 23
90 | 00:01:15,780 --> 00:01:18,400
91 | So set up the OpenAI Python package
92 |
93 | 24
94 | 00:01:18,400 --> 00:01:22,060
95 | and then also define our helper function, get_completion
96 |
97 | 25
98 | 00:01:22,060 --> 00:01:26,460
99 | Now we're going to write a custom email response to a customer review
100 |
101 | 26
102 | 00:01:26,460 --> 00:01:29,940
103 | So given a customer review and the sentiment
104 |
105 | 27
106 | 00:01:29,940 --> 00:01:32,680
107 | we're going to generate a custom response
108 |
109 | 28
110 | 00:01:32,680 --> 00:01:37,100
111 | Now we're going to use the language model to generate
112 |
113 | 29
114 | 00:01:37,100 --> 00:01:41,900
115 | a custom email to a customer based on a customer review
116 |
117 | 30
118 | 00:01:41,900 --> 00:01:44,020
119 | and the sentiment of the review
120 |
121 | 31
122 | 00:01:44,020 --> 00:01:47,100
123 | So we've already extracted the sentiment
124 |
125 | 32
126 | 00:01:47,100 --> 00:01:52,740
127 | using the kind of prompts that we saw in the inferring video
128 |
129 | 33
130 | 00:01:52,740 --> 00:01:57,020
131 | and then this is the customer review for a blender
132 |
133 | 34
134 | 00:01:57,100 --> 00:02:02,740
135 | Now we're going to customize the reply based on the sentiment
136 |
137 | 35
138 | 00:02:02,740 --> 00:02:05,180
139 | So here the instruction is
140 |
141 | 36
142 | 00:02:05,180 --> 00:02:08,260
143 | you are a customer service AI assistant
144 |
145 | 37
146 | 00:02:08,260 --> 00:02:11,180
147 | Your task is to send an email reply to a valued customer
148 |
149 | 38
150 | 00:02:11,180 --> 00:02:14,540
151 | Given the customer email delimited by three backticks
152 |
153 | 39
154 | 00:02:14,540 --> 00:02:16,860
155 | generate a reply to thank the customer for their review
156 |
157 | 40
158 | 00:02:16,860 --> 00:02:18,780
159 | If the sentiment is positive or neutral
160 |
161 | 41
162 | 00:02:18,780 --> 00:02:20,460
163 | thank them for their review
164 |
165 | 42
166 | 00:02:20,460 --> 00:02:21,980
167 | If the sentiment is negative
168 |
169 | 43
170 | 00:02:21,980 --> 00:02:25,260
171 | apologize and suggest that they can reach out to customer service
172 |
173 | 44
174 | 00:02:25,260 --> 00:02:27,820
175 | Make sure to use specific details from the review
176 |
177 | 45
178 | 00:02:27,820 --> 00:02:29,820
179 | write in a concise and professional tone
180 |
181 | 46
182 | 00:02:29,820 --> 00:02:32,460
183 | and sign the email as AI customer agent
184 |
185 | 47
186 | 00:02:32,460 --> 00:02:34,820
187 | When you're using a language model
188 |
189 | 48
190 | 00:02:34,820 --> 00:02:37,500
191 | to generate text that you're going to show to a user
192 |
193 | 49
194 | 00:02:37,500 --> 00:02:40,860
195 | it's very important to have this kind of transparency
196 |
197 | 50
198 | 00:02:40,860 --> 00:02:45,700
199 | and let the user know that the text they're seeing was generated by AI
200 |
201 | 51
202 | 00:02:45,700 --> 00:02:49,780
203 | Then we'll just input the customer review and the review sentiment
204 |
205 | 52
206 | 00:02:49,780 --> 00:02:53,220
207 | Also note that this part isn't necessarily important
208 |
209 | 53
210 | 00:02:53,220 --> 00:02:57,180
211 | because we could actually use this prompt to also extract the review sentiment
212 |
213 | 54
214 | 00:02:57,180 --> 00:02:59,300
215 | and then in a follow-up step, write the email
216 |
217 | 55
218 | 00:02:59,300 --> 00:03:01,140
219 | But just for the sake of the example
220 |
221 | 56
222 | 00:03:01,140 --> 00:03:04,300
223 | well, we've already extracted the sentiment from the review
224 |
225 | 57
226 | 00:03:04,300 --> 00:03:08,500
227 | So here we have a response to the customer
228 |
229 | 58
230 | 00:03:08,500 --> 00:03:13,580
231 | It addresses details that the customer mentioned in their review
232 |
233 | 59
234 | 00:03:13,580 --> 00:03:16,620
235 | and as we instructed
236 |
237 | 60
238 | 00:03:16,620 --> 00:03:19,100
239 | suggest that they reach out to customer service
240 |
241 | 61
242 | 00:03:19,100 --> 00:03:23,100
243 | because this is just an AI customer service agent
244 |
245 | 62
246 | 00:03:23,740 --> 00:03:30,420
247 | Next, we're going to use a parameter of the language model called temperature
248 |
249 | 63
250 | 00:03:30,420 --> 00:03:36,460
251 | that will allow us to change the variety of the model's responses
252 |
253 | 64
254 | 00:03:36,460 --> 00:03:38,900
255 | So you can think of temperature as
256 |
257 | 65
258 | 00:03:38,900 --> 00:03:43,380
259 | the degree of exploration or randomness of the model
260 |
261 | 66
262 | 00:03:43,380 --> 00:03:46,060
263 | So for this particular phrase
264 |
265 | 67
266 | 00:03:46,060 --> 00:03:47,500
267 | my favorite food is
268 |
269 | 68
270 | 00:03:47,500 --> 00:03:51,820
271 | the most likely next word that the model predicts is pizza
272 |
273 | 69
274 | 00:03:51,820 --> 00:03:53,580
275 | and the next two most likely
276 |
277 | 70
278 | 00:03:53,580 --> 00:03:55,900
279 | it suggests are sushi and tacos
280 |
281 | 71
282 | 00:03:55,900 --> 00:03:57,660
283 | So at a temperature of zero
284 |
285 | 72
286 | 00:03:57,660 --> 00:04:00,060
287 | the model will always choose the most likely next word
288 |
289 | 73
290 | 00:04:00,060 --> 00:04:01,460
291 | which in this case is pizza
292 |
293 | 74
294 | 00:04:01,460 --> 00:04:03,260
295 | and at a higher temperature
296 |
297 | 75
298 | 00:04:03,260 --> 00:04:07,100
299 | it will also choose one of the less likely words
300 |
301 | 76
302 | 00:04:07,100 --> 00:04:09,340
303 | and at an even higher temperature
304 |
305 | 77
306 | 00:04:09,340 --> 00:04:10,700
307 | it might even choose tacos
308 |
309 | 78
310 | 00:04:10,700 --> 00:04:15,380
311 | which only has a five percent chance of being chosen
312 |
313 | 79
314 | 00:04:15,380 --> 00:04:21,660
315 | You can imagine that as the model continues this final response
316 |
317 | 80
318 | 00:04:21,660 --> 00:04:23,300
319 | so my favorite food is pizza
320 |
321 | 81
322 | 00:04:23,300 --> 00:04:25,420
323 | and it continues to generate more words
324 |
325 | 82
326 | 00:04:25,420 --> 00:04:30,580
327 | this response will diverge from the first response
328 |
329 | 83
330 | 00:04:30,580 --> 00:04:32,340
331 | which is my favorite food is tacos
332 |
333 | 84
334 | 00:04:32,340 --> 00:04:34,100
335 | So as the model continues
336 |
337 | 85
338 | 00:04:34,100 --> 00:04:37,060
339 | these two responses will become more and more different
340 |
341 | 86
342 | 00:04:37,060 --> 00:04:40,500
343 | In general, when building applications where you want
344 |
345 | 87
346 | 00:04:40,500 --> 00:04:43,420
347 | a predictable response
348 |
349 | 88
350 | 00:04:43,420 --> 00:04:45,420
351 | I would recommend using temperature zero
352 |
353 | 89
354 | 00:04:45,420 --> 00:04:46,780
355 | Throughout all of these videos
356 |
357 | 90
358 | 00:04:46,780 --> 00:04:48,900
359 | we've been using temperature zero
360 |
361 | 91
362 | 00:04:48,900 --> 00:04:51,380
363 | and I think that if you're trying to build a system that
364 |
365 | 92
366 | 00:04:51,380 --> 00:04:54,660
367 | is reliable and predictable, you should go with this
368 |
369 | 93
370 | 00:04:54,660 --> 00:04:58,780
371 | If you're trying to use the model in a more creative way
372 |
373 | 94
374 | 00:04:58,780 --> 00:05:04,220
375 | where you might want a wider variety of different outputs
376 |
377 | 95
378 | 00:05:04,220 --> 00:05:06,860
379 | you might want to use a higher temperature
380 |
381 | 96
382 | 00:05:06,860 --> 00:05:11,620
383 | So now let's take this same prompt that we just used
384 |
385 | 97
386 | 00:05:11,620 --> 00:05:14,220
387 | and let's try generating an e-mail
388 |
389 | 98
390 | 00:05:14,220 --> 00:05:16,140
391 | but let's use a higher temperature
392 |
393 | 99
394 | 00:05:16,140 --> 00:05:21,540
395 | So in our get_completion function that we've been using throughout the videos
396 |
397 | 100
398 | 00:05:21,540 --> 00:05:25,100
399 | we have specified a model and then also a temperature
400 |
401 | 101
402 | 00:05:25,100 --> 00:05:26,540
403 | but we've set them to default
404 |
405 | 102
406 | 00:05:26,540 --> 00:05:29,420
407 | So now let's try varying the temperature
408 |
409 | 103
410 | 00:05:30,140 --> 00:05:32,860
411 | So we use the prompt
412 |
413 | 104
414 | 00:05:32,860 --> 00:05:39,340
415 | and then let's try temperature=0.7
416 |
417 | 105
418 | 00:05:43,620 --> 00:05:45,340
419 | And so with temperature=0
420 |
421 | 106
422 | 00:05:45,340 --> 00:05:47,220
423 | every time you execute the same prompt
424 |
425 | 107
426 | 00:05:47,220 --> 00:05:50,580
427 | you should expect the same completion
428 |
429 | 108
430 | 00:05:50,580 --> 00:05:52,580
431 | whereas with temperature 0.7
432 |
433 | 109
434 | 00:05:52,580 --> 00:05:55,060
435 | you'll get a different output every time
436 |
437 | 110
438 | 00:05:55,060 --> 00:05:58,100
439 | So here we have our e-mail
440 |
441 | 111
442 | 00:05:58,100 --> 00:06:00,980
443 | and as you can see, it's different to the e-mail
444 |
445 | 112
446 | 00:06:00,980 --> 00:06:02,900
447 | that we received previously
448 |
449 | 113
450 | 00:06:02,900 --> 00:06:08,060
451 | And let's just execute it again to show that we'll get a different e-mail again
452 |
453 | 114
454 | 00:06:08,060 --> 00:06:11,340
455 | And here we have another different e-mail
456 |
457 | 115
458 | 00:06:11,340 --> 00:06:16,780
459 | So I recommend that you play around with temperature yourself
460 |
461 | 116
462 | 00:06:16,780 --> 00:06:20,820
463 | Maybe you could pause the video now and try this prompt
464 |
465 | 117
466 | 00:06:20,820 --> 00:06:22,620
467 | with a variety of different temperatures
468 |
469 | 118
470 | 00:06:22,620 --> 00:06:25,100
471 | just to see how the outputs vary
472 |
473 | 119
474 | 00:06:25,100 --> 00:06:28,500
475 | So to summarize, at higher temperatures
476 |
477 | 120
478 | 00:06:28,500 --> 00:06:31,700
479 | the outputs from the model are kind of more random
480 |
481 | 121
482 | 00:06:31,700 --> 00:06:34,500
483 | You can almost think of it as that at higher temperatures
484 |
485 | 122
486 | 00:06:34,500 --> 00:06:36,500
487 | the assistant is more distractible
488 |
489 | 123
490 | 00:06:36,500 --> 00:06:38,220
491 | but maybe more creative
492 |
493 | 124
494 | 00:06:39,620 --> 00:06:42,260
495 | In the next video, we're going to talk more about
496 |
497 | 125
498 | 00:06:42,260 --> 00:06:44,540
499 | the chat completions endpoint format
500 |
501 | 126
502 | 00:06:44,540 --> 00:07:00,060
503 | and how you can create a custom chatbot using this format
504 |
505 |
--------------------------------------------------------------------------------
/chinese_subtitles/prompt_eng_06_transforming_chinese.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:09,840
3 | 大语言模型非常善于将其输入转换为不同的格式
4 |
5 | 2
6 | 00:00:09,840 --> 00:00:14,100
7 | 例如,输入一种语言的文本并将其转换或
8 |
9 | 3
10 | 00:00:14,100 --> 00:00:19,300
11 | 把它翻译成不同的语言,或者帮助进行拼写和语法的修正
12 |
13 | 4
14 | 00:00:19,300 --> 00:00:21,780
15 | 因此,将一段可能不符合标准的语法文本作为输入
16 |
17 | 5
18 | 00:00:21,780 --> 00:00:25,020
19 | 并让它帮助你纠正拼写和语法
20 |
21 | 6
22 | 00:00:25,020 --> 00:00:28,380
23 | 或甚至转换格式,如
24 |
25 | 7
26 | 00:00:28,380 --> 00:00:31,100
27 | 输入HTML和输出JSON
28 |
29 | 8
30 | 00:00:31,100 --> 00:00:35,140
31 | 所以,我以前写的一些应用程序有点痛苦,用的是
32 |
33 | 9
34 | 00:00:35,140 --> 00:00:38,100
35 | 一堆正则表达式的应用
36 |
37 | 10
38 | 00:00:38,100 --> 00:00:41,800
39 | 现在用一个大语言模型和一些提示语就可以更简单地实现
40 |
41 | 11
42 | 00:00:41,800 --> 00:00:46,500
43 | 是的,我现在用ChatGPT来校对我写的几乎所有东西
44 |
45 | 12
46 | 00:00:46,500 --> 00:00:50,340
47 | 所以我很高兴现在向你展示Notebook中的一些更多的例子
48 |
49 | 13
50 | 00:00:50,340 --> 00:00:55,900
51 | 所以,首先,我们将导入openai,同时
52 |
53 | 14
54 | 00:00:55,900 --> 00:01:01,180
55 | 使用我们在整个视频中一直使用的get_completion辅助函数
56 |
57 | 15
58 | 00:01:01,180 --> 00:01:04,540
59 | 我们要做的第一件事是一个翻译任务
60 |
61 | 16
62 | 00:01:04,540 --> 00:01:09,940
63 | 因此,大语言模型是在许多来源的大量文本上训练出来的
64 |
65 | 17
66 | 00:01:09,940 --> 00:01:11,100
67 | 其中有很多是互联网
68 |
69 | 18
70 | 00:01:11,100 --> 00:01:13,600
71 | 这当然是用许多不同的语言
72 |
73 | 19
74 | 00:01:13,600 --> 00:01:17,580
75 | 因此,这使模型具有翻译能力
76 |
77 | 20
78 | 00:01:17,580 --> 00:01:22,380
79 | 这些模型知道数百种语言的不同程度的熟练程度
80 |
81 | 21
82 | 00:01:22,380 --> 00:01:26,540
83 | 所以我们将通过一些例子来说明如何使用这种能力
84 |
85 | 22
86 | 00:01:26,540 --> 00:01:29,580
87 | 所以,让我们从简单的东西开始
88 |
89 | 23
90 | 00:01:29,580 --> 00:01:31,540
91 | 所以在这第一个例子中
92 |
93 | 24
94 | 00:01:31,540 --> 00:01:35,700
95 | 提示是将以下英文文本翻译成西班牙语
96 |
97 | 25
98 | 00:01:35,700 --> 00:01:38,260
99 | 你好,我想订购一台搅拌机
100 |
101 | 26
102 | 00:01:38,260 --> 00:01:40,620
103 | 响应是:Hola
104 |
105 | 27
106 | 00:01:40,620 --> 00:01:45,580
107 | me gustaría ordenar una licuadora.
108 |
109 | 28
110 | 00:01:45,580 --> 00:01:48,660
111 | 我对所有讲西班牙语的人感到非常抱歉
112 |
113 | 29
114 | 00:01:48,660 --> 00:01:53,620
115 | 我从来没有学过西班牙语,很不幸,你肯定能看出来
116 |
117 | 30
118 | 00:01:54,500 --> 00:01:57,220
119 | 让我们尝试另一个例子
120 |
121 | 31
122 | 00:01:57,220 --> 00:02:00,460
123 | 所以在这个例子中
124 |
125 | 32
126 | 00:02:00,460 --> 00:02:04,220
127 | 提示是,告诉我这是什么语言
128 |
129 | 33
130 | 00:02:04,220 --> 00:02:06,980
131 | 那么这是用法语说的
132 |
133 | 34
134 | 00:02:06,980 --> 00:02:09,700
135 | combien coûte le lampadaire?
136 |
137 | 35
138 | 00:02:09,700 --> 00:02:12,020
139 | 所以我们来运行这个
140 |
141 | 36
142 | 00:02:12,820 --> 00:02:17,340
143 | 该模型已经识别出这是法语
144 |
145 | 37
146 | 00:02:17,340 --> 00:02:22,220
147 | 该模型还可以一次做多个翻译
148 |
149 | 38
150 | 00:02:22,220 --> 00:02:23,900
151 | 所以在这个例子中
152 |
153 | 39
154 | 00:02:23,900 --> 00:02:27,740
155 | 让我们说把下面的文字翻译成法语和西班牙语
156 |
157 | 40
158 | 00:02:27,740 --> 00:02:29,940
159 | 你知道吗,让我们再加一个
160 |
161 | 41
162 | 00:02:29,940 --> 00:02:34,060
163 | 英国海盗
164 |
165 | 42
166 | 00:02:34,380 --> 00:02:38,500
167 | 这段文字是,我想订购一个篮球
168 |
169 | 43
170 | 00:02:40,460 --> 00:02:43,180
171 | 所以这里我们有法语
172 |
173 | 44
174 | 00:02:43,180 --> 00:02:47,300
175 | 西班牙文,和英国海盗
176 |
177 | 45
178 | 00:02:47,300 --> 00:02:49,300
179 | 所以在某些语言中
180 |
181 | 46
182 | 00:02:49,300 --> 00:02:51,340
183 | 翻译可以改变,取决于
184 |
185 | 47
186 | 00:02:51,340 --> 00:02:53,660
187 | 说话人与听话人的关系
188 |
189 | 48
190 | 00:02:53,660 --> 00:02:56,860
191 | 你也可以向语言模型解释这一点
192 |
193 | 49
194 | 00:02:56,860 --> 00:03:00,380
195 | 这样它就能进行相应的翻译
196 |
197 | 50
198 | 00:03:00,380 --> 00:03:02,540
199 | 所以在这个例子中
200 |
201 | 51
202 | 00:03:02,540 --> 00:03:07,220
203 | 我们说把下面的文字以正式和非正式的形式翻译成西班牙语
204 |
205 | 52
206 | 00:03:07,220 --> 00:03:09,060
207 | 你想订购一个枕头吗?
208 |
209 | 53
210 | 00:03:09,060 --> 00:03:11,260
211 | 还注意到,我们在这里使用了
212 |
213 | 54
214 | 00:03:11,260 --> 00:03:14,300
215 | 不同的分隔符,而不是这些双引号
216 |
217 | 55
218 | 00:03:14,300 --> 00:03:18,260
219 | 其实这并不重要,只要它是一个清晰的分隔
220 |
221 | 56
222 | 00:03:18,260 --> 00:03:22,700
223 | 所以这里我们有正式和非正式
224 |
225 | 57
226 | 00:03:22,700 --> 00:03:25,580
227 | 因此,正式的是当你和某人说话时,他是
228 |
229 | 58
230 | 00:03:25,580 --> 00:03:28,980
231 | 也许比你高级的人,或者你是在一个专业的情况下
232 |
233 | 59
234 | 00:03:28,980 --> 00:03:30,340
235 | 这时你要使用正式语气
236 |
237 | 60
238 | 00:03:30,340 --> 00:03:34,540
239 | 然后非正式的是当你和一群朋友说话时
240 |
241 | 61
242 | 00:03:34,540 --> 00:03:36,300
243 | 我实际上不会说西班牙语
244 |
245 | 62
246 | 00:03:36,300 --> 00:03:39,500
247 | 但我父亲会,他说这是正确的
248 |
249 | 63
250 | 00:03:39,500 --> 00:03:42,020
251 | 因此,对于
252 |
253 | 64
254 | 00:03:42,020 --> 00:03:47,900
255 | 我们要假装自己是一家跨国电子商务公司的负责人
256 |
257 | 65
258 | 00:03:47,900 --> 00:03:51,780
259 | 用户的信息将使用所有不同的语言
260 |
261 | 66
262 | 00:03:51,780 --> 00:03:57,340
263 | 因此,用户将用各种不同的语言告诉我们关于IT的问题
264 |
265 | 67
266 | 00:03:57,340 --> 00:04:00,300
267 | 所以我们需要一个通用的翻译器
268 |
269 | 68
270 | 00:04:00,300 --> 00:04:06,980
271 | 因此,首先,我们将粘贴一个各种不同语言的用户信息的列表
272 |
273 | 69
274 | 00:04:06,980 --> 00:04:15,660
275 | 现在,我们将循环浏览这些用户信息中的每一条
276 |
277 | 70
278 | 00:04:15,660 --> 00:04:19,900
279 | 因此,对于用户信息中的问题
280 |
281 | 71
282 | 00:04:19,980 --> 00:04:25,220
283 | 然后我将复制稍长的代码块
284 |
285 | 72
286 | 00:04:25,220 --> 00:04:28,740
287 | 所以我们要做的第一件事是要求模型
288 |
289 | 73
290 | 00:04:28,740 --> 00:04:32,420
291 | 告诉我们这个问题是什么语言的
292 |
293 | 74
294 | 00:04:32,420 --> 00:04:34,260
295 | 所以这里是提示
296 |
297 | 75
298 | 00:04:34,260 --> 00:04:40,380
299 | 然后,我们将打印出原始信息的语言和问题
300 |
301 | 76
302 | 00:04:40,380 --> 00:04:45,100
303 | 然后我们将要求模型将其翻译成英语和韩语
304 |
305 | 77
306 | 00:04:45,100 --> 00:04:51,860
307 | 所以让我们运行这个。所以,原始信息是法语
308 |
309 | 78
310 | 00:04:55,740 --> 00:04:58,300
311 | 所以我们有各种语言
312 |
313 | 79
314 | 00:04:58,300 --> 00:05:02,940
315 | 然后模型将它们翻译成英语和韩语
316 |
317 | 80
318 | 00:05:02,940 --> 00:05:06,180
319 | 你可以看到这里,所以模型说
320 |
321 | 81
322 | 00:05:06,180 --> 00:05:07,700
323 | 这是法语
324 |
325 | 82
326 | 00:05:07,700 --> 00:05:13,380
327 | 所以这是因为这个提示的反应将是,这是法语
328 |
329 | 83
330 | 00:05:13,380 --> 00:05:16,180
331 | 你可以尝试将这个提示编辑成这样的内容
332 |
333 | 84
334 | 00:05:16,180 --> 00:05:17,540
335 | 告诉我这是什么语言
336 |
337 | 85
338 | 00:05:17,540 --> 00:05:22,220
339 | 只用一个词来回答或不用句子
340 |
341 | 86
342 | 00:05:22,220 --> 00:05:25,340
343 | 如果你希望这只是一个词的话
344 |
345 | 87
346 | 00:05:25,340 --> 00:05:28,580
347 | 或者你可以要求它以JSON格式或类似的东西
348 |
349 | 88
350 | 00:05:28,580 --> 00:05:33,420
351 | 这可能会鼓励它不要使用整个句子
352 |
353 | 89
354 | 00:05:33,420 --> 00:05:38,620
355 | 因此,令人惊讶的是,你刚刚建立了一个通用翻译器
356 |
357 | 90
358 | 00:05:38,620 --> 00:05:45,180
359 | 也可以随时暂停视频,在这里添加任何你想尝试的其他语言
360 |
361 | 91
362 | 00:05:45,180 --> 00:05:47,340
363 | 也许是你自己说的语言
364 |
365 | 92
366 | 00:05:47,340 --> 00:05:49,860
367 | 看看这个模型是怎么做的
368 |
369 | 93
370 | 00:05:49,860 --> 00:05:55,060
371 | 因此,我们接下来要深入研究的是语气转换
372 |
373 | 94
374 | 00:05:55,060 --> 00:05:58,300
375 | 写作可以根据目标受众而有所不同
376 |
377 | 95
378 | 00:05:58,300 --> 00:06:03,140
379 | 我给同事或教授写电子邮件的方式
380 |
381 | 96
382 | 00:06:03,140 --> 00:06:06,820
383 | 显然会与我给我弟弟发短信的方式完全不同
384 |
385 | 97
386 | 00:06:06,820 --> 00:06:10,980
387 | 所以ChatGPT实际上也可以帮助产生不同的语气
388 |
389 | 98
390 | 00:06:10,980 --> 00:06:14,260
391 | 因此,让我们看一些例子
392 |
393 | 99
394 | 00:06:14,260 --> 00:06:16,620
395 | 在这第一个例子中
396 |
397 | 100
398 | 00:06:16,620 --> 00:06:20,780
399 | 提示是,将以下内容从俚语翻译成商务信函
400 |
401 | 101
402 | 00:06:20,780 --> 00:06:22,100
403 | 老兄,这是乔
404 |
405 | 102
406 | 00:06:22,100 --> 00:06:25,180
407 | 检查一下这盏落地灯的规格
408 |
409 | 103
410 | 00:06:25,180 --> 00:06:29,460
411 | 因此,让我们来执行这个
412 |
413 | 104
414 | 00:06:30,460 --> 00:06:35,500
415 | 正如你所看到的,我们有一封更正式的商业信函
416 |
417 | 105
418 | 00:06:35,500 --> 00:06:39,660
419 | 有一个关于落地灯规格的建议
420 |
421 | 106
422 | 00:06:39,660 --> 00:06:44,580
423 | 我们要做的下一件事是在不同的格式之间进行转换
424 |
425 | 107
426 | 00:06:44,580 --> 00:06:50,260
427 | ChatGPT非常善于在不同的格式之间进行转换,如JSON到HTML
428 |
429 | 108
430 | 00:06:50,260 --> 00:06:54,300
431 | XML,各种各样的东西,markdown
432 |
433 | 109
434 | 00:06:54,300 --> 00:06:58,660
435 | 所以在提示中,我们将描述输入和输出的格式
436 |
437 | 110
438 | 00:06:58,660 --> 00:07:01,900
439 | 所以这里有一个例子
440 |
441 | 111
442 | 00:07:01,900 --> 00:07:05,100
443 | 所以我们有这样一个JSON
444 |
445 | 112
446 | 00:07:05,100 --> 00:07:10,340
447 | 它包含一个餐厅员工的名单,包括他们的名字和电子邮件
448 |
449 | 113
450 | 00:07:10,340 --> 00:07:12,580
451 | 然后在提示中
452 |
453 | 114
454 | 00:07:12,580 --> 00:07:17,940
455 | 我们将要求模型将其从JSON翻译成HTML
456 |
457 | 115
458 | 00:07:17,940 --> 00:07:22,100
459 | 所以提示是,把下面的Python字典从JSON翻译成
460 |
461 | 116
462 | 00:07:22,100 --> 00:07:26,260
463 | HTML,包括列头和标题
464 |
465 | 117
466 | 00:07:28,220 --> 00:07:35,380
467 | 然后我们将从模型中得到响应并打印出来
468 |
469 | 118
470 | 00:07:35,380 --> 00:07:44,140
471 | 所以这里我们有一些HTML显示所有的雇员姓名和电子邮件
472 |
473 | 119
474 | 00:07:44,140 --> 00:07:49,220
475 | 那么现在让我们来看看我们是否可以作为
476 |
477 | 120
478 | 00:07:49,220 --> 00:07:54,460
479 | 所以我们要使用这个Python库中的这个显示函数
480 |
481 | 121
482 | 00:07:54,460 --> 00:07:58,860
483 | 显示 HTML 响应
484 |
485 | 122
486 | 00:08:00,100 --> 00:08:06,340
487 | 在这里你可以看到这是一个正确格式化的HTML表格
488 |
489 | 123
490 | 00:08:06,420 --> 00:08:13,100
491 | 我们要做的下一个转换任务是拼写检查和语法检查
492 |
493 | 124
494 | 00:08:13,100 --> 00:08:16,740
495 | 这是ChatGPT的一个非常流行的用途
496 |
497 | 125
498 | 00:08:16,740 --> 00:08:18,780
499 | 我强烈建议这样做
500 |
501 | 126
502 | 00:08:18,780 --> 00:08:20,060
503 | 我一直在做这个
504 |
505 | 127
506 | 00:08:20,060 --> 00:08:23,380
507 | 当你用非母语工作时,它尤其有用
508 |
509 | 128
510 | 00:08:23,380 --> 00:08:28,140
511 | 因此,这里有一些常见的语法和拼写问题的例子
512 |
513 | 129
514 | 00:08:28,140 --> 00:08:31,580
515 | 以及语言模型如何帮助解决这些问题
516 |
517 | 130
518 | 00:08:31,580 --> 00:08:40,500
519 | 所以我将粘贴一个有一些语法或拼写错误的句子列表
520 |
521 | 131
522 | 00:08:40,500 --> 00:08:46,420
523 | 然后,我们将循环浏览每一个句子
524 |
525 | 132
526 | 00:08:49,140 --> 00:08:50,740
527 | 然后
528 |
529 | 133
530 | 00:08:51,620 --> 00:08:56,620
531 | 让模型进行校对
532 |
533 | 134
534 | 00:08:56,620 --> 00:09:02,500
535 | 校对并进行修正。然后我们将使用一些分隔符
536 |
537 | 135
538 | 00:09:11,500 --> 00:09:15,500
539 | 然后我们将获取响应并将其打印出来,就像往常一样
540 |
541 | 136
542 | 00:09:35,260 --> 00:09:41,420
543 | 就这样,这个模型能够纠正所有这些语法错误
544 |
545 | 137
546 | 00:09:41,420 --> 00:09:44,180
547 | 我们可以使用我们之前讨论过的一些技术
548 |
549 | 138
550 | 00:09:44,180 --> 00:09:50,100
551 | 因此,为了改进提示,我们可以说校对和纠正以下文字
552 |
553 | 139
554 | 00:09:50,100 --> 00:09:54,580
555 | 并重写
556 |
557 | 140
558 | 00:09:54,580 --> 00:09:55,580
559 | 哦
560 |
561 | 141
562 | 00:09:55,580 --> 00:10:05,580
563 | 并重写整个
564 |
565 | 142
566 | 00:10:05,580 --> 00:10:10,580
567 | 并重写
568 |
569 | 143
570 | 00:10:10,580 --> 00:10:16,580
571 | 改正后的版本
572 |
573 | 144
574 | 00:10:16,580 --> 00:10:25,700
575 | 如果你没有发现任何错误,就说没有发现错误
576 |
577 | 145
578 | 00:10:25,700 --> 00:10:29,700
579 | 让我们来试试这个
580 |
581 | 146
582 | 00:10:29,700 --> 00:10:37,700
583 | 因此,这种方式我们能够,哦,他们在这里仍然使用引号
584 |
585 | 147
586 | 00:10:37,700 --> 00:10:42,940
587 | 但你可以想象,你能够找到一种方法,用一点点的
588 |
589 | 148
590 | 00:10:42,940 --> 00:10:45,780
591 | 迭代提示开发
592 |
593 | 149
594 | 00:10:45,780 --> 00:10:49,260
595 | 找到一种更可靠的提示方式,每一次都能正常工作
596 |
597 | 150
598 | 00:10:49,260 --> 00:10:51,700
599 | 因此,现在我们将实现另一个例子
600 |
601 | 151
602 | 00:10:51,700 --> 00:10:56,040
603 | 在你把你的文本发布到公共论坛之前,检查它总是有用的
604 |
605 | 152
606 | 00:10:56,040 --> 00:10:59,100
607 | 因此,我们将通过一个检查评论的例子
608 |
609 | 153
610 | 00:10:59,100 --> 00:11:01,980
611 | 这里有一个关于毛绒熊猫的评论
612 |
613 | 154
614 | 00:11:01,980 --> 00:11:06,740
615 | 因此,我们将要求模型校对和纠正评论
616 |
617 | 155
618 | 00:11:06,740 --> 00:11:11,100
619 | 很好。所以我们有了这个更正的版本
620 |
621 | 156
622 | 00:11:11,100 --> 00:11:14,860
623 | 我们可以做的一件很酷的事情是找到
624 |
625 | 157
626 | 00:11:14,860 --> 00:11:19,180
627 | 我们的原始评论和模型的输出之间的差异
628 |
629 | 158
630 | 00:11:19,180 --> 00:11:24,380
631 | 所以我们要基于这个Redlines Python包来做这个
632 |
633 | 159
634 | 00:11:24,380 --> 00:11:26,800
635 | 我们将得到以下的差异
636 |
637 | 160
638 | 00:11:26,800 --> 00:11:32,460
639 | 我们评论的原文和模型的输出之间的差异
640 |
641 | 161
642 | 00:11:32,460 --> 00:11:36,740
643 | 然后显示这个
644 |
645 | 162
646 | 00:11:36,740 --> 00:11:40,340
647 | 所以在这里你可以看到原始评论和模型输出之间的差异
648 |
649 | 163
650 | 00:11:40,340 --> 00:11:44,940
651 | 和模型输出之间的差异,以及那些已经被纠正的东西
652 |
653 | 164
654 | 00:11:44,940 --> 00:11:49,380
655 | 因此,我们使用的提示是校对和纠正这个评论
656 |
657 | 165
658 | 00:11:49,380 --> 00:11:52,820
659 | 但你也可以做一些更戏剧性的改变
660 |
661 | 166
662 | 00:11:52,820 --> 00:11:55,700
663 | 语气的变化,以及诸如此类的事情
664 |
665 | 167
666 | 00:11:55,700 --> 00:12:00,340
667 | 因此,让我们再试一试
668 |
669 | 168
670 | 00:12:00,340 --> 00:12:04,500
671 | 所以在这个提示中,我们将要求模特校对和纠正
672 |
673 | 169
674 | 00:12:04,500 --> 00:12:08,700
675 | 同样的评论,但也要使其更有说服力,并确保其
676 |
677 | 170
678 | 00:12:08,700 --> 00:12:11,860
679 | 遵循APA风格,并针对高级读者
680 |
681 | 171
682 | 00:12:11,860 --> 00:12:14,860
683 | 我们还将要求以Markdown格式输出结果
684 |
685 | 172
686 | 00:12:14,860 --> 00:12:18,780
687 | 因此,我们在这里使用原始审查的相同文本
688 |
689 | 173
690 | 00:12:18,780 --> 00:12:23,260
691 | 因此,让我们来执行这个
692 |
693 | 174
694 | 00:12:23,260 --> 00:12:30,380
695 | 在这里,我们有一个扩展的APA风格的毛绒熊猫的评论
696 |
697 | 175
698 | 00:12:30,380 --> 00:12:32,300
699 | 因此,这是它的转换视频
700 |
701 | 176
702 | 00:12:32,300 --> 00:12:35,700
703 | 接下来,我们将使用扩写功能,采取较短的提示
704 |
705 | 177
706 | 00:12:35,700 --> 00:12:54,180
707 | 并从语言模型中产生一个更长、更自由的反应
708 |
709 |
--------------------------------------------------------------------------------
/course_notebooks/l5-inferring.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "attachments": {},
5 | "cell_type": "markdown",
6 | "metadata": {},
7 | "source": [
8 | "[](https://colab.research.google.com/github/GitHubDaily/ChatGPT-Prompt-Engineering-for-Developers-in-Chinese/blob/master/assets/5-Inferring/l5-inferring.ipynb)\n",
9 | "# Inferring\n",
10 | "In this lesson, you will infer sentiment and topics from product reviews and news articles.\n",
11 | "\n",
12 | "## Setup"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": null,
18 | "metadata": {},
19 | "outputs": [],
20 | "source": [
21 | "# Basic congfig \n",
22 | "# Install basic package and set key\n",
23 | "!pip install openai\n",
24 | "!export OPENAI_API_KEY='sk-...'"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": null,
30 | "metadata": {},
31 | "outputs": [],
32 | "source": [
33 | "import openai\n",
34 | "import os\n",
35 | "\n",
36 | "from dotenv import load_dotenv, find_dotenv\n",
37 | "_ = load_dotenv(find_dotenv()) # read local .env file\n",
38 | "\n",
39 | "openai.api_key = os.getenv('OPENAI_API_KEY')"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "def get_completion(prompt, model=\"gpt-3.5-turbo\"):\n",
49 | " messages = [{\"role\": \"user\", \"content\": prompt}]\n",
50 | " response = openai.ChatCompletion.create(\n",
51 | " model=model,\n",
52 | " messages=messages,\n",
53 | " temperature=0, # this is the degree of randomness of the model's output\n",
54 | " )\n",
55 | " return response.choices[0].message[\"content\"]"
56 | ]
57 | },
58 | {
59 | "attachments": {},
60 | "cell_type": "markdown",
61 | "metadata": {},
62 | "source": [
63 | "## Product review text"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "lamp_review = \"\"\"\n",
73 | "Needed a nice lamp for my bedroom, and this one had \\\n",
74 | "additional storage and not too high of a price point. \\\n",
75 | "Got it fast. The string to our lamp broke during the \\\n",
76 | "transit and the company happily sent over a new one. \\\n",
77 | "Came within a few days as well. It was easy to put \\\n",
78 | "together. I had a missing part, so I contacted their \\\n",
79 | "support and they very quickly got me the missing piece! \\\n",
80 | "Lumina seems to me to be a great company that cares \\\n",
81 | "about their customers and products!!\n",
82 | "\"\"\""
83 | ]
84 | },
85 | {
86 | "attachments": {},
87 | "cell_type": "markdown",
88 | "metadata": {},
89 | "source": [
90 | "## Sentiment (positive/negative)\n"
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "execution_count": null,
96 | "metadata": {},
97 | "outputs": [],
98 | "source": [
99 | "prompt = f\"\"\"\n",
100 | "What is the sentiment of the following product review, \n",
101 | "which is delimited with triple backticks?\n",
102 | "\n",
103 | "Review text: '''{lamp_review}'''\n",
104 | "\"\"\"\n",
105 | "response = get_completion(prompt)\n",
106 | "print(response)"
107 | ]
108 | },
109 | {
110 | "cell_type": "code",
111 | "execution_count": null,
112 | "metadata": {},
113 | "outputs": [],
114 | "source": [
115 | "prompt = f\"\"\"\n",
116 | "What is the sentiment of the following product review, \n",
117 | "which is delimited with triple backticks?\n",
118 | "\n",
119 | "Give your answer as a single word, either \"positive\" \\\n",
120 | "or \"negative\".\n",
121 | "\n",
122 | "Review text: '''{lamp_review}'''\n",
123 | "\"\"\"\n",
124 | "response = get_completion(prompt)\n",
125 | "print(response)"
126 | ]
127 | },
128 | {
129 | "attachments": {},
130 | "cell_type": "markdown",
131 | "metadata": {},
132 | "source": [
133 | "## Identify types of emotions"
134 | ]
135 | },
136 | {
137 | "cell_type": "code",
138 | "execution_count": null,
139 | "metadata": {},
140 | "outputs": [],
141 | "source": [
142 | "prompt = f\"\"\"\n",
143 | "Identify a list of emotions that the writer of the \\\n",
144 | "following review is expressing. Include no more than \\\n",
145 | "five items in the list. Format your answer as a list of \\\n",
146 | "lower-case words separated by commas.\n",
147 | "\n",
148 | "Review text: '''{lamp_review}'''\n",
149 | "\"\"\"\n",
150 | "response = get_completion(prompt)\n",
151 | "print(response)"
152 | ]
153 | },
154 | {
155 | "attachments": {},
156 | "cell_type": "markdown",
157 | "metadata": {},
158 | "source": [
159 | "## Identify anger"
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": null,
165 | "metadata": {},
166 | "outputs": [],
167 | "source": [
168 | "prompt = f\"\"\"\n",
169 | "Is the writer of the following review expressing anger?\\\n",
170 | "The review is delimited with triple backticks. \\\n",
171 | "Give your answer as either yes or no.\n",
172 | "\n",
173 | "Review text: '''{lamp_review}'''\n",
174 | "\"\"\"\n",
175 | "response = get_completion(prompt)\n",
176 | "print(response)"
177 | ]
178 | },
179 | {
180 | "attachments": {},
181 | "cell_type": "markdown",
182 | "metadata": {},
183 | "source": [
184 | "## Extract product and company name from customer reviews"
185 | ]
186 | },
187 | {
188 | "cell_type": "code",
189 | "execution_count": null,
190 | "metadata": {},
191 | "outputs": [],
192 | "source": [
193 | "prompt = f\"\"\"\n",
194 | "Identify the following items from the review text: \n",
195 | "- Item purchased by reviewer\n",
196 | "- Company that made the item\n",
197 | "\n",
198 | "The review is delimited with triple backticks. \\\n",
199 | "Format your response as a JSON object with \\\n",
200 | "\"Item\" and \"Brand\" as the keys. \n",
201 | "If the information isn't present, use \"unknown\" \\\n",
202 | "as the value.\n",
203 | "Make your response as short as possible.\n",
204 | " \n",
205 | "Review text: '''{lamp_review}'''\n",
206 | "\"\"\"\n",
207 | "response = get_completion(prompt)\n",
208 | "print(response)"
209 | ]
210 | },
211 | {
212 | "attachments": {},
213 | "cell_type": "markdown",
214 | "metadata": {},
215 | "source": [
216 | "## Doing multiple tasks at once"
217 | ]
218 | },
219 | {
220 | "cell_type": "code",
221 | "execution_count": null,
222 | "metadata": {},
223 | "outputs": [],
224 | "source": [
225 | "prompt = f\"\"\"\n",
226 | "Identify the following items from the review text: \n",
227 | "- Sentiment (positive or negative)\n",
228 | "- Is the reviewer expressing anger? (true or false)\n",
229 | "- Item purchased by reviewer\n",
230 | "- Company that made the item\n",
231 | "\n",
232 | "The review is delimited with triple backticks. \\\n",
233 | "Format your response as a JSON object with \\\n",
234 | "\"Sentiment\", \"Anger\", \"Item\" and \"Brand\" as the keys.\n",
235 | "If the information isn't present, use \"unknown\" \\\n",
236 | "as the value.\n",
237 | "Make your response as short as possible.\n",
238 | "Format the Anger value as a boolean.\n",
239 | "\n",
240 | "Review text: '''{lamp_review}'''\n",
241 | "\"\"\"\n",
242 | "response = get_completion(prompt)\n",
243 | "print(response)"
244 | ]
245 | },
246 | {
247 | "attachments": {},
248 | "cell_type": "markdown",
249 | "metadata": {},
250 | "source": [
251 | "## Inferring topics"
252 | ]
253 | },
254 | {
255 | "cell_type": "code",
256 | "execution_count": null,
257 | "metadata": {},
258 | "outputs": [],
259 | "source": [
260 | "story = \"\"\"\n",
261 | "In a recent survey conducted by the government, \n",
262 | "public sector employees were asked to rate their level \n",
263 | "of satisfaction with the department they work at. \n",
264 | "The results revealed that NASA was the most popular \n",
265 | "department with a satisfaction rating of 95%.\n",
266 | "\n",
267 | "One NASA employee, John Smith, commented on the findings, \n",
268 | "stating, \"I'm not surprised that NASA came out on top. \n",
269 | "It's a great place to work with amazing people and \n",
270 | "incredible opportunities. I'm proud to be a part of \n",
271 | "such an innovative organization.\"\n",
272 | "\n",
273 | "The results were also welcomed by NASA's management team, \n",
274 | "with Director Tom Johnson stating, \"We are thrilled to \n",
275 | "hear that our employees are satisfied with their work at NASA. \n",
276 | "We have a talented and dedicated team who work tirelessly \n",
277 | "to achieve our goals, and it's fantastic to see that their \n",
278 | "hard work is paying off.\"\n",
279 | "\n",
280 | "The survey also revealed that the \n",
281 | "Social Security Administration had the lowest satisfaction \n",
282 | "rating, with only 45% of employees indicating they were \n",
283 | "satisfied with their job. The government has pledged to \n",
284 | "address the concerns raised by employees in the survey and \n",
285 | "work towards improving job satisfaction across all departments.\n",
286 | "\"\"\""
287 | ]
288 | },
289 | {
290 | "attachments": {},
291 | "cell_type": "markdown",
292 | "metadata": {},
293 | "source": [
294 | "## Infer 5 topics"
295 | ]
296 | },
297 | {
298 | "cell_type": "code",
299 | "execution_count": null,
300 | "metadata": {},
301 | "outputs": [],
302 | "source": [
303 | "prompt = f\"\"\"\n",
304 | "Determine five topics that are being discussed in the \\\n",
305 | "following text, which is delimited by triple backticks.\n",
306 | "\n",
307 | "Make each item one or two words long. \n",
308 | "\n",
309 | "Format your response as a list of items separated by commas.\n",
310 | "\n",
311 | "Text sample: '''{story}'''\n",
312 | "\"\"\"\n",
313 | "response = get_completion(prompt)\n",
314 | "print(response)"
315 | ]
316 | },
317 | {
318 | "cell_type": "code",
319 | "execution_count": null,
320 | "metadata": {},
321 | "outputs": [],
322 | "source": [
323 | "response.split(sep=',')"
324 | ]
325 | },
326 | {
327 | "cell_type": "code",
328 | "execution_count": null,
329 | "metadata": {},
330 | "outputs": [],
331 | "source": [
332 | "topic_list = [\n",
333 | " \"nasa\", \"local government\", \"engineering\", \n",
334 | " \"employee satisfaction\", \"federal government\"\n",
335 | "]"
336 | ]
337 | },
338 | {
339 | "attachments": {},
340 | "cell_type": "markdown",
341 | "metadata": {},
342 | "source": [
343 | "## Make a news alert for certain topics"
344 | ]
345 | },
346 | {
347 | "cell_type": "code",
348 | "execution_count": null,
349 | "metadata": {},
350 | "outputs": [],
351 | "source": [
352 | "prompt = f\"\"\"\n",
353 | "Determine whether each item in the following list of \\\n",
354 | "topics is a topic in the text below, which\n",
355 | "is delimited with triple backticks.\n",
356 | "\n",
357 | "Give your answer as list with 0 or 1 for each topic.\\\n",
358 | "\n",
359 | "List of topics: {\", \".join(topic_list)}\n",
360 | "\n",
361 | "Text sample: '''{story}'''\n",
362 | "\"\"\"\n",
363 | "response = get_completion(prompt)\n",
364 | "print(response)"
365 | ]
366 | },
367 | {
368 | "cell_type": "code",
369 | "execution_count": null,
370 | "metadata": {},
371 | "outputs": [],
372 | "source": [
373 | "topic_dict = {i.split(': ')[0]: int(i.split(': ')[1]) for i in response.split(sep='\\n')}\n",
374 | "if topic_dict['nasa'] == 1:\n",
375 | " print(\"ALERT: New NASA story!\")"
376 | ]
377 | },
378 | {
379 | "cell_type": "markdown",
380 | "metadata": {},
381 | "source": []
382 | }
383 | ],
384 | "metadata": {
385 | "kernelspec": {
386 | "display_name": "gpt_index",
387 | "language": "python",
388 | "name": "python3"
389 | },
390 | "language_info": {
391 | "codemirror_mode": {
392 | "name": "ipython",
393 | "version": 3
394 | },
395 | "file_extension": ".py",
396 | "mimetype": "text/x-python",
397 | "name": "python",
398 | "nbconvert_exporter": "python",
399 | "pygments_lexer": "ipython3",
400 | "version": "3.8.16"
401 | },
402 | "orig_nbformat": 4
403 | },
404 | "nbformat": 4,
405 | "nbformat_minor": 2
406 | }
407 |
--------------------------------------------------------------------------------
/course_notebooks/l6-transforming.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "attachments": {},
5 | "cell_type": "markdown",
6 | "metadata": {},
7 | "source": [
8 | "[](https://colab.research.google.com/github/GitHubDaily/ChatGPT-Prompt-Engineering-for-Developers-in-Chinese/blob/master/assets/6-Transforming/l6-transforming.ipynb)\n",
9 | "# Transforming\n",
10 | "\n",
11 | "In this notebook, we will explore how to use Large Language Models for text transformation tasks such as language translation, spelling and grammar checking, tone adjustment, and format conversion.\n",
12 | "\n",
13 | "## Setup"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": null,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "# Basic congfig \n",
23 | "# Install basic package and set key\n",
24 | "!pip install openai\n",
25 | "!export OPENAI_API_KEY='sk-...'"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": null,
31 | "metadata": {},
32 | "outputs": [],
33 | "source": [
34 | "import openai\n",
35 | "import os\n",
36 | "\n",
37 | "from dotenv import load_dotenv, find_dotenv\n",
38 | "_ = load_dotenv(find_dotenv()) # read local .env file\n",
39 | "\n",
40 | "openai.api_key = os.getenv('OPENAI_API_KEY')"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {},
47 | "outputs": [],
48 | "source": [
49 | "def get_completion(prompt, model=\"gpt-3.5-turbo\", temperature=0): \n",
50 | " messages = [{\"role\": \"user\", \"content\": prompt}]\n",
51 | " response = openai.ChatCompletion.create(\n",
52 | " model=model,\n",
53 | " messages=messages,\n",
54 | " temperature=temperature, \n",
55 | " )\n",
56 | " return response.choices[0].message[\"content\"]"
57 | ]
58 | },
59 | {
60 | "attachments": {},
61 | "cell_type": "markdown",
62 | "metadata": {},
63 | "source": [
64 | "## Translation\n",
65 | "\n",
66 | "ChatGPT is trained with sources in many languages. This gives the model the ability to do translation. Here are some examples of how to use this capability."
67 | ]
68 | },
69 | {
70 | "cell_type": "code",
71 | "execution_count": null,
72 | "metadata": {},
73 | "outputs": [],
74 | "source": [
75 | "prompt = f\"\"\"\n",
76 | "Translate the following English text to Spanish: \\ \n",
77 | "```Hi, I would like to order a blender```\n",
78 | "\"\"\"\n",
79 | "response = get_completion(prompt)\n",
80 | "print(response)"
81 | ]
82 | },
83 | {
84 | "cell_type": "code",
85 | "execution_count": null,
86 | "metadata": {},
87 | "outputs": [],
88 | "source": [
89 | "prompt = f\"\"\"\n",
90 | "Tell me which language this is: \n",
91 | "```Combien coûte le lampadaire?```\n",
92 | "\"\"\"\n",
93 | "response = get_completion(prompt)\n",
94 | "print(response)"
95 | ]
96 | },
97 | {
98 | "cell_type": "code",
99 | "execution_count": null,
100 | "metadata": {},
101 | "outputs": [],
102 | "source": [
103 | "prompt = f\"\"\"\n",
104 | "Translate the following text to French and Spanish\n",
105 | "and English pirate: \\\n",
106 | "```I want to order a basketball```\n",
107 | "\"\"\"\n",
108 | "response = get_completion(prompt)\n",
109 | "print(response)"
110 | ]
111 | },
112 | {
113 | "cell_type": "code",
114 | "execution_count": null,
115 | "metadata": {},
116 | "outputs": [],
117 | "source": [
118 | "prompt = f\"\"\"\n",
119 | "Translate the following text to Spanish in both the \\\n",
120 | "formal and informal forms: \n",
121 | "'Would you like to order a pillow?'\n",
122 | "\"\"\"\n",
123 | "response = get_completion(prompt)\n",
124 | "print(response)"
125 | ]
126 | },
127 | {
128 | "attachments": {},
129 | "cell_type": "markdown",
130 | "metadata": {},
131 | "source": [
132 | "### Universal Translator\n",
133 | "Imagine you are in charge of IT at a large multinational e-commerce company. Users are messaging you with IT issues in all their native languages. Your staff is from all over the world and speaks only their native languages. You need a universal translator!"
134 | ]
135 | },
136 | {
137 | "cell_type": "code",
138 | "execution_count": null,
139 | "metadata": {},
140 | "outputs": [],
141 | "source": [
142 | "user_messages = [\n",
143 | " \"La performance du système est plus lente que d'habitude.\", # System performance is slower than normal \n",
144 | " \"Mi monitor tiene píxeles que no se iluminan.\", # My monitor has pixels that are not lighting\n",
145 | " \"Il mio mouse non funziona\", # My mouse is not working\n",
146 | " \"Mój klawisz Ctrl jest zepsuty\", # My keyboard has a broken control key\n",
147 | " \"我的屏幕在闪烁\" # My screen is flashing\n",
148 | "] "
149 | ]
150 | },
151 | {
152 | "cell_type": "code",
153 | "execution_count": null,
154 | "metadata": {},
155 | "outputs": [],
156 | "source": [
157 | "for issue in user_messages:\n",
158 | " prompt = f\"Tell me what language this is: ```{issue}```\"\n",
159 | " lang = get_completion(prompt)\n",
160 | " print(f\"Original message ({lang}): {issue}\")\n",
161 | "\n",
162 | " prompt = f\"\"\"\n",
163 | " Translate the following text to English \\\n",
164 | " and Korean: ```{issue}```\n",
165 | " \"\"\"\n",
166 | " response = get_completion(prompt)\n",
167 | " print(response, \"\\n\")"
168 | ]
169 | },
170 | {
171 | "attachments": {},
172 | "cell_type": "markdown",
173 | "metadata": {},
174 | "source": [
175 | "## Try it yourself!\n",
176 | "Try some translations on your own!"
177 | ]
178 | },
179 | {
180 | "cell_type": "code",
181 | "execution_count": null,
182 | "metadata": {},
183 | "outputs": [],
184 | "source": []
185 | },
186 | {
187 | "attachments": {},
188 | "cell_type": "markdown",
189 | "metadata": {},
190 | "source": [
191 | "## Tone Transformation\n",
192 | "Writing can vary based on the intended audience. ChatGPT can produce different tones.\n"
193 | ]
194 | },
195 | {
196 | "cell_type": "code",
197 | "execution_count": null,
198 | "metadata": {},
199 | "outputs": [],
200 | "source": [
201 | "prompt = f\"\"\"\n",
202 | "Translate the following from slang to a business letter: \n",
203 | "'Dude, This is Joe, check out this spec on this standing lamp.'\n",
204 | "\"\"\"\n",
205 | "response = get_completion(prompt)\n",
206 | "print(response)"
207 | ]
208 | },
209 | {
210 | "attachments": {},
211 | "cell_type": "markdown",
212 | "metadata": {},
213 | "source": [
214 | "## Format Conversion\n",
215 | "ChatGPT can translate between formats. The prompt should describe the input and output formats."
216 | ]
217 | },
218 | {
219 | "cell_type": "code",
220 | "execution_count": null,
221 | "metadata": {},
222 | "outputs": [],
223 | "source": [
224 | "data_json = { \"resturant employees\" :[ \n",
225 | " {\"name\":\"Shyam\", \"email\":\"shyamjaiswal@gmail.com\"},\n",
226 | " {\"name\":\"Bob\", \"email\":\"bob32@gmail.com\"},\n",
227 | " {\"name\":\"Jai\", \"email\":\"jai87@gmail.com\"}\n",
228 | "]}\n",
229 | "\n",
230 | "prompt = f\"\"\"\n",
231 | "Translate the following python dictionary from JSON to an HTML \\\n",
232 | "table with column headers and title: {data_json}\n",
233 | "\"\"\"\n",
234 | "response = get_completion(prompt)\n",
235 | "print(response)"
236 | ]
237 | },
238 | {
239 | "cell_type": "code",
240 | "execution_count": null,
241 | "metadata": {},
242 | "outputs": [],
243 | "source": [
244 | "from IPython.display import display, Markdown, Latex, HTML, JSON\n",
245 | "display(HTML(response))"
246 | ]
247 | },
248 | {
249 | "attachments": {},
250 | "cell_type": "markdown",
251 | "metadata": {},
252 | "source": [
253 | "## Spellcheck/Grammar check.\n",
254 | "\n",
255 | "Here are some examples of common grammar and spelling problems and the LLM's response. \n",
256 | "\n",
257 | "To signal to the LLM that you want it to proofread your text, you instruct the model to 'proofread' or 'proofread and correct'."
258 | ]
259 | },
260 | {
261 | "cell_type": "code",
262 | "execution_count": null,
263 | "metadata": {},
264 | "outputs": [],
265 | "source": [
266 | "text = [ \n",
267 | " \"The girl with the black and white puppies have a ball.\", # The girl has a ball.\n",
268 | " \"Yolanda has her notebook.\", # ok\n",
269 | " \"Its going to be a long day. Does the car need it’s oil changed?\", # Homonyms\n",
270 | " \"Their goes my freedom. There going to bring they’re suitcases.\", # Homonyms\n",
271 | " \"Your going to need you’re notebook.\", # Homonyms\n",
272 | " \"That medicine effects my ability to sleep. Have you heard of the butterfly affect?\", # Homonyms\n",
273 | " \"This phrase is to cherck chatGPT for speling abilitty\" # spelling\n",
274 | "]\n",
275 | "for t in text:\n",
276 | " prompt = f\"\"\"Proofread and correct the following text\n",
277 | " and rewrite the corrected version. If you don't find\n",
278 | " and errors, just say \"No errors found\". Don't use \n",
279 | " any punctuation around the text:\n",
280 | " ```{t}```\"\"\"\n",
281 | " response = get_completion(prompt)\n",
282 | " print(response)"
283 | ]
284 | },
285 | {
286 | "cell_type": "code",
287 | "execution_count": null,
288 | "metadata": {},
289 | "outputs": [],
290 | "source": [
291 | "text = f\"\"\"\n",
292 | "Got this for my daughter for her birthday cuz she keeps taking \\\n",
293 | "mine from my room. Yes, adults also like pandas too. She takes \\\n",
294 | "it everywhere with her, and it's super soft and cute. One of the \\\n",
295 | "ears is a bit lower than the other, and I don't think that was \\\n",
296 | "designed to be asymmetrical. It's a bit small for what I paid for it \\\n",
297 | "though. I think there might be other options that are bigger for \\\n",
298 | "the same price. It arrived a day earlier than expected, so I got \\\n",
299 | "to play with it myself before I gave it to my daughter.\n",
300 | "\"\"\"\n",
301 | "prompt = f\"proofread and correct this review: ```{text}```\"\n",
302 | "response = get_completion(prompt)\n",
303 | "print(response)"
304 | ]
305 | },
306 | {
307 | "cell_type": "code",
308 | "execution_count": null,
309 | "metadata": {},
310 | "outputs": [],
311 | "source": [
312 | "!pip install redlines\n",
313 | "from redlines import Redlines\n",
314 | "\n",
315 | "diff = Redlines(text,response)\n",
316 | "display(Markdown(diff.output_markdown))"
317 | ]
318 | },
319 | {
320 | "cell_type": "code",
321 | "execution_count": null,
322 | "metadata": {},
323 | "outputs": [],
324 | "source": [
325 | "prompt = f\"\"\"\n",
326 | "proofread and correct this review. Make it more compelling. \n",
327 | "Ensure it follows APA style guide and targets an advanced reader. \n",
328 | "Output in markdown format.\n",
329 | "Text: ```{text}```\n",
330 | "\"\"\"\n",
331 | "response = get_completion(prompt)\n",
332 | "display(Markdown(response))"
333 | ]
334 | },
335 | {
336 | "attachments": {},
337 | "cell_type": "markdown",
338 | "metadata": {},
339 | "source": [
340 | "## Try it yourself!\n",
341 | "Try changing the instructions to form your own review."
342 | ]
343 | },
344 | {
345 | "cell_type": "markdown",
346 | "metadata": {},
347 | "source": []
348 | },
349 | {
350 | "cell_type": "code",
351 | "execution_count": null,
352 | "metadata": {},
353 | "outputs": [],
354 | "source": []
355 | },
356 | {
357 | "attachments": {},
358 | "cell_type": "markdown",
359 | "metadata": {},
360 | "source": [
361 | "Thanks to the following sites:\n",
362 | "\n",
363 | "https://writingprompts.com/bad-grammar-examples/"
364 | ]
365 | },
366 | {
367 | "cell_type": "markdown",
368 | "metadata": {},
369 | "source": []
370 | }
371 | ],
372 | "metadata": {
373 | "kernelspec": {
374 | "display_name": "gpt_index",
375 | "language": "python",
376 | "name": "python3"
377 | },
378 | "language_info": {
379 | "codemirror_mode": {
380 | "name": "ipython",
381 | "version": 3
382 | },
383 | "file_extension": ".py",
384 | "mimetype": "text/x-python",
385 | "name": "python",
386 | "nbconvert_exporter": "python",
387 | "pygments_lexer": "ipython3",
388 | "version": "3.8.16"
389 | },
390 | "orig_nbformat": 4
391 | },
392 | "nbformat": 4,
393 | "nbformat_minor": 2
394 | }
395 |
--------------------------------------------------------------------------------
/course_notebooks/l4-summarizing.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "attachments": {},
5 | "cell_type": "markdown",
6 | "metadata": {},
7 | "source": [
8 | "[](https://colab.research.google.com/github/GitHubDaily/ChatGPT-Prompt-Engineering-for-Developers-in-Chinese/blob/master/assets/4-Summarizing/l4-summarizing.ipynb)\n",
9 | "# Summarizing\n",
10 | "In this lesson, you will summarize text with a focus on specific topics.\n",
11 | "\n",
12 | "## Setup"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": null,
18 | "metadata": {},
19 | "outputs": [],
20 | "source": [
21 | "# Basic congfig \n",
22 | "# Install basic package and set key\n",
23 | "!pip install openai\n",
24 | "!export OPENAI_API_KEY='sk-...'"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": null,
30 | "metadata": {},
31 | "outputs": [],
32 | "source": [
33 | "import openai\n",
34 | "import os\n",
35 | "\n",
36 | "from dotenv import load_dotenv, find_dotenv\n",
37 | "_ = load_dotenv(find_dotenv()) # read local .env file\n",
38 | "\n",
39 | "openai.api_key = os.getenv('OPENAI_API_KEY')"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "def get_completion(prompt, model=\"gpt-3.5-turbo\"): # Andrew mentioned that the prompt/ completion paradigm is preferable for this class\n",
49 | " messages = [{\"role\": \"user\", \"content\": prompt}]\n",
50 | " response = openai.ChatCompletion.create(\n",
51 | " model=model,\n",
52 | " messages=messages,\n",
53 | " temperature=0, # this is the degree of randomness of the model's output\n",
54 | " )\n",
55 | " return response.choices[0].message[\"content\"]"
56 | ]
57 | },
58 | {
59 | "attachments": {},
60 | "cell_type": "markdown",
61 | "metadata": {},
62 | "source": [
63 | "## Text to summarize"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "prod_review = \"\"\"\n",
73 | "Got this panda plush toy for my daughter's birthday, \\\n",
74 | "who loves it and takes it everywhere. It's soft and \\ \n",
75 | "super cute, and its face has a friendly look. It's \\ \n",
76 | "a bit small for what I paid though. I think there \\ \n",
77 | "might be other options that are bigger for the \\ \n",
78 | "same price. It arrived a day earlier than expected, \\ \n",
79 | "so I got to play with it myself before I gave it \\ \n",
80 | "to her.\n",
81 | "\"\"\""
82 | ]
83 | },
84 | {
85 | "attachments": {},
86 | "cell_type": "markdown",
87 | "metadata": {},
88 | "source": [
89 | "## Summarize with a word/sentence/character limit"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {},
96 | "outputs": [],
97 | "source": [
98 | "prompt = f\"\"\"\n",
99 | "Your task is to generate a short summary of a product \\\n",
100 | "review from an ecommerce site. \n",
101 | "\n",
102 | "Summarize the review below, delimited by triple \n",
103 | "backticks, in at most 30 words. \n",
104 | "\n",
105 | "Review: ```{prod_review}```\n",
106 | "\"\"\"\n",
107 | "\n",
108 | "response = get_completion(prompt)\n",
109 | "print(response)"
110 | ]
111 | },
112 | {
113 | "attachments": {},
114 | "cell_type": "markdown",
115 | "metadata": {},
116 | "source": [
117 | "## Summarize with a focus on shipping and delivery"
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "execution_count": null,
123 | "metadata": {},
124 | "outputs": [],
125 | "source": [
126 | "prompt = f\"\"\"\n",
127 | "Your task is to generate a short summary of a product \\\n",
128 | "review from an ecommerce site to give feedback to the \\\n",
129 | "Shipping deparmtment. \n",
130 | "\n",
131 | "Summarize the review below, delimited by triple \n",
132 | "backticks, in at most 30 words, and focusing on any aspects \\\n",
133 | "that mention shipping and delivery of the product. \n",
134 | "\n",
135 | "Review: ```{prod_review}```\n",
136 | "\"\"\"\n",
137 | "\n",
138 | "response = get_completion(prompt)\n",
139 | "print(response)"
140 | ]
141 | },
142 | {
143 | "attachments": {},
144 | "cell_type": "markdown",
145 | "metadata": {},
146 | "source": [
147 | "## Summarize with a focus on price and value"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": null,
153 | "metadata": {},
154 | "outputs": [],
155 | "source": [
156 | "prompt = f\"\"\"\n",
157 | "Your task is to generate a short summary of a product \\\n",
158 | "review from an ecommerce site to give feedback to the \\\n",
159 | "Shipping deparmtment. \n",
160 | "\n",
161 | "Summarize the review below, delimited by triple \n",
162 | "backticks, in at most 30 words, and focusing on any aspects \\\n",
163 | "that mention shipping and delivery of the product. \n",
164 | "\n",
165 | "Review: ```{prod_review}```\n",
166 | "\"\"\"\n",
167 | "\n",
168 | "response = get_completion(prompt)\n",
169 | "print(response)"
170 | ]
171 | },
172 | {
173 | "attachments": {},
174 | "cell_type": "markdown",
175 | "metadata": {},
176 | "source": [
177 | "## Summarize with a focus on price and value"
178 | ]
179 | },
180 | {
181 | "cell_type": "code",
182 | "execution_count": null,
183 | "metadata": {},
184 | "outputs": [],
185 | "source": [
186 | "prompt = f\"\"\"\n",
187 | "Your task is to generate a short summary of a product \\\n",
188 | "review from an ecommerce site to give feedback to the \\\n",
189 | "pricing deparmtment, responsible for determining the \\\n",
190 | "price of the product. \n",
191 | "\n",
192 | "Summarize the review below, delimited by triple \n",
193 | "backticks, in at most 30 words, and focusing on any aspects \\\n",
194 | "that are relevant to the price and perceived value. \n",
195 | "\n",
196 | "Review: ```{prod_review}```\n",
197 | "\"\"\"\n",
198 | "\n",
199 | "response = get_completion(prompt)\n",
200 | "print(response)"
201 | ]
202 | },
203 | {
204 | "attachments": {},
205 | "cell_type": "markdown",
206 | "metadata": {},
207 | "source": [
208 | "#### Comment\n",
209 | "- Summaries include topics that are not related to the topic of focus."
210 | ]
211 | },
212 | {
213 | "attachments": {},
214 | "cell_type": "markdown",
215 | "metadata": {},
216 | "source": [
217 | "## Try \"extract\" instead of \"summarize\""
218 | ]
219 | },
220 | {
221 | "cell_type": "code",
222 | "execution_count": null,
223 | "metadata": {},
224 | "outputs": [],
225 | "source": [
226 | "prompt = f\"\"\"\n",
227 | "Your task is to extract relevant information from \\ \n",
228 | "a product review from an ecommerce site to give \\\n",
229 | "feedback to the Shipping department. \n",
230 | "\n",
231 | "From the review below, delimited by triple quotes \\\n",
232 | "extract the information relevant to shipping and \\ \n",
233 | "delivery. Limit to 30 words. \n",
234 | "\n",
235 | "Review: ```{prod_review}```\n",
236 | "\"\"\"\n",
237 | "\n",
238 | "response = get_completion(prompt)\n",
239 | "print(response)"
240 | ]
241 | },
242 | {
243 | "attachments": {},
244 | "cell_type": "markdown",
245 | "metadata": {},
246 | "source": [
247 | "## Summarize multiple product reviews"
248 | ]
249 | },
250 | {
251 | "cell_type": "code",
252 | "execution_count": null,
253 | "metadata": {},
254 | "outputs": [],
255 | "source": [
256 | "review_1 = prod_review \n",
257 | "\n",
258 | "# review for a standing lamp\n",
259 | "review_2 = \"\"\"\n",
260 | "Needed a nice lamp for my bedroom, and this one \\\n",
261 | "had additional storage and not too high of a price \\\n",
262 | "point. Got it fast - arrived in 2 days. The string \\\n",
263 | "to the lamp broke during the transit and the company \\\n",
264 | "happily sent over a new one. Came within a few days \\\n",
265 | "as well. It was easy to put together. Then I had a \\\n",
266 | "missing part, so I contacted their support and they \\\n",
267 | "very quickly got me the missing piece! Seems to me \\\n",
268 | "to be a great company that cares about their customers \\\n",
269 | "and products. \n",
270 | "\"\"\"\n",
271 | "\n",
272 | "# review for an electric toothbrush\n",
273 | "review_3 = \"\"\"\n",
274 | "My dental hygienist recommended an electric toothbrush, \\\n",
275 | "which is why I got this. The battery life seems to be \\\n",
276 | "pretty impressive so far. After initial charging and \\\n",
277 | "leaving the charger plugged in for the first week to \\\n",
278 | "condition the battery, I've unplugged the charger and \\\n",
279 | "been using it for twice daily brushing for the last \\\n",
280 | "3 weeks all on the same charge. But the toothbrush head \\\n",
281 | "is too small. I’ve seen baby toothbrushes bigger than \\\n",
282 | "this one. I wish the head was bigger with different \\\n",
283 | "length bristles to get between teeth better because \\\n",
284 | "this one doesn’t. Overall if you can get this one \\\n",
285 | "around the $50 mark, it's a good deal. The manufactuer's \\\n",
286 | "replacements heads are pretty expensive, but you can \\\n",
287 | "get generic ones that're more reasonably priced. This \\\n",
288 | "toothbrush makes me feel like I've been to the dentist \\\n",
289 | "every day. My teeth feel sparkly clean! \n",
290 | "\"\"\"\n",
291 | "\n",
292 | "# review for a blender\n",
293 | "review_4 = \"\"\"\n",
294 | "So, they still had the 17 piece system on seasonal \\\n",
295 | "sale for around $49 in the month of November, about \\\n",
296 | "half off, but for some reason (call it price gouging) \\\n",
297 | "around the second week of December the prices all went \\\n",
298 | "up to about anywhere from between $70-$89 for the same \\\n",
299 | "system. And the 11 piece system went up around $10 or \\\n",
300 | "so in price also from the earlier sale price of $29. \\\n",
301 | "So it looks okay, but if you look at the base, the part \\\n",
302 | "where the blade locks into place doesn’t look as good \\\n",
303 | "as in previous editions from a few years ago, but I \\\n",
304 | "plan to be very gentle with it (example, I crush \\\n",
305 | "very hard items like beans, ice, rice, etc. in the \\ \n",
306 | "blender first then pulverize them in the serving size \\\n",
307 | "I want in the blender then switch to the whipping \\\n",
308 | "blade for a finer flour, and use the cross cutting blade \\\n",
309 | "first when making smoothies, then use the flat blade \\\n",
310 | "if I need them finer/less pulpy). Special tip when making \\\n",
311 | "smoothies, finely cut and freeze the fruits and \\\n",
312 | "vegetables (if using spinach-lightly stew soften the \\ \n",
313 | "spinach then freeze until ready for use-and if making \\\n",
314 | "sorbet, use a small to medium sized food processor) \\ \n",
315 | "that you plan to use that way you can avoid adding so \\\n",
316 | "much ice if at all-when making your smoothie. \\\n",
317 | "After about a year, the motor was making a funny noise. \\\n",
318 | "I called customer service but the warranty expired \\\n",
319 | "already, so I had to buy another one. FYI: The overall \\\n",
320 | "quality has gone done in these types of products, so \\\n",
321 | "they are kind of counting on brand recognition and \\\n",
322 | "consumer loyalty to maintain sales. Got it in about \\\n",
323 | "two days.\n",
324 | "\"\"\"\n",
325 | "\n",
326 | "reviews = [review_1, review_2, review_3, review_4]\n"
327 | ]
328 | },
329 | {
330 | "cell_type": "code",
331 | "execution_count": null,
332 | "metadata": {},
333 | "outputs": [],
334 | "source": [
335 | "for i in range(len(reviews)):\n",
336 | " prompt = f\"\"\"\n",
337 | " Your task is to generate a short summary of a product \\ \n",
338 | " review from an ecommerce site. \n",
339 | "\n",
340 | " Summarize the review below, delimited by triple \\\n",
341 | " backticks in at most 20 words. \n",
342 | "\n",
343 | " Review: ```{reviews[i]}```\n",
344 | " \"\"\"\n",
345 | "\n",
346 | " response = get_completion(prompt)\n",
347 | " print(i, response, \"\\n\")"
348 | ]
349 | },
350 | {
351 | "cell_type": "code",
352 | "execution_count": null,
353 | "metadata": {},
354 | "outputs": [],
355 | "source": []
356 | }
357 | ],
358 | "metadata": {
359 | "kernelspec": {
360 | "display_name": "gpt_index",
361 | "language": "python",
362 | "name": "python3"
363 | },
364 | "language_info": {
365 | "codemirror_mode": {
366 | "name": "ipython",
367 | "version": 3
368 | },
369 | "file_extension": ".py",
370 | "mimetype": "text/x-python",
371 | "name": "python",
372 | "nbconvert_exporter": "python",
373 | "pygments_lexer": "ipython3",
374 | "version": "3.8.16"
375 | },
376 | "orig_nbformat": 4
377 | },
378 | "nbformat": 4,
379 | "nbformat_minor": 2
380 | }
381 |
--------------------------------------------------------------------------------
/subtitles/raw/prompt_eng_04_summarizing.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:09,680
3 | 当今世界有如此多的文字,但我们几乎没有人有足够的时间
4 | There's so much text in today's world, pretty much none of us have enough time to read all
5 |
6 | 2
7 | 00:00:09,680 --> 00:00:12,760
8 | 来阅读这些文字
9 | the things we wish we had time to
10 |
11 | 3
12 | 00:00:12,760 --> 00:00:16,920
13 | 因此,我认为,大语言模型最令人兴奋的应用之一
14 | So one of the most exciting applications I've seen of large language models is to use it
15 |
16 | 4
17 | 00:00:16,920 --> 00:00:18,660
18 | 是用它来对文本进行总结
19 | to summarize text
20 |
21 | 5
22 | 00:00:18,660 --> 00:00:24,480
23 | 这也是我看到多个团队在不同软件应用中构建的东西
24 | And this is something that I'm seeing multiple teams build into multiple software applications
25 |
26 | 6
27 | 00:00:24,480 --> 00:00:26,880
28 | 你可以在ChatGPT网站上这样做
29 | You can do this in the ChatGPT web interface
30 |
31 | 7
32 | 00:00:26,880 --> 00:00:31,000
33 | 我经常用这种方式来总结文章
34 | I do this all the time to summarize articles so I can just kind of read the content of
35 |
36 | 8
37 | 00:00:31,000 --> 00:00:33,000
38 | 这样我就可以比以前多读很多文章
39 | many more articles than I previously could
40 |
41 | 9
42 | 00:00:33,000 --> 00:00:37,880
43 | 你将在本课程中,学习如何以编程方式来实现这个任务
44 | And if you want to do this more programmatically, you'll see how to in this lesson
45 |
46 | 10
47 | 00:00:37,880 --> 00:00:43,520
48 | 因此,让我们深入研究代码,看看你如何使用它来总结文本
49 | So that's let's dig into the code to see how you could use this yourself to summarize text
50 |
51 | 11
52 | 00:00:43,520 --> 00:00:48,280
53 | 让我们从之前的初始代码开始,导入openai,加载
54 | So let's start off with the same starter code as you saw before of import openai, load the
55 |
56 | 12
57 | 00:00:48,280 --> 00:00:52,620
58 | API Key,这里是get_completion辅助函数
59 | API key and here's that get_completion helper function
60 |
61 | 13
62 | 00:00:52,620 --> 00:01:00,640
63 | 我将以“总结此产品评价”的任务作为运行示例
64 | I'm going to use as the running example, the task of summarizing this product review
65 |
66 | 14
67 | 00:01:00,640 --> 00:01:04,640
68 | 我为女儿的生日买了这只熊猫毛绒玩具,女儿非常喜欢
69 | Got this panda plush toy for my daughter's birthday
70 |
71 | 15
72 | 00:01:04,640 --> 00:01:06,320
73 | 无论去哪儿都要带上它,诸如此类
74 | and so on and so on
75 |
76 | 16
77 | 00:01:06,320 --> 00:01:13,640
78 | 如果你正在建立一个电子商务网站,并且有大量的评论
79 | If you're building an e commerce website, and there's just a large volume of reviews
80 |
81 | 17
82 | 00:01:13,640 --> 00:01:18,680
83 | 有一个工具可以用来总结冗长的评论,给你提供一种方式
84 | having a tool to summarize the lengthy reviews could give you a way to very quickly glance
85 |
86 | 18
87 | 00:01:18,680 --> 00:01:24,200
88 | 让你可以浏览更多评论,更好地了解所有客户的想法
89 | over more reviews to get a better sense of what all your customers are thinking
90 |
91 | 19
92 | 00:01:24,200 --> 00:01:27,280
93 | 因此,这里有一个生成摘要的提示
94 | So here's a prompt for generating a summary
95 |
96 | 20
97 | 00:01:27,280 --> 00:01:30,600
98 | 你的任务是对电子商务网站上的产品评论生成一个简短的总结,总结如下
99 | Your task is generate a short summary of a product review from e commerce website, summarize
100 |
101 | 21
102 | 00:01:30,600 --> 00:01:36,800
103 | 下面的评论等等,最多只能用30个字
104 | review below, and so on, in at most 30 words
105 |
106 | 22
107 | 00:01:36,800 --> 00:01:42,400
108 | 因此,这个柔软可爱的熊猫毛绒玩具受到女儿的喜爱,但价格有点小贵
109 | And so this is soft and cute panda plush toy loved by daughter, but small for the price
110 |
111 | 23
112 | 00:01:42,400 --> 00:01:43,400
113 | 提前到货
114 | arrived early
115 |
116 | 24
117 | 00:01:43,400 --> 00:01:44,400
118 | 还不错
119 | Not bad
120 |
121 | 25
122 | 00:01:44,400 --> 00:01:45,400
123 | 这是个相当好的总结
124 | It's a pretty good summary
125 |
126 | 26
127 | 00:01:45,400 --> 00:01:49,760
128 | 正如你在前面的视频中看到的,你还可以玩一些东西,比如控制
129 | And as you saw in the previous video, you can also play with things like controlling
130 |
131 | 27
132 | 00:01:49,760 --> 00:01:55,720
133 | 字符数或句子数来影响这个摘要的长度
134 | the character count or the number of sentences to affect the length of this summary
135 |
136 | 28
137 | 00:01:55,720 --> 00:01:59,920
138 | 现在,有时在创建一个摘要时,如果你有一个非常具体的目的
139 | Now sometimes when creating a summary, if you have a very specific purpose in mind for
140 |
141 | 29
142 | 00:01:59,920 --> 00:02:05,600
143 | 例如,你想给运输部门提供反馈
144 | the summary, for example, if you want to give feedback to the shipping department, you can
145 |
146 | 30
147 | 00:02:05,600 --> 00:02:11,200
148 | 你也可以修改提示来突出这点,这样他们就可以生成一个更好的总结
149 | also modify the prompt to reflect that so that they can generate a summary that is more
150 |
151 | 31
152 | 00:02:11,200 --> 00:02:15,600
153 | 适用于你业务中的一个特定群体
154 | applicable to one particular group in your business
155 |
156 | 32
157 | 00:02:15,600 --> 00:02:26,880
158 | 例如,如果我想要给运输部门反馈
159 | So for example, if I add to give feedback to the shipping department, let's say I change
160 |
161 | 33
162 | 00:02:26,880 --> 00:02:35,800
163 | 那么我会将关注点集中在商品的运输和交付等方面
164 | this to start to focus on any aspects that mention shipping and delivery of the product
165 |
166 | 34
167 | 00:02:35,800 --> 00:02:42,560
168 | 如果我运行这个指令,那么你会得到一个新的摘要
169 | And if I run this, then again, you get a summary, but instead of starting off with soft and
170 |
171 | 35
172 | 00:02:42,560 --> 00:02:49,120
173 | 这次不是以“柔软可爱的熊猫毛绒玩具”开始,而是强调它比预期提前了一天送达
174 | cute panda plush toy, it now focuses on the fact that it arrived a day earlier than expected
175 |
176 | 36
177 | 00:02:49,120 --> 00:02:53,600
178 | 然后它仍然有其他细节
179 | And then it still has, you know, other details
180 |
181 | 37
182 | 00:02:53,600 --> 00:02:59,640
183 | 或者作为另一个例子,如果我们不是想给运输部门提供反馈
184 | Or as another example, if we aren't trying to give feedback to the shipping department
185 |
186 | 38
187 | 00:02:59,640 --> 00:03:09,520
188 | 而是给定价部门提供反馈
189 | but let's say we want to give feedback to the pricing department
190 |
191 | 39
192 | 00:03:09,520 --> 00:03:15,760
193 | 定价部门负责确定产品的价格
194 | So the pricing department is responsible for determining the price of the product
195 |
196 | 40
197 | 00:03:15,760 --> 00:03:22,960
198 | 我会告诉它专注于与产品价格和感知价值相关的任何方面
199 | And I'm going to tell it to focus on any aspects that are relevant to the price and perceived
200 |
201 | 41
202 | 00:03:22,960 --> 00:03:25,240
203 | 价值
204 | value
205 |
206 | 42
207 | 00:03:25,240 --> 00:03:31,520
208 | 那么这将生成一个不同的总结,它说
209 | Then this generates a different summary that it says
210 |
211 | 43
212 | 00:03:31,520 --> 00:03:33,480
213 | 也许这个尺寸的价格可能太高了
214 | maybe the price may be too high for a size
215 |
216 | 44
217 | 00:03:33,480 --> 00:03:38,640
218 | 现在,在我为运输部门或定价部门生成的摘要中
219 | Now in the summaries that I've generated for the shipping department or the pricing department
220 |
221 | 45
222 | 00:03:38,640 --> 00:03:44,400
223 | 它更侧重于与这些特定部门有关的信息
224 | it focuses a bit more on information relevant to those specific departments
225 |
226 | 46
227 | 00:03:44,400 --> 00:03:50,000
228 | 事实上,你可以随时暂停视频
229 | And in fact, feel free to pause the video now and maybe ask it to generate information
230 |
231 | 47
232 | 00:03:50,000 --> 00:03:55,360
233 | 然后让它为负责产品客户体验的部门提供有关产品的信息
234 | for the product department responsible for the customer experience of the product or
235 |
236 | 48
237 | 00:03:55,360 --> 00:04:01,920
238 | 或者为你认为对电子商务站点有趣的其他某些方面提供信息
239 | for something else that you think might be interesting to an e-commerce site
240 |
241 | 49
242 | 00:04:01,920 --> 00:04:07,000
243 | 但在这些摘要中,尽管它生成了与运输有关的信息
244 | But in these summaries, even though it generated the information relevant to shipping, it had
245 |
246 | 50
247 | 00:04:07,000 --> 00:04:12,240
248 | 但也有一些其他信息,你可以决定这些信息是否有帮助
249 | some other information too, which you could decide may or may not be helpful
250 |
251 | 51
252 | 00:04:12,240 --> 00:04:20,120
253 | 因此,根据你想要总结的方式,你也可以要求它提取信息
254 | So depending on how you want to summarize it, you can also ask it to extract information
255 |
256 | 52
257 | 00:04:20,120 --> 00:04:22,960
258 | 而不是对其进行总结
259 | rather than summarize it
260 |
261 | 53
262 | 00:04:22,960 --> 00:04:27,920
263 | 因此,这里有一个提示,说你的任务是
264 | So here's a prompt that says you're tasked to extract relevant information to give feedback
265 |
266 | 54
267 | 00:04:27,920 --> 00:04:29,200
268 | 提取相关的信息来反馈给给运输部门
269 | to the shipping department
270 |
271 | 55
272 | 00:04:29,200 --> 00:04:35,440
273 | 现在它只是说,产品比预期早到了一天,没有其他的信息
274 | And now it just says, product arrived a day earlier than expected without all of the other
275 |
276 | 56
277 | 00:04:35,440 --> 00:04:41,240
278 | 这在一般的总结中也是有帮助的,但如果想知道运输方面发生了什么
279 | information, which was also helpful in a general summary, but less specific to the shipping
280 |
281 | 57
282 | 00:04:41,240 --> 00:04:45,000
283 | 就不那么具体了
284 | department if all it wants to know is what happened with the shipping
285 |
286 | 58
287 | 00:04:45,000 --> 00:04:50,600
288 | 最后,让我与你分享一个具体的例子,说明如何在工作流程中使用这个方法
289 | Lastly, let me just share with you a concrete example for how to use this in a workflow
290 |
291 | 59
292 | 00:04:50,600 --> 00:04:56,760
293 | 来帮助总结多个评论,使其更容易阅读
294 | to help summarize multiple reviews to make them easier to read
295 |
296 | 60
297 | 00:04:56,760 --> 00:04:59,920
298 | 因此,这里有几条评论
299 | So here are a few reviews
300 |
301 | 61
302 | 00:04:59,920 --> 00:05:03,920
303 | 这有点长,但这是对落地灯的第二个评论
304 | This is kind of long, but here's a second review for a standing lamp
305 |
306 | 62
307 | 00:05:03,920 --> 00:05:04,920
308 | 需要一盏灯放在卧室里
309 | need a lamp on a bedroom
310 |
311 | 63
312 | 00:05:04,920 --> 00:05:07,280
313 | 这是关于电动牙刷的第三条评论
314 | Here's a third review for an electric toothbrush
315 |
316 | 64
317 | 00:05:07,280 --> 00:05:09,600
318 | 我的牙科保健师推荐的
319 | My dental hygienist recommended
320 |
321 | 65
322 | 00:05:09,600 --> 00:05:12,640
323 | 关于电动牙刷的评论有点长
324 | Kind of a long review about the electric toothbrush
325 |
326 | 66
327 | 00:05:12,640 --> 00:05:17,920
328 | 这是关于搅拌机的评论,当时它说是季节性销售的17件套装系统
329 | This is a review for a blender when it said, so said 17 piece system on seasonal sale and
330 |
331 | 67
332 | 00:05:17,920 --> 00:05:18,920
333 | 诸如此类
334 | so on and so on
335 |
336 | 68
337 | 00:05:18,920 --> 00:05:20,280
338 | 这实际上是很多的文字
339 | This is actually a lot of text
340 |
341 | 69
342 | 00:05:20,280 --> 00:05:23,280
343 | 如果你愿意,可以随意暂停视频,读完这些文字
344 | If you want, feel free to pause the video and read through all this text
345 |
346 | 70
347 | 00:05:23,280 --> 00:05:28,480
348 | 但是,如果你想知道这些评论者写了什么,而不必停下来阅读所有的
349 | But what if you want to know what these reviewers wrote without having to stop and read all
350 |
351 | 71
352 | 00:05:28,480 --> 00:05:29,480
353 | 这方面的细节呢?
354 | this in detail?
355 |
356 | 72
357 | 00:05:29,480 --> 00:05:41,600
358 | 所以我要把 review_1 设为我们之前展示的那个产品评论
359 | So I'm going to set review_1 to be just the product review that we had up there
360 |
361 | 73
362 | 00:05:41,600 --> 00:05:45,320
363 | 我将把所有这些评论放到一个列表中
364 | I'm going to put all of these reviews into a list
365 |
366 | 74
367 | 00:05:45,320 --> 00:05:53,800
368 | 现在,如果我对这些评论实施一个for循环
369 | And now if I implement a for loop over the reviews
370 |
371 | 75
372 | 00:05:53,800 --> 00:06:01,240
373 | 这是我的提示,我要求它最多用20个字来总结它
374 | So here's my prompt and here I've asked it to summarize it in at most 20 words
375 |
376 | 76
377 | 00:06:01,240 --> 00:06:07,320
378 | 然后让它得到响应并打印出来
379 | Then let's have it get the response and print it out
380 |
381 | 77
382 | 00:06:07,320 --> 00:06:10,760
383 | 让我们运行这个程序
384 | And let's run that
385 |
386 | 78
387 | 00:06:10,760 --> 00:06:16,360
388 | 它打印出的第一条评论是熊猫玩具的评论,灯的总结评论
389 | And it prints out the first review is that PandaToy review, summary review of the lamp
390 |
391 | 79
392 | 00:06:16,360 --> 00:06:21,880
393 | 牙刷的摘要评论,然后是搅拌器
394 | summary review of the toothbrush, and then the blender
395 |
396 | 80
397 | 00:06:21,880 --> 00:06:29,800
398 | 因此,如果你有一个网站,你有数百条评论,你可以想象你如何
399 | And so if you have a website where you have hundreds of reviews, you can imagine how you
400 |
401 | 81
402 | 00:06:29,800 --> 00:06:35,360
403 | 使用它来建立一个控制面板,为大量的评论,生成简短的摘要
404 | might use this to build a dashboard, to take huge numbers of reviews, generate short summaries
405 |
406 | 82
407 | 00:06:35,360 --> 00:06:40,760
408 | 这样你或其他人就可以更快地浏览这些评论
409 | of them so that you or someone else can browse the reviews much more quickly
410 |
411 | 83
412 | 00:06:40,760 --> 00:06:46,200
413 | 然后,如果他们愿意,可以点击查看原始的长篇评论
414 | And then if they wish, maybe click in to see the original longer review
415 |
416 | 84
417 | 00:06:46,200 --> 00:06:51,640
418 | 这可以帮助你更高效地了解所有客户的想法
419 | And this can help you efficiently get a better sense of what all of your customers are thinking
420 |
421 | 85
422 | 00:06:51,640 --> 00:06:55,640
423 | 好了,总结就到这里
424 | All right, so that's it for summarizing
425 |
426 | 86
427 | 00:06:55,640 --> 00:07:00,960
428 | 我希望你能想象一下,如果你有任何有许多文本的应用
429 | And I hope that you can picture if you have any applications with many pieces of text
430 |
431 | 87
432 | 00:07:00,960 --> 00:07:05,680
433 | 你可以使用这样的提示来总结,帮助人们快速了解文字中的内容和各种文本
434 | how you can use prompts like these to summarize them to help people quickly get a sense of
435 |
436 | 88
437 | 00:07:05,680 --> 00:07:10,240
438 | 可以选择进一步深入挖掘
439 | what's in the text, the many pieces of text, and perhaps optionally dig in more
440 |
441 | 89
442 | 00:07:10,240 --> 00:07:12,520
443 | 如果有需要的话
444 | if they wish
445 |
446 | 90
447 | 00:07:12,520 --> 00:07:17,640
448 | 在下一个视频中,我们将看到大语言模型的另一个能力,即
449 | In the next video, we'll look at another capability of large language models, which is to make
450 |
451 | 91
452 | 00:07:17,640 --> 00:07:19,880
453 | 推断的能力
454 | inferences using text
455 |
456 | 92
457 | 00:07:19,880 --> 00:07:24,280
458 | 例如,如果你有一些产品评论数据
459 | For example, what if you had, again, product reviews, and you wanted to very quickly get
460 |
461 | 93
462 | 00:07:24,280 --> 00:07:29,680
463 | 你希望快速了解哪些评论具有积极或消极情感,该怎么办?
464 | a sense of which product reviews have a positive or a negative sentiment?
465 |
466 | 94
467 | 00:07:29,680 --> 00:07:49,840
468 | 让我们在下一个视频中看看如何实现这个功能
469 | Let's take a look at how to do that in the next video
470 |
471 |
--------------------------------------------------------------------------------
/subtitles/raw/prompt_eng_01_intro.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:09,000
3 | 欢迎学习《面向开发者的 ChatGPT Prompt 工程》课程
4 | Welcome to this course on ChatGPT Prompt Engineering for Developers
5 |
6 | 2
7 | 00:00:09,000 --> 00:00:14,000
8 | 很高兴能邀请到 Isa Fulford 和我一起授课
9 | I'm thrilled to have with me Iza Fulford to teach this along with me
10 |
11 | 3
12 | 00:00:14,000 --> 00:00:18,000
13 | 她是 OpenAI 的技术人员之一,曾建立了流行的
14 | She is a member of the technical staff of OpenAI and had built the popular
15 |
16 | 4
17 | 00:00:18,000 --> 00:00:23,000
18 | ChatGPT 检索插件,她大部分工作是教人们
19 | ChatGPT Retrieval plugin and a large part of her work has been teaching people
20 |
21 | 5
22 | 00:00:23,000 --> 00:00:27,000
23 | 如何在产品中使用LLM或大语言模型技术
24 | how to use LLM or large language model technology in products
25 |
26 | 6
27 | 00:00:27,000 --> 00:00:31,000
28 | 她还为OpenAI手册做出了贡献,教会人们如何使用提示
29 | She's also contributed to the OpenAI cookbook that teaches people prompting
30 |
31 | 7
32 | 00:00:31,000 --> 00:00:32,000
33 | 所以,很高兴有你参与
34 | So thrilled to have you with you
35 |
36 | 8
37 | 00:00:32,000 --> 00:00:37,000
38 | 我也很高兴能在这里与大家分享一些提示的最佳实践
39 | And I'm thrilled to be here and share some prompting best practices with you all
40 |
41 | 9
42 | 00:00:37,000 --> 00:00:42,000
43 | 在互联网上有很多关于提示资料以及一些文章
44 | So there's been a lot of material on the internet for prompting with articles
45 |
46 | 10
47 | 00:00:42,000 --> 00:00:45,000
48 | 比如,每个人都必须知道的30个提示
49 | like 30 prompts everyone has to know
50 |
51 | 11
52 | 00:00:45,000 --> 00:00:50,000
53 | 许多人正在使用 ChatGPT 的 Web 用户界面
54 | A lot of that has been focused on the ChatGPT web user interface
55 |
56 | 12
57 | 00:00:50,000 --> 00:00:54,000
58 | 来完成特定而且通常是一次性的任务
59 | which many people are using to do specific and often one-off tasks
60 |
61 | 13
62 | 00:00:54,000 --> 00:01:00,000
63 | 但作为一名开发者,我认为LLMs和大语言模型的强大也是不可忽视的
64 | But I think the power of LLMs, large language models as a developer too
65 |
66 | 14
67 | 00:01:00,000 --> 00:01:04,000
68 | 那就是通过API调用LLM来快速构建软件应用程序
69 | that is using API calls to LLMs to quickly build software applications
70 |
71 | 15
72 | 00:01:04,000 --> 00:01:08,000
73 | 我认为这仍然被严重低估
74 | I think that is still very underappreciated
75 |
76 | 16
77 | 00:01:08,000 --> 00:01:12,000
78 | 事实上,我在AI Fund的团队,也就是Deep Learning.AI的姐妹公司
79 | In fact, my team at AI Fund, which is a sister company to Deep Learning.AI
80 |
81 | 17
82 | 00:01:12,000 --> 00:01:16,000
83 | 一直在与许多初创公司、不同项目合作
84 | has been working with many startups on applying these technologies
85 |
86 | 18
87 | 00:01:16,000 --> 00:01:18,000
88 | 来应用这些技术
89 | to many different applications
90 |
91 | 19
92 | 00:01:18,000 --> 00:01:23,000
93 | 看到LLM API能够让开发者快速建立一些东西
94 | And it's been exciting to see what LLM APIs can enable developers
95 |
96 | 20
97 | 00:01:23,000 --> 00:01:25,000
98 | 这很令人兴奋
99 | to very quickly build
100 |
101 | 21
102 | 00:01:25,000 --> 00:01:29,000
103 | 所以在这个课程中,我们将与你分享一些可能性
104 | So in this course, we'll share with you some of the possibilities
105 |
106 | 22
107 | 00:01:29,000 --> 00:01:34,000
108 | 你可以做什么,以及如何做的最佳实践
109 | for what you can do as well as best practices for how you can do them
110 |
111 | 23
112 | 00:01:34,000 --> 00:01:36,000
113 | 这里会覆盖很多资料
114 | There's a lot of material to cover
115 |
116 | 24
117 | 00:01:36,000 --> 00:01:41,000
118 | 首先,你将学习一些软件开发的提示词最佳实践
119 | First, you'll learn some prompting best practices for software development
120 |
121 | 25
122 | 00:01:41,000 --> 00:01:45,000
123 | 然后,我们将涵盖一些常见的用例、总结、推断
124 | Then we'll cover some common use cases, summarizing, inferring
125 |
126 | 26
127 | 00:01:45,000 --> 00:01:50,000
128 | 转化、扩展,然后使用LLM建立一个聊天机器人
129 | transforming, expanding, and then you'll build a chatbot using an LLM
130 |
131 | 27
132 | 00:01:50,000 --> 00:01:53,000
133 | 我们希望这将激发你
134 | We hope that this will spark your imagination about new applications
135 |
136 | 28
137 | 00:01:53,000 --> 00:01:55,000
138 | 开发新应用的想象力
139 | that you can build
140 |
141 | 29
142 | 00:01:55,000 --> 00:01:58,000
143 | 因此,在大型语言模型或LLM的发展中
144 | So in the development of large language models or LLMs
145 |
146 | 30
147 | 00:01:58,000 --> 00:02:02,000
148 | 大体上有两种类型的LLM,我把它们称为
149 | there have been broadly two types of LLMs, which I'm going to refer to
150 |
151 | 31
152 | 00:02:02,000 --> 00:02:06,000
153 | 基础LLM和指令学习LLM
154 | as base LLMs and instruction-tuned LLMs
155 |
156 | 32
157 | 00:02:06,000 --> 00:02:11,000
158 | 基础LLM已经被训练成基于文本训练数据来预测下一个单词
159 | So base LLM has been trained to predict the next word based on text training data
160 |
161 | 33
162 | 00:02:11,000 --> 00:02:15,000
163 | 通常通过互联网和其他来源训练大量数据
164 | often trained on a large amount of data from the internet and other sources
165 |
166 | 34
167 | 00:02:15,000 --> 00:02:19,000
168 | 并计算出下一个最可能出现的词是什么
169 | to figure out what's the next most likely word to follow
170 |
171 | 35
172 | 00:02:19,000 --> 00:02:24,000
173 | 比如,你输入这个提示:"从前有一只独角兽"
174 | So for example, if you were to prompt this, once upon a time there was a unicorn
175 |
176 | 36
177 | 00:02:24,000 --> 00:02:28,000
178 | 它会进行补全,并预测接下来的几个词是
179 | it may complete this, that is, it may predict the next several words are
180 |
181 | 37
182 | 00:02:28,000 --> 00:02:31,000
183 | "和所有独角兽朋友一起生活在一个神奇的森林里"
184 | that live in a magical forest with all unicorn friends
185 |
186 | 38
187 | 00:02:31,000 --> 00:02:35,000
188 | 但是如果你是用"法国的首都是什么"作为提示
189 | But if you were to prompt this with what is the capital of France
190 |
191 | 39
192 | 00:02:35,000 --> 00:02:40,000
193 | 那么根据互联网上的文章
194 | then based on what articles on the internet might have
195 |
196 | 40
197 | 00:02:40,000 --> 00:02:44,000
198 | 很有可能是,基础LLM会以下列方式完成这个任务
199 | it's quite possible that the base LLM will complete this with
200 |
201 | 41
202 | 00:02:44,000 --> 00:02:48,000
203 | 什么是法国最大的城市,什么是法国的人口,等等
204 | what is France's largest city, what is France's population, and so on
205 |
206 | 42
207 | 00:02:48,000 --> 00:02:52,000
208 | 因为互联网上的文章,可能会列出
209 | because articles on the internet could quite plausibly be lists of quiz questions
210 |
211 | 43
212 | 00:02:52,000 --> 00:02:55,000
213 | 关于法国的小测验问题列表
214 | about the country of France
215 |
216 | 44
217 | 00:02:55,000 --> 00:03:00,000
218 | 与此相反,指令学习LLM,发展势头较猛
219 | In contrast, an instruction-tuned LLM, which is where a lot of momentum
220 |
221 | 45
222 | 00:03:00,000 --> 00:03:04,000
223 | LLM的研究和实践一直在进行
224 | of LLM research and practice has been going
225 |
226 | 46
227 | 00:03:04,000 --> 00:03:08,000
228 | 一个经过指令学习的LLM已经被训练得能够遵循指令
229 | an instruction-tuned LLM has been trained to follow instructions
230 |
231 | 47
232 | 00:03:08,000 --> 00:03:11,000
233 | 因此,如果你问它,法国的首都是什么?
234 | So if you were to ask it, what is the capital of France
235 |
236 | 48
237 | 00:03:11,000 --> 00:03:15,000
238 | 它很可能输出法国的首都是巴黎
239 | it's much more likely to output something like the capital of France is Paris
240 |
241 | 49
242 | 00:03:15,000 --> 00:03:19,000
243 | 因此,指令学习的LLM的典型训练方式是
244 | So the way that instruction-tuned LLMs are typically trained is
245 |
246 | 50
247 | 00:03:19,000 --> 00:03:23,000
248 | 从一个在大量文本数据上训练过的基础LLM开始
249 | you start off with a base LLM that's been trained on a huge amount of text data
250 |
251 | 51
252 | 00:03:23,000 --> 00:03:28,000
253 | 然后进一步训练它,用输入和输出来进一步微调它
254 | and further train it, further fine-tune it with inputs and outputs
255 |
256 | 52
257 | 00:03:28,000 --> 00:03:32,000
258 | 这些输入和输出都是指令,也是遵循这些指令的良好尝试
259 | that are instructions and good attempts to follow those instructions
260 |
261 | 53
262 | 00:03:32,000 --> 00:03:36,000
263 | 然后经常使用一种叫做RLHF的技术进一步完善
264 | and then often further refine using a technique called RLHF
265 |
266 | 54
267 | 00:03:36,000 --> 00:03:41,000
268 | 从人类反馈中进行强化学习,以使系统能够更好地
269 | reinforcement learning from human feedback, to make the system better able
270 |
271 | 55
272 | 00:03:41,000 --> 00:03:43,000
273 | 提供帮助并遵循指令
274 | to be helpful and follow instructions
275 |
276 | 56
277 | 00:03:43,000 --> 00:03:47,000
278 | 因为经过指令学习的LLM已经被训练得很有帮助
279 | Because instruction-tuned LLMs have been trained to be helpful
280 |
281 | 57
282 | 00:03:47,000 --> 00:03:51,000
283 | 诚实且无害,因此,举例来说,它们不太可能输出
284 | honest, and harmless, so for example, they're less likely to output
285 |
286 | 58
287 | 00:03:51,000 --> 00:03:55,000
288 | 那些与基础LLM相比,会出问题的文本,如有害的输出
289 | problematic text, such as toxic outputs, compared to base LLM
290 |
291 | 59
292 | 00:03:55,000 --> 00:03:59,000
293 | 很多实际应用场景已经开始向
294 | a lot of the practical usage scenarios have been shifting
295 |
296 | 60
297 | 00:03:59,000 --> 00:04:01,000
298 | 指令学习LLM转移
299 | toward instruction-tuned LLMs
300 |
301 | 61
302 | 00:04:01,000 --> 00:04:04,000
303 | 你在互联网上找到的一些最佳实践可能更适用于基础LLM
304 | Some of the best practices you find on the internet may be more suited
305 |
306 | 62
307 | 00:04:04,000 --> 00:04:08,000
308 | 但对于今天的大多数实际应用情况来说,它们可能不太合适
309 | for a base LLM, but for most practical applications today
310 |
311 | 63
312 | 00:04:08,000 --> 00:04:13,000
313 | 我们建议大多数人多关注指令学习LLM
314 | we would recommend most people instead focus on instruction-tuned LLMs
315 |
316 | 64
317 | 00:04:13,000 --> 00:04:17,000
318 | 它们更容易使用,而且由于OpenAI
319 | which are easier to use, and also because of the work of OpenAI
320 |
321 | 65
322 | 00:04:17,000 --> 00:04:22,000
323 | 和其他LLM公司的工作,也将变得更加安全和一致
324 | and other LLM companies, becoming safer and more aligned
325 |
326 | 66
327 | 00:04:22,000 --> 00:04:27,000
328 | 因此,本课程将重点介绍指令学习LLM的最佳实践
329 | So this course will focus on best practices for instruction-tuned LLMs
330 |
331 | 67
332 | 00:04:27,000 --> 00:04:32,000
333 | 这也是我们建议你在大多数应用中使用的
334 | which is what we recommend you use for most of your applications
335 |
336 | 68
337 | 00:04:32,000 --> 00:04:36,000
338 | 在继续之前,我想感谢来自OpenAI
339 | Before moving on, I just want to acknowledge the team from OpenAI
340 |
341 | 69
342 | 00:04:36,000 --> 00:04:39,000
343 | 和DeepLearning.ai的团队
344 | and DeepLearning.ai that had contributed to the materials
345 |
346 | 70
347 | 00:04:39,000 --> 00:04:42,000
348 | 他们为我和Isa将要介绍的资料做出了贡献
349 | that Isa and I will be presenting
350 |
351 | 71
352 | 00:04:42,000 --> 00:04:45,000
353 | 我非常感谢Andrew Main, Joe Palermo, Boris Power
354 | I'm very grateful to Andrew Main, Joe Palermo, Boris Power
355 |
356 | 72
357 | 00:04:45,000 --> 00:04:49,000
358 | Ted Sanders,以及来自OpenAI的Lilian Wang
359 | Ted Sanders, and Lilian Wang from OpenAI that were very involved
360 |
361 | 73
362 | 00:04:49,000 --> 00:04:53,000
363 | 与我们一起集思广益,审核资料
364 | with us brainstorming materials, vetting the materials to put together
365 |
366 | 74
367 | 00:04:53,000 --> 00:04:55,000
368 | 并做成这个简短的课程
369 | the curriculum for this short course
370 |
371 | 75
372 | 00:04:55,000 --> 00:04:58,000
373 | 我也很感谢DeepLearning方面的工作
374 | And I'm also grateful on the DeepLearning side for the work
375 |
376 | 76
377 | 00:04:58,000 --> 00:05:01,000
378 | Jeff Ludwig、Eddie Hsu和Tommy Nelson的工作
379 | of Jeff Ludwig, Eddie Hsu, and Tommy Nelson
380 |
381 | 77
382 | 00:05:01,000 --> 00:05:06,000
383 | 因此,当你使用一个指令学习LLM时,可以将其看作是
384 | So when you use an instruction-tuned LLM, think of giving instructions
385 |
386 | 78
387 | 00:05:06,000 --> 00:05:10,000
388 | 向另一个人发出指令,比如一个聪明但不知道
389 | to another person, say someone that's smart but doesn't know
390 |
391 | 79
392 | 00:05:10,000 --> 00:05:12,000
393 | 任务细节的人
394 | the specifics of your task
395 |
396 | 80
397 | 00:05:12,000 --> 00:05:16,000
398 | 因此,当一个LLM不工作时,有时是因为指令
399 | So when an LLM doesn't work, sometimes it's because the instructions
400 |
401 | 81
402 | 00:05:16,000 --> 00:05:17,000
403 | 不够清楚
404 | weren't clear enough
405 |
406 | 82
407 | 00:05:17,000 --> 00:05:20,000
408 | 例如,如果你说,请给我写一些
409 | For example, if you were to say, please write me something
410 |
411 | 83
412 | 00:05:20,000 --> 00:05:22,000
413 | 关于艾伦-图灵的东西
414 | about Alan Turing
415 |
416 | 84
417 | 00:05:22,000 --> 00:05:26,000
418 | 那么,除此之外,明确以下几点也会有所帮助
419 | Well, in addition to that, it can be helpful to be clear about
420 |
421 | 85
422 | 00:05:26,000 --> 00:05:30,000
423 | 你想让文章侧重于他的科学工作
424 | whether you want the text to focus on his scientific work
425 |
426 | 86
427 | 00:05:30,000 --> 00:05:34,000
428 | 他的个人生活、他在历史上的作用或其他方向
429 | or his personal life or his role in history or something else
430 |
431 | 87
432 | 00:05:34,000 --> 00:05:39,000
433 | 如果你指定了想要文本的语调
434 | And if you specify what you want the tone of the text to be
435 |
436 | 88
437 | 00:05:39,000 --> 00:05:43,000
438 | 它是否会根据指定的语调来写,比如像专业记者写的那样
439 | should it take on the tone like a professional journalist would write
440 |
441 | 89
442 | 00:05:43,000 --> 00:05:46,000
443 | 还是更像随手写给朋友的轻松语气?
444 | or is it more of a casual note that you dash off to a friend?
445 |
446 | 90
447 | 00:05:46,000 --> 00:05:47,000
448 | 这一点是成立的
449 | That holds
450 |
451 | 91
452 | 00:05:47,000 --> 00:05:49,000
453 | LLM会产生你想要的东西
454 | The LLM generates what you want
455 |
456 | 92
457 | 00:05:49,000 --> 00:05:52,000
458 | 当然,如果你想象是自己在问,比如
459 | And of course, if you picture yourself asking, say
460 |
461 | 93
462 | 00:05:52,000 --> 00:05:56,000
463 | 一个刚毕业的大学生为你完成这项任务
464 | a fresh college graduate to carry out this task for you
465 |
466 | 94
467 | 00:05:56,000 --> 00:05:59,000
468 | 如果你甚至可以指定他们应该阅读哪些文本片段
469 | if you can even specify what snippets of text they should read
470 |
471 | 95
472 | 00:05:59,000 --> 00:06:02,000
473 | 提前写出这篇关于艾伦-图灵的文章
474 | in advance to write this text about Alan Turing
475 |
476 | 96
477 | 00:06:02,000 --> 00:06:06,000
478 | 那么,这能成功让那个刚毕业的大学生
479 | then that even better sets up that fresh college grad for success
480 |
481 | 97
482 | 00:06:06,000 --> 00:06:09,000
483 | 更好的为你完成这项任务
484 | to carry out this task for you
485 |
486 | 98
487 | 00:06:09,000 --> 00:06:13,000
488 | 因此,在接下来的视频中,你会看到如何清晰且明确
489 | So in the next video, you see examples of how to be clear
490 |
491 | 99
492 | 00:06:13,000 --> 00:06:17,000
493 | 描述提示,这是一个重要的LLM提示准则
494 | and specific, which is an important principle of prompting LLMs
495 |
496 | 100
497 | 00:06:17,000 --> 00:06:21,000
498 | 而且你还将从Isa那里学到了第二个提示词准则
499 | And you also learn from Isa a second principle of prompting
500 |
501 | 101
502 | 00:06:21,000 --> 00:06:24,000
503 | 那就是给LLM时间来思考
504 | that is giving a LLM time to think
505 |
506 | 102
507 | 00:06:24,000 --> 00:06:29,000
508 | 因此,让我们继续观看下一个视频
509 | So with that, let's go on to the next video
510 |
511 |
--------------------------------------------------------------------------------
/chinese_subtitles/prompt_eng_05_inferring_chinese.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:07,080
3 | 接下来的这段视频是关于推断的
4 |
5 | 2
6 | 00:00:07,080 --> 00:00:09,540
7 | 我喜欢把这些任务看成是模型将一个文本作为输入并进行某种分析
8 |
9 | 3
10 | 00:00:09,540 --> 00:00:12,160
11 | 作为输入的文本并进行某种分析
12 |
13 | 4
14 | 00:00:12,160 --> 00:00:14,640
15 | 所以这可能是提取标签
16 |
17 | 5
18 | 00:00:14,640 --> 00:00:19,280
19 | 提取名字,理解文本的情感,诸如此类的事情
20 |
21 | 6
22 | 00:00:19,280 --> 00:00:22,480
23 | 因此,如果你想提取一个情感
24 |
25 | 7
26 | 00:00:22,480 --> 00:00:24,240
27 | 正面或负面的文本
28 |
29 | 8
30 | 00:00:24,240 --> 00:00:26,920
31 | 在传统的机器学习工作流程中
32 |
33 | 9
34 | 00:00:26,920 --> 00:00:29,680
35 | 你必须要收集标签数据集
36 |
37 | 10
38 | 00:00:29,680 --> 00:00:33,200
39 | 训练一个模型,弄清楚如何在云端的某个地方部署这个模型
40 |
41 | 11
42 | 00:00:33,200 --> 00:00:34,240
43 | 并做出推断
44 |
45 | 12
46 | 00:00:34,240 --> 00:00:35,320
47 | 这可以很好地工作
48 |
49 | 13
50 | 00:00:35,320 --> 00:00:38,560
51 | 但要经历这个过程,实在是一件很费力的事情
52 |
53 | 14
54 | 00:00:38,560 --> 00:00:43,680
55 | 此外,对于每一项任务,如情感分析与提取名字或其他东西
56 |
57 | 15
58 | 00:00:43,680 --> 00:00:46,920
59 | 你必须训练和部署一个单独的模型
60 |
61 | 16
62 | 00:00:46,920 --> 00:00:48,760
63 | 关于大语言模型的一个好处是
64 |
65 | 17
66 | 00:00:48,760 --> 00:00:51,400
67 | 对于许多像这样的任务
68 |
69 | 18
70 | 00:00:51,400 --> 00:00:56,240
71 | 你可以只写一个提示,然后让它马上开始生成结果
72 |
73 | 19
74 | 00:00:56,240 --> 00:01:00,080
75 | 这给应用程序的开发带来了巨大的提速
76 |
77 | 20
78 | 00:01:00,080 --> 00:01:02,360
79 | 你也可以只使用一个模型
80 |
81 | 21
82 | 00:01:02,360 --> 00:01:05,520
83 | 一个API来完成许多不同的任务,而不需要
84 |
85 | 22
86 | 00:01:05,520 --> 00:01:09,200
87 | 弄清楚如何训练和部署许多不同的模型
88 |
89 | 23
90 | 00:01:09,200 --> 00:01:13,840
91 | 有了这些,让我们跳进代码,看看你如何利用这个优势
92 |
93 | 24
94 | 00:01:13,840 --> 00:01:16,160
95 | 这里是我们通常的初始代码
96 |
97 | 25
98 | 00:01:16,160 --> 00:01:19,200
99 | 运行这个
100 |
101 | 26
102 | 00:01:19,200 --> 00:01:24,640
103 | 我使用的最多的例子,是关于一盏灯的评论
104 |
105 | 27
106 | 00:01:24,640 --> 00:01:26,880
107 | 卧室里需要一盏漂亮的灯
108 |
109 | 28
110 | 00:01:26,880 --> 00:01:30,240
111 | 和额外存储空间的家具,等等
112 |
113 | 29
114 | 00:01:31,920 --> 00:01:39,400
115 | 让我写一个提示,对这个的情绪进行分类
116 |
117 | 30
118 | 00:01:39,400 --> 00:01:44,520
119 | 如果我想让系统告诉我这是什么情绪
120 |
121 | 31
122 | 00:01:44,520 --> 00:01:55,720
123 | 我可以直接写出 "以下产品评论的情感是什么"
124 |
125 | 32
126 | 00:01:58,960 --> 00:02:04,520
127 | 加上通常的分隔符和评论文本等等,然后让我们运行这个提示
128 |
129 | 33
130 | 00:02:04,640 --> 00:02:08,880
131 | 这表示该产品评论的情绪是积极的
132 |
133 | 34
134 | 00:02:08,880 --> 00:02:11,400
135 | 这实际上似乎很正确
136 |
137 | 35
138 | 00:02:11,400 --> 00:02:14,720
139 | 这盏灯并不完美,但这位顾客看起来很满意
140 |
141 | 36
142 | 00:02:14,720 --> 00:02:17,000
143 | 这似乎是一个关心客户和产品的伟大公司
144 |
145 | 37
146 | 00:02:17,000 --> 00:02:20,360
147 | 我认为积极的情绪似乎是正确的答案
148 |
149 | 38
150 | 00:02:20,360 --> 00:02:22,440
151 | 现在,这就把整个句子打印出来
152 |
153 | 39
154 | 00:02:22,440 --> 00:02:25,480
155 | 该产品评论的情绪是积极的
156 |
157 | 40
158 | 00:02:25,480 --> 00:02:31,720
159 | 如果你想给出一个更简洁的回答,以便于后期处理
160 |
161 | 41
162 | 00:02:31,720 --> 00:02:35,120
163 | 我可以在这个提示中加入另一条指令
164 |
165 | 42
166 | 00:02:35,120 --> 00:02:37,320
167 | 只给你一个单词的答案
168 |
169 | 43
170 | 00:02:37,320 --> 00:02:38,960
171 | 正面或负面
172 |
173 | 44
174 | 00:02:38,960 --> 00:02:42,840
175 | 它只是像这样打印出正面,这对一段文字来说更容易
176 |
177 | 45
178 | 00:02:42,840 --> 00:02:46,760
179 | 来处理这个输出,并对它做一些处理
180 |
181 | 46
182 | 00:02:46,760 --> 00:02:49,320
183 | 让我们看一下另一个提示
184 |
185 | 47
186 | 00:02:49,320 --> 00:02:52,160
187 | 再来一遍,仍然使用关于台灯的评论
188 |
189 | 48
190 | 00:02:52,160 --> 00:02:55,760
191 | 在这里,我让它识别一个列表
192 |
193 | 49
194 | 00:02:55,760 --> 00:02:58,360
195 | 以下评论的作者所表达的情绪
196 |
197 | 50
198 | 00:02:58,360 --> 00:03:01,840
199 | 在这个列表中包括不超过五个项目
200 |
201 | 51
202 | 00:03:01,840 --> 00:03:04,680
203 | 大语言模型在以下方面相当出色
204 |
205 | 52
206 | 00:03:04,680 --> 00:03:08,320
207 | 从一段文本中提取特定的东西
208 |
209 | 53
210 | 00:03:08,320 --> 00:03:11,760
211 | 在这种情况下,我们要表达的是情绪
212 |
213 | 54
214 | 00:03:11,760 --> 00:03:14,720
215 | 这对于了解
216 |
217 | 55
218 | 00:03:14,720 --> 00:03:18,320
219 | 你的客户对某一特定产品的看法
220 |
221 | 56
222 | 00:03:18,320 --> 00:03:21,480
223 | 对于很多客户支持机构来说,了解客户对产品的看法很重要
224 |
225 | 57
226 | 00:03:21,480 --> 00:03:26,640
227 | 理解一个特定的用户是否对你的产品非常不满是非常重要的
228 |
229 | 58
230 | 00:03:26,640 --> 00:03:30,400
231 | 你可能有这样一个不同的分类问题
232 |
233 | 59
234 | 00:03:30,400 --> 00:03:33,040
235 | 下面这篇评论的作者是否在表达愤怒?
236 |
237 | 60
238 | 00:03:33,040 --> 00:03:34,880
239 | 因为如果某人真的很生气
240 |
241 | 61
242 | 00:03:34,880 --> 00:03:39,840
243 | 它可能值得付出额外的关注来获得客户评论
244 |
245 | 62
246 | 00:03:39,840 --> 00:03:41,920
247 | 获得客户支持或成功拿下客户
248 |
249 | 63
250 | 00:03:41,920 --> 00:03:46,000
251 | 伸出援手,弄清楚发生了什么事,并为客户把事情做好
252 |
253 | 64
254 | 00:03:46,000 --> 00:03:48,960
255 | 在这种情况下,客户并不生气
256 |
257 | 65
258 | 00:03:48,960 --> 00:03:52,240
259 | 注意,有了监督学习
260 |
261 | 66
262 | 00:03:52,240 --> 00:03:55,400
263 | 如果我想建立所有这些分类器
264 |
265 | 67
266 | 00:03:55,400 --> 00:03:58,880
267 | 我不可能用监督学习在短短几分钟内完成这些工作
268 |
269 | 68
270 | 00:03:58,880 --> 00:04:04,040
271 | 而你在这段视频中看到我这样做了
272 |
273 | 69
274 | 00:04:04,040 --> 00:04:08,520
275 | 我鼓励你暂停这个视频,并尝试改变其中的一些提示
276 |
277 | 70
278 | 00:04:08,520 --> 00:04:12,680
279 | 也许问一下客户是否表达了喜悦之情,或者问一下是否有
280 |
281 | 71
282 | 00:04:12,680 --> 00:04:15,320
283 | 任何缺失的部分,看看你是否能得到一个提示来
284 |
285 | 72
286 | 00:04:15,320 --> 00:04:20,120
287 | 对这个实验室进行不同的推断
288 |
289 | 73
290 | 00:04:20,600 --> 00:04:28,360
291 | 让我再展示一下你可以用这个系统做的一些事情
292 |
293 | 74
294 | 00:04:28,360 --> 00:04:35,360
295 | 特别是从客户评论中提取更丰富的信息
296 |
297 | 75
298 | 00:04:35,640 --> 00:04:39,920
299 | 信息提取是NLP的一部分
300 |
301 | 76
302 | 00:04:39,920 --> 00:04:43,160
303 | 自然语言处理的一部分,它涉及到将一段文本
304 |
305 | 77
306 | 00:04:43,160 --> 00:04:48,240
307 | 并从文本中提取出你想知道的某些东西
308 |
309 | 78
310 | 00:04:48,240 --> 00:04:50,600
311 | 在这个提示中,我问它
312 |
313 | 79
314 | 00:04:50,600 --> 00:04:52,840
315 | 确定以下项目
316 |
317 | 80
318 | 00:04:52,840 --> 00:04:57,360
319 | 购买的物品和制造该物品的公司名称
320 |
321 | 81
322 | 00:04:57,360 --> 00:05:05,320
323 | 同样,如果你想从一个在线购物的电子商务网站上总结出许多评论
324 |
325 | 82
326 | 00:05:05,320 --> 00:05:07,920
327 | 对于你收集的大量评论来说
328 |
329 | 83
330 | 00:05:07,920 --> 00:05:10,160
331 | 弄清楚这些评论所涉及的物品可能会很有用
332 |
333 | 84
334 | 00:05:10,160 --> 00:05:13,600
335 | 可以通过分析评论中的内容,找出评论涉及的物品制造商
336 |
337 | 85
338 | 00:05:13,600 --> 00:05:16,680
339 | 并确定积极和消极情绪
340 |
341 | 86
342 | 00:05:16,680 --> 00:05:20,480
343 | 以追踪特定物品或制造商的积极或消极情绪趋势
344 |
345 | 87
346 | 00:05:20,480 --> 00:05:24,960
347 | 在这个例子中,我将要求它把响应格式化为
348 |
349 | 88
350 | 00:05:24,960 --> 00:05:29,560
351 | 一个以项目和品牌为键的JSON对象
352 |
353 | 89
354 | 00:05:29,560 --> 00:05:33,840
355 | 如果我这样做了,它就会说这个物品是一盏灯
356 |
357 | 90
358 | 00:05:33,840 --> 00:05:35,880
359 | 品牌是Luminar
360 |
361 | 91
362 | 00:05:35,880 --> 00:05:38,000
363 | 你可以很容易地将其加载到
364 |
365 | 92
366 | 00:05:38,000 --> 00:05:42,880
367 | Python字典中,然后对这个输出做额外的处理
368 |
369 | 93
370 | 00:05:42,880 --> 00:05:44,600
371 | 在我们所经历的例子中
372 |
373 | 94
374 | 00:05:44,600 --> 00:05:48,640
375 | 你看到了如何写一个提示来识别情感
376 |
377 | 95
378 | 00:05:48,640 --> 00:05:50,960
379 | 弄清某人是否生气
380 |
381 | 96
382 | 00:05:50,960 --> 00:05:54,600
383 | 然后再提取物品和品牌
384 |
385 | 97
386 | 00:05:54,600 --> 00:06:01,920
387 | 提取所有这些信息的一个方法是使用三或四个提示语
388 |
389 | 98
390 | 00:06:01,920 --> 00:06:06,400
391 | 并调用三次或四次get_completion
392 |
393 | 99
394 | 00:06:06,400 --> 00:06:09,960
395 | 一次一次地提取这些不同的字段
396 |
397 | 100
398 | 00:06:09,960 --> 00:06:13,080
399 | 但事实证明,你实际上可以只写一个提示符
400 |
401 | 101
402 | 00:06:13,080 --> 00:06:16,480
403 | 来同时提取所有这些信息
404 |
405 | 102
406 | 00:06:16,480 --> 00:06:18,960
407 | 比方说识别以下项目
408 |
409 | 103
410 | 00:06:18,960 --> 00:06:23,040
411 | 提取情绪,是评论者表达愤怒
412 |
413 | 104
414 | 00:06:23,040 --> 00:06:25,840
415 | 项目的购买,公司的动画
416 |
417 | 105
418 | 00:06:25,840 --> 00:06:33,480
419 | 然后在这里,我还要告诉它把愤怒值格式化为一个布尔值
420 |
421 | 106
422 | 00:06:33,480 --> 00:06:35,960
423 | 让我运行它
424 |
425 | 107
426 | 00:06:35,960 --> 00:06:43,480
427 | 这将输出一个JSON,其中情绪是积极的
428 |
429 | 108
430 | 00:06:43,480 --> 00:06:45,880
431 | 愤怒,然后在false周围没有引号
432 |
433 | 109
434 | 00:06:45,880 --> 00:06:48,840
435 | 因为它也只是把它输出为一个布尔值
436 |
437 | 110
438 | 00:06:48,840 --> 00:06:52,520
439 | 提取出"lamp with additional storage"作为物品,而不仅仅是"lamp"
440 |
441 | 111
442 | 00:06:52,520 --> 00:06:53,880
443 | 看起来还不错
444 |
445 | 112
446 | 00:06:53,880 --> 00:06:57,760
447 | 这种方法让你只需一个提示
448 |
449 | 113
450 | 00:06:57,760 --> 00:07:02,400
451 | 就可以从一段文本中提取多个字段
452 |
453 | 114
454 | 00:07:02,400 --> 00:07:05,200
455 | 像往常一样,请随意暂停视频
456 |
457 | 115
458 | 00:07:05,200 --> 00:07:08,160
459 | 并在此基础上试玩一下,感受不同变化
460 |
461 | 116
462 | 00:07:08,160 --> 00:07:12,080
463 | 或者甚至可以尝试输入一个完全不同的评论,看看你是否
464 |
465 | 117
466 | 00:07:12,080 --> 00:07:15,480
467 | 能否仍然准确地提取这些东西
468 |
469 | 118
470 | 00:07:15,480 --> 00:07:19,440
471 | 现在,我看到大型语言模型很酷的应用之一
472 |
473 | 119
474 | 00:07:19,440 --> 00:07:22,600
475 | 是推断主题
476 |
477 | 120
478 | 00:07:22,600 --> 00:07:25,000
479 | 给出一段长的文字
480 |
481 | 121
482 | 00:07:25,000 --> 00:07:28,040
483 | 这段文字是关于什么的?
484 |
485 | 122
486 | 00:07:28,040 --> 00:07:29,480
487 | 主题是什么?
488 |
489 | 123
490 | 00:07:29,480 --> 00:07:33,360
491 | 这是一篇虚构的报纸文章,关于如何
492 |
493 | 124
494 | 00:07:33,360 --> 00:07:37,720
495 | 政府工作人员对他们所工作的机构的感受
496 |
497 | 125
498 | 00:07:37,720 --> 00:07:41,440
499 | 最近由政府等进行的调查
500 |
501 | 126
502 | 00:07:41,440 --> 00:07:43,160
503 | 结果审查,NASA是
504 |
505 | 127
506 | 00:07:43,160 --> 00:07:46,400
507 | 一个受欢迎的部门,满意度很高
508 |
509 | 128
510 | 00:07:46,400 --> 00:07:48,000
511 | 我是NASA的粉丝
512 |
513 | 129
514 | 00:07:48,000 --> 00:07:51,040
515 | 喜欢他们所做的工作,但这是一篇虚构的文章
516 |
517 | 130
518 | 00:07:51,040 --> 00:07:53,280
519 | 鉴于这样的文章
520 |
521 | 131
522 | 00:07:53,280 --> 00:07:57,920
523 | 我们可以用这个提示来问它
524 |
525 | 132
526 | 00:07:57,920 --> 00:08:03,320
527 | 确定以下文本中讨论的五个主题
528 |
529 | 133
530 | 00:08:03,320 --> 00:08:05,760
531 | 让我们把每一项都写成一到两个字的长度
532 |
533 | 134
534 | 00:08:05,760 --> 00:08:09,320
535 | 为我的回答,用逗号分隔的列表
536 |
537 | 135
538 | 00:08:09,320 --> 00:08:11,160
539 | 如果我们运行这个
540 |
541 | 136
542 | 00:08:11,160 --> 00:08:14,680
543 | 我们就会发现,这篇文章是关于政府调查的
544 |
545 | 137
546 | 00:08:14,680 --> 00:08:17,880
547 | 是关于工作满意度的,是关于NASA的,等等
548 |
549 | 138
550 | 00:08:17,880 --> 00:08:23,320
551 | 总的来说,我认为相当不错的主题列表的提取
552 |
553 | 139
554 | 00:08:23,320 --> 00:08:28,280
555 | 当然,你也可以把它分开,这样你就可以得到
556 |
557 | 140
558 | 00:08:28,280 --> 00:08:34,360
559 | 一个包含这篇文章所涉及的五个主题的Python列表
560 |
561 | 141
562 | 00:08:34,360 --> 00:08:38,600
563 | 如果你有一个文章的集合,并提取主题
564 |
565 | 142
566 | 00:08:38,600 --> 00:08:40,800
567 | 那么你还可以使用
568 |
569 | 143
570 | 00:08:40,800 --> 00:08:45,640
571 | 一个大语言模型来帮助你索引到不同的主题
572 |
573 | 144
574 | 00:08:45,640 --> 00:08:48,560
575 | 让我用一个稍微不同的主题列表
576 |
577 | 145
578 | 00:08:48,560 --> 00:08:52,240
579 | 比方说,我们是一个新闻网站或其他什么
580 |
581 | 146
582 | 00:08:52,240 --> 00:08:54,720
583 | 而这些是我们追踪的主题
584 |
585 | 147
586 | 00:08:54,720 --> 00:08:56,480
587 | NASA,当地政府,工程
588 |
589 | 148
590 | 00:08:56,480 --> 00:08:59,480
591 | 员工满意度,联邦政府
592 |
593 | 149
594 | 00:08:59,480 --> 00:09:01,680
595 | 比方说,你想弄清楚
596 |
597 | 150
598 | 00:09:01,680 --> 00:09:03,280
599 | 给出一篇新闻文章
600 |
601 | 151
602 | 00:09:03,280 --> 00:09:07,720
603 | 这篇新闻报道中涉及哪些主题
604 |
605 | 152
606 | 00:09:07,720 --> 00:09:10,760
607 | 这里有一个提示,我可以使用
608 |
609 | 153
610 | 00:09:10,760 --> 00:09:13,720
611 | 我想说的是,确定 "有趣的主题清单 "中的每一项
612 |
613 | 154
614 | 00:09:13,720 --> 00:09:16,840
615 | 是否是下面文本中的一个主题
616 |
617 | 155
618 | 00:09:16,840 --> 00:09:20,880
619 | 给出你的答案,这是每个话题的01
620 |
621 | 156
622 | 00:09:22,320 --> 00:09:25,880
623 | 很好。这是和之前一样的故事文本
624 |
625 | 157
626 | 00:09:25,880 --> 00:09:28,240
627 | 这个东西是一个故事。它是关于NASA的
628 |
629 | 158
630 | 00:09:28,240 --> 00:09:30,840
631 | 这不是关于地方政府,不是关于工程
632 |
633 | 159
634 | 00:09:30,840 --> 00:09:35,080
635 | 它是关于员工满意度的,它是关于联邦政府的
636 |
637 | 160
638 | 00:09:35,080 --> 00:09:37,720
639 | 有了这个,在机器学习中
640 |
641 | 161
642 | 00:09:37,720 --> 00:09:42,320
643 | 这有时被称为 "零示例学习算法"
644 |
645 | 162
646 | 00:09:42,320 --> 00:09:45,600
647 | 因为我们没有给它任何有标签的训练数据
648 |
649 | 163
650 | 00:09:45,600 --> 00:09:47,440
651 | 这就是零示例
652 |
653 | 164
654 | 00:09:47,440 --> 00:09:48,960
655 | 只需一个提示
656 |
657 | 165
658 | 00:09:48,960 --> 00:09:51,480
659 | 它就能够确定哪些
660 |
661 | 166
662 | 00:09:51,480 --> 00:09:55,880
663 | 这些主题在那篇新闻报道中被涵盖
664 |
665 | 167
666 | 00:09:55,880 --> 00:10:00,800
667 | 如果你想生成一个新闻警报
668 |
669 | 168
670 | 00:10:00,800 --> 00:10:05,840
671 | 这样处理新闻,我真的很喜欢NASA做的很多工作
672 |
673 | 169
674 | 00:10:05,840 --> 00:10:10,560
675 | 如果你想建立一个系统,可以把这个
676 |
677 | 170
678 | 00:10:10,560 --> 00:10:13,440
679 | 把这些信息放到一个字典里,每当
680 |
681 | 171
682 | 00:10:13,440 --> 00:10:15,960
683 | NASA的新闻出现,就打印提醒
684 |
685 | 172
686 | 00:10:15,960 --> 00:10:20,520
687 | 新的NASA故事,他们可以用这个来非常迅速地采取任何文章
688 |
689 | 173
690 | 00:10:20,520 --> 00:10:22,680
691 | 弄清楚它是关于什么主题的
692 |
693 | 174
694 | 00:10:22,680 --> 00:10:24,600
695 | 如果该主题包括NASA
696 |
697 | 175
698 | 00:10:24,600 --> 00:10:27,920
699 | 让它打印出警报,新的NASA故事
700 |
701 | 176
702 | 00:10:27,920 --> 00:10:32,480
703 | 只有一件事,我在下面使用这个主题词典
704 |
705 | 177
706 | 00:10:32,480 --> 00:10:36,200
707 | 我在上面使用的这个提示不是很强大
708 |
709 | 178
710 | 00:10:36,200 --> 00:10:38,080
711 | 如果我想要一个生产系统
712 |
713 | 179
714 | 00:10:38,080 --> 00:10:43,680
715 | 我可能会让它以JSON格式输出答案
716 |
717 | 180
718 | 00:10:43,680 --> 00:10:46,400
719 | 而不是作为一个列表,因为输出的
720 |
721 | 181
722 | 00:10:46,400 --> 00:10:49,640
723 | 大语言模型会有一点不一致
724 |
725 | 182
726 | 00:10:49,640 --> 00:10:52,240
727 | 这实际上是一段很脆弱 的代码
728 |
729 | 183
730 | 00:10:52,240 --> 00:10:54,800
731 | 但是,如果你想,当你看完这个视频后
732 |
733 | 184
734 | 00:10:54,800 --> 00:10:58,520
735 | 可以看看你能不能想出办法来修改这个提示
736 |
737 | 185
738 | 00:10:58,520 --> 00:11:01,320
739 | 让它输出JSON而不是像这样的一个列表
740 |
741 | 186
742 | 00:11:01,320 --> 00:11:07,720
743 | 然后有一个更强大的方法来判断某篇文章是否是关于NASA的故事
744 |
745 | 187
746 | 00:11:07,720 --> 00:11:10,800
747 | 所以,这就是推断的内容
748 |
749 | 188
750 | 00:11:10,800 --> 00:11:12,600
751 | 在短短的几分钟内
752 |
753 | 189
754 | 00:11:12,600 --> 00:11:16,720
755 | 你可以建立多个系统,对文本进行推断
756 |
757 | 190
758 | 00:11:16,720 --> 00:11:19,760
759 | 这些推断以前需要一名熟练的机器学习开发人员
760 |
761 | 191
762 | 00:11:19,760 --> 00:11:23,680
763 | 花费数天甚至数周才能完成
764 |
765 | 192
766 | 00:11:23,680 --> 00:11:27,120
767 | 我认为,无论是对于熟练的机器学习开发人员
768 |
769 | 193
770 | 00:11:27,120 --> 00:11:29,280
771 | 还是机器学习新手而言
772 |
773 | 194
774 | 00:11:29,280 --> 00:11:31,720
775 | 这都是非常令人兴奋的消息
776 |
777 | 195
778 | 00:11:31,720 --> 00:11:37,080
779 | 你现在可以使用提示来非常快速地建立并开始
780 |
781 | 196
782 | 00:11:37,080 --> 00:11:42,880
783 | 对这些相当复杂的自然语言处理任务做出推断
784 |
785 | 197
786 | 00:11:42,880 --> 00:11:44,240
787 | 在下一个视频中
788 |
789 | 198
790 | 00:11:44,240 --> 00:11:47,520
791 | 我们将继续讨论令人激动的事情,你可以用
792 |
793 | 199
794 | 00:11:47,520 --> 00:11:51,240
795 | 大语言模型,我们将继续进行转换
796 |
797 | 200
798 | 00:11:51,240 --> 00:11:54,800
799 | 把一段文本转换为
800 |
801 | 201
802 | 00:11:54,800 --> 00:11:58,440
803 | 不同的文本,如翻译成不同的语言
804 |
805 | 202
806 | 00:11:58,440 --> 00:12:07,600
807 | 让我们继续看下一个视频
808 |
809 |
--------------------------------------------------------------------------------
/chinese_subtitles/prompt_eng_08_chatbot_chinese.srt:
--------------------------------------------------------------------------------
1 | 1
2 | 00:00:05,000 --> 00:00:08,600
3 | 关于大语言模型的一个令人兴奋的事情,是你可以用它来
4 |
5 | 2
6 | 00:00:08,600 --> 00:00:12,680
7 | 构建一个自定义的聊天机器人,只需花费少量的精力
8 |
9 | 3
10 | 00:00:12,680 --> 00:00:17,660
11 | ChatGPT的Web界面能让你通过一个大语言模型
12 |
13 | 4
14 | 00:00:17,660 --> 00:00:20,500
15 | 进行对话
16 |
17 | 5
18 | 00:00:20,500 --> 00:00:23,120
19 | 但其中一个很酷的事情是你也可以使用
20 |
21 | 6
22 | 00:00:23,120 --> 00:00:25,680
23 | 一个大语言模型来建立你的自定义聊天机器人
24 |
25 | 7
26 | 00:00:25,680 --> 00:00:28,920
27 | 也许可以扮演一个AI客户服务代理或
28 |
29 | 8
30 | 00:00:28,920 --> 00:00:31,480
31 | 餐馆的AI接单员
32 |
33 | 9
34 | 00:00:31,480 --> 00:00:34,400
35 | 在这段视频中,你将学习如何做这件事
36 |
37 | 10
38 | 00:00:34,400 --> 00:00:37,080
39 | 我将描述以下内容
40 |
41 | 11
42 | 00:00:37,080 --> 00:00:39,960
43 | 我将更详细地描述OpenAI的聊天补全格式
44 |
45 | 12
46 | 00:00:39,960 --> 00:00:42,540
47 | 然后你将自己建立一个聊天机器人
48 |
49 | 13
50 | 00:00:42,540 --> 00:00:44,400
51 | 所以让我们开始吧
52 |
53 | 14
54 | 00:00:44,400 --> 00:00:49,000
55 | 首先,我们将像往常一样设置OpenAI Python包
56 |
57 | 15
58 | 00:00:49,000 --> 00:00:53,380
59 | 因此,像ChatGPT这样的聊天模型实际上是被训练成以一系列的信息作为输入
60 |
61 | 16
62 | 00:00:53,380 --> 00:00:57,640
63 | 并返回模型生成的信息作为输出
64 |
65 | 17
66 | 00:00:57,640 --> 00:00:59,960
67 | 因此,尽管聊天格式的设计是为了
68 |
69 | 18
70 | 00:00:59,960 --> 00:01:02,320
71 | 使得像这样的多轮对话变得容易
72 |
73 | 19
74 | 00:01:02,320 --> 00:01:06,000
75 | 我们在之前的视频中已经看到
76 |
77 | 20
78 | 00:01:06,000 --> 00:01:09,560
79 | 它也适用于没有对话的单个任务
80 |
81 | 21
82 | 00:01:09,560 --> 00:01:14,200
83 | 所以接下来,我们要定义两个辅助函数
84 |
85 | 22
86 | 00:01:14,200 --> 00:01:17,080
87 | 就是我们在所有视频中一直在使用的一个
88 |
89 | 23
90 | 00:01:17,080 --> 00:01:20,360
91 | get_completion函数
92 |
93 | 24
94 | 00:01:20,360 --> 00:01:22,080
95 | 但是,如果你看一下它
96 |
97 | 25
98 | 00:01:22,080 --> 00:01:25,040
99 | 我们给出了一个提示,但是在这个函数里面
100 |
101 | 26
102 | 00:01:25,040 --> 00:01:29,320
103 | 我们实际上在做的是把这个提示放到一个
104 |
105 | 27
106 | 00:01:29,320 --> 00:01:32,160
107 | 看起来像某种用户信息
108 |
109 | 28
110 | 00:01:32,160 --> 00:01:37,200
111 | 这是因为ChatGPT模型是一个聊天模型
112 |
113 | 29
114 | 00:01:37,200 --> 00:01:40,200
115 | 这意味着它被训练成以一系列信息作为输入
116 |
117 | 30
118 | 00:01:40,200 --> 00:01:44,000
119 | 然后返回模型生成的信息输出
120 |
121 | 31
122 | 00:01:44,000 --> 00:01:45,880
123 | 所以用户信息是一种输入
124 |
125 | 32
126 | 00:01:45,880 --> 00:01:49,320
127 | 然后助理的信息是输出
128 |
129 | 33
130 | 00:01:49,320 --> 00:01:51,320
131 | 所以在这个视频中
132 |
133 | 34
134 | 00:01:51,320 --> 00:01:53,760
135 | 我们将使用一个不同的辅助函数
136 |
137 | 35
138 | 00:01:53,760 --> 00:01:55,640
139 | 而不是把
140 |
141 | 36
142 | 00:01:55,640 --> 00:01:58,400
143 | 单一提示作为输入并获得单一结果
144 |
145 | 37
146 | 00:01:58,400 --> 00:02:01,680
147 | 我们将传入一个信息列表
148 |
149 | 38
150 | 00:02:01,680 --> 00:02:05,400
151 | 这些信息可以来自各种不同的角色
152 |
153 | 39
154 | 00:02:05,400 --> 00:02:07,160
155 | 所以我将描述这些
156 |
157 | 40
158 | 00:02:07,160 --> 00:02:10,040
159 | 这里有一个消息列表的例子
160 |
161 | 41
162 | 00:02:10,040 --> 00:02:12,040
163 | 第一条信息是
164 |
165 | 42
166 | 00:02:12,040 --> 00:02:15,200
167 | 一个系统消息,它给出了一个总体指令
168 |
169 | 43
170 | 00:02:15,200 --> 00:02:16,360
171 | 然后在这个消息之后
172 |
173 | 44
174 | 00:02:16,360 --> 00:02:20,040
175 | 我们在用户和助理之间有几轮对话
176 |
177 | 45
178 | 00:02:20,040 --> 00:02:21,920
179 | 而且这种对话通常会继续下去
180 |
181 | 46
182 | 00:02:21,920 --> 00:02:24,800
183 | 如果你曾经使用过ChatGPT的Web界面
184 |
185 | 47
186 | 00:02:24,800 --> 00:02:27,680
187 | 那么你输入的信息就是用户信息
188 |
189 | 48
190 | 00:02:27,680 --> 00:02:30,880
191 | 然后ChatGPT的信息是助理的信息
192 |
193 | 49
194 | 00:02:30,880 --> 00:02:33,440
195 | 因此,系统信息有助于在某种程度上
196 |
197 | 50
198 | 00:02:33,440 --> 00:02:35,800
199 | 设定助理的行为和角色
200 |
201 | 51
202 | 00:02:35,800 --> 00:02:38,920
203 | 它就像对话的高级指令一样
204 |
205 | 52
206 | 00:02:38,920 --> 00:02:40,640
207 | 所以你可以把它看成是
208 |
209 | 53
210 | 00:02:40,640 --> 00:02:42,440
211 | 在助理的耳边说的话,并引导
212 |
213 | 54
214 | 00:02:42,440 --> 00:02:46,320
215 | 它的反应,而用户并不知道系统的信息
216 |
217 | 55
218 | 00:02:46,320 --> 00:02:47,960
219 | 因此,作为用户
220 |
221 | 56
222 | 00:02:47,960 --> 00:02:49,400
223 | 如果你曾经使用过ChatGPT
224 |
225 | 57
226 | 00:02:49,400 --> 00:02:52,640
227 | 你可能不知道ChatGPT的系统消息里有什么
228 |
229 | 58
230 | 00:02:52,640 --> 00:02:55,360
231 | 系统消息的好处是
232 |
233 | 59
234 | 00:02:55,360 --> 00:02:57,240
235 | 它为开发者提供了一种方法来框定会话
236 |
237 | 60
238 | 00:02:57,240 --> 00:02:59,120
239 | 而不是让请求本身
240 |
241 | 61
242 | 00:02:59,120 --> 00:03:01,320
243 | 成为对话的一部分
244 |
245 | 62
246 | 00:03:01,320 --> 00:03:04,880
247 | 这样,你就可以在不让用户察觉的情况下引导助理
248 |
249 | 63
250 | 00:03:04,880 --> 00:03:09,640
251 | 并指导其回复
252 |
253 | 64
254 | 00:03:10,280 --> 00:03:15,440
255 | 所以现在让我们试着在对话中使用这些信息
256 |
257 | 65
258 | 00:03:16,080 --> 00:03:19,160
259 | 所以我们将使用我们的新助理函数
260 |
261 | 66
262 | 00:03:19,160 --> 00:03:21,720
263 | 来补全消息内容
264 |
265 | 67
266 | 00:03:22,600 --> 00:03:27,200
267 | 而且我们也在使用更高的temperature
268 |
269 | 68
270 | 00:03:27,200 --> 00:03:29,400
271 | 所以系统消息说
272 |
273 | 69
274 | 00:03:29,400 --> 00:03:31,440
275 | 你是一个说话像莎士比亚的助理
276 |
277 | 70
278 | 00:03:31,440 --> 00:03:33,160
279 | 所以这是我们在向助理描述
280 |
281 | 71
282 | 00:03:33,160 --> 00:03:35,960
283 | 向助理描述它应该如何表现
284 |
285 | 72
286 | 00:03:35,960 --> 00:03:38,680
287 | 然后第一个用户信息是,告诉我一个笑话
288 |
289 | 73
290 | 00:03:38,680 --> 00:03:41,640
291 | 接下来是,鸡为什么要过马路?
292 |
293 | 74
294 | 00:03:41,640 --> 00:03:45,520
295 | 然后最后的用户信息是,我不知道
296 |
297 | 75
298 | 00:03:45,520 --> 00:03:49,880
299 | 所以,如果我们运行这个
300 |
301 | 76
302 | 00:03:50,600 --> 00:03:55,400
303 | 响应是"去到另一边"。让我们再试一次
304 |
305 | 77
306 | 00:03:55,720 --> 00:03:57,920
307 | "要到另一边去"
308 |
309 | 78
310 | 00:03:57,920 --> 00:03:59,240
311 | 公平的先生或女士
312 |
313 | 79
314 | 00:03:59,240 --> 00:04:02,040
315 | 这是一个古老而经典的方法,永远不会失败
316 |
317 | 80
318 | 00:04:02,040 --> 00:04:05,120
319 | 所以这就是我们的莎士比亚式响应
320 |
321 | 81
322 | 00:04:05,640 --> 00:04:08,960
323 | 让我们再试一次
324 |
325 | 82
326 | 00:04:08,960 --> 00:04:11,520
327 | 因为我想让它更清楚,这是助理的信息
328 |
329 | 83
330 | 00:04:11,520 --> 00:04:19,360
331 | 所以在这里,让我们去打印整个消息的回应
332 |
333 | 84
334 | 00:04:32,880 --> 00:04:36,240
335 | 所以只是为了让这个更清楚
336 |
337 | 85
338 | 00:04:36,240 --> 00:04:41,160
339 | 这个响应是一个助理信息
340 |
341 | 86
342 | 00:04:41,160 --> 00:04:45,680
343 | 所以角色是助理,然后内容是消息本身
344 |
345 | 87
346 | 00:04:45,680 --> 00:04:48,000
347 | 所以这就是在这个辅助函数中发生的事情
348 |
349 | 88
350 | 00:04:48,000 --> 00:04:51,880
351 | 我们只是传出了消息的内容
352 |
353 | 89
354 | 00:05:04,960 --> 00:05:07,960
355 | 所以现在让我们再做一个例子
356 |
357 | 90
358 | 00:05:07,960 --> 00:05:09,840
359 | 这里我们的消息是
360 |
361 | 91
362 | 00:05:09,840 --> 00:05:13,160
363 | 系统信息是你是一个友好的聊天机器人
364 |
365 | 92
366 | 00:05:13,160 --> 00:05:14,560
367 | 而第一个用户信息是
368 |
369 | 93
370 | 00:05:14,560 --> 00:05:16,120
371 | 嗨,我的名字是Isa
372 |
373 | 94
374 | 00:05:16,120 --> 00:05:20,640
375 | 我们想获得第一个用户的信息
376 |
377 | 95
378 | 00:05:20,640 --> 00:05:22,080
379 | 所以让我们执行这个
380 |
381 | 96
382 | 00:05:22,080 --> 00:05:24,640
383 | 第一条助理信息
384 |
385 | 97
386 | 00:05:24,640 --> 00:05:26,880
387 | 因此,第一条信息是
388 |
389 | 98
390 | 00:05:26,880 --> 00:05:28,400
391 | 你好,Isa,很高兴见到你
392 |
393 | 99
394 | 00:05:28,400 --> 00:05:30,760
395 | 我今天有什么可以帮助你的吗?
396 |
397 | 100
398 | 00:05:36,000 --> 00:05:38,760
399 | 现在让我们试试另一个例子
400 |
401 | 101
402 | 00:05:39,320 --> 00:05:43,720
403 | 所以这里我们的信息是系统信息
404 |
405 | 102
406 | 00:05:43,720 --> 00:05:45,120
407 | 你是一个友好的聊天机器人
408 |
409 | 103
410 | 00:05:45,120 --> 00:05:47,080
411 | 和第一个用户信息是
412 |
413 | 104
414 | 00:05:47,080 --> 00:05:53,880
415 | 是的,你能提醒我我的名字是什么吗?
416 |
417 | 105
418 | 00:05:53,880 --> 00:05:56,400
419 | 让我们得到回应
420 |
421 | 106
422 | 00:05:56,400 --> 00:06:01,440
423 | 正如你所看到的
424 |
425 | 107
426 | 00:06:01,440 --> 00:06:05,800
427 | 该模型实际上并不知道我的名字
428 |
429 | 108
430 | 00:06:05,800 --> 00:06:10,680
431 | 因此,与语言模型的每一次对话都是一个独立的互动
432 |
433 | 109
434 | 00:06:10,680 --> 00:06:13,200
435 | 这意味着,你必须提供所有相关的信息
436 |
437 | 110
438 | 00:06:13,200 --> 00:06:16,120
439 | 供模型在当前对话中使用
440 |
441 | 111
442 | 00:06:16,120 --> 00:06:18,560
443 | 如果你想让模型从或中汲取
444 |
445 | 112
446 | 00:06:18,560 --> 00:06:21,240
447 | 引述,记住一个对话的早期部分
448 |
449 | 113
450 | 00:06:21,240 --> 00:06:24,640
451 | 你必须在模型的输入中提供早期的对话交互内容
452 |
453 | 114
454 | 00:06:24,640 --> 00:06:26,960
455 | 我们也把这称为上下文
456 |
457 | 115
458 | 00:06:26,960 --> 00:06:30,240
459 | 所以,让我们来试试这个
460 |
461 | 116
462 | 00:06:34,440 --> 00:06:39,000
463 | 所以现在我们已经给出了模型需要的上下文
464 |
465 | 117
466 | 00:06:39,000 --> 00:06:41,600
467 | 这是我在以前的信息中的名字
468 |
469 | 118
470 | 00:06:41,600 --> 00:06:43,160
471 | 我们将问同样的问题
472 |
473 | 119
474 | 00:06:43,160 --> 00:06:45,640
475 | 所以我们会问我的名字是什么
476 |
477 | 120
478 | 00:06:45,960 --> 00:06:50,320
479 | 模型能够作出反应,因为它有所有的上下文
480 |
481 | 121
482 | 00:06:50,320 --> 00:06:55,520
483 | 在我们输入的消息列表中需要它
484 |
485 | 122
486 | 00:06:55,520 --> 00:06:58,760
487 | 所以现在你要建立你自己的聊天机器人
488 |
489 | 123
490 | 00:06:58,760 --> 00:07:02,040
491 | 这个聊天机器人将被称为orderbot(点餐机器人)
492 |
493 | 124
494 | 00:07:02,040 --> 00:07:05,520
495 | 我们将自动收集
496 |
497 | 125
498 | 00:07:05,520 --> 00:07:09,480
499 | 我们将自动收集用户的提示和助理的回应,以建立这个订单机器人
500 |
501 | 126
502 | 00:07:09,480 --> 00:07:12,200
503 | 它将在一家披萨店接受订单
504 |
505 | 127
506 | 00:07:12,200 --> 00:07:16,040
507 | 所以首先,我们要定义这个助理函数
508 |
509 | 128
510 | 00:07:16,040 --> 00:07:19,040
511 | 这个函数要做的是收集
512 |
513 | 129
514 | 00:07:19,040 --> 00:07:24,840
515 | 我们的用户信息,这样我们就可以避免像上面那样用手输入信息了
516 |
517 | 130
518 | 00:07:24,840 --> 00:07:29,760
519 | 这将从我们下面建立的用户界面上收集提示信息
520 |
521 | 131
522 | 00:07:29,760 --> 00:07:32,800
523 | 然后将其追加到一个叫做"上下文"的列表中
524 |
525 | 132
526 | 00:07:32,800 --> 00:07:36,280
527 | 然后它每次都会用这个上下文调用模型
528 |
529 | 133
530 | 00:07:36,280 --> 00:07:39,320
531 | 然后模型的响应也会被添加到上下文中
532 |
533 | 134
534 | 00:07:39,320 --> 00:07:43,560
535 | 所以模型的信息被添加到上下文中
536 |
537 | 135
538 | 00:07:43,560 --> 00:07:45,160
539 | 用户信息被添加到上下文中
540 |
541 | 136
542 | 00:07:45,160 --> 00:07:47,880
543 | 以此类推,它只会越来越长
544 |
545 | 137
546 | 00:07:47,880 --> 00:07:52,680
547 | 这样一来,模型就有了它所需要的信息来决定下一步该做什么
548 |
549 | 138
550 | 00:07:52,680 --> 00:07:58,600
551 | 现在我们将设置并运行这个用户界面来显示订单机器人
552 |
553 | 139
554 | 00:07:58,600 --> 00:08:00,360
555 | 所以这里是上下文
556 |
557 | 140
558 | 00:08:00,360 --> 00:08:04,200
559 | 并且它包含了包含菜单的系统信息
560 |
561 | 141
562 | 00:08:04,560 --> 00:08:08,160
563 | 请注意,每次我们调用语言模型的时候
564 |
565 | 142
566 | 00:08:08,160 --> 00:08:13,400
567 | 我们都会使用相同的上下文,而且这个上下文是随着时间的推移而建立的
568 |
569 | 143
570 | 00:08:13,400 --> 00:08:19,040
571 | 然后让我们来执行这个
572 |
573 | 144
574 | 00:08:22,880 --> 00:08:25,760
575 | 我要说,你好
576 |
577 | 145
578 | 00:08:25,760 --> 00:08:29,440
579 | 我想订购一个比萨饼
580 |
581 | 146
582 | 00:08:33,080 --> 00:08:35,400
583 | 助理说,太好了
584 |
585 | 147
586 | 00:08:35,400 --> 00:08:36,880
587 | 你想点什么比萨饼?
588 |
589 | 148
590 | 00:08:36,880 --> 00:08:40,520
591 | 我们有意大利香肠、奶酪和茄子比萨
592 |
593 | 149
594 | 00:08:40,520 --> 00:08:44,680
595 | 多少钱?
596 |
597 | 150
598 | 00:08:53,080 --> 00:08:56,880
599 | 很好。好的,我们得到了价格
600 |
601 | 151
602 | 00:08:56,880 --> 00:09:12,000
603 | 我想我觉得是中号茄子比萨。所以你可以想象
604 |
605 | 152
606 | 00:09:12,000 --> 00:09:14,000
607 | 我们可以继续这个对话
608 |
609 | 153
610 | 00:09:14,000 --> 00:09:17,720
611 | 让我们看看我们在系统信息中放了什么
612 |
613 | 154
614 | 00:09:18,280 --> 00:09:20,400
615 | 所以你是orderbot
616 |
617 | 155
618 | 00:09:20,400 --> 00:09:23,280
619 | 为一家比萨店收集订单的自动化服务
620 |
621 | 156
622 | 00:09:23,280 --> 00:09:24,600
623 | 你首先要问候顾客
624 |
625 | 157
626 | 00:09:24,600 --> 00:09:27,800
627 | 然后收集订单,再问是自取还是配送
628 |
629 | 158
630 | 00:09:27,800 --> 00:09:29,480
631 | 你等待收集整个订单
632 |
633 | 159
634 | 00:09:29,480 --> 00:09:31,680
635 | 然后总结一下,最后进行检查
636 |
637 | 160
638 | 00:09:31,680 --> 00:09:33,800
639 | 如果顾客还想添加其他东西
640 |
641 | 161
642 | 00:09:33,800 --> 00:09:36,400
643 | 如果是送货,你可以要求提供地址
644 |
645 | 162
646 | 00:09:36,400 --> 00:09:38,040
647 | 最后,你拿到付款
648 |
649 | 163
650 | 00:09:38,040 --> 00:09:40,240
651 | 确保清晰描述所有选项、附加服务、额外费用
652 |
653 | 164
654 | 00:09:40,240 --> 00:09:43,120
655 | 和尺寸,以便从菜单上精确识别该项目
656 |
657 | 165
658 | 00:09:43,120 --> 00:09:44,920
659 | 你需要以简短的
660 |
661 | 166
662 | 00:09:44,920 --> 00:09:46,840
663 | 健谈的、友好的风格来回答
664 |
665 | 167
666 | 00:09:46,840 --> 00:09:50,880
667 | 菜单包括,然后在这里我们有菜单
668 |
669 | 168
670 | 00:09:51,120 --> 00:09:54,200
671 | 所以让我们回到我们的对话
672 |
673 | 169
674 | 00:09:54,200 --> 00:09:58,720
675 | 让我们看看助理是否一直在遵循指示
676 |
677 | 170
678 | 00:09:58,720 --> 00:10:01,720
679 | 好的,很好。助理问我们是否需要任何配料
680 |
681 | 171
682 | 00:10:01,720 --> 00:10:05,760
683 | 我们在系统信息中指定了这一点
684 |
685 | 172
686 | 00:10:05,760 --> 00:10:09,600
687 | 所以我想我们不需要额外的配料
688 |
689 | 173
690 | 00:10:15,600 --> 00:10:18,680
691 | 当然可以。还有什么我们想点的吗?
692 |
693 | 174
694 | 00:10:18,680 --> 00:10:22,240
695 | 嗯。让我们来点水
696 |
697 | 175
698 | 00:10:22,240 --> 00:10:26,240
699 | 事实上,薯条
700 |
701 | 176
702 | 00:10:32,240 --> 00:10:34,240
703 | 小的还是大的?
704 |
705 | 177
706 | 00:10:34,240 --> 00:10:36,240
707 | 这很好,因为我们在系统信息中
708 |
709 | 178
710 | 00:10:36,240 --> 00:10:41,240
711 | 要求助理在系统信息中说明额外的东西和配菜
712 |
713 | 179
714 | 00:10:46,240 --> 00:10:50,240
715 | 这样你就明白了,你可以随意试玩一下这个过程
716 |
717 | 180
718 | 00:10:50,240 --> 00:10:55,240
719 | 可以暂停视频,在左边的Notebook上运行这个
720 |
721 | 181
722 | 00:10:55,240 --> 00:10:59,240
723 | 现在我们可以要求该模型创建一个JSON摘要
724 |
725 | 182
726 | 00:10:59,240 --> 00:11:03,240
727 | 我们可以在对话的基础上发送至订单系统
728 |
729 | 183
730 | 00:11:03,240 --> 00:11:06,240
731 | 所以,我们现在要附加另一个系统消息
732 |
733 | 184
734 | 00:11:06,240 --> 00:11:08,240
735 | 这是一个指令
736 |
737 | 185
738 | 00:11:08,240 --> 00:11:11,240
739 | 我们在说创建一个关于之前食品订单的JSON摘要
740 |
741 | 186
742 | 00:11:11,240 --> 00:11:13,240
743 | 逐项列出每一项的价格
744 |
745 | 187
746 | 00:11:13,240 --> 00:11:18,240
747 | 字段应该是一个比萨饼,包括配菜
748 |
749 | 188
750 | 00:11:18,240 --> 00:11:21,240
751 | 两张配料表,三张饮料表
752 |
753 | 189
754 | 00:11:21,240 --> 00:11:23,240
755 | 和四份配菜清单
756 |
757 | 190
758 | 00:11:23,240 --> 00:11:25,240
759 | 最后是总价格
760 |
761 | 191
762 | 00:11:25,240 --> 00:11:29,240
763 | 你也可以在这里使用一个用户信息
764 |
765 | 192
766 | 00:11:29,240 --> 00:11:33,240
767 | 这不一定是一个系统消息
768 |
769 | 193
770 | 00:11:33,240 --> 00:11:36,240
771 | 所以让我们来执行这个
772 |
773 | 194
774 | 00:11:36,240 --> 00:11:39,240
775 | 注意在这种情况下,我们需要使用更低的temperature
776 |
777 | 195
778 | 00:11:39,240 --> 00:11:41,240
779 | 因为对于这些类型的任务
780 |
781 | 196
782 | 00:11:41,240 --> 00:11:43,240
783 | 我们希望输出是相当可预测的
784 |
785 | 197
786 | 00:11:43,240 --> 00:11:47,240
787 | 对于一个对话式的代理,你可能想使用更高的temperature
788 |
789 | 198
790 | 00:11:47,240 --> 00:11:50,240
791 | 然而,在这种情况下,我可能也会使用一个较低的temperature
792 |
793 | 199
794 | 00:11:50,240 --> 00:11:53,240
795 | 因为对于一个客户助理聊天机器人来说
796 |
797 | 200
798 | 00:11:53,240 --> 00:11:59,240
799 | 你可能想让输出更可预测一些
800 |
801 | 201
802 | 00:11:59,240 --> 00:12:02,240
803 | 因此,在这里我们有我们的订单摘要
804 |
805 | 202
806 | 00:12:02,240 --> 00:12:07,240
807 | 如果我们想的话,我们可以把这个提交给订单系统
808 |
809 | 203
810 | 00:12:07,240 --> 00:12:08,240
811 | 这就是我们需要的
812 |
813 | 204
814 | 00:12:08,240 --> 00:12:11,240
815 | 你已经建立了你自己的订单聊天机器人
816 |
817 | 205
818 | 00:12:11,240 --> 00:12:13,240
819 | 你可以自由地定制它
820 |
821 | 206
822 | 00:12:13,240 --> 00:12:16,240
823 | 试玩一下系统信息
824 |
825 | 207
826 | 00:12:16,240 --> 00:12:19,240
827 | 并改变聊天机器人的行为
828 |
829 | 208
830 | 00:12:19,240 --> 00:12:46,240
831 | 让它作为具有不同知识的不同角色行事
832 |
833 |
--------------------------------------------------------------------------------