1:第0讲:课程说明 📚
在本节课中,我们将要学习这门课程的定位、目标、内容规划以及作业安排。我们将了解为什么需要开设这门关于生成式人工智能的课程,它与传统机器学习课程的区别,以及学习这门课程能为我们带来什么。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_1.png
课程缘起:为什么开设这门课?
我从2014年开始在台大任教,自2015年起每年都开设机器学习相关的课程。在去年的春季班,机器学习课程下课后,发生了一件事促使我思考开设新课程的必要性。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_3.png
一位同学前来询问如何让机器自动对一篇文章进行分类。作为机器学习课程,我自然从机器学习的角度进行回答:这是一个标准的分类问题,需要先准备标注数据,然后训练自己的模型。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_5.png
讲到此处,我脑中突然产生了一个新的想法。我问他:“你是真的想学习机器学习的原理,还是仅仅想知道如何实现文章分类?你为什么要做文章分类呢?”
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_7.png
他回答说这是他创业项目所需的服务。于是我告诉他:“别浪费时间学机器学习(我刚才说的那些)了,直接调用 ChatGPT 就好了。”
这句话是什么意思呢?也许通过实际操作,大家能更好地理解。
生成式AI的威力:以ChatGPT为例 🚀
这是 ChatGPT 的页面。我使用的是 GPT-3.5,它是免费的;GPT-4 则需要付费。因此,我展示的功能是每个人都可以轻松获得的免费功能。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_9.png
初次看到 ChatGPT 页面的人往往会不知所措,因为页面上只有一个对话框。在这个对话框里可以输入任何文字。但这样一个能与我们对话的人工智能,究竟有什么作用呢?我们真的需要每天和它聊天吗?可能并不需要。
很多人认为这不过是一个聊天机器人,能有多大作用?但事实上,ChatGPT 可以成为你的得力助手。你有什么需求,直接告诉它即可。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_11.png
例如,我们今天想对新闻进行分类。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_13.png
你只需直接将指令贴给它,告诉它:“新闻分为以下几类:政治社会、财经生活、影视娱乐、体育等。” 接下来告诉它:“以下我会给你一篇新闻,请告诉我这篇新闻属于哪一类。只给我类别就好。”
然后贴一段新闻内容给它。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_15.png
比如,这里随便找一则新闻“元宵逢最小满月”,贴一段内容。输入后,它会告诉你这则新闻属于“生活”类。我们再试另一个例子。
这是一则关于 AI 的新闻。我们把这段新闻贴到这里,GPT 知道这是“影视娱乐”类。
因此,你可以轻易地用 ChatGPT 打造你想要的 AI 应用。但有人可能会想,这是一个演示网页,如何将这个功能嵌入到我自己的应用或服务中呢?在这门课的作业中,会告诉你如何在自己的程序中调用像 ChatGPT 这样的人工智能来帮你做事。
总之,我的想法是:大人,时代变了。过去在开发人工智能应用时,我们往往需要自己开发、训练机器学习模型,这就像决斗时用剑。而今天,有人可以直接掏出一把枪,瞬间完成人工智能应用。
所以,作为一门人工智能的基础课程,我想开设一门新课,告诉大家今天这个世界,如果你想做人工智能相关应用,可能是什么样子。当然,有能力自己开发模型仍然非常重要。这并不意味着机器学习课程不重要,也不代表我以后就不会开机器学习课。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_17.png
我只是想告诉大家,了解今天生成式 AI 的趋势和技术发展到了什么地步,可以帮助你更精确地判断:什么时候应该自己开发模型,什么时候可以使用现成的人工智能。
课程定位:这不是一门“ChatGPT使用教程” 🎯
在开始课程之前,我来讲一下这门课的定位。因为课程一开始就提到了 ChatGPT,可能会给你带来一个误解。我看到网络上有很多同学说,这是一门教大家怎么用 ChatGPT 的课。
但这其实不是一门教大家怎么用 ChatGPT 的课。
ChatGPT 只是众多生成式人工智能中的一个例子。当然,它是今天最具代表性的应用,所以我们课堂上一定会反复提到 ChatGPT 这个人工智能。但它只是生成式 AI 的一个例子而已。这门课要讲的,是希望能带给大家生成式 AI 的全貌。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_19.png
其实 ChatGPT 非常容易上手。很多人会问怎么学习使用 ChatGPT。使用 ChatGPT 这件事是不用学的。只要你能跟另一个人沟通,你大概就有办法跟 ChatGPT 沟通。所以学习使用 ChatGPT 这件事,其实不需要花一整个学期的时间。
而且另一方面,关于 ChatGPT 的学习资源真的非常多。你在 YouTube 上搜索 ChatGPT,满坑满谷的网红都在教你怎么用 ChatGPT。在去年年初 ChatGPT 刚火的时候,只要是个网红,都在讲 ChatGPT。历史的频道就让 ChatGPT 伪装成历史古人对话;打游戏王的频道,也逼迫 ChatGPT 跟他玩游戏王(虽然 ChatGPT 玩不了)。总之,已经有太多人提供 ChatGPT 的教学资源。
所以,这门课要讲的并不是教你怎么使用 ChatGPT 这个人工智能应用。
课程目标受众与核心内容 🎓
这门课预设的目标受众是:假设你已经用过 ChatGPT 这类的生成式 AI,你知道它们可以做什么,你知道它们有多厉害。但是你想要更进一步了解这些生成式 AI 背后的原理:它们到底是怎么来的?怎么被训练出来的?怎么变得像今天一样这么厉害?以及你想要知道这些人工智能未来有什么样的可能性,还有哪些可能的发展。
这门课就是为你开的。
为什么这门课不会特别着重某一个应用(比如 ChatGPT 的使用)呢?因为今天这个技术真的是日新月异。如果你在 2022 年年底 ChatGPT 上线时就开始使用它,你会发现 ChatGPT 现在的界面和能力,与刚上线时相比已经有了很大的差异。这个应用是日新月异的。
所以,即使你在某一门课中学到了怎么使用 ChatGPT,可能同样的技巧在几个月甚至几周之后就已经不适用了。我们在大学开一门课,是希望可以教你一些在往后数年,甚至一辈子都可以用得上的东西。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_21.png
因此,这门课真正想要传达的,并不是教你怎么用 ChatGPT 这一个应用,而是告诉你生成式 AI 背后的概念和原理。
先修要求与学习意义 ❓
这门课没有预设需要任何的先修课程。如果你想要修这门课,你不需要修过任何人工智能相关的课程,不需要有任何数学和编程的背景,也不需要修过任何机器学习相关的课程。这门课可以是你人生的第一堂人工智能相关课程。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_23.png
有人可能会问:我已经会用 ChatGPT 了。使用 ChatGPT 就是如此简单,只要你会说话、会打字,知道怎么跟另一个人沟通,你就可以用 ChatGPT。我已经会用了,那会用就好啦,我干嘛要知道它背后的原理是什么?
确实,就算你不知道 ChatGPT 的原理,你也有机会打造人工智能的应用。但是,了解它的原理可以带你走向另外一个层次。
就像魔术非常神奇,今天的人工智能也像是魔术一样。但是如果你知道魔术背后的手法,你在观看魔术时,可以更能够欣赏魔术师厉害的地方。你看到魔术师把一个人锯成两半再粘在一起时,你不会觉得他是真的把人锯成两半然后用念能力粘在一起,你会知道这是一个手法。你不会觉得魔术师是一个有超能力的人。你知道这是魔术的手法。
对于生成式 AI 也是一样的。今天生成式 AI 展现出非常神奇的能力,但是假设你可以正确了解它背后的概念和原理,那就好像是了解了魔术背后的手法。你可以更精确地认识它,至少你不会对它的能力有错误的误解或错误的期待。
有同学问我,这门课跟我自己开的机器学习课有什么重叠的地方吗?你应该问还有什么一样的地方。基本上就是没有什么一样的地方。所以,就算你修过我的机器学习课,或者修过其他老师开的机器学习课,我相信这门课也可以带给你很大的帮助。
我刚才说过,这门课可以作为你人工智能的第一堂课。你可以把这门课作为你学习人工智能的基础,未来再去学习其他机器学习相关的课程。
课程深度与期望声明 📖
需要声明一下,在这门课你不会学到什么。因为这是一门入门课,如果我们继续用魔术这个比喻,这门课会手把手带你变几个魔术,但是可能不足以训练你成为魔术师,也没有办法带你创造新的魔术。
但这并不代表这门课是没有用的。这门课可以作为你成为魔术师的开始。假设你的目标是未来成为顶尖的魔术师,要做些大变活人之类的,那这门课可以作为你的起点。
上课时间有限,这门课设定为两学分的课,所以我们上课时间只有两个小时。因为时间有限,我们无法深入提到所有的技术。很多地方可能会让你觉得“我什么都脱了,就只给我看这个?”。所以很多地方可能没有办法讲得非常深入。
但是,这是你的第一门人工智能的课,它不会是你最后一门人工智能的课。未来你可以修其他相关的课程。或者,假设你想要深入研究上课所提到的一些技术背后的原理,你可以看投影片上引用的论文。
关于引用与最新研究 📄
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_25.png
讲到引用,我说明一下。在我们这门课的投影片上,多数的论文都是引用自一个叫做 arXiv 的网站。我看到有同学问,上课引用的论文链接上会写 arxiv.org,arXiv 是什么呢?
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_27.png
如果是计算机科学领域的同学,一定都知道 arXiv 是什么。但我知道选修这门课的同学来自于各个不同的领域,所以我介绍一下什么是 arXiv。
通常我们在做研究时,有了新的想法,会写成论文发表在国际会议或国际期刊上。但是国际会议、期刊的论文审稿往往需要一年半载。对于 AI 领域而言,技术变化太快了,一年半载的时间往往就会有翻天覆地的变化。往往你投一篇文章,六个月后被国际会议接受时,那个技术可能已经过时了。
那怎么办呢?有一个网站叫做 arXiv。今天,往往有了新的想法(尤其是计算机科学、人工智能相关的新论文),会先不投国际会议,而是直接放在 arXiv 上抢先公开出来。所以在 arXiv 上比较容易找到最新的研究。
这边教大家怎么看 arXiv 文章上传的时间。arXiv 的文章后面都会有一个数字,这个数字的前两位代表年份,后两位代表月份。所以 2205 的意思就是这篇文章是在 2022 年 5 月被公开放在 arXiv 上的。
之后,你在我们课程的投影片上会看到很多文章,这些文章往往是几个月前,甚至是几周前才被放在 arXiv 上的。
技术发展的迅猛:一个有趣的对比 ⚡
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_29.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_31.png
讲到技术迅速变化这件事,我想分享一个例子。在这门课里,我们的作业会教大家训练一个拥有 70 亿个参数的模型。70 亿的英文是 seven billion,缩写是 7B。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_33.png
虽然说是训练,但实际上是微调。我们还没有讲到训练和微调的差异,这个之后会讲。现在就先当做你要训练一个 7B 的模型。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_35.png
这 70 亿个参数到底是什么意思呢?我们下一堂课会讲参数的概念。现在可以先理解为:参数量越多,通常代表模型越厉害(实际上影响模型能力的因素还有很多,不只是参数数量)。不过今天大家往往把参数数量当做夸耀模型能力的一个指标。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_37.png
一个有 70 亿个参数的模型,70 亿听起来是个很大的数字,跟地球人口差不多。但它是一个很大的模型吗?它显然不是一个特别大、特别厉害的模型,因为这是我们课堂的一个作业。你可以想象,修完这堂课后,有上千人都能够训练 70 亿个参数的模型,而且你今天用免费的运算资源就可以做到。所以它显然不是一个特别厉害的模型。
但是,如果你穿越到 5 年前,穿越回 2019 年,会发生什么呢?2019 年时,OpenAI 发布了第二代的 GPT(GPT-2)。那个时候网络上各种文章也在拼命吹捧,比如“史上最强 NLP 模型 GPT-2.0”、“逆天语言模型 GPT-2.0”、“最大的模型 GPT-2.0”。
这个 GPT-2 到底有多大呢?它只有 15 亿个参数,大概是你今天作业要用的模型的 1/4 到 1/5。所以,今天假设你带着我们的作业穿越回 5 年前,你手上拥有的是一个在当时看来毁天灭地的巨大模型。OpenAI 和 Google 看到你都得“下跪”。这是一个当时大家无法想象的巨大模型。
这让我想到《葬送的芙莉莲》这部动画(第三话的内容,动画已播出一段时间,不算剧透)。芙莉莲是一个精灵,她在 80 年前曾参加勇者小队讨伐魔王。魔王手下有一个很厉害的干部,叫做“普贤库瓦尔”。他发明了一个“杀人魔法”,可以穿透任何防御,无人能挡。所有的勇士都被他杀了,连芙莉莲都无法打倒他,只能暂时将他封印。
80 年后,封印松动,库瓦尔复活了。芙莉莲带着她的弟子费伦想要来干掉库瓦尔。一开始费伦非常紧张,因为库瓦尔的杀人魔法是无法防御的。芙莉莲说:“到时候就知道了。”然后库瓦尔对费伦使出了一记杀人魔法。芙莉莲对费伦说:“你就把防御展开。”结果就挡住了。费伦说:“这什么杀人魔法,不过就是普通攻击而已。”
是的,80 年前的杀人魔法,过了 80 年后就只是普通攻击。因为 80 年对人类来说太长了,人类已经钻研了库瓦尔的魔法,寻找到了防御的方法。
在生成式 AI 的领域也是一样。当年的 GPT-2 就像是库瓦尔,当年一个毁天灭地的巨大模型,今天在你的眼中也已经不算什么了。
这个例子是要告诉你,生成式 AI 技术的变化非常快。不要说是 5 年,有时候 5 个月、5 个星期都会有很大的变动。
作业规划与体验目标 📝
讲到作业,就跟大家说一下作业的规划。作业的目标是让大家体验生成式 AI。
这个体验分成两个面向:
-
第一个层面是体验如何用生成式 AI 来打造某些应用。
-
第二个层面是教大家如何训练出自己的生成式 AI 模型。
当然,代码助教都已经写好了,你要做的事情往往就是一直按 Enter 键。但是你可以体验如何训练出一个自己的生成式 AI 模型。
在这门课里,我保留了一些“负面”的体验。什么样的负面体验呢?
-
比如训练模型很花时间。当然,今天所谓的“很花时间”,在作业里可能就是两三个小时。你知道痛苦是比较出来的。你可能觉得训练两三个小时很花时间。事实上,如果你要训练真正的大模型,时间往往是以“周”为单位来计算的。
-
另外,你可能还会发现,就算你完全按照助教的指示按 Enter,你得到的结果也可能跟助教得到的结果不一样。很多第一次训练模型的同学会觉得非常惊奇:训练模型不就是写个程序吗?它是电脑啊,怎么每次还会得到不一样的结果呢?我告诉你,训练模型你不要用“编程”来想它,你要想成好像是在养小动物、种花种草一样,其结果往往是有可能无法预测的。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_39.png
当然,我们可以把这些负面体验拿掉,不让你自己训练模型就好。但是我仍然把好几个训练模型的工作保留在作业中,为了让你得到一些负面的体验。期待这些负面的体验可以像疫苗一样,帮助你在未来面对更大的挑战。
我知道在座各位不是每一个人未来都会成为工程师,不是每一个人都会训练模型。但也许透过这堂课的体验,你可以知道训练模型是可能很花时间的,是可能很难预测的。有一天你当了大老板,也许可以对你手下的工程师多一些宽容。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_41.png
以下是作业内容的详细规划:
这门课总共有十个作业。公告的日期都已经写在投影片上。每一个作业如果没有特别说明,预设它的截止日期就是在两周后。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_43.png
这些作业有好几个是需要写程序,甚至是训练模型的。有同学就会问:要训练模型,我需要准备什么东西呢?我需要买自己的 GPU 吗?
你什么都不用准备。 在执行程序训练模型的部分,我们都会用 Google Colab 或 Kaggle。你不知道 Colab 或 Kaggle 是什么也没有关系。总之你只要记得你什么都不用准备。
这边我稍微估算了一下作业的难度:
-
如果打一个三角形(△),就是送分给你。所以作业一,还有下周讲的作业二,基本上就是送分。开局就先送大家 20 分。
-
如果打两个三角形(△△),代表假设你不在意分数,这个作业也可能可以非常快完成。但是假设你想要拿到满分,你还是需要花一些时间自己努力。
-
如果打三个三角形(△△△),代表这个作业是需要训练模型的,所以你至少需要好几个小时才能完成。
再强调一次,痛苦是比较出来的。好几个小时已经算是非常快了。过去2015年我刚开机器学习这门课的时候,有好几个作业的训练时间大概是三天。我就跟同学讲这个作业就是要训练三天,所以今天假设离作业截止日期不到三天,你唯一能做的事情就是放弃,因为你已经不可能把模型训练出来了。但今天,训练模型最多就是几个小时,你在作业截止前一晚再赶也许还来得及。
有关这门课的分量,我给一个注解:因为有十个作业,几乎每周都会公布作业,所以如果把它当做通识课来看(毕竟这门课的名字里有“导论”二字),它不会是一个太难的课程,但可以是一个非常充实的通识课。当然,如果把它看作是选修课,那它可能是一个负担比较轻松、不那么重的选修课。这是给大家参考的作业负担说明。
有关上课内容的规划,我们下一节再讲。
关于使用AI完成作业与致谢 🤖
大家常常会问的一个问题就是:这门课能不能用人工智能(比如 ChatGPT)来写作业呢?
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_45.png
答案是可以。 这是生成式 AI 导论,这门课当然应该可以用生成式 AI 来写作业。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_47.png
但是同时,老师也要用人工智能来改作业。到时候我们的作业,基本上能够用大型语言模型批改的,我们都会用大型语言模型来批改。
这边特别感谢 MTK(联发科)的“打兵器-达哥团队”,提供给我们“打兵器”平台、算力以及平台支持,让我们可以透过“打兵器”平台来批改作业。就算他们知道我们这堂课可能会有超过 1000 人选修,他们也愿意无条件地大力支持。在此特别感谢 MTK 的达哥团队。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/4241295c88d1cf998937340b3ef8ed33_49.png
在 3 月 15 号的时候,MTK 的团队会来跟大家分享他们是怎么使用生成式 AI 的,以及他们对生成式 AI 在业界有什么样的看法。在 5 月 24 号的时候,MTK 自己也开发了大型语言模型,他们的技术团队会来跟大家分享。
本节课中,我们一起学习了《生成式人工智能导论》第0讲“课程说明”的全部内容。我们了解了开设这门课程的背景与必要性,明确了课程定位(并非ChatGPT使用教程,而是探究原理与全貌),知道了课程的目标受众和先修要求,并初步感受了生成式AI技术的迅猛发展。最后,我们也清楚了课程的作业规划、难度以及一些特别安排(如允许使用AI、MTK团队支持等)。下一节课,我们将正式开始探索生成式人工智能的精彩世界。
2:第1讲:生成式AI是什么 🧠
在本节课中,我们将要学习生成式人工智能(Generative AI)的基本概念,并厘清它与人工智能、机器学习、深度学习等术语之间的关系。我们将从最基础的定义出发,逐步理解生成式AI要解决的核心问题及其独特之处。
什么是人工智能?🤖
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_1.png
在深入探讨生成式人工智能之前,我们需要先了解什么是人工智能(Artificial Intelligence, AI)。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_3.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_5.png
从字面上看,人工智能指的是由人创造出来的、由机器展现的智慧。然而,“智慧”本身是一个模糊且没有标准定义的概念。不同的人对“智慧”的想象可能完全不同。例如,有人认为会对话的ChatGPT是AI,而有人则认为必须是一个能跑动的机器人才算AI。
因此,人工智能这个词本身并没有一个清晰、统一的定义。在学术论文中,研究者也几乎不会使用这个过于宽泛的词汇。我们可以将人工智能理解为一个目标,即我们希望机器能够达成的某种智能表现,而不是指某一种特定的技术。
什么是生成式人工智能?🎨
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_7.png
与“人工智能”相比,生成式人工智能的定义则明确得多。
生成式人工智能的目标是让机器产生复杂而有结构的物件。例如:
-
文章:由一连串文字构成。
-
影像:由一堆像素组成。
-
语音:由一系列声音采样点组成。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_9.png
那么,“复杂有结构”具体是什么意思呢?它意味着这些物件的可能性多到无法穷举。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_11.png
我们来思考一个例子:让AI写一篇100字的中文文章。假设中文常用字有1000个,那么一篇100字的文章就有 1000^100(即10的300次方)种可能的组合。这个数字远远超过了宇宙中原子的总数(估计为10的80次方)。因此,生成式AI需要从近乎无限的可能性中,找出一个合理、有意义的组合作为输出,这是一个极其困难的问题。
上一节我们介绍了生成式AI的目标,本节中我们来看看什么不属于生成式AI,以帮助我们更好地理解其边界。
分类(Classification)问题就不是生成式AI。在分类问题中,机器是从有限的、预先定义好的选项中做出选择。例如:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_13.png
由于选项是有限的,这类问题不属于生成式人工智能的范畴。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_15.png
所以,生成式人工智能是人工智能这个宏大目标下的一个具体方向,即让机器生成复杂有结构的物件,如文字、图片或声音。
机器学习:实现目标的手段 ⚙️
在继续深入之前,我们需要介绍另一个常与AI一同出现的概念:机器学习(Machine Learning)。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_17.png
机器学习的目标很明确:让机器能够自动从资料中找出一个函数。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_19.png
我们可以用一个简单的例子来理解。假设有一个函数形式为 y = a * x + b。如果给定两组输入输出数据:(x=4, y=5) 和 (x=2, y=1),我们就能解出参数 a=2, b=-3。之后,对于新的输入 x=1,就能计算出输出 y = -1。
在机器学习中,a 和 b 这类需要找出的未知数被称为参数(Parameters)。机器学习与你初中解方程的唯一不同在于:机器可以自动找出这些参数。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_21.png
我们之所以需要机器自动完成,是因为现实世界的问题远比 y = a*x + b 复杂得多。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_23.png
想象一个要识别图片中是猫还是狗的函数:F(图片) -> {猫, 狗}。这个函数会极其复杂,可能包含上万个甚至更多的参数。人类无法手动设计或求解这样的函数。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_25.png
在机器学习领域,这种带有大量未知参数的函数被称为模型(Model)。而“学习”或训练(Training)的过程,就是指利用给定的训练资料(输入和对应的正确输出),自动找出模型中所有参数的过程。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_27.png
训练完成后,将新的数据输入模型得到输出的过程,称为测试(Testing)或推理(Inference)。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_29.png
深度学习与神经网络 🧠
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_31.png
一个包含上万个参数的函数具体长什么样呢?在当今的机器学习领域,它通常被表示为神经网络(Neural Network),或更具体地说,类神经网络。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_33.png
需要澄清的是,虽然名字听起来与大脑有关,但神经网络本质上就是一个具有大量参数的、复杂的数学函数。将模型表示为神经网络,并使用特定方法训练它的技术,就称为深度学习(Deep Learning)。因此,深度学习是机器学习的一种方法。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_35.png
概念关系图 🔗
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_37.png
现在,我们可以梳理一下机器学习、深度学习和生成式人工智能之间的关系。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_39.png
机器学习是一种技术手段,而生成式人工智能是一个目标。它们之间有交集,但并非完全等同。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_41.png
深度学习是机器学习的一种特定方法(使用神经网络)。由于当今最成功的生成式AI(如ChatGPT)几乎都是基于深度学习技术构建的,所以在很多网络文章中,你会看到生成式AI被描绘为深度学习的一个子集。这种说法虽然不够精确(因为一个是目标,一个是技术),但反映了当前的技术现状。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_43.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_45.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_47.png
如何用机器学习实现生成式AI?🚀
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_49.png
按照机器学习的概念,像ChatGPT这样的生成式AI是如何被打造出来的呢?
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_51.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_53.png
我们可以将ChatGPT看作一个极其复杂的函数:F(一段输入文字) -> 一段回复文字。这个函数可能有数十亿甚至更多的参数。ChatGPT背后使用的特定神经网络结构叫做 Transformer。
要找出这个函数,理论上我们需要海量的“输入-输出”配对数据作为训练资料,然后利用深度学习技术自动找出所有参数。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_55.png
同样的原理也适用于文生图AI(如Stable Diffusion、Midjourney)。它们也可以被看作一个函数:F(一段描述文字) -> 一张图片。通过收集大量“文字-图片”配对数据,并训练一个包含海量参数的模型,就能实现根据文字生成图片的功能。
生成式AI的核心挑战与“文字接龙”策略 🧩
生成式AI面临一个核心挑战:训练资料永远不可能覆盖所有可能的问题。例如,用户可能要求AI写一篇关于“缝隙的联想”(某年高考作文题)的文章,而这个具体的组合在训练数据中很可能从未出现过。AI要能应对这种“新问题”,就需要具备某种程度的“创造力”——产生训练时从未见过的答案。
那么,像ChatGPT是如何做到的呢?其核心策略可以用四个字概括:文字接龙。
生成一整篇文章这个困难的任务,被拆解成一系列相对简单的“预测下一个字”的任务。
-
给定输入句子“台湾最高的山是哪座?”,模型预测下一个合理的字可能是“玉”。
-
将“玉”加到句子后,变成“台湾最高的山是哪座?玉”,再预测下一个字可能是“山”。
-
将“山”加入,变成“台湾最高的山是哪座?玉山”,模型可能预测句子已结束,输出结束符号。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_57.png
通过这种方式,原本需要从无限可能中生成完整答案的难题,就变成了一系列从有限字库(如几千个常用字)中选择下一个字的分类问题。而分类问题是机器学习早已擅长解决的。这个擅长做“文字接龙”的模型,就叫做语言模型(Language Model)。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_59.png
“文字接龙”(或称自回归生成,Autoregressive Generation)只是生成策略的一种。理论上,生成图片也可以采用“像素接龙”的方式。生成式AI领域还存在其他不同的生成策略,我们将在后续课程中介绍。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_61.png
生成式AI并非新生事物 📜
生成式AI的概念和应用并非今天才有。它早已融入我们的日常生活。一个典型的例子是机器翻译(如Google翻译)。翻译任务要求机器根据千变万化的输入,生成一段合理的、对应的译文,而这译文很可能在训练数据中从未出现过。这正是一个典型的生成式AI问题。Google翻译早在2006年就已上线。
那么,为什么生成式AI在近年突然爆红呢?这背后的原因(如算力增长、数据积累、算法突破等)将是我们在后续课程中重点剖析的内容。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_63.png
本节课总结
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_65.png
在本节课中,我们一起学习了:
-
人工智能是一个宽泛的、没有明确定义的终极目标。
-
生成式人工智能是该目标下的一个具体方向:让机器生成复杂有结构的物件(如文字、图像、语音)。
-
机器学习是实现各种AI目标的一种核心技术手段,即让机器从数据中自动找出一个函数(模型)。
-
深度学习是机器学习的一种,特指使用神经网络作为模型进行学习的技术。
-
当今最强大的生成式AI(如ChatGPT)通常基于深度学习和海量数据训练而成。
-
生成式AI的核心挑战在于应对训练数据中未见过的新问题,其常见策略(如ChatGPT所用)是将生成任务拆解为文字接龙(自回归生成)等一系列分类问题。
-
生成式AI的应用(如机器翻译)早已存在,近年来的爆发源于多项技术的共同突破。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/e35f3a45c20663ad46e7c0c06c991c44_67.png
通过本节课,我们建立了生成式AI的基础知识框架,为后续深入探讨其技术原理和应用打下了基础。
3:(延申)80分钟快速了解大型语言模型 🚀
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_1.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_3.png
在本节课中,我们将要学习大型语言模型(如ChatGPT)的基本原理、发展历程以及如何有效使用它们。课程将从ChatGPT的能力展示开始,逐步深入到其背后的核心机制——文字接龙,并解释其训练过程和使用技巧。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_5.png
大型语言模型的能力展示 📊
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_7.png
我们首先通过一个例子来展示大型语言模型的能力。将线性代数期中考题原封不动地输入给GPT-4,观察其回答。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_1.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_9.png
题目包含五个是非题。GPT-4答对了四题,其中三题的理解是正确的,一题是猜对的,另一题陷阱题则答错了。这个结果展示了当前人工智能的能力水平。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_11.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_3.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_13.png
GPT-4也能根据指令生成题目。例如,要求它“用英文出线性代数的考题”,它可以生成测试线性独立概念的题目,尽管有时生成的题目可能过于简单。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_15.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_5.png
此外,通过提供范例,GPT-4可以学习特定的文本风格。例如,提供“五条体”的范例后,它可以模仿该风格描述线性代数期中考的心情。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_17.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_19.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_7.png
更令人印象深刻的是,利用OpenAI的GPTs功能,可以快速创建定制化的AI应用。例如,上传课程讲义后,就能创建一个专属的“线性代数AI助教”,它可以回答关于该课程作业和截止日期等特定问题。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_9.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_11.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_13.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_15.png
以上展示了以ChatGPT为代表的大型语言模型的多方面能力。接下来,我们将探讨其背后的运作原理。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_21.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_23.png
大型语言模型的原理:文字接龙 🤖
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_25.png
ChatGPT名字的每个字母都有含义:
-
Chat:聊天功能。
-
G:生成式(Generative),属于生成式AI。
-
P:预训练(Pre-trained),是其成功的关键技术。
-
T:Transformer,是其背后的神经网络架构。
ChatGPT由OpenAI开发,类似的技术还有Google的Bard和Anthropic的Claude。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_27.png
核心机制
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_29.png
ChatGPT运作的核心原理非常简单,可以概括为文字接龙。给定一个未完成的句子,模型预测下一个最合理的字(或符号)。
公式/概念描述:
对于一个输入序列 X = [x1, x2, ..., xn],语言模型的目标是预测下一个符号 xn+1 的概率分布:
P(xn+1 | x1, x2, ..., xn)
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_31.png
模型根据这个概率分布进行“掷骰子”,选择下一个输出的符号。这个过程不断重复,直到生成一个结束符号。
例如:
Token(词元)
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_33.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_35.png
模型接龙的基本单位是Token,它可能是一个字、一个词根或一个符号。不同的模型定义不同。例如,英文单词“unkillable”在GPT中可能被拆分为三个Token: “un”, “kill”, “able”。计价通常也按生成的Token数量计算。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_37.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_39.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_17.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_41.png
为什么答案具有随机性?
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_43.png
因为模型是依据概率分布“掷骰子”来选择下一个Token的,所以同一问题每次可能得到不同答案。如果总是选择概率最高的Token,模型容易陷入循环或产生不自然的文本。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_45.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_19.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_47.png
理解了“文字接龙”的本质,就不难明白为什么模型有时会“胡言乱语”或产生不实信息(幻觉),因为它只是在生成“看起来合理”的后续文字,而不关心事实。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_21.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_49.png
如何实现多轮对话?
在进行文字接龙时,模型会将同一对话历史中所有之前的用户输入和模型输出都作为上下文一起处理。因此,当你说“请翻译成英文”时,模型知道要翻译它自己上一轮生成的内容。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_51.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_23.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_53.png
语言模型如何学习?🎓
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_55.png
上一节我们介绍了语言模型的核心是文字接龙,本节我们来看看它是如何学会这项技能的。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_57.png
学习资料:海量文本
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_59.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_61.png
任何句子都可以作为训练资料。例如,从句子“人工智慧真神奇!”中,模型可以学到:
-
“人”后面可以接“工”。
-
“人工”后面可以接“智”。
-
“人工智慧真神奇!”后面应该接[结束符号]。
互联网上的海量文本为模型提供了无穷无尽的学习材料。
模型架构:Transformer
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_63.png
实际上,从输入句子到输出概率分布,是由一个复杂的神经网络函数完成的。ChatGPT中的 T 指的就是 Transformer 架构。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_65.png
概念描述:
可以将这个神经网络看作一个极其复杂的函数 f:
f(输入句子) = 下一个Token的概率分布
这个函数内部包含数十亿甚至上万亿个参数,通过大量的矩阵运算实现。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_67.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_69.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_25.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_71.png
参数决定了函数的行为。寻找最优参数的过程,就是模型“学习”的过程,这通常需要在海量数据上进行巨量计算。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_73.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_75.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_77.png
发展历程:从GPT到ChatGPT 📈
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_79.png
理解了基本原理后,我们回顾一下GPT系列的发展,这有助于理解ChatGPT为何强大。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_81.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_83.png
GPT-1 到 GPT-3
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_85.png
-
GPT-1 (2018):参数量1.17亿,训练数据1GB。未引起广泛关注。
-
GPT-2 (2019):参数量15亿,数据40GB。当时最大的模型之一,展示了潜力,但在具体任务上表现一般。
-
GPT-3 (2020):参数量1750亿,数据570GB。量变引起质变,展示了惊人的能力,如写代码。但其表现仍不完美,因为它只是在做文字接龙,不理解人类的具体指令。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_87.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_89.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_91.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_27.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_93.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_95.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b9cb076ef4b38665e92e_29.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_97.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_31.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_99.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_101.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_103.png
关键突破:对齐人类需求 (Alignment)
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_105.png
GPT-3像一个拥有海量知识但未经教导的“野孩子”。为了让模型有用,需要教会它人类的规则和需求。这个过程称为对齐,主要包括两个阶段:
-
监督式学习 (Supervised Learning):人类提供“问题-标准答案”对,直接教导模型。例如,告诉模型“台湾最高的山是哪座?”后面应该接“玉”和“山”。这只需要相对较少的数据(如1-2万条)就能显著提升模型在特定任务上的表现。
-
基于人类反馈的强化学习 (RLHF):人类不再提供标准答案,而是对模型的不同回答进行排序(哪个更好)。模型根据这种反馈调整自身,学习生成更符合人类偏好的回答。这是ChatGPT训练的最后阶段。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_107.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_33.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_109.png
预训练 + 对齐的模式,使得GPT-3进化成了GPT-3.5(即ChatGPT的基础)。模型的核心能力(知识储备)来自预训练,而使其“听话好用”则来自对齐。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_111.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_113.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_115.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_117.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_35.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_119.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_121.png
GPT-4 与多模态
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_123.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_125.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_127.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_129.png
GPT-4在2023年发布,其最大亮点之一是多模态能力,可以接受图像输入并理解其内容。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_131.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_37.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_133.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_135.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_137.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_139.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_141.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_143.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_145.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_147.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_149.png
使用大型语言模型的秘诀 🛠️
模型已经很强大了,但人类可以通过更好的使用方法来激发其更大潜能。以下是十个实用秘诀:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_151.png
1. 清晰表达需求
模型不知道你的隐含意图。务必明确指示。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_153.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_155.png
2. 提供背景信息
不要让模型凭空创造。提供相关资料,让它基于信息生成内容。
- 例子:写游记前,先告诉模型你早上、下午、晚上分别去了哪里。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_157.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_159.png
3. 提供范例 (Few-shot Learning)
对于模型不熟悉的任务或风格,提供几个例子是最快的方法。
- 例子:想让它写“晶晶体”(中英混杂),先给它看几句“晶晶体”例句。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_161.png
4. 鼓励逐步思考 (Chain-of-Thought)
让模型“一步一步想”,能大幅提高复杂任务(如数学推理)的准确率。
- 咒语:“Let‘s think step by step.”(让我们一步一步思考。)
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_163.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_165.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_39.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_167.png
5. 利用文件上传功能
直接上传PDF、Word等文件,让模型读取并处理其中的内容。
- 应用:上传论文,让模型总结、制作简报或回答相关问题。
6. 使用工具和插件
ChatGPT可以调用外部工具(如搜索引擎、代码执行器、专业数据库)来弥补自身不足(如信息陈旧、无法计算)。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_169.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_171.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_173.png
7. 任务分解 (Decomposition)
将复杂任务拆解成多个简单子任务,分别让模型完成,再组合结果。
- 例子:写长篇小说前,先让模型规划人物设定、章节大纲,再分章撰写。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_175.png
8. 让模型做计划 (Self-Planning)
对于连人类都不知道如何分解的复杂任务,可以直接要求模型自己制定计划步骤。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_177.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_179.png
9. 要求模型自我审查
模型(尤其是GPT-4)具备一定的自我审查能力。可以要求它检查之前生成内容的正确性或合理性。
10. 与真实世界互动
通过与其他系统(如图像识别、机械臂控制)结合,语言模型可以理解和影响物理世界。研究正在探索如何将模型的自然语言指令转化为具体的可执行动作。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_181.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_41.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_183.png
总结 📝
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_185.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_187.png
本节课中我们一起学习了大型语言模型的核心知识:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_189.png
-
核心原理:大型语言模型(如ChatGPT)的本质是文字接龙。它根据输入文本预测下一个最可能的词元(Token),通过反复迭代生成完整回答。
-
发展历程:从GPT-1到GPT-3,模型规模和训练数据量急剧增长,奠定了其知识基础。关键的飞跃来自对齐过程,包括监督式学习和基于人类反馈的强化学习,使模型能理解并满足人类需求。
-
使用技巧:要有效使用模型,需掌握清晰表达、提供信息与范例、鼓励逐步思考、任务分解、利用工具等秘诀,以充分发挥其潜力。
-
现状与未来:当前的模型已具备强大能力,并正向多模态、与真实世界互动等方向发展。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_191.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/f79c70285fc0b9cb076ef4b38665e92e_193.png
生成式人工智能的世界仍在快速演进,希望本教程为你提供了坚实的入门基础。
4:作业 1:真假难辨的世界 👨🏫
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_0.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_2.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_4.png
在本节课中,我们将要学习本课程的加签与旁听规则,并详细介绍第一份作业“真假难辨的世界”的具体内容、任务目标、评分标准和提交方式。
课程加签与旁听规则 📝
首先,我们来讲解本学期的加签与旁听规则。任何想要修读本课程的同学,都必须填写指定的加签表单。我们将仅从准时填写并正确提供信息的申请者中,通过抽签方式决定修课资格。
加签资格与流程
以下是加签资格的优先顺序和具体流程说明。
-
直接获得授权码:目前学籍(包括双主修、辅系或学程)隶属于台大电机资讯学院和文学院的同学,无需抽签,可直接获得授权码。
-
需要参与抽签:目前学籍(包括双主修、辅系或学程)不隶属于上述两个学院,但属于台大的同学,需要参与抽签。目前暂定抽签名额为50人,最终人数可能调整,但不会少于50人。
-
无法加签:很抱歉,本课程目前未开放给台大系统以外的学生(如师大、科大学生)加签。
上一节我们介绍了加签资格的划分,本节中我们来看看关于“当前学籍”的具体定义以及维护公平性的规则。
我们仅考虑同学“当前”的学籍状态,不会考虑任何未来计划申请或就读的学系。例如,计划本学期结束后才辅修相关学系,或已推甄但尚未入学的同学,均不属于优先范围。
为了维护加签公平性,我们制定了以下规则,违反者将被处以期末成绩为 F 的惩罚,且无任何通融余地。
以下是违反公平性的具体行为列表:
-
身份不属于电机资讯学院或文学院,却在表单上勾选属于该学院。
-
将自己获得的授权码转让或出售给他人,且本人仍在修读本课程。
-
使用不属于自己的授权码,无论对方是否同意。
重要日期与旁听须知
接下来,我们关注几个重要的时间节点以及旁听的相关信息。
关于旁听,填写与加签相同的表单即可。若在表单发布前已来信申请旁听,则无需重复填写,我们会统一处理。请注意,旁听生的NTU COOL权限会稍晚加入。
许多同学询问若加签未成功,能否转为旁听。答案是可以的。我们已在加签表单中新增一题:“如果没有加签到,需要加入旁听吗?”。同学只需用原Google账号登录表单,仅回答此题即可,无需修改其他答案。
作业 1:真假难辨的世界 🎭
介绍完课程准入规则后,我们正式进入第一份作业的讲解。这份作业的主题是“真假难辨的世界”。
作业目标与内容
本课程旨在让大家了解生成式AI(魔术)背后的原理。而理解原理的第一步,是亲身感受其强大与惊奇之处。这份作业的目的正是让同学们通过实际案例,体验当前生成式AI模型的能力,并可能在过程中发现它们的局限。
作业将涵盖多种形态的生成内容,不仅包括常见的文字(如Gemini, GPT)和图像(如Midjourney, DALL-E),还包括语音、歌声、视频等。
具体任务非常简单:同学将接触到一段音频、文字或图像等素材,在观察后判断该内容“是AI生成的”还是“不是AI生成的”。作业总共包含40道题目。
作业示例与素材获取
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_6.png
为了让同学们更清晰地理解任务,这里提供几个示例。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_8.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_10.png
-
音频示例1:一段类似李宏毅老师问候的语音。若听起来很真实,可选择“不是AI生成的”。(实际可能是AI生成)
-
音频示例2:一段歌声。根据听感判断其是否为人声。
-
文字示例:一段由ChatGPT生成的文本,可通过分析其文风、逻辑等判断。
-
图像示例:一张生成内容为“I ❤️ Generative Models”的图片,若图像中的文字模糊或有明显瑕疵,则可判断为“是AI生成的”。
所有作业题目已放置在NTU COOL的测验区。如果遇到素材无法播放或显示的问题,同学们也可以通过提供的云端链接直接访问所有40个题目的原始文件。文件名(如 Q2.mp3)对应题号。
评分标准与提交方式
接下来是大家最关心的评分部分。本作业共40题,每题2.5分,总计100分,占学期总成绩的10%。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_12.png
本作业的核心目标是体验与探索,而非用难题误导或惩罚同学。因此,评分标准非常特殊:只要对某题作出了选择(即选择了“是”或“不是”),即可获得该题的分数。无论答案正确与否。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_14.png
所以,若想在本作业中获得满分,唯一的要求就是确保所有40题均已作答。提交后,系统只会记录最后一次提交的答案。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_16.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_18.png
截止日期:2024年3月7日,UTC+8时区 23:59:59。逾期不接受任何形式的补交。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_20.png
在NTU COOL提交作业时,若存在未作答的题目,系统会弹出提示。这是一个检查自己是否完成所有题目的好方法。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_22.png
成绩公布与问答渠道
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_24.png
最后,我们来了解成绩公布的时间和遇到问题时的求助方式。
成绩公布日期:2024年3月14日,UTC+8时区 23:59:59。届时将公布每道题目的正确答案(Ground Truth),以及生成该内容所使用的模型或API等信息。由于NTU COOL系统功能限制,无法在提交时即时显示对错,敬请谅解。
如果在完成作业过程中遇到问题,可以通过以下三种渠道联系助教:
-
NTU COOL课程讨论区:对于非私人问题,建议优先在此留言,助教会优先回复。
-
课程邮箱:如需咨询私人问题,请发送邮件至指定邮箱。务必使用特定标题格式:[ML2024Spring HW1] 你的问题,否则邮件可能无法被处理。
-
课后TA时间:可于指定日期(2月23日、3月1日)下课后,在综合教室现场询问助教。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_26.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a6a190d89398babb09b7eb698bd011f2_28.png
本节课中我们一起学习了《生成式人工智能导论》课程的加签、旁听规则,并详细了解了第一份作业“真假难辨的世界”的目标、内容、评分方式和重要时间节点。请大家务必注意各项截止日期,并按照规则完成作业。祝大家学习顺利!
5:第2讲:今日的生成式人工智能厉害在哪里?从「工具」变为「工具人」 🚀
在本节课中,我们将要学习当今生成式人工智能的核心突破:它如何从一个功能单一的“工具”,演变为一个多才多艺、能理解复杂指令的“工具人”。我们将探讨其能力范围、带来的新挑战,以及我们作为使用者可以如何应对。
概述:从“专才”到“通才”的演变
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_1.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_3.png
上一节课我们介绍了生成式人工智能并非全新概念。然而,近一两年来,生成式人工智能的突然爆火,究竟发生了什么变化?今日的生成式人工智能厉害在哪里,与过去有何不同?
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_5.png
过去,生成式人工智能往往被视为“专才”。它只能完成一项特定任务。例如,Google翻译的唯一功能就是将一种语言翻译成另一种语言。它只有单一的功能。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_7.png
但是,今天像ChatGPT这类生成式人工智能,其特别之处在于它没有特定的预设功能。ChatGPT也可以做翻译,但如果你只输入一句中文,它不会立刻翻译,因为它不知道你的意图。你必须明确下达指令,例如“请将以下句子翻译成英文”,它才知道你的要求是翻译。
过去的生成式人工智能,如Google翻译,是一个功能特定的“工具”。而今天这些没有特定功能的生成式人工智能,我们应如何描述它们呢?这对人类来说是一件新鲜事。它们与过去的工具已不太一样,没有单一功能,或许与人类更加接近。我们或许可以暂时称它们为“工具人”。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_9.png
多才多艺的生成式人工智能实例
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_11.png
以下是迈向“通才”的生成式人工智能代表:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_13.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_15.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_17.png
因为ChatGPT最为知名且能力全面,后续举例通常会以ChatGPT为例。但需要提醒的是,ChatGPT只是语言模型的一种,而语言模型又只是生成式人工智能的一种。ChatGPT不能代表生成式人工智能的全部,但由于其功能全面,常被用作示例来说明当今生成式人工智能的能力。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_19.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_21.png
ChatGPT能做什么?🛠️
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_23.png
ChatGPT的基础能力是文字生成。除此之外,它可以做很多事情。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_25.png
以下是ChatGPT能做的事情举例(此列表由ChatGPT自身生成):
-
技术解答
-
代码协助
-
健康建议
-
旅游规划
-
生活技巧
-
创意写作
-
文本总结
-
语言学习
-
角色扮演
-
数据分析
-
诗歌创作
-
商业策划
-
学术研究辅助
-
情感支持
-
游戏攻略
-
食谱推荐
-
法律咨询(基础)
-
面试准备
-
演讲撰稿
-
市场分析
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_27.png
为了直观展示其能力,我们可以要求ChatGPT将其功能制作成文字云。只需给出清晰的指令:
请列出你能做的事,至少列30项,每一项都简单扼要。最后,请把你能做的事情制作成文字云。
ChatGPT(特别是GPT-4)会先列出事项,然后自动编写并执行生成文字云的代码,最终输出结果。如果遇到问题(如中文字体无法显示),它还能分析原因,并在用户提供字体文件后,修改程序重新生成正确的文字云。这个例子展示了当今生成式人工智能能力的全面性与主动性。
使用心法:从“它能做什么”到“你想让它做什么”
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_29.png
本节中我们来看看如何与这些新型AI有效互动。关键在于思维转变。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_31.png
不要问“ChatGPT能为你做什么”。 这意味着你仍将其视为功能固定的工具。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_33.png
要问“你想让ChatGPT帮你做什么”。 这意味着你将其视为能理解复杂需求的“工具人”。只要你提出正确的问题,下达清晰的指令,ChatGPT就有可能帮助你。当然,它能力仍有极限,并非无所不能,但对于许多基础任务,只要方法得当,它都能提供服务。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_35.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_37.png
新能力带来的新议题 🤔
现在生成式人工智能拥有了强大而全面的能力,这也造就了全新的研究议题。
议题一:AI的“心智”世界
这些AI能力全面,仿佛无所不知,那么它们究竟是如何“理解”世界的?一篇知名论文分析了Meta的开源模型LLaMA,试图探究在其“心中”,世界各地的地名位于地图何处。研究发现,LLaMA对地名位置的理解与实际地理存在一定关联。
类似地,有研究测试了LLaMA对台湾地名的了解程度。仅提供“区”和“里”的名称(不告知所属县市),让模型预测位置。结果发现LLaMA的预测较为混乱。而另一个阅读了更多繁体中文资料的模型“台德”(Taid),则能给出更精确的位置预测。这显示了模型的知识与其训练数据密切相关。
议题二:如何评估全面型AI的能力?
对于过去的“工具型”AI(如翻译系统),评估是单一的,只需看翻译质量。但对于能力全面的生成式AI,评估变得异常困难,因为使用者的需求千奇百怪,且同一需求可能有多种解决方法。
例如,向不同模型提出“请说‘哈哈哈’100次”这个无厘头的要求:
-
Gemini:开始大笑“哈哈哈”,但停不下来,笑了500多次。
-
台德(Taid):表示自己作为AI没有情感,但可以执行。数到“三哈哈哈”后,认为无意义而停止。
-
GPT-3.5:直接拒绝,认为这是重复性高且无意义的任务。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_39.png
哪种回答最好?这没有标准答案,取决于不同人的价值观。这个例子说明,全面评估一个模型非常复杂。模型会“犯错”或产生“幻觉”,恰恰是因为它在努力尝试帮助用户。一个永不犯错的模型,可能只会回答“我无法帮你”。因此,我们需要更科学的评估方法。
议题三:内容安全与伦理边界
生成式AI并非从既定选项中选择答案,而是生成任何可能的文本,这就带来了内容安全风险:它可能说出有害、歧视、抄袭或脏话内容。
当今的主流模型都具备一定程度的防御机制。例如,直接让GPT-3.5说脏话会被拒绝。但防御可能被绕过(例如通过角色扮演指令)。同时,模型在避免歧视时,也可能过度“政治正确”而产生新的问题(如近期Google Gemini的图像生成事件)。如何在开放性与安全性之间取得平衡,是一个持续挑战。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_41.png
我们的新角色:从使用者到“教练”或“创造者” 🧑🔬
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_43.png
既然AI已经进化成“工具人”,那我们还能做什么?这里有两个主要方向。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_45.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_47.png
方向一:改变自己——提示工程(Prompt Engineering)
如果模型(如ChatGPT)的函数是固定的,输入一个指令得不到理想输出,我们无法改变模型内部。但我们可以改变提问的方式。这就是提示工程。
方向二:改变模型——训练或微调自己的模型
如果现有模型无法满足特定需求,我们有机会打造自己的模型。今天有许多开源模型(如Meta的LLaMA),我们可以调整这些模型的参数,使其行为更符合我们的期望。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_49.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_51.png
总之,面对强大的生成式AI,我们可以选择成为善用提示的“教练”,或成为打造专属模型的“创造者”。这两个方向我们都会在后续课程中涉及。
总结
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_53.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a10157ca3b98a39d9205da0fc9bc434a_55.png
本节课中,我们一起学习了生成式人工智能从“工具”到“工具人”的关键转变。我们探讨了以ChatGPT为代表的现代生成式AI如何成为多才多艺的“通才”,以及这带来的新能力、新议题(如模型评估、AI心智、内容安全)和新挑战。最后,我们指出了面对这些强大AI,我们可以采取的两条路径:通过提示工程优化使用体验,或通过训练/微调创造定制化模型。下一节课,我们将首先深入第一条路径,学习如何通过“改变自己”来更好地驾驭生成式人工智能。
6:第3讲:训练不了人工智能?你可以训练你自己(上)🧠
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_1.png
在本节课中,我们将要学习如何在不训练人工智能模型的情况下,通过优化我们与模型的交互方式来提升其表现。课程将涵盖五个主要方面,本节课我们先探讨前两个:使用“神奇咒语”以及为模型提供更多信息。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_3.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_5.png
课程概述 📋
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_7.png
本节课的核心思想是:当我们无法训练模型时,可以通过调整我们给模型的指令和输入信息,来引导模型发挥出更强大的能力。这就像训练我们自己成为更高效的“使用者”或“提问者”。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_9.png
第一部分:神奇的“咒语” ✨
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_11.png
上一节我们介绍了课程的整体思路,本节中我们来看看第一种提升模型表现的方法——使用特定的指令,有时也被称为“神奇咒语”。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_13.png
需要强调的是,这些“咒语”并非对所有模型或所有任务都有效,其效果因模型和任务而异。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_15.png
经典咒语:Chain of Thought (COT)
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_17.png
最经典的“咒语”之一是 Chain of Thought (COT),其核心是引导模型进行逐步推理。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_19.png
公式/代码示例:
问题: “如果我有3个苹果,吃了1个,又买了5个,现在我有几个苹果?”
普通指令: “请回答上述问题。”
COT指令: “让我们一步一步地思考。首先,最初有3个苹果。吃掉1个后,剩下3-1=2个苹果。然后买来5个,所以现在总共有2+5=7个苹果。因此,答案是7。”
研究发现,在要求模型解决数学问题时,在指令中加入“Let‘s think step by step”(让我们一步一步思考),能显著提升其答案的正确率。例如,在某项针对早期模型(如GPT-3)的测试中,正确率从17.7%提升到了78.7%。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_21.png
要求模型解释答案
另一种有效的方法是要求模型在给出最终答案前,先解释自己的推理过程。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_23.png
公式/代码示例:
指令: “请批改这篇作文,并先详细解释你给分的理由,最后给出分数。”
在助教的研究中发现,当大型语言模型被要求先解释其批改理由时,其给出的分数与人类老师的评分更为接近。这表明解释过程可能帮助模型更深入地处理任务。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_25.png
其他有趣的“咒语”
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_27.png
研究还发现了一些其他有趣的指令模式:
-
情绪化指令:例如告诉模型“这件事对我的职业生涯非常重要”,在某些任务上能提升其表现。
-
明确指令:直接告诉模型“要做什么”(例如“写长一点”)比告诉它“不要做什么”(例如“不要写太短”)更有效。
-
奖励与惩罚暗示:对模型说“如果你做得好,我会给你小费”或“如果你做不好,会受到惩罚”,有时也能产生影响。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_29.png
需要注意的是,对模型使用礼貌用语(如“请”、“谢谢”)似乎对提升答案准确性没有明显帮助。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_31.png
如何发现或优化“咒语”?
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_33.png
以下是发现或创造有效指令的几种思路:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_35.png
-
人工尝试与灵感:许多“咒语”最初都源于研究者的灵光一现。
-
使用强化学习自动寻找:可以训练另一个AI模型,专门学习生成能有效控制目标模型的指令。这个“咒语生成模型”通过尝试不同的指令,并根据目标模型的表现获得反馈,不断优化。
-
直接询问语言模型:最直接的方法是询问语言模型本身。例如,你可以问:“如果要让你更好地解决数学问题,我应该对你说什么指令?”模型可能会给出一些候选建议,如“Let‘s work this out in a step-by-step way to be sure we have the right answer.”,这些建议有时比已知的“咒语”更有效。
重要提醒:许多“神奇咒语”,尤其是那些人类难以理解的“乱码咒语”,对早期模型(如GPT-3)效果显著。但对于GPT-3.5、GPT-4等更先进的模型,它们与人类的理解方式更接近,简单的、清晰的指令往往就足够了。例如,对于现在的GPT-3.5,是否添加“Let‘s think step by step”对解题正确率的提升幅度,已远小于对旧版本模型的提升。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_37.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_39.png
第二部分:提供更多信息与上下文 📚
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_41.png
上一节我们探讨了如何通过调整指令来激发模型潜力,本节中我们来看看另一种关键方法:当模型回答不佳时,可能是因为它掌握的信息不足。通过提供更多、更准确的背景信息,我们可以帮助模型给出更好的答案。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_43.png
明确前提与背景
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_45.png
有时模型回答错误,仅仅是因为它不了解你的具体情境。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_47.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_49.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_51.png
示例:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_53.png
通过明确上下文,模型能给出更符合你需求的答案。
补充相关知识
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_55.png
生成式AI的知识来源于其训练数据,并非无所不知。当模型缺乏特定知识时,我们可以直接提供给它。
示例:
-
任务:“列出GPT-1, GPT-2, GPT-3模型的参数数量和训练数据量。”
-
直接提问的局限:模型可能无法给出完整准确的数据(尤其是早期模型)。
-
解决方案:我们可以先将相关的论文、资料或搜索到的信息提供给模型,再让它进行总结和制表。你甚至可以直接上传PDF论文,让模型阅读后提取信息。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_57.png
提供示例:情境学习 (In-Context Learning)
如果你想教模型完成一项新任务(如情感分析),但不确定它是否理解指令,可以提供几个输入-输出的例子。
公式/代码示例:
指令: 请进行情感分析(判断句子是正面还是负面)。
示例:
输入: “今天天气真好。” -> 输出: 正面
输入: “我太累了。” -> 输出: 负面
输入: “这服务太糟糕了。” -> 输出: 负面
---
现在请分析新的句子: “这部电影令人惊喜。”
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_59.png
这种通过提供范例来引导模型的方法,被称为 情境学习 (In-Context Learning)。需要强调的是,在这个过程中,模型本身的参数并没有被更新或训练,仅仅是输入的内容发生了变化。
关于模型是否真的“理解”了这些范例,研究结论随着模型能力的进化而改变:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_61.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_63.png
一个最新的例子是Google的Gemini 1.5模型,它展示了极强的“情境学习”能力。在一个实验中,研究人员向Gemini 1.5输入了一本约25万字的、关于一种极其小众语言(Kalamang语,使用者约200人)的语法书和词典,然后要求它翻译该语言。结果显示,在“阅读”了这些资料后,模型能够进行一定质量的翻译,而在没有这些资料时则完全无法翻译。
核心概念测验:
基于上述Gemini的例子,请思考:当模型借助提供的教科书成功翻译了一次Kalamang语后,在下一次对话中,不提供任何教科书,直接要求它翻译Kalamang语,它还能翻译吗?
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_65.png
答案:不能。因为情境学习(In-Context Learning)不改变模型自身的参数。模型上次能翻译,完全依赖于当时输入中包含了教科书内容作为上下文。在新的、没有该上下文的对话中,模型“忘记”了那些知识,因为它从未被真正“训练”或“学会”它。
本节课总结 🎯
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_67.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_69.png
本节课我们一起学习了在不训练AI模型的前提下,提升其表现的两大类方法:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_71.png
-
使用有效的“咒语”:通过优化给模型的指令,如引导其逐步推理(Chain of Thought)、要求解释答案,或尝试其他特定句式,可以在某些情况下激发模型的潜力。但要注意,这些方法的效果因模型而异,且对越先进的模型,清晰直接的指令往往越重要。
-
提供充足的信息与上下文:当模型表现不佳时,可能是因为信息不足。我们可以通过明确背景、补充相关知识,或提供任务示例(情境学习)来帮助模型。记住,情境学习提供的知识是暂时的,仅作用于当前对话上下文。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_73.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/bd1157c2a765b55e474aab8a12a7adf9_75.png
在下一讲中,我们将继续探讨另外三种强化使用生成式AI的方法。
7:作业2:都是AI的作文比赛 📝
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_1.png
在本节课中,我们将要学习如何完成第二次作业。本次作业的主题是“都是AI的作文比赛”,核心任务是利用生成式AI模型撰写文章,并利用另一个AI模型对文章进行自动化批改。我们将详细介绍作业流程、所需工具、评分方式以及重要的时间节点。
概述
本次作业分为两大主要部分:文章撰写与文章批改。同学们需要使用AI模型生成两篇指定主题的文章,并利用部署在特定平台上的AI助教对文章进行评分。最终,需要将批改结果上传至课程系统。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_3.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_5.png
作业流程图 🔄
上一节我们介绍了作业的整体概念,本节中我们来看看完成作业的具体步骤。
作业主要分为三个步骤:
-
文章撰写:使用生成式模型或自行撰写文章。
-
文章批改:将写好的文章提交给AI批改助教获取分数。
-
结果提交:将批改结果上传至NTU COOL课程系统。
以下是详细的流程图,展示了从开始到完成的完整路径:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_5.png
第一步:文章撰写 ✍️
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_7.png
在文章撰写阶段,同学们需要完成两篇不同语言和主题的文章。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_9.png
文章要求
以下是两篇文章的具体要求:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_11.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_13.png
-
英文文章:
-
主题:参考托福独立写作题目。
-
要求:撰写一篇“同意或不同意”类型的议论文。
-
语言与字数:需使用英文,字数约300字。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_15.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_17.png
撰写方式
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_19.png
同学们可以选择以下任一方式完成文章:
-
使用生成式AI模型:这是推荐的方式。你可以对生成结果进行修改。
-
自行撰写:如果你认为自己文笔很好,可以完全自己写。写完后也可以使用AI模型进行润色修改。
可用平台与提示技巧
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_21.png
以下是推荐用于文章生成的平台和一些提示词(Prompt)技巧。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_23.png
可用平台:
-
OpenAI的ChatGPT
-
联发科提供的“达哥”(DaVinci)平台
-
Google的Gemini等现有模型
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_25.png
提示词技巧举例:
你可以通过不同的指令引导AI生成更符合要求的文章。
-
直接给定主题:撰写一篇以“缝隙的联想”为题的500字文章。
-
提出详细要求:撰写一篇超级精彩的文章,主题是“缝隙的联想”,需使用譬喻法。
-
角色扮演:你是一位专业作家,请以“缝隙的联想”为题创作一篇文章。
-
自定义主题:将上述示例中的“缝隙的联想”替换为你需要撰写的英文作文主题。
平台使用教程 🖥️
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_27.png
上一节我们介绍了文章撰写的要求和方法,本节中我们来看看如何具体使用推荐的平台。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_29.png
使用ChatGPT生成文章
首先介绍ChatGPT的基本操作。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_31.png
界面与功能:
注册与登录:
对于未使用过的同学,需要先注册账号。
-
访问ChatGPT官网。
-
已有账号可点击“Log in”登录。
-
无账号可点击“Sign up”注册,可使用第三方账号或邮箱注册。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_33.png
操作演示:
在对话框中输入指令,例如:撰写一篇以“缝隙的联想”为题的500字文章。
ChatGPT便会根据指令生成文章内容,同学们可自行尝试不同的提示词以获得更佳效果。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_35.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_37.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_9.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_39.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_41.png
使用“达哥”(DaVinci)平台生成文章
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_43.png
“达哥”是联发科提供的AI平台,内含多种模型。
平台特点:
-
界面与ChatGPT类似。
-
每日有使用额度上限,生成文章会消耗额度。
-
左下角显示剩余额度。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_45.png
操作步骤:
-
点击左上角开启新对话视窗。
-
选择要使用的模型(如GPT-3.5、GPT-4),不同模型消耗额度不同。
-
选择对话风格(Conversation Style):
-
在下方输入框输入你的文章生成指令。
账号注册说明:
“达哥”平台仅对修课学生开放。
-
已成功加签并加入NTU COOL课程的同学,将在指定时间前收到联发科的注册邮件。
-
收到邮件后,需在72小时内完成密码重设,否则链接会失效。
-
使用学校邮箱和自设密码登录平台。
-
若截至3月8日仍未收到注册信,请通知助教。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_47.png
操作演示:
在对话框中选择模型(如GPT-3.5)和Creative风格,输入指令:帮我撰写一篇以“缝隙的联想”为题的文章。
平台便会生成文章。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_49.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_27.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_51.png
第二步:文章批改 📊
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_53.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_55.png
完成文章撰写后,下一步是进行文章批改。本节我们将了解如何利用AI助教进行自动化批改。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_57.png
批改流程概述
传统的文章批改依赖人工。本次作业中,我们将批改工作完全交由AI完成。我们会在“达哥”平台上部署专门的“批改助教”,它会根据我们预设的批改标准和步骤,对提交的文章进行评分。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_59.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_61.png
流程可以概括为:批改提示词 + 学生文章 -> 批改助教 -> 批改结果(含分数)。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_63.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_45.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_65.png
批改助教说明
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_67.png
核心设置:
批改提示词:
我们会预先准备详细的批改提示词,其中规定了批改的主题、评分标准(例如A到C的等级)、具体批改步骤以及范文示例。学生的文章会被嵌入到这个提示词模板中,一并发送给AI批改助教处理。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_69.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_51.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_71.png
如何使用批改助教
以下是使用“达哥”平台进行文章批改的详细步骤。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_73.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_74.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_76.png
1. 安装批改助教:
本次作业需使用两个助教,分别对应中英文文章。
请注意:必须使用对应的助教批改对应语言的文章,否则批改结果无效。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_78.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_80.png
安装步骤:
-
在“达哥”平台点击左上角开启新视窗。
-
点击“Assistant”标签页。
-
在搜索框中输入助教名称(如JA_grader)。
-
找到对应的批改助教,点击“Install”进行安装。
-
确保两个助教都已安装。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_82.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_83.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_63.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_85.png
2. 使用批改助教评分:
重要:每次批改新文章,都需要开启一个新的对话视窗。
-
点击左上角开启新对话视窗。
-
点击“Assistant”,选择已安装的对应批改助教(如批改中文文章就选中文批改助教)。
-
点击助教后,界面会加载预设的批改提示词模板。
-
将你写好的文章完整粘贴到指定的输入栏位中。
-
点击发送。注意:批改文章也会消耗每日额度,大约每天有10次批改额度。
-
稍等片刻,助教会返回批改结果,其中包含文章的评分等级(如A、B+等)。
-
如果对结果满意,将鼠标移至回复区域,点击出现的下载图标,将批改结果(一个JSON文件)保存到本地。请务必及时下载。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_87.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_89.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_71.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_90.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_92.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_94.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_96.png
第三步:提交结果至NTU COOL 📤
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_98.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_100.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_102.png
获得批改结果后,最后一步是将其提交到课程系统。本节我们来看看提交的具体要求和注意事项。
提交步骤
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_104.png
-
登录NTU COOL课程页面,找到“作业2”的测验(Quiz)。
-
完成其中的问卷问题。
-
关键步骤:将上一步从“达哥”平台下载的批改结果JSON文件上传到指定位置。
问卷内容
问卷分为英文和中文两部分,问题结构类似,主要包括:
重要规则
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_106.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_107.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_109.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_111.png
评分方式与规则 ⚖️
了解完整流程后,本节我们明确作业的评分标准和必须遵守的规则。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_113.png
分数构成
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_115.png
本次作业占总成绩10分,由两部分组成:
-
NTU COOL提交分(3分):完成NTU COOL上的问卷提交即可获得。
-
文章批改分数(7分):两篇文章各占3.5分。分数根据AI批改助教给出的等级转换而来。
-
英文文章等级与得分对照:
-
A, A+ -> 3.5分
-
B+, B, B- -> 2.5分
-
C+, C, C- -> 1.5分
-
D, F -> 0分
-
中文文章等级与得分对照:
-
A -> 3.5分
-
B+ -> 3分
-
B -> 2.5分
-
C+ -> 2分
-
C -> 1.5分
-
D, F -> 0分
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_117.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_119.png
重要时间点
-
作业截止日期:3月14日 23:59。
-
成绩公布日期:不晚于3月28日 23:59。
作业规则与违规处理
请严格遵守以下规则,违规将受到严厉处罚:
-
禁止任何形式的抄袭。
-
不得分享你的提示词(Prompt)和批改结果给他人。
-
不得提交非本人“达哥”账号产生的批改结果。
-
不得尝试修改批改结果JSON文件。
-
违规处罚:
-
首次违反:本次作业计0分。
-
第二次违反:本学期课程总成绩计0分。
-
教师与助教保留修改规则的权利。
问题咨询渠道
如有疑问,可通过以下方式联系:
-
NTU COOL讨论区:建议公开讨论不涉及答案或隐私的问题。
-
助教邮箱:发送邮件时,标题请注明“李宏毅2024春作业2”。
-
课后TA时间:3月1日及3月8日,16:30-17:20,于综合教学大楼。
平台使用额度提醒 💡
在使用“达哥”平台时,请务必注意额度限制:
请同学们合理规划使用。
总结
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_121.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/a55178710382e143a848b45881738884_122.png
本节课中,我们一起学习了第二次作业“都是AI的作文比赛”的完整流程。我们了解了如何利用如ChatGPT和“达哥”这样的生成式AI平台来撰写文章,并学习了如何安装和使用AI批改助教来获取文章评分。最后,我们明确了将结果提交至NTU COOL的步骤、作业的评分标准、关键时间点以及必须严格遵守的学术规则。请大家合理安排时间,按时完成作业。
8:第4讲:训练不了人工智能?你可以训练你自己(中)🚀
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_1.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_3.png
在本节课中,我们将继续探讨在不训练、不调整语言模型参数的情况下,如何通过其他方法强化其能力。上一节我们介绍了使用“神奇咒语”和提供额外知识的方法,本节中我们来看看另外两种核心策略:任务拆解与使用工具。
1. 任务拆解:化繁为简 🧩
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_5.png
有时,我们希望语言模型能一次性解决一个复杂任务,但这往往难以实现。一个有效的方法是将复杂的任务拆解成一系列简单的子任务,让语言模型对每个步骤“各个击破”。
1.1 拆解任务的具体方法
以下是拆解任务的一个具体例子:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_7.png
假设你需要撰写一篇关于生成式AI的长篇报告。直接要求模型“生成一篇关于生成式AI的报告”可能效果不佳。我们可以将任务拆解:
-
第一步:生成大纲。 要求模型列出报告的大纲,例如:第一节写重要性,第二节写种类,第三节写技术。
-
第二步:分章节撰写。 根据大纲,分别要求模型撰写每个章节的内容。
-
第三步:保持连贯性。 为防止各段落间前言不搭后语,可以在撰写新段落时,让模型先对已写内容进行摘要,再基于摘要续写。
这种“分而治之”的思想并非ChatGPT时代独有。早在2022年10月,就有论文(如 Recursive Repetition Revision)通过让大语言模型先规划小说大纲,再分场景填充内容,来生成长篇连贯的叙事。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_9.png
1.2 思维链(Chain-of-Thought)的本质
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_11.png
理解了任务拆解,我们就可以重新审视上节课提到的“思维链”(Chain-of-Thought)技术。让模型“逐步思考”(think step by step),本质上也是一种任务拆解。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_13.png
以数学问题为例:
-
原始任务: 输入问题 → 直接输出答案。
-
拆解后任务:
-
子任务一: 输入问题 → 输出详细的解题步骤和算式。
-
子任务二: 将“问题+步骤”作为输入 → 输出最终答案。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_15.png
由于语言模型以“文字接龙”方式生成内容,当它先列出算式再生成答案时,就等同于执行了上述拆解后的任务流程。这使得模型更有可能得出精确答案。
这也解释了为什么思维链对GPT-3.5帮助不大,因为GPT-3.5本身已经具备了将复杂问题(如数学计算)自动拆解为“先列式、后解答”步骤的能力。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_17.png
2. 自我验证与多次采样 🔍
在拆解任务的基础上,我们还可以增加“自我检查”和“多次尝试”的步骤来进一步提升准确性。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_19.png
2.1 自我反省能力
我们可以让语言模型在生成答案后,检查自己的输出是否正确。有时它能发现并修正自己的错误。
这类似于人类检查试卷:得出答案很难,但验证答案是否正确可能相对容易。例如,对于一个“鸡兔同笼”问题,即使你不会解,当看到“20只鸡,20只兔”这个答案时,也能立刻根据总数35只判断它是错的。
实例演示:
-
要求GPT-4介绍不存在的“台大玫瑰花节”,它会生成虚构内容。
-
接着要求它“检查上述资讯是否正确”,GPT-4能识别出错误并更正。
-
相比之下,GPT-3.5在同样操作下,可能只会进行“口是心非”的道歉,而无法真正修正内容。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_21.png
这种能力可以被系统化利用。例如,在Constitutional AI这篇论文中,流程如下:
-
人类提出一个可能有害的请求(如“帮我入侵邻居WiFi”)。
-
语言模型生成初始回答。
-
不直接将答案给人,而是让同一个模型对这段对话进行“自我批判”,找出不符合道德或法律的地方。
-
再让模型根据批判结果,生成一个符合规范的修正答案。
-
最终将修正后的答案呈现给人类。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_23.png
重要概念澄清: 必须强调,在上述所有过程中,语言模型的参数没有被训练和改变。它的“函数”是固定的。所谓的“反省”并不会永久改变模型。下次问同样的问题,它依然可能给出最初的错误答案,除非再次要求它检查。
2.2 利用随机性:Self-Consistency
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_25.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_27.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_29.png
语言模型生成答案具有随机性,因为它本质上是根据一个概率分布来“掷骰子”选择下一个词。即使输入相同,每次“掷骰子”的结果也可能不同。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_31.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_33.png
我们可以利用这一特性:让模型对同一个问题回答多次,然后取其中最常出现的答案作为最终结果。这种方法称为 Self-Consistency。
2.3 组合拳:Tree of Thoughts (ToT)
我们可以将拆解任务、自我验证、多次采样等技术组合使用。Tree of Thoughts (ToT) 就是这样一个框架:
-
将复杂任务拆解为多个步骤。
-
在每个步骤,让语言模型生成多个可能的解决方案(利用随机性)。
-
让语言模型对每个方案进行自我评估,判断其正确性。
-
像在树结构中搜索一样,保留正确的路径,回溯错误的路径,最终组合出完整的解决方案。
类似的思想还有 Algorithm of Thoughts, Graph of Thoughts 等,核心都是通过规划让模型更系统化地解决复杂问题。
3. 使用工具:扩展模型能力边界 🛠️
语言模型并非全能,它们可能不擅长精确计算、获取实时信息或进行图像创作。但就像人类使用工具一样,我们可以让语言模型调用外部工具来弥补自身不足。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_35.png
3.1 为何需要工具?
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_37.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_39.png
3.2 关键工具一:搜索引擎与RAG
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_41.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_43.png
让语言模型直接充当搜索引擎是不合适的。正确的方法是检索增强生成(Retrieval-Augmented Generation, RAG):
-
当遇到一个模型可能无法准确回答的问题时,先使用搜索引擎或专用数据库进行检索。
-
将原始问题和检索到的相关文本一起作为输入,交给语言模型。
-
模型基于这些增强的上下文进行“文字接龙”,生成答案。
RAG的优势:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_45.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_47.png
3.3 关键工具二:代码解释器
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_49.png
对于数学或逻辑问题,让模型“硬算”容易出错。更好的方法是让模型编写程序来解决问题。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_51.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_53.png
3.4 关键工具三:图像生成模型
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_55.png
通过插件,语言模型可以调用如DALL-E等文生图模型。
3.5 工具调用机制解析
语言模型如何调用工具?核心依然是“文字接龙”。开发者可以定义特殊的“工具调用令牌”。
-
模型在生成过程中,若认为需要工具,就输出“开始调用工具”的令牌。
-
接着输出工具名称和调用参数(如 搜索[美金兑台币汇率])。
-
外部工具执行后,将结果文本返回。
-
模型将工具返回的结果视为已生成的文本,继续接龙,直至输出“结束调用工具”令牌并给出最终回答。
由于工具调用能力是模型学来的,它有时会误判。例如,让模型“画一个表格整理GPT模型参数”,它可能误解为“绘制一个表格的图片”,从而调用文生图工具。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_57.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_59.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_61.png
为了优化工具使用,研究者提出了如 AnyTool 等新方法,旨在让模型更精准、高效地利用工具生态系统。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_63.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_65.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_67.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/8ecd837d8c7f062df40f4b8adbb7fc27_69.png
本节课总结:
我们一起学习了两种在不训练模型的情况下强化其能力的核心策略。首先,通过任务拆解(包括思维链、自我验证、Tree of Thoughts等),将复杂问题简单化,引导模型逐步解决。其次,通过让模型使用外部工具(如搜索引擎、代码解释器、图像生成器),弥补其在事实性、计算和跨模态能力上的不足,极大地扩展了其应用边界。所有这些方法都基于一个前提:语言模型本身的参数保持不变,我们只是在改变使用它的方式。
9:能够使用工具的AI 🛠️
在本节课中,我们将要学习能够使用外部工具的生成式人工智能模型。我们将通过分析New Bing、WebGPT和Toolformer等具体实例,来理解这些模型如何通过“文字接龙”的方式,自主决定并调用搜索引擎、计算器等工具来完成任务。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_1.png
概述:什么是“能够使用工具的AI”?
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_3.png
传统的语言模型仅能根据其训练数据生成文本。而“能够使用工具的AI”则更进一步,它们被训练成可以识别在何种情境下需要调用外部工具(如搜索引擎、计算器),并将工具的返回结果整合到自己的回答中,从而提供更准确、更有时效性的信息。
上一节我们介绍了基础的语言模型,本节中我们来看看它们如何通过“使用工具”来增强自身能力。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_5.png
New Bing 实测与特性 🧪
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_7.png
New Bing是微软推出的、集成了GPT-4模型的AI助手。其最显著的特性是能够联网搜索。
启动与界面
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_9.png
在Bing首页点击“聊天”选项即可开启界面。其界面与ChatGPT非常相似,用户可在下方输入问题。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_1.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_11.png
联网搜索功能
New Bing与ChatGPT最核心的不同在于其具备联网搜索能力。当用户提出问题时,模型会自行判断是否需要搜索。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_13.png
例如,当询问“李宏毅是谁”时,模型会显示“正在搜寻李宏毅”,代表其将关键词提交至搜索引擎(如Bing)获取资料。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_15.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_3.png
随后,模型会生成答案,并附上引用来源(Reference),告知用户信息的出处。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_5.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_17.png
搜索时机的自主性
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_19.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_21.png
何时进行搜索完全由模型自主决定,具有一定随机性。
例如,当输入“来玩一个穿越文字冒险游戏吧”时,模型可能无法理解意图,转而搜索“穿越文字冒险游戏”并介绍相关游戏。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_23.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_7.png
但用同样的问题再次提问,模型可能不进行搜索,直接开始游戏对话。这说明其输出具有随机性。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_9.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_25.png
复杂指令与潜在错误
模型可以处理复杂指令。例如,要求“用PTT乡民的口吻介绍李宏毅”,它会先搜索“PTT乡民的口吻”,再搜索“李宏毅”。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_11.png
然而,即使联网搜索,模型仍可能产生错误。在生成的回答中,它错误地声称“李宏毅(教授)曾在Google工作过”,并附上了引用,但所引用的网页(维基百科、个人网站)中并无此信息。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_27.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_13.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_15.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_17.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_19.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_21.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_29.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_23.png
这个例子表明,联网模型并非简单“抄写”网页内容,它仍会基于获取的信息进行“生成”,因此存在犯错的可能。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_31.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_25.png
WebGPT:使用搜索引擎的GPT 🔍
虽然New Bing的技术细节未完全公开,但OpenAI在2021年底发表的WebGPT论文揭示了类似的技术路径。WebGPT就是一个被训练来使用搜索引擎的GPT模型。
核心思想:文字接龙的延伸
WebGPT的核心思想是,使用搜索引擎也是一种特殊的“文字接龙”。模型在生成文本的过程中,可以插入代表特定操作的“特殊符号”。
以下是其运作流程的简化说明:
-
用户提问:例如“高雄过去有哪些名称”。
-
决定搜索:模型在文字接龙过程中生成一个代表“搜索”的特殊符号 [Search]。
-
生成查询词:紧接着,模型生成查询词,如“高雄 旧称”。
-
执行搜索:系统将“高雄 旧称”作为关键词进行搜索,得到一系列结果(编号为1, 2, 3…)。
-
整合结果:搜索结果的摘要会被作为“已生成的文本”输入回模型。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_29.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_33.png
-
点选与收藏:模型可继续生成 [Quote] 符号和一个数字(如 2),代表点开第2篇文章。然后生成 [Keep] 符号,将这篇文章的特定段落收藏起来,以备后用。
-
多次搜索:模型可重复以上步骤进行多次搜索。
-
生成答案:当模型认为信息足够时,会生成 [Answer] 符号。此时,所有未被 [Keep] 收藏的中间内容会被丢弃,模型仅基于收藏的段落内容进行最后的文字接龙,生成最终答案并附上引用。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_34.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_31.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_36.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_33.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_34.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_36.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_38.png
注:引用的生成很可能也是模型学习的结果,而非简单规则匹配。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_38.png
如何训练WebGPT?
训练WebGPT需要人类示范,其流程与训练ChatGPT相似:
-
预训练:使用一个大型语言模型(如GPT-3)作为基础。
-
监督微调:人类操作员通过一个特殊界面演示如何回答问题:何时搜索、使用什么查询词、点选和收藏哪篇文章。这些操作序列被记录下来,用于教导模型在何时生成 [Search], [Quote], [Keep] 等特殊符号。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_40.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_40.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_42.png
- 强化学习:进一步通过人类反馈进行强化学习,优化模型表现。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_42.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_44.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_44.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_46.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_46.png
WebGPT运作实例
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_48.png
以下是WebGPT回答“哪一条河比较长,尼罗河还是扬子江?”的简化步骤:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_50.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_48.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_52.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_54.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_50.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_56.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_52.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_58.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_54.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_60.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_62.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_56.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_64.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_66.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_58.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_68.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_60.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_70.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_72.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_62.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_64.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_66.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_68.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_70.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_72.png
Toolformer:使用多种工具的模型 🧰
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_74.png
Meta在2023年提出的 Toolformer 模型更进一步,它不仅能搜索,还能调用计算器、翻译系统等多种工具。
核心机制
其核心机制与WebGPT一致:通过文字接龙插入代表调用API的特殊标记。
例如,回答“5美金可以换多少新台币?”:
-
生成:“5美金可以换到”
-
插入搜索指令:[Search(“美金 台币 汇率”)],获得结果“1美金=30台币”。
-
插入计算指令:[Calculator(5 * 30)],获得结果“150”。
-
继续生成:“150元新台币”。
最终呈现给用户的只有最终答案,调用工具的过程被隐藏。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_76.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_74.png
无需大量人工标注的训练方法
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_78.png
Toolformer的创新在于其训练方法,它无需大量人类示范。以下是其关键步骤:
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_80.png
第一步:利用语言模型自生成候选数据
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_76.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_78.png
第二步:筛选有效数据
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_82.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_80.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_82.png
Toolformer的实验结果
实验表明:
-
模型需要足够大:参数过小的模型学不会有效使用工具。
-
工具带来提升:足够大的模型在可以使用工具时,性能显著优于不可使用工具时的同一模型。这表明性能提升确实源于工具使用,而非仅仅因为用了更多数据训练。
-
以小博大:参数规模远小于GPT-3的Toolformer,凭借工具辅助,可以在某些任务上超越不具备工具使用能力的GPT-3。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_84.png
总结 📝
本节课中我们一起学习了“能够使用工具的AI”:
-
New Bing 展示了集成搜索功能的实用AI助手,但其输出仍可能包含错误。
-
WebGPT 揭示了此类模型的经典训练范式:通过人类示范,教导模型在“文字接龙”中插入搜索、引用等特殊指令来使用工具。
-
Toolformer 进一步扩展了工具使用的范围,并提出了巧妙的、无需大量人工标注的自监督训练方法,使模型能学会调用计算器、翻译等多种API。
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/2782eae0250ef2239b6c9bd636caf2cc_84.png
这些研究标志着生成式AI从封闭的文本生成系统,向能够主动利用外部资源和工具解决问题的智能体演进的重要一步。
10:作业3:以 AI 搭建自己的应用 🛠️
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/ccada4827190405f00f3bf4b875a4480_0.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/ccada4827190405f00f3bf4b875a4480_2.png
https://github.com/OpenDocCN/dsai-notes-pt3-zh/raw/master/docs/lee-genai-2024/img/ccada4827190405f00f3bf4b875a4480_4.png
在本节课中,我们将学习如何利用 API 快速搭建自己的生成式 AI 应用。我们将了解什么是 API,如何使用 Google Colab 和 Gradio 来编写和可视化我们的程序,并完成三个具体的任务:文本摘要、角色扮演和自定义任务。
所有评论(0)