2023谷歌大型語言模型概念指南_第1頁
2023谷歌大型語言模型概念指南_第2頁
2023谷歌大型語言模型概念指南_第3頁
2023谷歌大型語言模型概念指南_第4頁
2023谷歌大型語言模型概念指南_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

PAGEPAGE10/11LLM

LLM概念指南Attheirmostbasiclevel,LargeLanguageModels(LLMs)arelikesophisticatedautocomplete.Giveninputtext("YoucanleadahorsetoLLMsoutputtextthat'sstatisticallylikelytofollow("butyoumakeitdrink"),basedonpatternslearnedfromtheirtrainingdata.canusethisbasicpropertyofLLMstopowerseveraldifferenttypesofapplications:在最基本的層面上,大型語言模型(LLMs)就像是復(fù)雜的自動完成。給定輸入文本(“你可以帶馬到水邊,”),LLMs會輸出基于其訓(xùn)練數(shù)據(jù)中學(xué)習(xí)到的模式,統(tǒng)計上可能跟隨的文本(“但你不能強(qiáng)迫它喝水”)。您可以使用LLMs的這種基本屬性來驅(qū)動幾種不同類型的應(yīng)用程序:Generatepoetry,shortstories,metaphors,blogposts,andothercreativecopy生成詩歌、短篇小說、隱喻、博客文章和其他創(chuàng)意文本Convertstructureddatatofreeformtext將結(jié)構(gòu)化數(shù)據(jù)轉(zhuǎn)換為自由形式的文本Extractandsummarizeinformationfromfreeformtext從自由形式的文本中提取和總結(jié)信息Generatecode生成代碼Translate翻譯Buildachatbotetc.構(gòu)建聊天機(jī)器人等。UsingLLMstobuildthesefeaturesdoesn'trequireanyMachineLearning(ML)expertise.needtocollectalargedatasetortrainamodel.AllittakestostartyourfirstLLMprototypeistodescribewhatyouwantthemodeltodoinafewsentences.使用LLMs構(gòu)建這些功能不需要任何機(jī)器學(xué)習(xí)(ML)專業(yè)知識。您不需要收集大量數(shù)據(jù)集或訓(xùn)練模型。要啟動您的第一個LLM原型,只需用幾句話描述您希望模型執(zhí)行的任務(wù)即可。Exampleapplications示例應(yīng)用PoemGenerator詩歌生成器Userinput:

WritemeWritemeafour-linepoemaboutpuppiesandAndroidsureitrhymes.Writemeafour-linepoemaboutpuppiesandAndroidphones.Makephones.Makesureitphones.MakesureitModeloutput:模型輸出:Puppiesarecute,AndroidPuppiesarecute,AndroidphonesareTheybothbringjoy,Andmakelifecomplete.ListGenerator列表生成器GenerateaGenerateabulletedlistofitemsIneedtopackfor用戶輸入:campingtrip.GenerateabulletedlistofitemsIneedtopackforathree-daythree-daycampingthree-daycampingModeloutput:Modeloutput:TentSleepingbagSleepingpadCampstovePotsandpansUtensilsFoodWaterFirst-aidkitSunscreenInsectrepellent* …cangetLLMstoproduceallsortsofusefulbehaviorslikethis,justbycraftingtheinputtext,alsocalledaprompt.TheartandscienceoffiguringouttherightwordingtogetLLMstodowhatyouwantiscalledpromptdesign(alsocalled"promptengineering"orsimply"prompting").您可以通過精心設(shè)計正確的輸入文本(也稱為提示)來讓LLMs產(chǎn)生各種有用的行為,就像上面的例子一樣。找出正確的措辭讓LLMs執(zhí)行您想要的操作的藝術(shù)和科學(xué)稱為提示設(shè)計(也稱為“提示工程”或簡稱“提示”)。PromptDesign101提示設(shè)計101Theprevioussectionshowedsomeexamplesofpromptsthatcontainaninstruction,likemeaThiskindofinstructionmayworkwellforcertaintypesoftasks.forotherapplications,anotherpromptingtechniquecalledfew-shotpromptingmayworkFew-shotpromptstakeadvantageofthefactthatlargelanguagemodelsareincrediblygoodatrecognizingandreplicatingpatternsintextdata.TheideaistosendtheLLMatextpatternthatitlearnstocomplete.Forexample,let'ssayyouwanttobuildanapplicationthattakesasinputacountrynameandoutputsitscapitalatextpromptdesignedtodojust前面的部分展示了一些包含指令的提示示例,例如“寫一首詩”。這種指令可能對某些類型的任務(wù)有效。但是,對于其他應(yīng)用程序,另一種提示技術(shù)稱為few-shot提示可能更有效。Few-shot提示利用了大型語言模型在文本數(shù)據(jù)中識別和復(fù)制模式的能力。其想法是向LLM發(fā)送一個文本模式,出其首都城市。這是一個旨在實(shí)現(xiàn)此目的的文本提示:Italy:RomeFrance:Italy:RomeFrance:Germany:Inthisprompt,youestablishapattern:[country]:[capital].Ifyousendthisprompttolargelanguagemodel,itwillautocompletethepatternandreturnsomethinglikethis:[country]:[country]:[capital]型,則它將自動完成該模式并返回類似于以下內(nèi)容:

。如果將此提示發(fā)送到大型語言模BerlinTurkey:BerlinTurkey:Greece:Thismodelresponsemaylookalittlestrange.ThemodelreturnednotonlythecapitalofGermany(thelastcountryinyourhand-writtenprompt),butalsoawholelistofadditionalcountry/capitalpairs.That'sbecausetheLLMis"continuingthepattern."Ifallyou'retryingtodoisbuildafunctionthattellsyouthecapitalofaninputcity("Germany:Berlin"),youreallycareaboutanyofthetextthemodelgeneratesafterIndeed,asapplicationdesigners,you'dprobablywanttotruncatethoseextraneousexamples.What'smore,you'dprobablywanttoparameterizetheinput,sothatGermanyisnotafixedstringbutavariablethattheenduserprovides:這個模型響應(yīng)可能看起來有點(diǎn)奇怪。該模型不僅返回了德國的首都(手寫提示中的最后一個國家),還返回了整個附加的國家/首都對列表。這是因?yàn)長LM正在“繼續(xù)模式”。如果您要構(gòu)建的所有內(nèi)容都是一個函數(shù),該函數(shù)告訴您輸入城市的首都(“德國:柏林”),那么您可能并不關(guān)心模型在“柏林”之后生成的任何文本。實(shí)際上,作為應(yīng)用程序設(shè)計者,您可能希望截斷那些無關(guān)的Italy:RomeFrance:Italy:RomeFrance:<userinputhere>:Youhavejustwrittenafew-shotpromptforgeneratingcountrycapitals.你剛剛寫了一個用于生成國家首都的few-shot提示。Youcanaccomplishalargenumberoftasksbyfollowingthisfew-shotprompttemplate.Here'safew-shotpromptwithaslightlydifferentformatthatconvertsPythontoJavascript:few-shotpromptpromptPythonJavascript:ConvertConvertPythontoJavascript.Python:print("helloworld")Javascript:console.log("helloworld")Python:forxinrange(0,100):Javascript:for(vari=0;i<100;i++){Python:${USERINPUTHERE}Javascript:takethis"reversedictionary"prompt.Givenadefinition,itreturnsthewordthatfitsthatdefinition:或者,接受這個“反向詞典”提示。給定一個定義,它會返回符合該定義的單詞:Givenadefinition,returntheworditGivenadefinition,returntheworditdefines.Definition:Whenyou'rehappythatotherpeoplearealsosad.Word:schadenfreudeDefinition:existingpurelyinthemind,butnotinphysicalrealityWord:abstractDefinition:Definition:${USERINPUTWord:mighthavenoticedthattheexactpatternofthesefew-shotpromptsvariesslightly.Inadditiontocontainingexamples,providinginstructionsinyourpromptsisanadditionalstrategytoconsiderwhenwritingyourownprompts,asithelpstocommunicateyourintentthemodel.您可能已經(jīng)注意到這些少樣本提示的確切模式略有不同。除了包含示例外,在提示中提供說明是編寫自己的提示時要考慮的另一種策略,因?yàn)樗兄谙蚰P蛡鬟_(dá)您的意圖。Promptingvstraditionalsoftwaredevelopment提示與傳統(tǒng)軟件開發(fā)Unliketraditionalsoftwarethat'sdesignedtoacarefullywrittenspec,thebehaviorofLLMsislargelyopaqueeventothemodeltrainers.Asaresult,youoftenpredictinadvancewhattypesofpromptstructureswillworkbestforaparticularmodel.What'smore,thebehaviorofanLLMisdeterminedinlargepartbyitstrainingdata,andsincemodelsarecontinuallyonnewdatasets,sometimesthemodelchangesenoughthatitinadvertentlychangewhichpromptstructuresworkbest.Whatdoesthismeanforyou?Experiment!differentpromptformats.與專門設(shè)計為精心編寫的規(guī)范的傳統(tǒng)軟件不同,LLM的行為對于模型訓(xùn)練者來說很大程度上是不透明的。因此,您通常無法預(yù)測哪種提示結(jié)構(gòu)對于特定模型最有效。更重要的是,LLM的行為在很大程度上取決于其訓(xùn)練數(shù)據(jù),由于模型不斷地在新數(shù)據(jù)集上進(jìn)行調(diào)整,有時模型會發(fā)生足以無意中改變哪些提示結(jié)構(gòu)最有效的變化。這對您意味著什么?實(shí)驗(yàn)!嘗試不同的提示格式。Model模型參數(shù)Everypromptyousendtothemodelincludesparametervaluesthatcontrolhowthemodelgeneratesaresponse.ThemodelcangeneratedifferentresultsfordifferentparameterThemostcommonmodelparametersare:您發(fā)送給模型的每個提示都包括控制模型生成響應(yīng)的參數(shù)值。模型可以根據(jù)不同的參數(shù)值生成不同的結(jié)果。最常見的模型參數(shù)包括:Maxoutputtokens:Specifiesthemaximumnumberoftokensthatcanbegeneratedtheresponse.Atokenisapproximatelyfourcharacters.100tokenscorrespondtoroughly60-80words.最大輸出標(biāo)記數(shù):指定響應(yīng)中可以生成的標(biāo)記的最大數(shù)量。一個標(biāo)記大約是四個字符。100個標(biāo)記大約對應(yīng)60-80個單詞。Temperature:Thetemperaturecontrolsthedegreeofrandomnessintokenselection.Thetemperatureisusedforsamplingduringresponsegeneration,whichoccurswhentopPandtopKareapplied.Lowertemperaturesaregoodforpromptsthatrequireamoredeterministic/lessopen-endedresponse,whilehighertemperaturescanleadtomorediverseorcreativeresults.Atemperatureof0isdeterministic,meaningthatthehighestprobabilityresponseisalwaysselected.topP溫度:溫度控制令牌選擇中的隨機(jī)程度。溫度用于響應(yīng)生成期間的抽樣,當(dāng)應(yīng)用 和topPtopK時發(fā)生。較低的溫度適用于需要更確定性/以導(dǎo)致更多樣化或創(chuàng)造性的結(jié)果。溫度為0是確定性的,這意味著始終選擇最高概率響應(yīng)。topKtopK:ThetopKparameterchangeshowthemodelselectstokensforoutput.AtopKofmeanstheselectedtokenisthemostprobableamongallthetokensinthemodel’svocabulary(alsocalledgreedydecoding),whileatopKof3meansthatthenexttokenselectedfromamongthe3mostprobableusingthetemperature.Foreachtokenselectionstep,thetopKtokenswiththehighestprobabilitiesaresampled.arethenfurtherfilteredbasedontopPwiththefinaltokenselectedusingtemperaturesampling.topKtopKtopKtopK: 參數(shù)改變了模型選擇輸出令牌的方式。1topKtopKtopKtopK表中所有令牌中最有可能的(也稱為貪婪解碼),而3的 意味著下一個令牌是從使用topK溫度最有可能的3個令牌中選擇的。對于每個令牌選擇步驟,將抽樣最高概率的 個令topKtopP牌。然后根據(jù) 進(jìn)一步過濾令牌,使用溫度抽樣選擇最終令牌。topPtopP:ThetopPparameterchangeshowthemodelselectstokensforoutput.areselectedfromthemosttoleastprobableuntilthesumoftheirprobabilitiesequalsthetopPvalue.Forexample,iftokensA,B,andChaveaprobabilityof0.3,0.2,and0.1andthetopPvalueis0.5,thenthemodelwillselecteitherAorBasthenexttokenbyusingthetemperatureandexcludeCasacandidate.ThedefaulttopPvalueis0.95.topPtopP: 參數(shù)會改變模型選擇輸出令牌的方式。令牌按照從最可能到最不可能的順序topPtopPtopP選擇,直到它們的概率之和等于 值。例如,如果令牌A、B和C的概率分別為0.3、topPtopP0.2和0.1, 值為0.5,則模型將使用溫度選擇A或B作為下一個令牌,并將C排除topPtopP在候選之外。默認(rèn)的 值為0.95。topPTypesofprompts提示類型Dependingonthelevelofcontextualinformationcontainedinthem,promptsareclassifiedintothreetypes.根據(jù)它們所包含的上下文信息的程度,提示被廣泛地分為三種類型。Zero-shotprompts零樣本提示Thesepromptsdonotcontainexamplesforthemodeltoreplicate.Zero-shotpromptsessentiallyshowthemodel’sabilitytocompletethepromptwithoutanyadditionalexamplesinformation.Itmeansthemodelhastorelyonitspre-existingknowledgetogenerateaplausible這些提示不包含模型復(fù)制的示例。零-shot提示基本上展示了模型在沒有任何額外示例或信息的情況下完成提示的能力。這意味著模型必須依靠其現(xiàn)有的知識來生成一個合理的答案。Somecommonlyusedzero-shotpromptpatternsare:一些常用的零-shot提示模式包括:Instruction-content指令內(nèi)容<Overallinstruction><Overallinstruction><Contenttooperateon>Forexample,例如,Summarizethefollowingintotwosentencesatthethird-gradelevel:Summarizethefollowingintotwosentencesatthethird-gradelevel:Hummingbirdsarethesmallestbirdsintheworld,andtheyarealsooneofthemostfascinating.TheyarefoundinNorthandSouthAmerica,andtheyareknownfortheirlong,thinbeaksandtheirabilitytoflyathighspeeds.Hummingbirdsaremadeupofthreemainparts:thehead,thebody,andthetail.TheTheheadissmallandround,anditcontainstheeyes,thebeak,andthebrain.Thebodyislongandslender,anditcontainsthewings,thelegs,andtheheart.Thetailislongandforked,andithelpsthehummingbirdtobalancewhileitisflying.Hummingbirdsarealsoknownfortheircoloration.Theycomeinavarietyofcolors,includinggreen,blue,red,andpurple.Somehummingbirdsareevenabletochangetheircolor!Hummingbirdsareveryactivecreatures.Theyspendmostoftheirtimeflying,andtheyarealsoverygoodathovering.Hummingbirdsneedtoeatalotoffoodinordertomaintaintheirenergy,andtheyoftenvisitflowerstodrinknectar.Hummingbirdsareamazingcreatures.Theyaresmall,buttheyarealsoverypowerful.Theyarebeautiful,andtheyareveryimportanttotheecosystem.Instruction-content-instruction指令-內(nèi)容-指令<Overallinstructionorcontextsetting><Overallinstructionorcontextsetting><Contenttooperateon><Finalinstruction>Forexample,例如,HereissometextI'dlikeyoutosummarize:HereissometextI'dlikeyoutosummarize:Summarizethefollowingintotwosentencesatthethird-gradelevel:Hummingbirdsarethesmallestbirdsintheworld,andtheyarealsooneofthemostfascinating.TheyarefoundinNorthandSouthAmerica,andtheyareknownfortheirlong,thinbeaksandtheirabilitytoflyathighspeeds.Hummingbirdsaremadeupofthreemainparts:thehead,thebody,andthetail.Theheadissmallandround,anditcontainstheeyes,thebeak,andthebrain.Thebodyislongandslender,anditcontainsthewings,thelegs,andtheheart.Thetailislongandforked,andithelpsthehummingbirdtobalancewhileitisflying.Hummingbirdsarealsoknownfortheircoloration.Theycomeinavarietyofcolors,includinggreen,blue,red,andpurple.Somehummingbirdsareevenabletochangetheircolor!Hummingbirdsareveryactivecreatures.Theyspendmostoftheirtimeflying,andtheyarealsoverygoodathovering.Hummingbirdsneedtoeatalotoffoodinordertomaintaintheirenergy,andtheyoftenvisitflowerstodrinknectar.Hummingbirdsareamazingcreatures.Theyaresmall,buttheytheyarealsoverypowerful.Theyarebeautiful,andtheyareveryimportanttotheecosystem.Summarizeitintwosentencesatthethird-gradereadinglevel.Continuation.Sometimes,youcanhavethemodelcontinuetextwithoutanyinstructions.Forexample,hereisazero-shotpromptwherethemodelisintendedtocontinueinputprovided:繼續(xù)。有時,您可以讓模型在沒有任何指令的情況下繼續(xù)文本。例如,這是一個零-shot提示,模型旨在繼續(xù)提供的輸入:OnceOnceuponatime,therewasalittlesparrowbuildinganestinafarmer'sbarn.ThissparrowUsezero-shotpromptstogeneratecreativetextformats,suchaspoems,code,scripts,musicalpieces,email,letters,etc.使用零-shot提示生成創(chuàng)意文本格式,例如詩歌、代碼、腳本、音樂作品、電子郵件、信件等。One-shotprompts一次性提示Thesepromptsprovidethemodelwithasingleexampletoreplicateandcontinuethepattern.Thisallowsforthegenerationofpredictableresponsesfromthemodel.這些提示為模型提供了一個單一的示例來復(fù)制和繼續(xù)模式。這允許模型生成可預(yù)測的響應(yīng)。Forexample,youcangeneratefoodpairingslike:例如,您可以生成食品搭配,如:Food:AppleFood:ApplePairswith:Food:PearPairswith:Few-shotprompts少樣本提示Thesepromptsprovidethemodelwithmultipleexamplestoreplicate.Usefew-shottocompletecomplicatedtasks,suchassynthesizingdatabasedonapattern.這些提示為模型提供了多個示例來復(fù)制。使用少量提示來完成復(fù)雜的任務(wù),例如基于模式合成數(shù)據(jù)。Anexamplepromptmaybe:一個示例提示可能是:Generateagroceryshoppinglistforaweekforoneperson.UsetheJSONformatgivenbelow.{"item":"eggs","quantity":"6"}{"artist":"bread","quantity":"oneloaf"}LLMsunderthehoodLLM底層原理Thissectionaimstoanswerthequestion-IsthererandomnessinLLMs'responses,oraretheydeterministic?本節(jié)旨在回答一個問題——LLM的回答中是否存在隨機(jī)性,或者它們是確定性的?Theshortanswer-yestoboth.WhenyoupromptanLLM,itstextresponseisgeneratedinstages.Inthefirststage,theLLMprocessestheinputpromptandgeneratesaprobabilitydistributionoverpossibletokens(words)thatarelikelytocomenext.Forexample,ifpromptwiththeinputtext“Thedogjumpedoverthe…”,theLLMwillproduceanarrayofprobablenextwords:簡短的回答是——兩者都有。當(dāng)您提示LLM時,它的文本回答是通過兩個階段生成的。在第一階段,LLM處理輸入提示并生成一個可能的令牌(單詞)概率分布,這些單詞可能是接下來出現(xiàn)的。例如,如果您提示輸入文本“狗跳過了……”,LLM將生成一個可能的下一個單詞數(shù)組:[("fence",0.77),("ledge",0.12),("blanket",0.03),…]Thisprocessisdeterministic;anLLMwillproducethissamedistributioneverytimethesameprompttext.這個過程是確定性的;每次輸入相同的提示文本,LLM都會產(chǎn)生相同的分布。Inthesecondstage,theLLMconvertsthesedistributionsintoactualtextresponsesoneofseveraldecodingstrategies.Asimpledecodingstrategymightselectthemostlikelytokenateverytim

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論