HowGPT3WorksVisualizationsandAnimationsGPT3的工作原理可视化和动画 JayAlammar发表的一篇blog,我用机器翻译转给大家看看,关于最火热的GPT3的工作原理。 原文地址: https:jalammar。github。iohowgpt3worksvisualizationsanimations ThetechworldisabuzzwithGPT3hype。Massivelanguagemodels(likeGPT3)arestartingtosurpriseuswiththeirabilities。Whilenotyetcompletelyreliableformostbusinessestoputinfrontoftheircustomers,thesemodelsareshowingsparksofclevernessthataresuretoacceleratethemarchofautomationandthepossibilitiesofintelligentcomputersystems。Let’sremovetheauraofmysteryaroundGPT3andlearnhowit’strainedandhowitworks。 科技界充斥着GPT3炒作。大规模语言模型(如GPT3)的能力开始让我们大吃一惊。虽然对于大多数企业来说,展示在客户面前的这些模型还不是完全可靠,但这些模型正在显示出聪明的火花,这些火花肯定会加速自动化的进程和智能计算机系统的可能性。让我们揭开GPT3的神秘面纱,了解它的训练方式和工作原理。 Atrainedlanguagemodelgeneratestext。 经过训练的语言模型生成文本。 Wecanoptionallypassitsometextasinput,whichinfluencesitsoutput。 我们可以选择将一些文本作为输入传递给它,这会影响它的输出。 Theoutputisgeneratedfromwhatthemodellearnedduringitstrainingperiodwhereitscannedvastamountsoftext。 输出是根据模型在扫描大量文本的训练期间学习的内容生成的。 Trainingistheprocessofexposingthemodeltolotsoftext。Thatprocesshasbeencompleted。Alltheexperimentsyouseenowarefromthatonetrainedmodel。Itwasestimatedtocost355GPUyearsandcost4。6m。 训练是将模型暴露于大量文本的过程。该过程已经完成。你现在看到的所有实验都来自那个训练有素的模型。估计耗资355GPU年,耗资460万美元。 Thedatasetof300billiontokensoftextisusedtogeneratetrainingexamplesforthemodel。Forexample,thesearethreetrainingexamplesgeneratedfromtheonesentenceatthetop。 3000亿个文本标记的数据集用于生成模型的训练示例。例如,这些是从顶部的一个句子生成的三个训练示例。 Youcanseehowyoucanslideawindowacrossallthetextandmakelotsofexamples。 您可以看到如何在所有文本上滑动一个窗口并提供大量示例。 Themodelispresentedwithanexample。Weonlyshowitthefeaturesandaskittopredictthenextword。 该模型提供了一个示例。我们只向它展示特征并要求它预测下一个单词。 Themodel’spredictionwillbewrong。Wecalculatetheerrorinitspredictionandupdatethemodelsonexttimeitmakesabetterprediction。 模型的预测将是错误的。我们计算其预测中的误差并更新模型,以便下次做出更好的预测。 Repeatmillionsoftimes重复数百万次 Nowlet’slookatthesesamestepswithabitmoredetail。 现在让我们更详细地看一下这些相同的步骤。 GPT3actuallygeneratesoutputonetokenatatime(let’sassumeatokenisawordfornow)。 GPT3实际上一次生成一个输出标记(让我们假设一个标记现在是一个词)。 Pleasenote:ThisisadescriptionofhowGPT3worksandnotadiscussionofwhatisnovelaboutit(whichismainlytheridiculouslylargescale)。Thearchitectureisatransformerdecodermodelbasedonthispaperhttps:arxiv。orgpdf1801。10198。pdf 请注意:这是对GPT3工作原理的描述,而不是讨论它的新颖之处(主要是荒谬的大规模)。该架构是基于本文https:arxiv。orgpdf1801。10198。pdf的transformer解码器模型 GPT3isMASSIVE。Itencodeswhatitlearnsfromtrainingin175billionnumbers(calledparameters)。Thesenumbersareusedtocalculatewhichtokentogenerateateachrun。 GPT3是巨大的。它用1750亿个数字(称为参数)对从训练中学到的内容进行编码。这些数字用于计算每次运行时要生成的令牌。 Theuntrainedmodelstartswithrandomparameters。Trainingfindsvaluesthatleadtobetterpredictions。 未经训练的模型以随机参数开始。训练会找到导致更好预测的值。 Thesenumbersarepartofhundredsofmatricesinsidethemodel。Predictionismostlyalotofmatrixmultiplication。 这些数字是模型中数百个矩阵的一部分。预测主要是很多矩阵乘法。 InmyIntrotoAIonYouTube,IshowedasimpleMLmodelwithoneparameter。Agoodstarttounpackthis175Bmonstrosity。 在我在YouTube上的人工智能介绍中,我展示了一个带有一个参数的简单ML模型。打开这个175B怪物的包装是一个好的开始。 Toshedlightonhowtheseparametersaredistributedandused,we’llneedtoopenthemodelandlookinside。 为了阐明这些参数的分布和使用方式,我们需要打开模型并查看内部。 GPT3is2048tokenswide。Thatisitscontextwindow。Thatmeansithas2048tracksalongwhichtokensareprocessed。 GPT3是2048个令牌宽。那就是它的上下文窗口。这意味着它有2048个处理令牌的轨道。 Let’sfollowthepurpletrack。HowdoesasystemprocessthewordroboticsandproduceA? 让我们跟随紫色轨道。系统如何处理robotics这个词并产生A? Highlevelsteps:高级步骤:Convertthewordtoavector(listofnumbers)representingtheword 将单词转换为表示单词的向量(数字列表)Computeprediction计算预测Convertresultingvectortoword将生成的向量转换为单词 TheimportantcalculationsoftheGPT3occurinsideitsstackof96transformerdecoderlayers。 GPT3的重要计算发生在其96个转换器解码器层的堆栈中。 Seealltheselayers?Thisisthedepthindeeplearning。 看到所有这些图层了吗?这就是深度学习中的深度。 Eachoftheselayershasitsown1。8Bparametertomakeitscalculations。Thatiswherethemagichappens。Thisisahighlevelviewofthatprocess: 这些层中的每一层都有自己的1。8B参数来进行计算。这就是魔法发生的地方。这是该过程的高级视图: YoucanseeadetailedexplanationofeverythinginsidethedecoderinmyblogpostTheIllustratedGPT2。 您可以在我的博文TheIllustratedGPT2中看到解码器内部所有内容的详细解释。 ThedifferencewithGPT3isthealternatingdenseandsparseselfattentionlayers。 与GPT3的不同之处在于密集和稀疏自注意力层的交替。 ThisisanXrayofaninputandresponse(Okayhuman)withinGPT3。Noticehoweverytokenflowsthroughtheentirelayerstack。Wedon’tcareabouttheoutputofthefirstwords。Whentheinputisdone,westartcaringabouttheoutput。Wefeedeverywordbackintothemodel。 这是GPT3中输入和响应(Okayhuman)的X射线图。注意每个令牌如何流经整个层堆栈。我们不关心第一个单词的输出。输入完成后,我们开始关心输出。我们将每个词反馈回模型。 IntheReactcodegenerationexample,thedescriptionwouldbetheinputprompt(ingreen),inadditiontoacoupleofexamplesofdescriptioncode,Ibelieve。Andthereactcodewouldbegeneratedlikethepinktokensheretokenaftertoken。 在Reactcodegenerationexample中,描述将是输入提示(绿色),此外还有几个descriptioncode示例,我相信。反应代码将像这里的粉红色令牌一样生成一个又一个令牌。 Myassumptionisthattheprimingexamplesandthedescriptionareappendedasinput,withspecifictokensseparatingexamplesandtheresults。Thenfedintothemodel。 我的假设是启动示例和描述作为输入附加,并使用特定标记分隔示例和结果。然后输入到模型中。 It’simpressivethatthisworkslikethis。BecauseyoujustwaituntilfinetuningisrolledoutfortheGPT3。Thepossibilitieswillbeevenmoreamazing。 令人印象深刻的是,它是这样工作的。因为您只需等到GPT3推出微调。可能性将更加惊人。 Finetuningactuallyupdatesthemodel’sweightstomakethemodelbetteratacertaintask。 微调实际上是更新模型的权重,使模型在某个任务上表现更好。 WrittenonJuly27,2020写于2020年7月27日