2. predavanje: Veliki jezikovni modeli
Izvirni naslov vira: Stanford CME295 Transformers & LLMs | Jesen 2026 | Predavanje 2 – Veliki jezikovni modeli
Veliki jezikovni modeli temeljijo na transformerjih, pri čemer je poleg pristopov, ki temeljijo na predstavitvah, kot je BERT, prevladujoča postala uporaba modelov zgolj z dekodirnikom za generiranje besedila. Njihova učinkovitost je odvisna od uravnoteženja velikosti modela in učnih podatkov, uporabe učinkovitih arhitektur ter izbire primernih metod dekodiranja. Tehnike pozivanja in sklepanja lahko izboljšajo odgovore brez spreminjanja uteži, vendar lahko daljši konteksti poslabšajo priklic informacij in povečajo stroške.
Video
- Le tu: 59
Kaj pravi
- Transformerski jezikovni modeli omogočajo dva glavna pristopa: BERT se uči dvosmernih predstavitev za naknadno prilagajanje posameznim nalogam, GPT pa besedilo generira avtoregresivno in lahko naloge rešuje na podlagi pozivov. Zakoni skaliranja povezujejo zmogljivost s številom parametrov, učnih žetonov in obsegom računanja; računsko optimalno učenje uravnoteži velikost modela in podatkovne zbirke, stroški izvajanja modela za uporabnike pa dodatno spodbujajo uporabo manjših modelov. Redka mešanica ekspertov poveča zmogljivost, ne da bi aktivirala vsak parameter, pri čemer z naučenim usmerjanjem in izgubami za uravnoteženje obremenitve preprečuje premajhno uporabo ekspertov. Sodobne arhitekture vključujejo rotacijske vložitve položaja, pozornost z drsečim oknom, pozornost z združenimi poizvedbami, normalizacijo pred podslojem in RMSNorm za kodiranje položaja, obvladovanje računskih zahtev in predpomnilnika ter podporo pretoku gradientov. Metode generiranja vključujejo požrešno dekodiranje, iskanje s snopom in vzorčenje, ki ga nadzirata izbira kandidatov in temperatura. Ničelna temperatura ne zagotavlja determinističnega izvajanja modela, dekodiranje s sintaktičnimi omejitvami pa izboljša zanesljivost strukturiranih izhodov. Kontekstna okna vključujejo tudi generirane žetone, daljši konteksti pa lahko poslabšajo priklic informacij. Primeri v kontekstu in prikazi verig sklepanja lahko izboljšajo odgovore brez posodabljanja uteži, vendar povečujejo stroške in lahko spodbujajo pretirano prilagajanje; metoda samoskladnosti stabilizira odgovore z glasovanjem med več potmi sklepanja.
- BERT, predstavljen leta 2018, uporablja kodirniški del transformerja in vsem vhodnim žetonom omogoča, da so pozorni drug na drugega. u17–19 ·
- Pri nalogi maskiranega jezikovnega modeliranja se izbrani vhodni žetoni v modelu BERT spremenijo, model pa se uči iz konteksta obnoviti izvirne žetone. u26–30 · Predavanje maskiranje opisuje kot poenostavitev dejanskega postopka spreminjanja žetonov.
- Pri nalogi napovedovanja naslednjega stavka BERT ugotavlja, ali si vhodna stavka v besedilu sledita, s čimer naj bi se naučil odnosov na ravni dokumenta. u31–34 ·
- Transformerji s kodirnikom in dekodirnikom uporabljajo dvosmerno pozornost nad vhodom, transformerji zgolj z dekodirnikom pa pozornost vsakega vhodnega žetona omejijo nanj samega in na predhodne žetone. Obe arhitekturi lahko besedilo generirata avtoregresivno. u51–54 ·
- FLOPs meri skupno število operacij s plavajočo vejico, FLOPS ali FLOP/s pa število operacij na sekundo in s tem računsko hitrost. u69–71 · Gre za razliko med obsegom računanja in hitrostjo računanja.
- Predavanje iz študije skaliranja iz leta 2022 navaja približno računsko optimalno razmerje 20 učnih žetonov na parameter modela. u76–77 · Razmerje se nanaša na optimalno uporabo računskih virov pri učenju.
- Izguba pri napovedovanju naslednjega žetona, obravnavana v razdelku o zakonih skaliranja, je križna entropija, ki primerja napovedano porazdelitev z dejanskim naslednjim žetonom. u79–80 ·
- Jezikovni model zaporedjem žetonov pripisuje verjetnosti. Predavanje velike jezikovne modele opisuje kot velike po številu parametrov, obsegu učnih podatkov in računskih zahtevah. u84–86 ·
- Transformer zgolj z dekodirnikom poleg kodirnika odstrani tudi navzkrižno pozornost med kodirnikom in dekodirnikom. Njegovo preostalo ogrodje sestavljata vzročna večglava pozornost in nevronska mreža s prehajanjem naprej. u87–89 ·
- Gosta MoE aktivira vse eksperte z različnimi utežmi, redka MoE pa le izbrane eksperte. Redka MoE združi izhode izbranih ekspertov z utežmi, ki jih določi usmerjevalnik. u99–104 ·
- Pri opisani pomožni izgubi MoE se delež žetonov, dodeljenih posameznemu ekspertu, obravnava kot konstanta. Vzvratno razširjanje posodablja usmerjevalnik prek verjetnosti usmerjanja, ne prek same diskretne izbire. u122–123 ·
- Predavatelj navaja, da sodobne zasnove MoE uporabljajo desetine ali stotine ekspertov namesto zgolj 8 ali 16, kar omogoča podrobnejšo specializacijo. Predavanje navaja tudi empirično ugotovljene izboljšave zmogljivosti zaradi ožje specializiranih ekspertov. u130–131 ·
- Novejši vrhunski odprtokodni modeli, prikazani na predavanju, imajo stotine ekspertov, med navedenimi primeri 384 in 256, pri posameznem prehodu naprej pa običajno aktivirajo približno osem ekspertov. Njihove skupne velikosti segajo od več sto milijard do približno bilijona parametrov. u131–134 · To so primeri z nedavnega posnetka zaslona, obravnavanega na predavanju, ne trditev o vseh modelih MoE.
- Sinusno kodiranje položaja, prikazano na predavanju, dimenziji 2i dodeli sin(ω_i m), dimenziji 2i+1 pa cos(ω_i m), pri čemer je ω_i = 10000^(−2i/d_model). Pari dimenzij z nižjimi indeksi se s položajem spreminjajo hitreje. u161–166 · Prikazana formula je pripisana delu Attention Is All You Need.
- Položajni odmik pri T5 pred uporabo softmaxa skaliranim rezultatom primerjave poizvedb in ključev prišteje naučen odmik za vsako glavo, ki temelji na relativni razdalji, razvrščeni v razrede. Pri ALiBi pa je odmik pozornosti linearna funkcija razlike med položajema. u186–191 ·
- RoPE poizvedbe in ključe zavrti glede na položaje njihovih žetonov, namesto da bi dodal odmik pozornosti. Tako dobljena interakcija med poizvedbo in ključem vključuje rotacijo, določeno z relativnim položajem n−m. u194–206 ·
- RoPE svojo konstrukcijo dvodimenzionalne rotacije razširi na večdimenzionalne vektorje z vrtenjem dvodimenzionalnih blokov za kote, odvisne od indeksa. Afshine Amidi poudarja, da se te položajne konstrukcije ni treba učiti in da jo je mogoče razširiti na poljubne položaje. u207–209 · Trditev se nanaša na položajno konstrukcijo in ne zagotavlja točnosti modela pri poljubnih dolžinah zaporedij.
- RMSNorm spremeni merilo aktivacij, ne da bi jih ponovno centriral, in uporablja naučen faktor skaliranja. Afshine Amidi pravi, da RMSNorm deluje prav tako dobro kot LayerNorm, kar utemeljuje njegovo uporabo. u247–249 · Primerjava je kvalitativna; odlomek ne vsebuje primerjalnega preizkusa ali izmerjene razlike.
- Vzorčenje top-k omeji kandidate za naslednji žeton na k najverjetnejših žetonov. Vzorčenje top-p pa kandidate izbira glede na prag kumulativne verjetnosti. u269–271 · Razlaga top-p v prepisu je kratka in ubeseditveno nepopolna.
- Temperatura T=1 da običajno porazdelitev softmax; višja temperatura izenačuje verjetnosti žetonov, nižja pa povečuje razlike med njimi. Shervine Amidi pojasnjuje, da se pri zelo visoki temperaturi porazdelitev približuje enakomerni, pri zelo nizki pa se verjetnost osredotoči na žeton z najvišjo oceno. u275–280 ·
- Predavanje kot standardno dolžino konteksta v panogi navaja približno milijon žetonov, kot običajno omejitev izhoda pa približno 100,000 žetonov. u301–303 · Predavatelj te vrednosti obravnava kot velikostne rede in pravi, da bi lahko novoizdani, neimenovani LLM nakazoval višje omejitve.
- Predavanje za grobo oceno števila žetonov navaja približno tri četrtine besede na žeton, 500 žetonov na stran, 100,000 žetonov za knjigo in milijon za obsežno knjigo. u303–304 · To so približne miselne predstave, ne natančne pretvorbe.
- Po navedbah predavanja so avtorji članka o verigi razmišljanja ugotovili, da je prikaz poti sklepanja v pozivih z nekaj primeri modelu pomagal usvojiti te poti in izboljšal njegovo splošno uspešnost. u316–317 · Odlomek ne navaja preizkušenih modelov, nalog ali velikosti izboljšanja.
- Jezikovni model, sestavljen samo iz dekodirnika, lahko izvaja klasifikacijo sentimenta tako, da prejme stavek skupaj z vprašanjem, ali je stavek pozitiven ali negativen. Predavanje dodatno učenje pri tem pristopu predstavlja kot možnost, ne kot nujen korak prilagoditve. u47–49 ·
- Pomožna funkcija izgube za uravnoteženje obremenitve lahko preprečuje kolaps usmerjanja tako, da spodbuja usmerjanje približno enakih deležev žetonov k različnim ekspertom. u120–121 · Odločitve o usmerjanju se sprejemajo za vsak žeton posebej, ne enkrat za celoten stavek.
- Za zanesljivo strukturiran izhod, kot je JSON, Shervine Amidi priporoča vodeno dekodiranje, ki glede na ciljno sintakso omejuje razpoložljive naslednje žetone, namesto da bi se zanašali le na navodilo o obliki izhoda. u289–292 · Mišljena je uporaba, pri kateri nepravilno oblikovan strukturiran izhod povzroči napake pri nadaljnjem razčlenjevanju.
- Predavanje priporoča zgoščevanje konteksta in začenjanje novih klepetov, da bi omejili tveganja kopičenja vse več vhodnega konteksta. u308–309 ·
- Vložitev žetona CLS v modelu BERT lahko predstavlja celotno vhodno zaporedje, ker samopozornost temu žetonu omogoča interakcijo z vsemi drugimi vhodnimi žetoni. Tako dobljeno predstavitev je nato mogoče uporabiti za naloge, kot je klasifikacija sentimenta. u19–22 ·
- Večji jezikovni modeli so lahko učinkovitejši pri izrabi žetonov: določeno raven uspešnosti lahko dosežejo po učenju na manj žetonih kot manjši modeli. u64–67 · Učinkovita izraba žetonov ne odpravi omejitve končnega proračuna za računanje.
- Predavanje umešča MoE v plasti transformatorja s povezavami naprej, ker te običajno opravijo večino računanja, medtem ko pozornost predvsem omogoča komunikacijo med žetoni. Vsak ekspert je zato nevronska mreža s povezavami naprej. u109–110 ·
- Kolaps usmerjanja se krepi sam od sebe: eksperti, izbrani na začetku, prejemajo posodobitve in se izboljšujejo, neizbrani pa ostajajo neuporabljeni. Osredotočanje usmerjanja na majhno podmnožico ekspertov zmanjšuje dejansko velikost modela. u116–119 · Ta povratna zanka je razlog za uvedbo pomožne funkcije izgube, ki spodbuja uporabo širšega nabora ekspertov.
- Vedno aktivni skupni eksperti lahko opravijo računanje, ki ga potrebuje vsak žeton, in tako preprečijo podvajanje skupnega temeljnega dela med specializiranimi eksperti. u128–129 ·
- Skalarni produkt sinusnih položajnih vložitev na položajih m in n je vsota členov cos(ω_i(m−n)), zato je podobnost odvisna od relativnega odmika, ne pa od obeh absolutnih položajev ločeno. Vsota je največja, ko je m enak n. u167–173 · Trigonometrična identiteta pojasnjuje, kako lahko kodiranje absolutnega položaja izraža podobnost glede na relativni položaj.
- Afshine Amidi trdi, da dodajanje položajnih vložitev vložitvam žetonov vsako plast po nepotrebnem izpostavi absolutnemu položaju. Kodiranje položaja neposredno v mehanizmu pozornosti pa je usmerjeno v operacijo, ki mora presojati odnose med žetoni. u183–186 · Mreža s povezavami naprej je predstavljena kot mreža, ki ji ni treba poznati absolutnega položaja žetona.
- Zlaganje blokov pozornosti z drsečim oknom žetonu prek vmesnih predstavitev omogoča prejemanje informacij tudi izven njegovega neposrednega okna pozornosti. Afshine Amidi širjenje tega dosega primerja z receptivnimi polji v konvolucijskih nevronskih mrežah. u219–224 · Lokalna pozornost v eni plasti ne pomeni, da končna predstavitev žetona vsebuje le informacije iz enega lokalnega okna.
- Pozornost z združenimi poizvedbami zmanjša pomnilnik za predpomnilnik pri dekodiranju, ker si glave pozornosti znotraj skupin delijo projekcije ključev in vrednosti. Poizvedbe niso enak cilj varčevanja s pomnilnikom, saj se vsaka uporabi le enkrat, prejšnji ključi in vrednosti pa se ohranijo za nadaljnje korake dekodiranja. u232–239 · Razlog je naraščajoča poraba pomnilnika za shranjene ključe in vrednosti med avtoregresivnim generiranjem.
- Pri predhodni normalizaciji se normalizacija izvede pred podplastjo, nato pa se izhod podplasti prišteje prvotnemu vhodu. Afshine Amidi pravi, da ohranitev rezidualnega vhoda zunaj normalizacije rezidualni povezavi omogoča bolj neposredno podporo pretoku gradientov kot pri naknadni normalizaciji. u242–245 · Pri naknadni normalizaciji se namesto tega normalizira vsota vhoda in izhoda podplasti.
- Učenje v kontekstu lahko izboljša odgovore LLM brez spreminjanja njegovih uteži: primeri vprašanj in želenih odgovorov ga lahko implicitno naučijo oblike odgovora in morda tudi sklepanja. u310–312 · Predavanje primere predstavlja kot alternativo prilagajanju uteži.
- Metoda samoskladnosti lahko ustali odgovore, na primer pri aritmetiki, tako da ustvari več poti sklepanja in odgovor izbere z večinskim glasovanjem. u318–319 · Metoda združuje več generiranih izhodov, namesto da bi se opirala na eno samo pot sklepanja.
- Predavanje predstavi dva glavna pristopa na osnovi transformerjev: izračun predstavitev in njihovo dodatno prilagajanje nalogi ali oblikovanje naloge kot generiranje besedila iz besedila. Modeli zgolj z dekodirnikom so postali prevladujoči pristop za generiranje besedila. u56–59 ·
- Zakoni skaliranja jezikovnih modelov povezujejo izboljšave zmogljivosti z učnimi podatki, številom parametrov in obsegom računanja. Pri omejenem računskem proračunu je treba velikost modela uravnotežiti s številom učnih žetonov, ne pa zgolj čim bolj povečati modela. u61–74 ·
- Modeli z redko mešanico ekspertov omogočajo povečevanje števila parametrov, ne da bi pri vsakem prehodu naprej aktivirali vse parametre. u140–142 ·
- Afshine Amidi predstavi RoPE, lokalno pozornost, pozornost z združenimi poizvedbami, normalizacijo pred podslojem in RMSNorm kot pogoste arhitekturne izbire v sodobnih velikih jezikovnih modelih ter jih primerja z izvirnim transformerjem. u249–250 ·
- Shervine Amidi generiranje z velikimi jezikovnimi modeli opiše kot avtoregresivno: obdelani žetoni tvorijo kontekst za generiranje naslednjih žetonov, enega za drugim. u253–255 ·
- Kontekstno okno velikega jezikovnega modela poleg uporabnikovega začetnega poziva vključuje tudi generirane žetone, ki se vračajo v vhod, zato je razpoložljivi kontekst povezan z dolžino izhoda. u297–299 ·
- Več vhodnih žetonov ni vedno bolje: zaradi degradacije konteksta je z rastjo konteksta velikega jezikovnega modela vse težje priklicati posamezno informacijo. u306–309 ·
- Ali kakovost učnih podatkov vpliva na uspešnost jezikovnega modela? u80–82 · Predavatelj priznava, da raziskave prihajajo do različnih sklepov, vendar pravi, da je pri predhodnem učenju pomembnejša količina, kakovost pa postane pomembnejša v poznejših fazah učenja.
- Raziskava skaliranja iz leta 2022, obravnavana na predavanju, je ugotovila, da so bili številni takratni jezikovni modeli preveliki glede na svoje učne podatkovne zbirke. Ob enakem proračunu za računanje je manjši model, učen na več žetonih, presegel večjega. u74–76 · Predhodna razprava o skaliranju bi lahko vzbudila vtis, da je izbira večjega modela vedno boljša.
- Sklepanje z velikimi jezikovnimi modeli je lahko tudi pri temperaturi nič nedeterministično, če združevanje zahtev v pakete spremeni vrstni red operacij s plavajočo vejico. Shervine Amidi te razlike pripisuje neizpolnjeni invariantnosti glede na paket in neasociativnosti seštevanja s plavajočo vejico. u281–287 · Pri nespremenjenih utežeh, nespremenjenih operacijah in temperaturi nič bi sicer pričakovali enake izhode za enake vhode.
- BERT lahko pri nadaljnjih nalogah doseže dobre rezultate z razmeroma malo označenimi podatki, vendar dodatno učenje za posamezno nalogo še vedno zahteva trud. Tudi generiranje besedila iz zasnove, ki temelji samo na kodirniku, ni očitno, čeprav predavanje izrecno pravi, da je mogoče. u38–41 · Predavanje razlago generiranja z modelom, sestavljenim samo iz kodirnika, prestavi na predavanje 8.
- Jezikovni model, optimiziran glede na računske stroške učenja, morda ni najboljša izbira za uporabo v produkciji. Obdelava velikega števila zahtev je dodatna spodbuda, da model ostane majhen. u78–79 · Stroški učenja in stroški ponavljajočega se sklepanja lahko narekujejo različne odločitve pri zasnovi.
- Prej obravnavana raziskava zakonov skaliranja je uporabljala goste jezikovne modele, zato njeni rezultati ne določajo neposredno, kako se s povečevanjem obsega obnaša drugačna zasnova MoE. Predavatelj opisuje izvajanje manjših poskusov skaliranja, prilagojenih posamezni arhitekturi, pred izbiro parametrov za večji obseg. u134–137 · Poskusi v manjšem obsegu podajo razmerje skaliranja za konkretno arhitekturo, ki jo razvijajo.
- Naučene absolutne položajne vložitve nimajo naučenih vnosov za položaje onkraj dolžine učnega zaporedja. Afshine Amidi pravi, da se deterministične formule za položaj tej omejitvi izognejo, in navaja, da so avtorji izvirnega transformatorja z obema pristopoma dosegli približno podobne rezultate. u150–153 · Namen je določiti informacije o položaju za daljša zaporedja pri sklepanju, ne da bi se bilo treba naučiti dodatnih položajnih vložitev.
- Afshine Amidi opisuje, da se velikost skalarnega produkta poizvedbe in ključa pri RoPE z večanjem razdalje med položajema praviloma zmanjšuje, vendar izrecno pravi, da zmanjševanje ni strogo monotono. u210–211 · Opis upadanja z razdaljo izraža splošno težnjo, ne pa stroge urejenosti vseh parov žetonov.
- Izbira najverjetnejšega naslednjega žetona ne zagotavlja največje skupne verjetnosti dokončanega zaporedja. Iskanje s snopom ohranja k kandidatnih poti za raziskovanje alternativ, vendar zahteva več računanja in ostaja deterministično. u257–263 · Iskanje s snopom je predstavljeno kot omejeno iskanje, ne kot izčrpna optimizacija verjetnosti zaporedja.
- Shervine Amidi trdi, da lahko raznoliki vzorčeni odgovori klepetalnim robotom dajejo manj robotski vtis, medtem ko so deterministični odgovori koristni, kadar je pomembna ponovljivost. Kot primera slednjega navaja ponavljajoče se povzemanje in dosledne ocene pri uporabi LLM kot ocenjevalca. u264–272 · Primer ponavljajočega se odgovora klepetalnega robota je miselni poskus, saj se lahko konteksti dejanskih zahtev spreminjajo.
- Nekaj primerov v pozivu lahko povzroči, da se LLM pretirano prilagodi podanim primerom, namesto da bi sklepal bolj splošno, dodatni vhodni žetoni pa povečajo stroške in zakasnitev. Predavanje pravi, da praktiki primere včasih nadomestijo z ročno oblikovanimi navodili. u313–314 · Predavanje vedenje, vezano na posamezne primere, postavlja nasproti želenemu poudarku na sklepanju.
- Učinkovito modeliranje jezika z velikimi modeli je odvisno od uravnoteženja obsega učenja, arhitekturne učinkovitosti, izbire dekodiranja in strategij pozivanja, ne pa zgolj od povečevanja modela ali dolžine konteksta. Kako se veliki jezikovni modeli na osnovi transformerjev učijo, skalirajo, arhitekturno izpopolnjujejo in uporabljajo za tvorjenje učinkovitih odgovorov?
Kako utemeljuje
- thesis Effective LLMs require balanced scale, architecture, decoding, and prompting How are transformer-based large language models trained, scaled, architecturally refined, and used to generate effective responses?
- theme From representations to task generation Transformers support both task-specific representation learning and text generation, with decoder-only models enabling tasks through prompts.
- idea Representations and generation offer two task-solving approaches
- idea LLMs model token probabilities at large scale
- theme Scale requires balancing competing resources Effective scaling balances parameters, training tokens, and compute, while accounting for serving costs and architectural differences.
- idea Compute budgets require balancing model size and tokens
- argument Larger models can reach performance with fewer tokens
- evidence Smaller models trained longer beat undertrained larger models
- evidence Study estimates twenty training tokens per parameter
- counterargument Serving costs can favor smaller than training-optimal models
- counterargument Dense scaling results require architecture-specific checks for MoE
- idea Compute budgets require balancing model size and tokens
- theme Sparse capacity needs effective expert routing Sparse MoE increases capacity without activating every parameter, but requires routing and specialization that make that capacity useful.
- idea Sparse experts grow capacity without activating every parameter
- mechanism Sparse routing selects and weights only some experts
- mechanism Experts replace computationally intensive feedforward layers
- counterargument Self-reinforcing routing collapse shrinks effective model capacity
- mechanism Shared experts avoid duplicating common foundational computation
- evidence Finer-grained expert specialization yields empirical performance gains
- example Frontier MoEs activate about eight among hundreds
- idea Sparse experts grow capacity without activating every parameter
- theme Architecture targets positional and computational efficiency Modern LLMs refine positional encoding, attention, and normalization to improve how transformers represent relationships and use resources.
- idea Modern LLMs refine positions, attention, and normalization
- argument Position belongs in attention rather than every layer
- example Stacked local attention expands the effective receptive field
- example Grouped queries reduce memory through shared cached keys
- example Pre-norm preserves a direct residual gradient path
- example RMSNorm rescales without recentering while retaining performance
- idea Deterministic positions avoid learned embedding length limits
- idea Modern LLMs refine positions, attention, and normalization
- theme Decoding choices determine generation behavior Autoregressive generation requires choices about search, sampling, reproducibility, and syntactic constraints.
- theme Longer context is not always better Context capacity must accommodate generated tokens, and accumulating more context can undermine retrieval rather than improve responses.
- theme Prompting teaches without updating weights Examples and reasoning demonstrations can improve responses, but their benefits must be weighed against overfitting, cost, and latency.
- theme From representations to task generation Transformers support both task-specific representation learning and text generation, with decoder-only models enabling tasks through prompts.
Kjer vir nasprotuje sam sebi
- Večji jezikovni modeli so lahko učinkovitejši pri izrabi žetonov: določeno raven uspešnosti lahko dosežejo po učenju na manj žetonih kot manjši modeli. proti Raziskava skaliranja iz leta 2022, obravnavana na predavanju, je ugotovila, da so bili številni takratni jezikovni modeli preveliki glede na svoje učne podatkovne zbirke. Ob enakem proračunu za računanje je manjši model, učen na več žetonih, presegel večjega.
The token-efficiency advantage of larger models does not necessarily translate into better performance under a fixed compute budget.
Vir, odlomek za odlomkom
Prepis, preveden z umetno inteligenco iz angleščine.
- u1 UvodIntroduction
- u2 Pozdravljeni vsi in dobrodošli na 2. predavanju pri predmetu CME 295. Danes je razburljiv dan, saj bomo govorili o velikih jezikovnih modelih in zlasti o tem, kako so povezani z arhitekturo transformerja, ki smo jo spoznali na prejšnjem predavanju. Preden začnemo, pa bomo ponovili, kaj smo obravnavali zadnjič.Hello, everyone, and welcome to lecture 2 of CME 295. So today is an exciting day because we'll be talking about large language models, and in particular, how they relate to the transformer architecture that we saw last lecture. But before we start, we will recap what we saw last time.
- u3 To bomo naredili na vsakem predavanju, da vidimo, kako se to povezuje s tem, kar bomo obravnavali danes. Če se spomnite, smo se zadnjič spraševali, kako lahko modeli obdelujejo besedilo. Modeli besedila ne razumejo takšnega, kot je, razumejo števila.And we will do that at every lecture to see how this connect to what we'll see today. So if you remember, last time we were wondering how models could process text. So models, they don't understand text as it is, they understand numbers.
- u4 Če se spomnite, smo najprej pogledali, kako besedilo razdeliti na nedeljive enote. Ta postopek se imenuje tokenizacija. Spoznali smo nekaj vrst algoritmov za tokenizacijo. Rekli smo, da je najpogostejši algoritem za tokenizacijoSo if you remember, one thing that we looked at was, first of all, how to divide our text into indivisible units. And this process is called tokenization. And we saw a few kinds of tokenization algorithms. And we said that the most common tokenization algorithm
0:53 · Lecturer in front of "Recap of last episode" slide · A still from a lecture video in a classroom with chalkboards. A man in a dark T-shirt and green pants stands gesturing with both hands while a projected Stanford University / ICME slide behind him shows the sentence "A cute teddy bear is reading." split into tokens. The slide appears to recap tokenization of text, with "teddy bear" kept as one token. - u5 dandanes tokenizacija na podbesede, saj ponuja dobro ravnovesje med besediščem, ki ga gradi, in dolžino zaporedja vhodnega besedila. Vendar to še ni bilo vse, saj kothese days is the subword tokenization because it has a nice trade-off between the vocabulary that it was building and the sequence length that input text would have. But this was not it, because once you
- u6 besedilo razdelite na tokene, je naslednji korak izračun vektorskih vložitev. Če se spomnite, smo spoznali Word2Vec kot način za izračun vložitev, vendar te niso upoštevale konteksta. Nato smo govorili o drugi skupini modelov, ki je bila zelo priljubljena v letih od 2010 do 2019 in se imenuje RNN,divide a text into tokens, the next step is to compute embeddings. So if you remember, we saw Word2Vec as a way to compute embeddings, but they were not aware of the context. So then we talked about another class of models that were very popular in the 2010s which is called RNNs,
- u7 rekurentne nevronske mreže. Nato smo rekli: v redu, težava je v tem, da običajno pozabljate stvari, ki so se zgodile v preteklosti. Leta 2017 je izšel prelomni članek z naslovom »Attention is All You Need«, ki je dejansko opustil načeloRecurrent Neural Networks. And then what we said was, OK, the problem is that you tend to forget things that happened in the past. And so in 2017, there was this landmark paper called "Attention is All You Need" that actually dropped the principle
1:49 · Recap: attention query, keys and values for "teddy bear" · A Stanford ICME lecture slide recapping self-attention on the sentence "A cute teddy bear is reading." The tokens a, cute, teddy bear, is, reading and "." each carry a key (kᵀ) and a value (v). The query for "teddy bear" connects by lines to every token's key. The upper sentence and tokenized row are faded, and a small inset shows the lecturer standing at the right. - u8 rekurence in uporabil neposredne povezave za izračun smiselnih predstavitev tokenov. Nekaj časa smo namenili oznakam. Če se spomnite, smo imeli poizvedbo, ključ in vrednost, s katerimi smo lahko ugotovili: v redu,of recurrence and had direct connections in order to compute meaningful representation of tokens. So we spent a little bit of time on some notations. So if you remember, we had query, key, and value, which were useful for us to know OK,
- u9 na katere druge tokene naj bo dani token pozoren? Spoznali smo, da se arhitektura, ki so jo predstavili avtorji, imenuje transformer in da se tukaj prikazana operacija pozornosti dejanskogiven a token, what other tokens should that token attend to? And we saw that the architecture that the authors introduced was called the transformer, and that the attention operation that is here is actually something
2:36 · Recap slide: attention and the Transformer architecture · A Stanford ICME lecture slide titled "Recap of last episode..." The right side shows the Transformer encoder-decoder diagram from "Attention Is All You Need" (Vaswani et al., 2017). The left side has a faded illustration of attention on the sentence "A cute teddy bear is reading.", with value, key and query vectors per token and the query for "teddy bear" linked to every key. A small inset in the top right shows a lecturer standing by a blackboard. - u10 izvaja v plasteh večglave pozornosti, ki so prisotne v kodirniku in dekodirniku. Rekli smo, da je bila ta arhitektura najprej razvita za strojno prevajanje in da se je model v tem kontekstu zelo dobro izkazal.that is happening in the multi-head attention layers, which are present in the encoder and the decoder. And what we said was that this architecture was first developed in the context of machine translation, in that in that context, that model performed really well.
- u11 Naravno vprašanje je torej: glede na to, da je ta arhitektura pri strojnem prevajanju res zelo uspešna, ali lahko te izboljšave prenesemo na druga področja? To si bomo ogledali v prvem delu. Govorili bomo o različnih različicahSo a natural question is, well, given that this architecture performs really, really well for machine translation, can we actually propagate the gains to other domains? And so this is what we're going to see in the first part. So we're going to talk about different variants
3:26 · Stanford ICME lecture slide: Transformers & Large Language Models · A title slide from a Stanford University ICME lecture video. The left half is white with the Stanford "S" logo and the title "Transformers & Large Language Models". The right half is crimson with an agenda of five topics, and the first is highlighted. A small inset at top right shows a person standing in front of a blackboard. - u12 izvirne arhitekture transformerja, s katerimi jo je bilo mogoče uporabiti na drugih področjih. Če se spomnite, transformer sestavljata dva glavna dela. Prvi je kodirnik, ki je na levi strani slike.of the original transformer architecture, such that it was possible to apply it to other domains. So if you recall, the transformer is composed of two main parts. The first part is the encoder, which is on the left side of the figure.
- u13 Cilj kodirnika je izračunati smiselne vektorske vložitve vhodnega besedila. Tukaj je šlo za strojno prevajanje. Vhodno besedilo si lahko predstavljate kot izvorno besedilo, ki ga želite prevesti. Nato smo imeli na desni strani drugi del, kiAnd the goal of the encoder is to compute meaningful embeddings of your input text. So here it was in the context of machine translation. So input text, you can think of it as the source text that you want to translate. And then you had a second part on the right side, which
- u14 je dekodirnik, katerega cilj je ustvarjati izhod po en token naenkrat na avtoregresiven način. To počne tako, da je pozoren na vse tokene, ki jih je doslej napovedal,is the decoder whose goal is to actually generate the output one token at a time in an autoregressive manner. And the way it does that is by attending to all the tokens that it has predicted so far,
- u15 in na smiselne vložitve vhoda, ki jih je izračunal kodirnik. To je bil izvirni transformer. Zelo naravno vprašanje je torej: kaj če se poskusimo malo poigrati z arhitekturo?plus the meaningful embeddings from the input that were computed by the encoder. So that was the original transformer. So a very natural question is, well, how about we try to play with the architecture?
- u16 BERT in modeli samo s kodirnikomBERT and encoder-only models
- u17 Poskusimo pogledati, kaj se zgodi, če vzamemo samo kodirnik. Predpostavimo, da vzamemo samo kodirnik. Ali lahko z njim kaj naredimo? To so ljudje poskusili kmalu po pojavu transformerja, leta 2018, v zelo pomembnem članku z naslovom BERT, kar pomeni Bidirectional EncoderWe try to see, well, what happens if we only take the encoder? Let's suppose we only take the encoder. Can we do something with it? Well, this is something that people have tried shortly after the transformer came out in 2018 with a very important paper called BERT, which stands for Bidirectional Encoder
- u18 Representation from Transformers. Ideja je vzeti samo kodirniške dele transformerja in izkoristiti plast večglave pozornosti, ki izvaja samopozornost nad vsemi svojimi vhodi,Representation from Transformers. So the idea is to take only the encoder parts of the transformer and to leverage the multi-head attention layer which performs the self-attention operation over all of its inputs
- u19 da so vsi vhodni tokeni pozorni drug na drugega. Tukaj pravijo: če to naredite in uvedete poseben token — tukaj je ta posebni token na levi strani zaporedja in se imenuje token CLS.in order to have all the input tokens attend to one another. And so here what they say is, well, if you do that and if you introduce a special token-- and here the special token is on the left side of the sequence called CLS token.
- u20 To je klasifikacijski token. Nato se lahko oprete na smiselno kodirano vložitev, ki ustreza tokenu CLS, da ugotovite, o čem govori vhodno zaporedje. Kodirnik namreč tukaj izvaja samopozornostSo it's a classification token. Then what you could do is rely on the meaningful encoded embedding corresponding to the CLS token in order to know what the input sequence is about. Because here the encoder is doing self-attention
- u21 med vsemi tokeni. Smiselna vložitev, ki ustreza tokenu CLS, je torej sodelovala z vsemi drugimi tokeni. Ideja modela BERT je, da lahko za neko vhodno besedilo izračunamo smiselno predstavitevacross all the tokens. So the meaningful embedding that is corresponding to the CLS token has interacted with all other tokens. So the idea of BERT is to say if you have some input text, then what I can do is to compute a meaningful representation
- u22 vhoda in jo nato uporabimo za neko nadaljnjo nalogo. Takrat je bila zelo pogosta naloga na primer prepoznavanje sentimenta. Je ta tvit pozitiven ali ne? Običajno lahko vzamete to vložitev in jo preslikate v ta razred.of the input and then use that representation for some downstream task. So at the time we had something like sentiment extraction as a very common task. So is this tweet positive or not? So typically what you could do is take that embedding and then project that onto that class.
- u23 To je en primer. Lahko pa vzamete tudi vložitev določenega tokena in poskusite ugotoviti, ali ta token ustreza, recimo, samostalniku ali glagolu in tako naprej. To je torej ideja.That's one example. But then you could also take the embedding of a given token, and then try to determine if that token is corresponding to let's say, a noun or a verb and so on. So that's the idea.
- u24 Je to smiselno? V redu, odlično. Naslednje vprašanje je, kako tak model dejansko učimo. To poteka v dveh korakih. Prvi korak se imenuje predučenje. Cilj je, da model razume, kako je besedilo napisano.Does that make sense? OK, great. So now the next question is, how do you actually train such a model? Well, this is done in two steps. The first step is called pre-training. And the goal is for the model to understand how text is written.
7:27 · BERT and encoder-only models lecture slide · A Stanford ICME lecture slide explains that BERT stands for Bidirectional Encoder Representations from Transformers. Its idea is to use encoded embeddings to make predictions. The diagram shows the tokens "[CLS] A cute teddy bear is reading [SEP]" entering an encoder block, with the [CLS] position projected into a single encoded embedding. A small video inset shows the lecturer standing at the top right. - u25 To dosežemo z nadomestnimi nalogami. Če se spomnite, je nadomestna naloga naloga, ki pravzaprav ni vaš končni cilj, temveč način, da dosežete nekaj drugega. Za nas je to nekaj drugega tukaj razumevanje besedila pri modelu.And so the way you do that is with some proxy tasks. So if you remember, a proxy task is a task that is not really your end goal, but that is a way for you to achieve something else. And for us, this something else here is the model understanding text.
- u26 Prva nadomestna naloga, s katero učimo ta model, se imenuje modeliranje jezika z maskiranjem, MLM. Ideja je, da model razume, kako so razporejeni tokeni.So the first proxy task that this model is trained with is called Masked Language Modeling, MLM. And the idea is for the model to understand how tokens are placed.
- u27 To naredi tako, da vzame vhodno besedilo in ga naključno pokvari. Naključno izbere nekaj tokenov in jih zamaskira. Pravzaprav je postopek nekoliko bolj zapleten, da ne bi uvedli pristranskosti.And so the way it does that is it takes the input text and then it corrupts it randomly. So the way it does that is it selects some tokens at random and it masks them. So actually, it's a little bit more complicated to not introduce biases.
8:34 · BERT pretraining with Masked Language Model, Stanford lecture slide · A Stanford lecture slide on BERT and encoder-only models, outlining the strategy's first step: pretraining with proxy tasks, specifically the Masked Language Model (MLM). A green ENCODER box sits above a token sequence "[CLS] A cute teddy bear is reading [SEP]", where "cute" and "reading" are shaded grey, marking them as the masked words. A small inset at top right shows the lecturer standing in a room. - u28 Ideja pa je pokvariti vhodno zaporedje. Nato izračunamo smiselne vložitve, ki ustrezajo tem pokvarjenim tokenom, da poskusimo napovedati dejanski token — izvirni token,But the idea is to corrupt the input sequence. And the idea is to compute meaningful embeddings corresponding to these corrupted tokens in order to try to predict the actual token-- the original token
- u29 ki je bil tam pred pokvarjenim tokenom. Če na primer vzamemo »prisrčen plišasti medvedek bere« in predpostavimo, da pokvarimo »prisrčen« in »bere«, bi bil naš cilj izračunati smiselno predstavitev teh pokvarjenih tokenov in poskusitithat was before that corrupted token. So here, as an example, if we take a cute Teddy Bear is reading and let's suppose we corrupt cute and we corrupt reading, then here our goal could be to compute a meaningful representation of these corrupted tokens and try
- u30 napovedati izvirni token. Model se bo pri tem poskušal opreti na ves mehanizem pozornosti, ki ga izvaja, da iz konteksta sklepa, kateri je bil izvirni token.to predict the original token. And what the model will try to do is to rely on all the attention mechanism that it is performing in order to deduce what the original token was from the context.
- u31 Z drugimi besedami, model poskuša razumeti, kako je jezik zapisan, in ugotoviti, katere besede so verjetne na mestih, kjer nekaj manjka. To je prva nadomestna naloga. Avtorji modela BERT so preizkusili še drugo nadomestno nalogo, imenovano NSP, kar pomeniSo in other words, the model is trying to understand how language is written and trying to understand, what are the words that are likely to be in places where it is missing? So that's the first proxy task. And then there's a second proxy task that the authors of BERT have also tried, which is called NSP, which stands
10:03 · BERT pretraining with Next Sentence Prediction · A Stanford ICME lecture slide on BERT and encoder-only models. It lists Step 1 of the strategy, pretraining with the proxy task Next Sentence Prediction (NSP). A diagram shows an encoder block fed the tokens "[CLS] Oh wow [SEP] What a cutie [SEP]", with brackets grouping the two sentences. A small video inset shows the lecturer standing at the top right. - u32 napovedovanje naslednje povedi. Ideja te nadomestne naloge je, da model razume, kako si povedi sledijo. Kot vhod torej podamo dve različni povedifor Next Sentence Prediction. And the idea behind that proxy task is for the model to understand how sentences are sequenced. So here the idea is to have two different sentences as input,
- u33 in model vprašamo, ali si ti povedi dejansko sledita ali ne. V praksi pogledamo besedilo, vzamemo dve zaporedni povedi, ju vstavimo sem in poskusimo napovedati, da si res sledita. Nato pa dve povedi, ki si ne sledita,and to ask the model if these two sentences actually follow each other or not. So in practice, what you would do is you would look at a text and take two sentences that follow each other, put it there, try to predict that it is indeed following. And then two sentences that are not following each other
- u34 in napovedati moramo, da si ne sledita. Ideja te nadomestne naloge je, da se model nauči besedila ne na ravni povedi, temveč na ravni dokumenta. To je prvi korak, imenovan predučenje.and you need to predict that it's not following. And the idea behind that proxy task is for the model to learn text, not at the sentence level, but at the document level. So that's the first step called pre-training.
- u35 Na tej stopnji predpostavljamo, da model zdaj veliko bolje razume besedilo. Zato lahko preidemo na drugo nalogo. Mimogrede, prva naloga je običajno zelo draga, izvedete jo samo enkrat in model učite na množici podatkov. Druga naloga pa je namenjena temu,And at that stage, you're assuming that your model now understands text much better. And that's why you can go to the second task. So by the way, the first task is typically very expensive, something you do just once, train on a bunch of data. And then the second task is for you
11:23 · Lecture on BERT and encoder-only models at Stanford · A presenter in a dark t-shirt and green trousers stands gesturing in a lecture hall in front of blackboards. A projected slide titled "BERT and encoder-only models" shows the strategy's Step 2, finetuning for a given end task, with an encoder box above the tokens "[CLS] I really love this teddy bear [SEP]". Step 1 (pretraining with proxy tasks) is greyed out. - u36 da model prilagodite konkretnemu primeru uporabe, ki vas zanima. Če vzamemo primer prepoznavanja sentimenta, kjer poskušamo napovedati, ali je poved, recimo, pozitivna ali negativna, uporabimo projekcijsko plast, ki prejme token CLS, ta pato adapt your model to the specific use case that you're interested in. So if we take the example of sentiment extraction, which is trying to predict if a sentence is, let's say, positive or negative, what you would do is have some projection layer that takes in the CLS token that
- u37 nosi vse informacije iz povedi, in ga preslika v razred — v razrede, ki nas zanimajo, torej pozitivno ali negativno. Za to potrebujete majhen nabor oznak. Potrebujete torej primere z dejanskimi oznakami.is carrying all the information from the sentence and project it onto the class-- the classes of interests which are positive or negative. And for that, you need to have a small set of labels. So you need the observations with actual labels.
- u38 Nato prilagodite uteži, da lahko to smiselno predstavitev preslikate v želeni prostor. Katere so prednosti in slabosti tega pristopa? Prednost je, da je prinesel precej dobre rezultate. Poleg tega temelji na mehanizmu samopozornosti.And then what you would do is to tune the weights, so that you can actually project that meaningful representation onto the space of interest. So what are the pros and cons of this approach? So the pro is, well, it led to pretty good performance. The other thing is it is relying on the self-attention mechanism.
- u39 Imamo torej povezave z obeh strani, kar je tudi razlog za ime BERT, saj pomeni Bidirectional Encoder Representation from Transformers. Druga prednost je, da sicer potrebujete fino prilagajanje, vendar običajno ne potrebujete toliko podatkov, ali od 100.So you have connections from both sides, which is actually the reason why BERT is called that way, because it's Bidirectional Encoder Representation from Transformers. Another pro is, well, you need to do fine tuning, but you don't need that much data typically or of 100.
- u40 Slabost pa je, da za fino prilagajanje sicer potrebujete majhno količino podatkov, vendar morate fino prilagajanje vseeno izvesti. Že to samo po sebi zahteva trud. To je slabost. Druga slabost pa je, da se ob pogledu na ta model morda sprašujete: kako lahko ustvarjam besedilo?But the con is, well, you need a small amount of data to do the fine-tuning, but you need to do the fine-tuning. So in itself, that's an effort. So that's a con. And then the other con is when you look at this model, you may be wondering, well, how can I generate text?
- u41 To ni očitno. Vendar bomo na 8. predavanju videli, da je besedilo dejansko mogoče ustvarjati tudi z modelom samo s kodirnikom. Za zdaj pa predpostavimo, da ni očitnega načina. Več o tem na 8. predavanju.And it's something that is not obvious. But actually, we will see in lecture 8 that it is actually possible to generate text with an encoder only model. But for now, let's suppose there's no obvious way. But more on that in lecture 8.
- u42 GPT in modeli samo z dekodirnikomGPT and decoder-only models
- u43 Super. Toliko o modelu samo s kodirnikom. Če se vrnemo k arhitekturi transformerja: poskusili smo odstraniti dekodirnik in uporabiti samo kodirnik. To smo dobili. Kaj pa, če odstranimo kodirnik in poskusimo samo z dekodirnikom?Cool. So that's for encoder only model. Well, going back to the transformer architecture, we tried removing the decoder, only going with the encoder. That's what we obtained. Now how about we remove the encoder and we try with just the decoder?
13:47 · Transformer variant: decoder-only architecture · A lecture slide adapted from the original Transformer diagram, with the encoder block crossed out in red to show that a decoder-only variant drops it. The remaining decoder generates the next token autoregressively. A small inset video in the top right shows a presenter standing in a lecture room. - u44 Pa poskusimo. Pravzaprav so to ljudje poskusili približno takrat, ko je bil objavljen BERT. Obstajala je še druga veja različic transformerja, ki se je osredotočala na transformerje samo z dekodirnikom. Tak primer je GPT, za kateregaWell, let's just try that. Well, actually, people have tried that roughly at the same time as BERT was published. There was another branch of transformer variants which were actually focusing on decoder only transformers. And this is the example of GPT, which
- u45 ste zagotovo že velikokrat slišali in ki pomeni Generative Pre-trained Transformer. Ideja je ohraniti samo dekodirniške dele transformerja in vsako nalogo oblikovati kot problem pretvorbe besedila v besedilo. Kaj to pomeni?I'm sure you have heard plenty of times, which stands for Generative Pre-trained Transformer. And the idea is to only keep the decoder parts of the transformer and formulates any task you have as a text-to-text problem. So what does that mean?
- u46 To pomeni, da imate neko besedilo kot vhod, vaša edina naloga pa je napovedati naslednji token. Tukaj torej začetek zaporedja, en, en, plišasti, plišasti medvedek, bere in tako naprej. Mimogrede, takšno dekodiranjeThat means you have some text as input and your only job is to predict the next token. So here beginning of sequence A, A, teddy, teddy bear, is, reading, and so on. So by the way, this kind of decoding
14:52 · GPT and decoder-only models lecture slide · A Stanford lecture slide defines GPT as Generative Pre-trained Transformer and states the idea of predicting the next token one at a time. A diagram shows a single DECODER box with a [BOS] token as the input beneath it, the start of an autoregressive generation sequence. A small inset at top right shows the lecturer standing in a classroom. - u47 se imenuje avtoregresivno dekodiranje, saj tokene napovedujete po enega naenkrat. To je ideja modela GPT. Ni vam treba — ni nujno, da izvajate kakršno koli fino prilagajanje, saj je model že pripravljen za prilagoditev kateremu koli primeru uporabe.is called autoregressive decoding because you predict tokens one at a time. And this is the idea behind GPT. So you don't need to do-- you don't necessarily need to do any fine-tuning because your model is already equipped to be adapted to any use case.
- u48 Dal vam bom primer. Prepoznavanje sentimenta. Predpostavimo, da imate tvit, ki ga želite razvrstiti kot pozitivnega ali negativnega. V model preprosto vnesete: je ta poved pozitivna ali negativna? Nato dodate poved.So I'll give you an example. The sentiment extraction. So let's assume you have a tweet you want to categorize as positive or negative. Well, you would just put into your model, is this sentence positive or negative? And then you put the sentence.
- u49 Model nato preprosto odgovori pozitivna ali negativna. Finega prilagajanja ne potrebujete, razen če želite model še izboljšati. Fino prilagajanje torej ni obvezen korak, kar je že precej privlačno.And then the model would just respond positive or negative. You don't need to do fine-tuning, unless you want to make your model even better. So fine-tuning is not a required step, which is already pretty appealing.
- u50 Kodirnik-dekodirnik v primerjavi s samim dekodirnikomEncoder-decoder versus decoder-only
- u51 Morda pa se sprašujete: zadnjič smo spoznali arhitekturo kodirnik-dekodirnik, izvirni transformer, ki je prav tako ustvarjal besedilo. Kakšna je razlika med tem novim modelom samo z dekodirnikom in modelom kodirnik-dekodirnik? Oba sta si podobna v tem, da lahko ustvarjata besediloBut you may be wondering, well, last time we saw the encoder-decoder architecture, the original transformer, which was also generating text. Well, what is the difference between this new decoder only model with the encoder-decoder model? Well, so both are similar in that they can generate text
- u52 avtoregresivno. Pri arhitekturi kodirnik-dekodirnik pa je vhod obravnavan posebej. Podan je v kodirnik in znotraj tega kodirnika lahko vsi tokeni sodelujejo drug z drugim.autoregressively. But in the case of the encoder-decoder architecture, the input has a special treatment. It is input into the encoder, and within that encoder, all the tokens are able to interact with one another.
- u53 To je torej čista samopozornost. Pri arhitekturi samo z dekodirnikom pa lahko vhodni tokeni sodelujejo le sami s seboj in s tokeni pred njimi. S tokeni za njimi ne morejo sodelovati.So it's like pure self-attention. Whereas in the decoder only architecture, what you have as input, the tokens can only interact between themselves and tokens before them. They cannot interact with tokens after them.
- u54 Pri samem dekodirniku imamo torej vzročno pozornost, pri vhodu arhitekture kodirnik-dekodirnik pa dvosmerno pozornost. To je prva razlika. Druga razlika je, da imamo dodaten kodirnik in moramo posebej poskrbeti za vhod.So you have causal attention for decoder only, but you have bidirectional attention for encoder-decoder for the input. That's the first difference. The second difference is that, well, you have an extra encoder and you need to have some special care for the input.
- u55 Obravnavamo ga drugače, kar je lahko smiselno pri strojnem prevajanju, saj imamo kot vhod izvorno besedilo, kot izhod pa želimo ciljno besedilo. Pri ustvarjanju besedila pa ni povsem jasno, kaj naj bi bilo vhod.You're treating it differently, so it may make sense for things like machine translation because, well, you have source texts as inputs and you want to have target text as outputs. But things like text generation, it's not super clear what should be as input.
- u56 Z drugimi besedami, sam dekodirnik je nekoliko splošnejši, saj vse obravnava enako. Ljudje so pri paradigmi besedilo-v-besedilo preizkusili oba pristopa in velika večina se je pravzapravSo in other words, decoder only is a little bit more general because it treats everything the same. So people have tried both approaches when it came to the text-to-text paradigm, and overwhelmingly they all pretty much
- u57 odločila za sam dekodirnik. Želim, da si zapomnite, da so ljudje preizkusili vse različne različice. Zlasti pri ustvarjanju besedila sta obstajali obe paradigmi. Vendar se je do danes ohranila tista samo z dekodirnikom.went with the decoder only. So what I want you to remember is that people have tried all different variants. And in particular when it comes to generating texts, there was both these paradigms. But the decoder only one is the one that actually lived through today.
18:21 · Encoder-decoder versus decoder-only transformer architectures · A Stanford lecture slide contrasts encoder-decoder models with decoder-only models. The encoder-decoder option on the left is greyed out, and the decoder-only option on the right is highlighted. Its diagram shows the encoder crossed out in red, leaving only the decoder, which generates the next token, and the bullets say both input and output use causal attention. A small inset at top right shows a person standing in a lecture room. - u58 Eden od razlogov je, da je preprostejša in da vhodov ne obravnava posebej. In ja, ne potrebujete kodirnika za ločeno obravnavo vhoda. Na splošno torej obstajata dve paradigmi. Bodisi izračunate smiselne vložitve in poskusite model fino prilagoditi svojemu primeru uporabe,And one of the reasons is, well, it's simpler and there is no special treatment of the inputs. And yeah, you don't need to have an encoder to treat the input separately. So overall, there are two paradigms. Either you compute meaningful embeddings and you try to fine-tuning for your use case,
- u59 bodisi ga oblikujete kot problem pretvorbe besedila v besedilo. Vse probleme lahko oblikujete kot probleme besedilo-v-besedilo. Drugo vprašanje je, ali je to učinkovito. To je drugo vprašanje. Vendar to lahko naredite. In to ljudje počnejo doslej. Super.or you frame it as a text to text problem. And you can frame all problems as text-to-text problems. Another question is, is it efficient? It's another question. But you can do that. And that's what people have been doing so far. Cool.
- u60 Zakoni skaliranjaScaling laws
- u61 Kot sem omenil, so se ljudje odločili za arhitekturo samo z dekodirnikom in jo preprosto povečevali, saj so opazili, da deluje vse bolje. Zlasti v začetku dvajsetih let tega stoletja je nekaj člankov dejansko kvantificiralo, kolikoWell, as I mentioned, people went with the decoder only architecture, and what they did was just to scale that up, because they have seen that it was performing better and better. And in particular, in the early 2020s, there were a couple of papers that actually quantified how
- u62 boljši postaja model, ko ga učite na več podatkih, z več parametri in z več računanja. To si bomo zdaj ogledali. Ta članek iz leta 2020 pravi, da lahko dejansko dobimo skoraj nekakšen zakon, kimuch better your model was getting as you were training it on more data, with more parameters, with more compute. And we'll see that now. So this paper from 2020 is actually saying that you can actually have almost like a law that
- u63 pove, koliko boljši bo model glede na število tokenov, na katerih ga učite. To je srednji graf, pa tudi glede na velikost modela, kar prikazuje skrajno desni graf. Zato so v letih 2020, 2021 in 2022tells you how much better your model will get as a function of the number of tokens that you're training on. So it's the middle chart, and as a function of how big your model is, which is the rightmost chart. And so that's the reason why in 2020, 2021, 2022,
- u64 ljudje vse bolj povečevali modele in jih učili na vse več tokenih. Ne le to, avtorji so opazili tudi, da so večji modeli učinkovitejši glede porabe tokenov.people have been increasing model size and training it on more tokens like increasingly. And not only that, the authors also saw that the bigger your model, the more token efficient they were as well.
- u65 Kaj to pomeni? Če imate večji model, potrebujete manj tokenov za učenje, da dosežete določeno uspešnost. Kaj torej pomenijo vse te barve na prosojnici? Na osi y je Teslova.So what does that mean? That means that if you have a bigger model, you need a fewer amount of tokens to train on in order to reach a certain performance. So on the slide, so what are all these colors? So on the y-axis, it's the Tesla's.
- u66 To je torej uspešnost modela. Nižje je bolje. Os x pa predstavlja število tokenov, obdelanih med učenjem. Te lepe barve povedo, da svetlejša barva pomeni večji model, ki običajno doseže boljšoSo it's the performance of your model. The lower the better. And then the x-axis is the number of tokens that were processed as part of the training. And so the beautiful colors, they're saying that the brighter you are, the bigger your model is, the more it tends to have a better
- u67 uspešnost prej. Zato pravimo, da so večji modeli tudi učinkovitejši glede tokenov. Za boljše delovanje potrebujejo manj učnih tokenov. Kot si lahko predstavljate, pa je strojna oprema omejena. Nimamo neskončno računskih virov.performance earlier. So that's why we're saying that bigger models are also more token efficient. They need fewer training tokens to perform better. But as you can imagine, well, hardware is limited. You don't have infinite compute.
- u68 Zato se povsem naravno sprašujete: če imam določen računski proračun, za koliko naj povečam model? In koliko naj ga namenim številu tokenov, na katerih naj ga učim? Preden spregovorimo o tem, želim predstaviti nekaj oznak,So very naturally, you're wondering, well, if I have a certain compute budget, how much should I scale my model in size? And how much should I attribute that to the number of tokens I should train it on? So before we talk about this, I want to introduce some notations
- u69 ki ste jih morda že videli, vendar želim zagotoviti, da jih vsi enako razumemo. Prva je FLOPs, kar pomeni operacije s plavajočo vejico. Bodite pozorni na mali s. Ta enota je namenjena merjenju količine računanja. Višji FLOPs torej pomeni več računanja.that I think maybe you have seen, but I want to make sure we're all on the same page. So the first one is FLOPs, which stands for Floating Point Operations. And please note the little S, lowercase S. So this is a unit that is meant to measure compute. So the higher the FLOPs, the more compute you actually have.
- u70 Za občutek velikostnega reda: FLOPs za učenje velikih jezikovnih modelov je približno 10 na 25. potenco. Lahko pa naletite tudi na drug FLOPS. FLOPS z velikim S ali celo /S. Ta dejansko označuje računsko hitrost. Je merilo zmogljivosti strojne opreme.So order of magnitude, so training FLOPs for LLMs is like 10 to the power of 25. But you may see another FLOPS out there. So FLOPS with a capital S or even /S. And that one is actually the compute speed. And it's actually a measure of how performant your hardware is.
- u71 Razlikuje se od prejšnjega FLOPs, vendar ju hitro zamenjamo. Na to sem želel opozoriti. Zdaj pa nazaj k temu, o čemer smo govorili. Živimo v svetu, kjer nimamo neomejenih računskih virov, vsaj za zdaj ne.It is different compared to the previous FLOPs, but it's easy to get mixed up. So just wanted to call that out. So with that said, back to what we were saying. So we live in a world where we don't have unlimited compute, or at least not yet.
23:00 · Lecturer in front of "Notations" slide on FLOPs · A still from a lecture video shows a man in a dark T-shirt and green trousers standing and gesturing in a classroom with blackboards. A projected Stanford/ICME slide titled "Notations" distinguishes FLOPs (total floating-point operations) from FLOPS or FLOP/s (operations per second). The slide gives rough computational performance for a smartphone, a computer and a supercomputer. - u72 Glede na količino računskih virov, ki jih imate na voljo, je naravno vprašanje: za koliko naj povečam model? In za koliko naj povečam učno množico, na kateri ga učim?So given the amount of compute that you have available, a natural question that you have is, how much should I increase my model size? Versus how much should I increase the training size on which I'm training my model?
- u73 Leta 2022 je izšel članek, ki je zastavil prav to vprašanje. Ugotovitve so bile precej zanimive. Ugotovil je, da obstaja optimalno ravnovesje med velikostjo modela in velikostjo učnih podatkov.And so there is this paper that came out in 2022 which exactly asked this question. And what it found was actually pretty interesting. It found that there was actually a sweet spot between model size and training data size.
- u74 Ugotovil je tudi, da je bila večina modelov takrat, leta 2022, premalo učena, kar pomeni, da so bili preveliki glede na število tokenov, na katerih so se učili. Bili so premalo učeni. To je pokazal tudi z učenjem dveh modelov.And it also found that most models at the time in 2022 were actually undertrained, meaning that they were too big for the amount of tokens that they were trained on. They were undertrained. And so it actually also showed that by training two models.
- u75 Eden je imel, mislim, 70 milijard parametrov, drugi pa dvesto in nekaj milijard, torej več kot prvi. Oba sta imela enak računski proračun. Prvi model je bil manjši, zato so ga učili na več tokenih.So one, which was, I believe, 70 billion parameters and another one 200 and something billion parameters, so higher than the previous one. And it had the same compute budget for the two. So the first one, given it's smaller in model size, it trained it on more tokens.
- u76 Mislim, da so ga učili na 1,4 bilijona tokenov. Drugi, večji model pa so učili na manj tokenih, ker je bil računski proračun enak. Pokazalo se je, da je bil manjši model dejansko uspešnejši. Dobili so torej neko razmerje med številom parametrovI believe it trained it on $1.4 trillion tokens. And the second one, which was bigger in size, it trained it on fewer tokens because it was the same compute budget. And it showed that the smaller model in terms of size was actually more performant. So they had some relationship between number of parameters
- u77 in številom tokenov za učenje, ki je bilo približno en parameter na 20 tokenov. To je bilo precej pomembno. Veliko ljudi se je vrnilo k svojim modelom in preverilo, ali so računsko optimalni. Ja, tudi to je precej pomemben članek.and number of tokens that you are training it on, which was something like one parameter for 20 tokens. And so this was quite important. A lot of people tried to go back and see OK, is my model compute optimal? So yeah, so this is also pretty important paper.
- u78 Drugo vprašanje, ki si ga lahko zastavite — če poskusimo razmišljati širše od tega članka — je, kakšen je vaš primer uporabe. Tukaj govorimo o računski optimalnosti učenja. Model pa morate uporabljati tudi v produkciji. Če z njim obdelujete zelo veliko zahtev,Another question you can ask yourself-- I mean, just trying to think beyond this paper is what your use case is. Because here we're talking about training compute optimal. But you also need to serve your model production. So if you serve it with many, many requests,
- u79 imate tudi razlog, da ni prevelik. Ampak to je drugo vprašanje. Želel sem ga le omeniti. Ja. Vprašanje je torej, ali gre za izgubo križne entropije. Odgovor je da, ker je vaša naloga napovedovanje naslednjega tokena.you also have an incentive to not have it be too big. But that's another question. But I just want to put it out. Yeah. So the question is, is it the cross-entropy loss? And the answer is yes, because your task is next token prediction.
- u80 Doseči želite, da je napoved čim bližje oznaki, ki je naslednji token. Da, običajno uporabljamo križno entropijo in ta je uporabljena tudi tukaj. Ja. Vprašanje je torej, ali je kakovost podatkov pomembna.And what you're trying to do is have your prediction be as close as the label, which is the next token. And yes, cross-entropy is typically the one that you use and it's the one that is here. Yeah. So the question is, does the quality of the data matter?
- u81 Rekel bi, da je o tem izšlo veliko člankov, mnogi z različnimi sklepi. Rekel bi, da je za predučenje količina pomembnejša od kakovosti. Na 3. predavanju bomo videli, da je pri naslednjih korakih učnega procesa kakovost pomembnejša,I would say there are many papers that came out from this, many with different conclusions. I would say for pre-training, what matters is the size more than the quality. We will see in lecture 3 that next steps of the training process matters, there's more importance towards quality
- u82 in to si bomo ogledali. V redu, super.and we will see that. OK, cool.
- u83 Opredelitev velikega jezikovnega modelaLarge Language Model definition
- u84 Preidimo k LLM. Zakaj LLM imenujemo LLM? LLM pomeni veliki jezikovni model. Jezikovni model zato, ker je to model, ki zaporedjem tokenov pripisuje določene verjetnosti.OK, moving on to LLM. So why do we call LLM, LLM? Well LLM stands for Large Language Model. So language model is, because it's a model that associates some probabilities to sequences of tokens.
26:49 · Terminology slide: LLM means Large Language Model · A Stanford lecture slide titled "Terminology" on a mostly blank white background. It gives one definition, LLM = Large Language Model, with the initials L, L and M in bold. A small inset at the top right shows the lecturer standing in front of a board. - u85 V tem primeru gre za model, ki poskuša napovedati naslednji token. Poskušamo torej določiti verjetnost naslednje napovedi. Zakaj pa je velik? Velik je zato, ker je velikost modela velika, običajno v milijardah, celo desetinah ali stotinah milijardSo in this case, it's a model that tries to predict the next token. So we're trying to put some probability towards what the next prediction is. And why is it large? Well, it is large because the model size is large, typically in the billions, even tens of billions or hundreds of billions
- u86 in celo bilijonih. Tudi učni podatki obsegajo stotine milijard tokenov. Vsaj dandanes gre tudi za desetine bilijonov tokenov. Pa tudi računanje. Potrebujete veliko grafičnih procesorjev. Kot sem omenil, se ljudje dandanes opirajo na transformer samo z dekodirnikom,and even trillions. Training data, also hundreds of billions of tokens. At least nowadays, it's also on the tens of trillions of tokens. And also compute. You need a lot of GPUs. And as I mentioned, nowadays people rely on the decoder only transformer,
- u87 ki je izvirni transformer brez kodirnika. Morda me boste vprašali: če pogledamo dekodirnik, ima komponento navzkrižne pozornosti, ki prejema smiselne vložitve iz kodirnika skupaj s tistimi,which is the original transformer without the encoder. Well, you may ask me, well, if you look into the decoder, you actually have a component, which is the cross-attention that takes in the meaningful embeddings from the encoder with the ones
- u88 ki prihajajo iz dekodirnika. In vprašate: kaj se zgodi s to komponento? Tudi to odstranite. Dekodirnik torej ni povsem isti dekodirnik. Odstranite tudi del, ki sodeluje s kodirnikom, in dobite to zelo preprosto ogrodje: plast vzročne večglave pozornosti, ki je pozorna samocoming from the decoder. And you're like, OK, what is happening with that components? Well, you also remove it. So the decoder is not exactly the decoder. You also remove the part that is interacting and you obtain this very simple backbone, which is a causal multi-head attention layer, which is only
- u89 na posamezni token in tokene pred njim, ter nevronsko mrežo s povezavami naprej, kjer poteka računanje. Super. V redu. Tukaj smo torej videli, da večji model pomeni boljšo uspešnost.attending to each token and the tokens that came before it and a feed forward neural network, which is where the compute happens. Cool. OK. So what we saw here is the bigger your model size, the better your performance.
- u90 Videli smo tudi, da obstaja kompromis med številom tokenov, na katerih model učimo, in velikostjo modela.And we saw that there was also a trade-off between the number of tokens you were training it on and the model size that you were having.
- u91 Mešanica strokovnjakov (MoE)Mixture of experts (MoE)
- u92 Naravno vprašanje bi bilo: ko imate vhod x v model in je model ogromen, to pomeni, da v njem poteka veliko računanja. Naravno vprašanje je, ali resA natural question could be, when you have an input x into your model, if your model is huge, then that means that there are a lot of computations happening in that model. A natural question can be do you really
29:05 · Lecture on Transformers and Large Language Models at Stanford · A man in a dark t-shirt and green trousers stands in a classroom, turned toward a projected slide. The slide is the title/outline slide for "Transformers & Large Language Models" from Stanford University and ICME, with the topic "Expert routing" highlighted in bold among six agenda items. - u93 potrebujete vse parametre modela za dani vhod x. Ali jih res potrebujete? To opažanje želim ponazoriti z drugim opažanjem. Predpostavimo, da sem tukaj v sobi, polni ljudi.need all the parameters in your model for that given input x? Do you really need that? And I want to motivate this observation with another observation. So let's assume I'm here in a room full of people.
- u94 Recimo, da imam matematično vprašanje. Predpostavimo, da vsi prihajate z različnih področij. Recimo, da ste vi strokovnjak za matematiko. Vi ste strokovnjak za fiziko, vi za biologijo. Jaz pa pridem s svojim matematičnim vprašanjem. Naj vprašam vse?And let's say I have a math question. Let's suppose you all are coming from different backgrounds. So let's assume you're a math expert. Let's assume you're a physics expert, biology expert. And I'm coming with my math question. Should I ask everyone?
- u95 Ali naj vprašam samo vas? Natanko takšno vprašanje so si zastavili ljudje. Kaj če za dane vhode dejansko aktiviramo samo podmnožico modela namesto vseh parametrov?Should I only ask you? And this is exactly the kind of question that people have asked themselves. How about we actually only activate a subset of the model for given inputs as opposed to all parameters?
30:07 · Motivation: only a subset of weights is used in the forward pass · A Stanford ICME lecture slide titled "Motivation" states the idea that not all weights are useful in the forward pass. A diagram shows input x flowing into a tall box whose top part, highlighted in blue, is labeled "Subset of the huge model" and whose lower part is faded, then an arrow leading out to the output ŷ. It suggests that only part of a large model needs to be active for a given input. A small video inset of the lecturer stands at top right. - u96 Če to naredimo, bi lahko povečali model, ne da bi imeli stroške izvajanja vseh teh operacij pri vsakem prehodu naprej? Kaj če bi to naredili?And so if you were to do that, then you could scale your model in size, but not incur the cost of having to go through all these operations for every forward pass? So how about you did that?
- u97 Izkazalo se je, da obstaja vrsta modela, ki je nastala že pred velikimi jezikovnimi modeli in se imenuje mešanica strokovnjakov. Kdo je že slišal za mešanico strokovnjakov? Da. V redu, odlično. Kakšna je ideja mešanice strokovnjakov? Imate strokovnjake.Well, it turns out there's a type of model out there that was actually predating LLMs, which is called a mixture of experts. So who has heard of mixture of experts? Yes. OK, great. So what is the idea behind mixture of experts? So you have experts.
- u98 Predstavljajte si strokovnjaka za matematiko, strokovnjake za fiziko in tako naprej. Nato imate vrata, imenovana tudi usmerjevalnik, ki poskuša glede na vhod ugotoviti, katerega strokovnjaka uporabiti in v kolikšni meri.So think of it as your math expert, physics experts, et cetera. And then you have a gate, also called a router, that tries to figure out, given your input, which expert should you use and to what extent?
- u99 Imate na primer vhod x, ki ga pošljete skozi vrata oziroma usmerjevalnik. Usmerjevalnik reče: v redu, strokovnjak 2, to je matematično vprašanje, vprašati moram tebe. Obstaja več vrst mešanic strokovnjakov oziroma MoE. Prva vrsta se imenuje gosta MoE.So for instance, you have some input x and you're passing it through your gate or your router. And the router says OK, expert 2, so this is a math question I should ask you. So there are several kinds of Mixture of Experts or MoEs. One first kind is called a dense MoE.
- u100 Kaj počne gosta MoE? Še vedno aktivira vse strokovnjake, vendar daje večjo težo tistim, ki so morda pomembnejši. Matematično vprašanje bi na primer dobilo veliko težo pri strokovnjaku za matematiko, morda manjšo pri strokovnjaku za fiziko in morda zelo majhnoA dense MoE, what does it do? It still activates all the experts, but it gives more weight towards experts that are maybe more relevant. So, for instance, the math question could be high weight for the math expert, maybe lower weight for the physics expert, but maybe a very small weight
- u101 pri strokovnjakih za biologijo. Slabost goste MoE je, da še vedno aktivirate vse parametre. Tega ne želite. Zato v kontekstu velikih jezikovnih modelov dejansko zelo zanimiva vrstafor the biology experts. So the bad thing with the dense MoE is you still activate all the parameters. It's not what you want to do. So that's why, in the context of LLMs, the kind that is actually very interesting
- u102 ni gosta MoE, temveč redka MoE, ki je vrsta streliva, ki dejansko izbere strokovnjake, ki naj se aktivirajo, in prezre vse druge. To je redka MoE.is actually not the dense MoE, it's the sparse MoE, which is the kind of ammo that actually selects experts that should be activated and that ignores all the other experts. This is the sparse MoE.
- u103 Običajno torej izberemo najboljših k strokovnjakov. k je lahko enak 1, lahko 2 ali nekemu številu, ki ga določite. Izhod, ki ga dobite, torej y s strešico, je vsota izhodov strokovnjakov, uteženih glede na njihovo pomembnost,So typically you have top k experts that were selected. So k can be equal to 1, can be equal to 2 to some number that you fix. And the output that you get, so y hat is the sum of the expert output weighted by how important they are,
- u104 ki jo določijo vrata. To je vsota samo po aktiviranih strokovnjakih — torej k strokovnjakih, ne po vseh.which is given by the gates. And it's only a sum over some experts that were activated-- so k experts, not all experts.
- u105 Veliki jezikovni modeli na osnovi MoEMoE-based LLMs
- u106 Super. V redu. Vse to je odlično. Zdaj pa se vrnimo v resničnost. Vrnimo se k našemu velikemu jezikovnemu modelu. Če se spomnite, gre za arhitekturo samo z dekodirnikom. To je naše ogrodje. Imam vprašanje za vas. Kam v arhitekturi bi umestili to shemo mešanice strokovnjakov?Cool. Well, OK. All that is great. But now let's go back to reality. Let's go back to our LLM. If you remember, it's a decoder only architecture. So we have this as a backbone. So I have a question for you. Where would you put this mixture of experts scheme in the architecture?
33:11 · MoE in Transformer-based models: decoder block starting point · A Stanford lecture slide titled "MoE in Transformer-based models" shows a single transformer decoder block adapted from "Attention Is All You Need". The block stacks Masked Multi-Head Attention, Add & Norm, Feed Forward, and Add & Norm, with residual connections, repeated N times. The right side is empty, likely where the mixture-of-experts modification will be added. A small inset shows a presenter standing at the top right. - u107 V katero plast bi jo dali? Ima kdo kak predlog? Da. Ja. Odgovor je torej, da lahko vzamete token in ga projicirate, da izberete strokovnjaka.Which layer would you put it? Does anyone have any suggestions? Yes. Yep. So the answer here is you can take a token and project it in order to select which expert it is.
- u108 Da. To je dejansko vloga usmerjevalnika. Tukaj me res zanima, kam bi v vsem tem umestili celotno mešanico strokovnjakov. Pomagal vam bom. Aha, ja. Oprostite. Ja. Odličen odgovor. Samo ponovil bom natanko to, kar ste rekli.Yes. So that is actually the role of the router. So here the thing that I'm really interested in is where would you put the whole mixture of experts in all of this? So I'll help you. Oh, yeah. Sorry. Yeah. It's a great answer. So I'll just exactly mention what you said.
- u109 Odgovor bi bil nevronska mreža s povezavami naprej, saj se tam običajno izvaja vse računanje. Da, popolnoma se strinjam z vami. Plast večglave pozornosti je dejansko mesto, kjer tokeni komunicirajo. Običajno tam ne izračunavamo smiselnih vložitevSo the answer would be feedforward neural network, because this is where all the compute typically resides. And yes, I completely agree with you. The multi-head attention layer is actually the place where tokens communicate. It's not where typically you compute meaningful embeddings
- u110 s projiciranjem. Običajno bi torej izbrali nevronsko mrežo s povezavami naprej. Odličen odgovor. Če se vrnem k vaši pripombi, bi tukaj imeli usmerjevalnik, ki za dani vhod odloči, katerega strokovnjaka aktivirati. Strokovnjak pa bi bil nevronska mreža s povezavami naprej.by projecting it. So you would typically go with the feedforward neural network. So a great answer. And so here what you would do is back to your point, have a router where for a given input, decides which expert to activate. And here the expert would be a feedforward neural network.
34:34 · Mixture of Experts in Transformer feed-forward layers · A Stanford lecture slide shows how a Mixture-of-Experts layer replaces the Transformer's feed-forward block. Input x goes to a gating network G, which selects which of the feed-forward experts FFNN1…FFNNn process x. In the diagram, only FFNN2 is selected (green check) and the others are rejected (red X). The outputs combine into ŷ. A faded Transformer block on the left highlights the Feed Forward component being replaced. - u111 Torej ja, odličen odgovor. Oprostite. Ja. Vprašanje oziroma pripomba je, da imamo v plasti pozornosti različne glave. Zakaj ne bi glav obravnavali kot strokovnjake? Odlična pripomba.So yeah, great answer. Sorry. Yeah. So the question is, well, or the remark I would say is that in the attention layer, you have different heads. Why wouldn't you treat heads as experts? So it's a great point.
- u112 Mislim, da lahko navsezadnje poskusite tudi to. Ko že govorimo o tem, bomo dejansko obravnavali manjšo spremembo, ki jo ljudje običajno naredijo pri večglavi pozornosti, saj niso vse glave enako uporabne.I think, at the end of the day, you can also try that. But speaking of that, we will actually talk about a small variation that people usually do on multi-head attention because, not all heads are as useful.
- u113 Na vaše vprašanje bom torej odgovoril čez približno 30 minut. Ja, odlično opažanje. Ja. Vprašanje je, kako usmerjevalnik ve, kdaj aktivirati posameznega strokovnjaka. S čarovnijo vzvratnega razširjanja, s čarovnijo učenja.So I'm going to just address your question in about 30 minutes. Yeah, but great point. Yep. So the question is, how does the router know when to activate each expert? So by with the magic of back propagation, magic of learning.
- u114 Imate učni proces in želite se naučiti, kako naj se obnaša vsaka komponenta. Preprosto izvedete vzvratno razširjanje in tako se nauči. To je dejansko odlično vprašanje, saj je eno od opažanjSo you have a training process and then you want to learn how each component should behave. And you just backpropagate and it just learns that way. And it's actually a great point because one observation
- u115 Izguba za uravnoteženje obremenitveLoad balancing loss
- u116 lahko naslednje: kaj bi modelu preprečilo, da se pretirano opira na določeno skupino strokovnjakov in ne raziskuje drugih? To je dejansko težava pri učenju velikih jezikovnih modelov na osnovi MoE, kiyou may tell me is, what would prevent your model from overrelying on a specific set of experts and not explore other experts? And so this is actually a problem when training MoE-based LLMs, which
- u117 pomeni težnjo modela, da se opira samo na majhno skupino strokovnjakov namesto na vse. Imenuje se kolaps usmerjanja. Obstaja veliko razlogov, zakaj to ni dobro. Eden je, da je dejanska velikost modela manjša od skupnega števila strokovnjakovis the tendency for your model to rely only on a small set of experts instead of all the experts. And it's called routing collapse. So there are many reasons why it's not good. But one of the reasons is your effective model size is actually smaller than the total number of experts
- u118 in uteži, ki jih imate. To se običajno zgodi zato, ker so med učenjem nekateri strokovnjaki izbrani že na samem začetku, nato pa se pri posodabljanju uteži ti strokovnjaki, ki so bili aktivirani na začetku,and weights that you have. And this typically occurs, because when you train your model, if some experts get chosen in the very beginning, then when it comes to updating the weights, those experts that were activated in the beginning, they
- u119 običajno posodobijo prvi. Zato postajajo vse boljši, vsi drugi strokovnjaki pa še vedno samo čakajo. Gre za problem, ko bogati postajajo še bogatejši. Zato so ljudje uvedli tudi del tako imenovane izgube, torej gre zatend to be updated at first. So they tend to get better and better, whereas all the other experts are still sitting there. So it's the problem of the rich getting richer. And so it's for that reason that people have also come up with a part of the last cult, so it's
37:34 · Routing collapse in mixture-of-experts and auxiliary loss remedy · A Stanford lecture slide on training challenges in mixture-of-experts models. The symptom, routing collapse, is that the same expert is selected most of the time. The remedy is an auxiliary loss, loss = α·N·Σ f_i·P_i, that forces other experts to take part. The slide cites Switch Transformers (Fedus et al., 2021). A small inset video shows a lecturer at a board. - u120 pomožno izgubo za uravnoteženje obremenitve, katere cilj je model prisiliti oziroma spodbuditi k raziskovanju drugih strokovnjakov, tako da spodbuja enakomeren ali bolj ali manj enakomeren delež preusmerjenih tokenova load balancing auxiliary loss, which is aimed at forcing your model to also incentivize exploring other experts by encouraging the fraction of the tokens that are being rerouted to be uniform or more or less uniform
- u121 med strokovnjaki. Morda tega nisem povedal, zato bom zdaj. Usmerjanje poteka na ravni tokenov. Če imate vhodno poved, se vsak token vpraša, h kateremu strokovnjaku naj gre. To torej poteka na ravni tokenov.across experts. And so maybe it's something that I didn't say, but I will say it now. The routing is done at the token level. So if you have an input sentence, each token will ask itself, which expert should I go to? So this is done at the token level.
- u122 Ta izguba torej spodbuja model — ja. Vprašanje je: če izberete enega ali dva, to ni odvedljivo. Odlično opažanje. Imate operator stop grad, ki nekatere vidike obravnava tako, kot da imajo odvod 0,And so here this loss is incentivizing your model-- yeah. So the question is, well, if you select one or two, it's not differentiable. It's a great point. So you have an operator that's called stop grad that is treating some aspects as being actually derivative of 0
- u123 in jih obravnava kot konstante. Skratka, pri izgubi delež tokenov, usmerjenih k strokovnjaku i, obravnavate kot konstanto. Vzvratno razširjanje pa izvajate samo skozi verjetnost usmerjanja. Tako lahko te usmerjevalnike še vedno spreminjate.and treating these as constants. So long story short is in the loss, you're treating the fraction of tokens routed to expert i as a constant. And you're only backpropagating through the routing probability. So you're still able to actually change those routers.
- u124 Ja, dobra pripomba. Naj pogledam. Mislim, da smo govorili o tem, da ta pomožna izguba spodbuja model, da izbere tudi druge strokovnjake in da ne pride do težave s kolapsom usmerjanja, ki smo joBut yeah, that's a good point. So let me see. So I think we're talking about the fact that these auxiliary loss is incentivizing your model to also choose other experts and not to have this routing collapse problem that we
- u125 omenili na začetku. Obstajajo tudi druge težave. Želim vam samo povedati, da je učenje velikega jezikovnega modela na osnovi MoE zahtevno, in to je del teh izzivov. Dobra stran pa je, da boste ob pravilni izvedbi imeli — tukaj na prosojnici viditementioned at the beginning. There are some other problems as well. I just want to just tell you that training an MoE based LLM is challenging, and this is part of its challenge. But the good thing is, if you do it properly, you will have-- so here on the slide, what you see
39:38 · Interpreting experts: colored MoE layer code from Mixtral · A Stanford ICME lecture slide titled "Interpreting experts" shows a PyTorch MoeLayer class with each token highlighted in a color. The slide says each color represents an expert, so the highlighting shows which expert handles which code tokens in Layer 0. A small video inset at top right shows a person standing in front of a board. - u126 vhodno besedilo, kjer barva vsakega odseka označuje določenega strokovnjaka, h kateremu je bil poslan posamezni token. To je na primer pri določeni plasti. To prihaja iz članka o modelu Mixtral. Tukaj je torej model z imenom Mixtral of experts.is an input text where the color of each section denotes a specific experts that a given token was sent to. And this is, for instance, at a given layer. And this is coming from a paper from Mixtral. So here is the model called Mixtral of experts.
- u127 Vidite, da so barve precej raznolike. To pomeni, da svoje strokovnjake dejansko precej dobro izkoriščate. O velikih jezikovnih modelih na osnovi MoE želim povedati še nekaj stvari. Zdaj smo torej v letu 2026.And you see that the colors are pretty diverse. So it means that you're actually leveraging your experts pretty well. And so I want to just say a few things about MoE-based LLMs. So now we're in 2026.
- u128 Mislim, da je bil ta članek iz leta 2024, kar je na področju umetne inteligence že kar dolgo nazaj. Dandanes ljudje uporabljajo strokovnjake, imajo pa tudi skupne strokovnjake, ki se aktivirajo ne glede na to, katere strokovnjake usmerjevalnikThis is something that I think the paper was from 2024, which is quite some time ago in the AI field. So nowadays, what people do is they use experts, but they also have shared experts that gets activated no matter which experts the router
- u129 oziroma vrata izberejo. Ideja je, da je za vsak token vedno potrebno določeno računanje. Želite preprečiti, da bi se strokovnjaki vedno učili iste osnove in se nato specializirali za nekaj.or the gate selects. And the idea behind this is for every token, there is always some computation that is always necessary. And you want to avoid your experts from always learning the same thing as a foundation and then specializing into something.
- u130 To torej ljudje počnejo dandanes. Druga stvar je število strokovnjakov: ne izberejo 8 ali 16. Izberejo več, 60 ali več sto. Intuitivni razlog za to je, da strokovnjakom preprosto omogočite,So that is something that people do nowadays. The second thing that people do is the number of experts, they don't choose it to be 8 or 16. They actually choose it to be higher, 60 or in the hundreds. And the reason why they do that is that intuitively, you just give the chance to your experts
- u131 da so zelo specializirani in zelo ozko usmerjeni. Tudi na grafih vidite, da je uspešnost pri bolj ozko specializiranih strokovnjakih višja. To je torej tudi empirično potrjeno. Ko govorimo o velikostnih redih: pri najnaprednejših odprtokodnih velikih jezikovnih modelih,to be very specialized, very fine-grained. But also on the charts, you see that the performance, when you have more fine-grained experts is just higher. So it's also just empirical. And so speaking of order of magnitudes. So when it comes to the frontier open source LLMs
- u132 ki so bili objavljeni pred kratkim — ta posnetek zaslona je dejansko star nekaj dni — pri najboljših modelih vidimo, da gre za modele na osnovi MoE. Število strokovnjakov je reda velikosti več sto. Tukaj sta 384 in 256.that were published recently. So here the screenshot is actually from a few days ago. If we take the top models, what we see is that-- so there are MoE-based LLMs. And the number of experts that they have is on the order of hundreds. So here are 384, 256.
- u133 Število strokovnjakov, aktiviranih pri vsakem prehodu naprej, pa je običajno približno osem. Imate tudi skupnega strokovnjaka, ki pa ni splošno uporabljen. V tem primeru ga na primer prvi model ne uporablja. Glede velikosti modela pa greAnd the number of experts that are activated at each forward pass is typically eight or so. And you also have a shared expert, which is not widely used. Like in this example, the first model is not using it. And in terms of the model size, it
- u134 za stotine milijard parametrov ali pri prvem celo za bilijon parametrov. To so torej precej veliki modeli. Da. Odlično vprašanje. Vprašanje je, ali zakon skaliranja še vedno velja za velike jezikovne modele na osnovi MoE.is in the hundreds of billions of parameters or even trillion parameter for the first one. So it's pretty big models. Yes. So it's a great question. The question is, does the scaling law still hold true for a MoE-based LLMs?
- u135 Odgovor je, da je tisti članek dejansko temeljil na gostem velikem jezikovnem modelu, ne na modelu na osnovi MoE. V člankih sem videl, da avtorji izvedejo poskuse z zakoni skaliranja za svojo postavitev, z majhnim številom tokenov in majhnimi modeli, da ugotovijo, kakšen zakon velja za to postavitev.So the answer is that paper was actually based on a dense LLM. It was not like an MoE-based LLM. So one thing that I've seen papers do is have these scaling law experiments for their own setup on small number of tokens, small model size to just see what the law is for the specific setup.
- u136 Glede vašega vprašanja torej mislim, da pri velikih jezikovnih modelih na osnovi MoE avtorji, če menijo, da sta njihova izbira in zasnova zelo drugačni od prej preizkušenih, izvedejo tak zelo majhen poskus in pogledajo, kakšen zakon iz njega izhaja,So to your question, I think for MoE-based LLMs, if authors feel that their choice, their design is very different from what was tested before, they would just do this very small experiment and see what is the kind of law that comes from there,
- u137 nato pa na tej osnovi izberejo parametre. Ja. Ja. Vprašanje je, zakaj je n, število strokovnjakov, v števcu. Tukaj dejansko seštevate po strokovnjakih.and then choose the parameters from there. Yep. Yep. So the question is, why is n the number of experts doing in the numerator? So here, actually, what you're doing is you are summing across the experts.
- u138 Če to zapišete matematično, želite dodati n — ker sta fi in Pi približno deljena z n, je to deljeno z n na kvadrat, krat n pa je približno deljeno z n. Torej je krat n. n pa je število strokovnjakov.And so if you actually write that mathematically, you actually want to add n to-- because fi and Pi is like over n, so it's over n squared, times n is like over n. So it's times n. But n is the number of experts.
- u139 V redu, odlično. Izvrstno nam gre. Kakšno vprašanje, še kakšno vprašanje? Kaj smo videli do zdaj? Videli smo, da so ljudje preizkusili različne različice transformerja.OK, great. We're doing amazing. Any questions, other questions? So far, what did we see? We saw that people have tried different variants of the transformer.
- u140 Pogledali so: kaj če vzamemo kodirnik? V redu, to lahko naredimo. Kaj če vzamemo dekodirnik? To obravnavamo kot problem besedilo-v-besedilo. To so povečevali. Opazili so, da se uspešnost vse bolj izboljšuje, ko povečujejo model in število tokenov, na katerih ga učijo.They saw OK, how about we take the encoder? Well, OK, you can do this. How about you take the decoder? You treat that as a text-to-text problem. They scale that up. And people have seen that the performance just gets better and better as people increase it in size and in number of tokens that it is trained on.
- u141 Videli smo, da moramo pri prevelikem modelu nekaj ukreniti, da stroški sklepanja niso nori. Zato so ljudje razvili velike jezikovne modele na osnovi MoE, ki omogočajo povečanje števila parametrov brez stroškov aktiviranjaWe've seen that when the model is too big, you need to do something in order for you to not have crazy inference costs. And so that's why people have developed a MoE-based LLMs that allow you to scale the number of parameters without having to incur the cost of also activating
- u142 vseh parametrov pri vsakem prehodu naprej. V tem delu se bomo osredotočili na številne spremembe, ki so jih ljudje uvedli v plasti, opisane v izvirni arhitekturi transformerja.all the parameters in each forward pass. So here in this part, what we will focus on is a number of changes that people have made in the layers that were originally described in the original transformer architecture.
- u143 Takoj boste videli, kaj mislim.So you will see in a second what I mean.
- u144 Položajne vložitvePosition embeddings
- u145 Če se spomnite, arhitektura transformerja temelji na mehanizmu samopozornosti, katerega ideja je vsem tokenom omogočiti komunikacijo z vsemi. Težava pri tem je,So if you remember, the transformer architecture relies on the self-attention mechanism, which is the idea of letting all your tokens communicate with everyone. So the problem when you do that is
45:36 · Need for position information in attention · A Stanford lecture slide on why transformers need position information: direct query-key links between tokens "lose" position info. It shows the sentence "a cute teddy bear is reading ." with a value vector above and a transposed key vector below each token. The query for "teddy bear" connects by lines to every key, including its own. - u146 da izgubite informacijo o položajih tokenov, ker imate te neposredne povezave. Če nikjer nimate vključene informacije o položajih posameznih tokenov, izgubite informacijo o tem, kje so tokeni. Izvirni članek o transformerju je preizkusil dva pristopa.that you lose the information of where tokens are positioned because you have these direct links. So if you don't have any information about positions about each of these tokens that are included anywhere, well, you lose the information of where tokens are located. So the original transformer paper tried two approaches.
- u147 Prvi je bil učenje položajnih vložitev in prištevanje teh vložitev vložitvam tokenov. Imate torej vhodno zaporedje in tokene. Vsakemu tokenu je pripisan indeks položaja.The first was learning position embeddings and adding those embeddings to the token embeddings. So what people would do is you have an input sequence, you have your tokens. Each token is associated with a position index.
- u148 Recimo 1, 2, 3 in tako naprej. Ideja je naučiti se vložitve, povezane z vsakim indeksom položaja. Položaj 1 bo imel svojo vložitev, položaj 2 svojo in tako naprej. Te vložitve bi se naučili.Let's assume 1, 2, 3, and so on. And here the idea is to learn an embedding that is associated with each position index. So position 1 will have an embedding, position 2 will have an embedding, and so on. And these embeddings would be learned.
- u149 Da bi model dejansko vedel, kje je posamezen token, bi, kot vidite na desni, vzeli vložitev tokena in ji prišteli vložitev, značilno za njegov položaj,And what would happen is, in order for your model to actually know about where each of these tokens are located, so if you see on the right, what people would do is take the token embedding and then add that position-specific embedding to the token
- u150 da bi odražali, da je token na točno določenem položaju. Težava tega pristopa pa je, kot smo omenili zadnjič, da če model učite na vhodnih podatkih določene dolžine in med sklepanjem naletite na zaporedje, ki je,just to reflect that token is at a very specific position. But the problem with this approach is, as we mentioned last time, that if you train your model on a given length of input data, if you ever come across some sequence at inference time, that is,
- u151 recimo, daljše, je težava v tem, da nikoli niste naleteli na položaje zunaj tistih, ki ste jih srečali med učenjem. Zato dejansko ne veste, kakšne so vložitve za takšne položaje. Ne veste.let's say longer, the problem is actually have never encountered positions beyond the ones that you encountered at training time. So you actually do not know what embeddings for such position are. You don't know.
- u152 Zato izvirni avtorji članka o transformerju niso preizkusili le naučenega pristopa, temveč tudi deterministični pristop na osnovi formule, ki si ga bomo takoj ogledali. Ta pristop so preizkusili zato,And so that's the reason why the original authors of the transformer paper, they not only tried the learned way, but they also tried a deterministic formula-based way that we're going to see in a second. And the reason why they tried this approach
- u153 ker se lahko posploši na katero koli dolžino zaporedja, ne da bi model morali učiti na daljših zaporedjih. Dejansko so navedli, da sta oba pristopa dosegla približno enako uspešnost.is because it can generalize to any sequence length without having you to actually train on longer sequences. And they actually said that both approaches were roughly leading to the same performance.
- u154 Fiksni pristop je torej boljši in zdaj si ga bomo ogledali. Izhajal bom iz analogije, ki sem jo omenil zadnjič. Ideja deterministične formulacije je vsak položaj izraziti z visokorazsežnim vektorjem.So the fixed one is better and we're going to see it now. So there was this analogy that I mentioned last time that I will start from in this session. So the idea behind the deterministic formulation is to express each position on a high dimensional vector.
- u155 Želite, da vam ta vektor natančno pove, na katerem položaju ste. To si torej želite. Želite tudi, da sta položaja vložena tako, da je podobnost med njunimaAnd what you want is that vector to exactly inform you in which position you're in. And so you want that. You also want two positions to be embedded, such that the similarity operation between these two
- u156 vložitvama visoka, če sta položaja blizu, in nizka, če sta daleč narazen. Zdaj bom pojasnil, zakaj so avtorji tako zasnovali formulo in pristop, ki gaembeddings are high if the positions are close and it's low when these positions are far. And so I'm going to just motivate how the authors have actually designed the formula and the design that they're
- u157 uporabljajo za položajno vložitev, predlagano tukaj. Če se vrnemo k analogiji, o kateri smo govorili: predpostavimo, da gledate svojo uro. Imate več kazalcev. Imate urni kazalec. Imate minutni kazalec.using for the position embedding that they're proposing here. So going through the analogy that we discussed, let's assume you're looking at your watch. You have several hands. You have the hour hand. You have the minute hand.
50:05 · Hardcoded position embeddings: clock analogy, hour hand · A Stanford lecture slide titled "Hardcoded position embeddings" states the idea of hardcoding position-embedding values. It uses a clock face with a single blue hand, labeled "Hour (slow)", as an analogy for encoding position with a cyclic signal. A small inset in the top right shows the lecturer standing in the room. - u158 Imate sekundni kazalec. Če vse te kazalce združite, natančno veste, koliko je ura. Vsak od njih se premika z drugačno frekvenco. Urni kazalec vam približno pove, kje v dnevu ste,You have the second hand. If you put all these hands together, you know exactly what time it is. And each of these hands, they're moving at different frequencies. So the hour tells you roughly when you are in the day,
- u159 minutni je malo natančnejši. Sekundni pa še natančnejši. Pri položajnih vložitvah bomo naredili nekaj zelo podobnega: imeli bomo funkcije z višjimi in nižjimi frekvencami, tako da boste, ko vse združite v en vektor,the minute is a little bit more precise. And then the second is like, even more precise. And so what we're going to do is do something very similar for the position embeddings, where we'll have a function of higher and lower frequency, such that when you put all of that together into one vector,
- u160 natančno vedeli, na katerem položaju ste. Zdaj bo malo več matematike. Opozorilo: upam, da se spomnite trigonometričnih formul. Če se jih ne, pa ne skrbite. Ogledali si jih bomo skupaj. Predpostavimo, da ste na položaju m.if you know exactly which position you're at. So it's going to get a little bit more into the math. So disclaimer, I hope you remember your trigonometry formula. But if not, don't worry. We'll also look at it together. So let's assume that you are at position m.
- u161 Tukaj gledate dva zaporedna indeksa — 2i in 2i plus 1. Avtorji predlagajo, da je eden kosinus, drugi sinus ali obratno,And so here you're looking at two consecutive indices-- so 2i and 2i plus 1. So what the authors propose is to have one be a cosine, the other one be a sine or vice versa,
- u162 frekvenca teh funkcij pa naj bo odvisna od indeksa. Če je i majhen, imate funkcijo z višjo frekvenco. Če je i velik, imate funkcijo z nižjo frekvenco,and have the frequency of these functions be a function of the index. So here, if i is low, then you have a higher frequency function. If i is high, you have a lower frequency function,
- u163 kar pomeni, da se sinus spreminja počasneje. Če pogledate graf — ne vem, ali dobro vidite osi — na desni strani prosojnice je na osi y položaj, na osi x pa razsežnost.meaning your sine will vary more slowly. So here, if you see on the graph, I'm not sure if you exactly read the axis. So on the right side of the slide, you have on the y-axis the position, and on the x-axis, the dimension.
- u164 Tukaj vidite, da če vzamete prvo vrstico in se premikate navzdol, greste od položaja 1 do poznejših položajev v zaporedju. Vidite, da se prve razsežnosti, prvi indeksi,So here what you see is if you take the first row and you're moving down, you're going from position 1 to later positions of your sequence. And you see that the first dimensions, the first indices,
- u165 tisti na levi, običajno spreminjajo zelo hitro, tisti na desni, poznejši indeksi, pa veliko, veliko počasneje. Z drugimi besedami, nižji indeksi imajo precej višjo frekvenco. Poznejši indeksi pa precej nižjo.the one on the left, they tend to vary very quickly, and the one on the right, the later indices, they tend to vary much, much more slowly. So in other words, your lower indices, they're much higher frequency. And the later indices, they are of much lower frequency.
- u166 Ta na videz strašljiva formula vam torej pove samo to. Gre za spreminjanje kosinusa in sinusa z različnimi frekvencami. Višja frekvenca pri nižjem indeksu, nižja frekvenca pri višjem indeksu. Predpostavimo, da to ogromno formulo označimo z omega i,So just to tell you that this seemingly scary formula is just telling you this. So it's varying cosine, sine with different frequencies. It's a higher frequency for a lower index, lower frequency for a higher index. So let's assume you note omega i, the huge formula,
53:13 · Hardcoded sinusoidal position embeddings from "Attention Is All You Need" · A Stanford lecture slide explains hardcoding position embedding values. Even dimensions 2i get a sine of ω_i × m, and odd dimensions 2i+1 get a cosine of the same argument. Arrows from the two formula boxes point to the matching cells in a vertical vector for position m. A small inset shows the lecturer standing at a board. - u167 da se nam ni treba ukvarjati z njo. Kaj se zgodi, če imamo položaj m in položaj n? Kako izračunamo podobnost? Vzamemo skalarni produkt. Če se spomnite, skalarni produkt dveh vektorjev izračunamo tako, da pomnožimo ustrezne komponente in vse seštejemo.so that we don't need to worry about it. Well, what happens if you have a position m and a position n? How do you compute the similarity? Well, you take the dot product. So if you remember the way you take the dot product of two vectors is you multiply each dimension and then you add everything up.
- u168 Na kratko ponovimo trigonometrijo. Kosinus a minus b je kosinus a krat kosinus b plus sinus a krat sinus b, to je trigonometrična formula. Če tukaj vzamete kosinus omega i krat m minus n,So just a refresher on trigonometry. So cosine of a minus b is cosine of a cosine of b plus sine of a sine of b just the trigonometry formula. So here if you take the cosine of omega i of m minus n,
53:58 · Hardcoded position embeddings using the cosine difference identity · A Stanford ICME lecture slide titled "Hardcoded position embeddings" with the idea of hardcoding position-embedding values. It faintly shows the identity cos(a−b)=cos(a)cos(b)+sin(a)sin(b), then applies it to cos(ω_i(m−n)), so a relative position m−n is written in terms of sines and cosines of the absolute positions m and n. A small inset at top right shows the lecturer standing in a lecture room. - u169 je to dejansko skalarni produkt med tema dvema indeksoma. Vprašanje je, ali je i odvisen od razsežnosti. Da.it's actually the dot product between these two indices. So the question, is i a function of the dimension? Yes.
- u170 i je torej odvisen od indeksa. Če imate manjši i, bo omega i takšen, da bo frekvenca višja. Da, odvisen je od indeksa. Odlično vprašanje. Če se vrnemo k naši najljubši trigonometrični formuli, želim opozoriti, da je kosinus omega i krat m minus nSo i is a function of the index. So if you have a lower i, then your omega i will be such that it will be of higher frequency. So yes, it's a function of the index. That's a great question. So here going back to our favorite trigonometric formula, so here I just want to point out that cosine of omega i m minus n
- u171 enak skalarnemu produktu teh dveh. Če želite izračunati skalarni produkt celotnih vektorjev, dobite vsoto kosinusov omega i za vse indekse, pomnoženih z m minus n.is equal to the dot product of these two. And if you actually want to take the dot product of the whole two vectors, you actually obtain a sum of the cosine of the omega i of all the indices multiplied by m minus n.
54:55 · Hardcoded position embeddings using cosine identity · A Stanford ICME lecture slide on hardcoding position embedding values. Faded trigonometric identities (cos(a−b) expanded into cos·cos + sin·sin) lead to the main result: the inner product of position embeddings PE_m and PE_n contains terms like cos(ω_i(m−n)), so it depends on the relative offset m−n. A small video inset shows the lecturer standing at a board. - u172 Ali vsi sledite do zdaj? Ja. Zakaj to govorim? Zato, ker je skalarni produkt položajnih vložitev na položajih m in n funkcija razlike m minus n. Morda se spomnite, da je kosinus 0Is everyone following so far? Yeah. So why am I saying this? I'm saying this because the dot product of the two position embeddings at position m and n is a function of m minus n. And you may remember that cosine of 0
- u173 največja vrednost, ki jo kosinus lahko zavzame. Z drugimi besedami, ko je m enak n, je vsota največja. Podobnost je torej največja. Vse to pomeni, da če vzamete ta izraz, ki je grafično glede nais the maximum value that cosine can take. So in other words, when m is equal to n, the sum is maximized. So the similarity is maximum. So all of that to say that if you take this expression that is graphically something that you see on the left in terms
55:50 · Hardcoded position embeddings in transformers (Stanford lecture slide) · A lecture slide presents the idea of hardcoding position-embedding values. The left heatmap shows sinusoidal embedding values for positions 0–50 across about 128 dimensions, with fast oscillation at low dimensions and slower, then near-constant stripes at higher ones. The right heatmap shows similarity between positions, with a strong dark diagonal that fades as positions move apart. A small video inset shows a person standing at the right. - u174 vrednosti vložitev videti tako kot na levi, dobite visoko podobnost med bližnjimi položaji in manjšo podobnost med bolj oddaljenimi položaji. To vidite na desni. Na desni imate položaje na osi xof the value of the embeddings, what you will obtain is that positions that are close together, they're actually of high similarity and positions that are farther together, they are of lower similarity. And that's what you see on the right. So on the right, you have the positions on the x-axis
- u175 in na osi y, za m in n. Vidite, da je pri enakih položajih podobnost največja. Skratka, mislim, da bi vas pogled na formule brez konteksta verjetno prestrašil.and on the y-axis of m and n. And you see that when the positions are equal, the similarity is maximum. So all of that to say that if you were to look at the formulas without any context, I think you'd be probably scared.
- u176 Upam pa, da so s tega vidika nekoliko manj strašljive. Zdaj vam želim povedati, da bi, če bi bilo vse odlično, danes uporabljali natanko to metodo.But I hope that with this perspective, it's a little bit less scary. So now what I want to tell you is that if everything was great, we would be using this exact method today.
- u177 Toda v resnici je ne. Tega ljudje danes dejansko ne uporabljajo. Uporabljajo nekaj drugega. Razlog je v tem, da vas, če pomislite, položaji tokenov zanimajo v točno določeni plasti.But the truth is we are not. This is actually not something that people use today. People use something differently. And the reason why that is the case is if you think about it, you care about where tokens are positioned in a very specific layer.
- u178 Zanimajo vas samo v plasti pozornosti, saj je to plast, kjer dejansko poteka komunikacija. Pri izračunu izraza poskušate ugotoviti, kateri tokeni so pomembni. Zato so ljudje dejanskoYou only care about it in the attention layer, because the attention layer is the layer where you actually are communicating. You're trying to determine which tokens are relevant when you do your expression. And so this is the reason why people have actually
57:38 · From absolute to relative position info in attention · A Stanford ICME lecture slide on moving from absolute to relative position information. The motivation is that relative position matters in the attention layer. The slide proposes changing the attention layer instead, with a faded example of query/key/value vectors for "a cute teddy bear is reading." and a faded Transformer diagram from "Attention Is All You Need." A small inset shows the lecturer standing at a board. - u179 poskušali najti metodo, ki ne vpliva na vse plasti, temveč jo natančno uporabimo samo v plasti pozornosti. Ja. Vprašanje je, ali bi s tem lahko povzročili,tried to find a method that is not affecting all the layers, but that is being surgically applied to the attention layer. Yeah. So the question is if you do that, then you may make
- u180 da bolj oddaljeni tokeni manj sodelujejo. To pa je bila morda težava rekurentnih nevronskih mrež. Zakaj torej to počnemo? Ideja je vnesti nekaj informacije o položaju in intuitivno so bolj oddaljeni tokeni preprosto manj pomembni.further token interact less. And that was maybe the problem of RNN. So why are we doing this? So here the idea is to inject some position information and intuitively tokens that are farther apart, they're just less relevant.
- u181 Vendar niso pomembni. Ideja je torej, da so v relativnem smislu bližji tokeni verjetneje pomembnejši. Še vedno pa ohranjate neposredne povezave in modelu še vedno dajete možnost,But they're not relevant. And so here the idea is that on a relative sense, closer token are just more likely to be more relevant. But you're still keeping the direct connections, and you're still giving a chance to your model
- u182 da s temi tokeni dejansko sodeluje. Razumem torej vaš pomislek. Kljub temu se je to izkazalo za uspešno in odraža idejo, da je pri, recimo, dokumentu z 10 stranmi tisto, kar je v isti povedi,to actually interact with those tokens. So I do get your concern. That being said, this is something that proved to work well, and it just reflects the idea that if let's say you have a 10 document page, then probably what you have in the same sentence
- u183 verjetno pomembnejše od nečesa zelo oddaljenega, vendar tem tokenom še vedno omogočate sodelovanje. V redu, odlično. Vrnimo se sem. Ena glavnih slabosti prejšnjega pristopa je, da se je ta položajna vložitev dejanskois probably more relevant than something that is very far apart, but you're still giving a chance to these tokens to interact. OK, great. So going back to here. So one major drawback of the previous approach is that this position embedding was actually
- u184 prištevala vložitvi tokena, ki so jo nato obdelovale vse plasti. Intuitivno pa tega pravzaprav ne želite, saj želite plasti pozornosti sporočiti, kdaj sta tokena daleč narazen. Ne želite pa svoji nevronski mreži s povezavami naprej sporočitibeing added to the token embedding, which was then being processed by all the layers. But intuitively, this is actually not what you want, because what you want is to let your attention layer know when two tokens are far apart. But you don't want to let your feedforward neural network know
- u185 da je vaš žeton na položaju 5 ali na položaju 12, ker nevronski mreži s povezavami naprej ni mar. Povsem mogoče je imeti stavek, v katerem je žeton na položaju 24 namesto 1. To je lahko povsem smiselno že zato, kerthat your token is at position 5 or at position 12 because the feedforward neural network doesn't care. Can very well have a sentence where a token is at position 24 versus 1. That can be very making sense just because you
- u186 imate več stavkov. Zato so ljudje poskušali to pomanjkljivost omiliti s ciljnimi posegi v plasti pozornosti. Predstavil bom nekaj metod,have multiple sentences. So this is the reason why people have tried to mitigate this drawback by surgically looking into the attention layers and doing something there. And in particular, I'll go through a few methods
1:00:18 · Linear bias in attention layer (T5 bias) · A Stanford lecture slide explaining how a bias is added to query-key attention scores. A diagram shows the query for "teddy bear" (position m) attending to the key for "cute" (position n) in the sentence "a cute teddy bear is reading .". The softmax formula adds bias(m,n) to the scaled dot product, and the T5 bias is learned per head as a function of bucketed relative distance m−n. - u187 ki so jih preizkusili. Ena od njih je metoda, namenjena učenju člena odmika znotraj funkcije Softmax. Če se spomnite, imamo v plasti pozornosti to formulo, za katero priporočam, da si jo zapomnite: Softmax od q krat transponirani k, deljeno z neko skalirno konstanto, kratthat people have tried. So one of them is a method which was meant to learn a bias term within the Softmax. So if you remember in the attention layer, you have this formula which I recommend you remember, which is Softmax of qk transpose over some scaling constant times
- u188 v. Znotraj funkcije Softmax se torej dejansko sprašujete, kako relevantna je poizvedba za vse druge ključe. Tu je to pomembno. Ideja je torej naučiti se odmika, ki je odvisen od tega, kako oddaljena sta vaš žeton m in vaš žeton n,v. So within the Softmax, you're actually trying to ask yourself how relevant the query is to all the other keys. So this is where that matters. And so here the idea is to learn a bias that is dependent on how far your token m and your token n
- u189 z učenjem odmika. Težava pri tem je, podobno kot pri čisto prvi metodi, da se morate odmika naučiti. Prvič, morda so že vaši učni podatki sami po sebi pristranski. Zato morda ne bo optimalen.are by learning a bias. The problem with this is, so similar to the very first method, you need to learn the bias. And so first of all, maybe your training data has some bias in itself. So it will maybe not optimal.
- u190 Druga stvar pa je, da tega ni mogoče posplošiti na vse možne razdalje. Zato so preizkušali tudi druge metode. Druga se imenuje ALiBi — torej pozornost z linearnimi odmiki. Tu je ideja, da se ta odmik dejansko spreminja kot funkcija m —But then the second thing is it's not generalizable to all possible distances. So that's why people have tried other methods as well. Another one is called ALiBi-- so Attention with Linear Biases. And so here the idea is to actually make that bias vary as a function of m--
- u191 oprostite, n minus m. Torej razdalje med m in n.sorry, n minus m. So the distance between m and n.
- u192 Rotacijske pozicijske vložitve (RoPE)Rotary position embeddings (RoPE)
- u193 Toda metoda, ki se danes pogosto uporablja, ni ALiBi in ni odmik T5, temveč RoPE. Kdo je že slišal za RoPE? Ja? V redu, odlično. Pogledali si bomo, zakaj je RoPE takšen, kot je. RoPE pomeni rotacijska pozicijska vložitev.But the method that is commonly used nowadays is not ALiBi, is not the T5 bias, it's RoPE. So who has heard of RoPE? Yeah? OK, great. So we're going to see why RoPE is the way it is. So RoPE stands for Rotary Position Embedding.
1:01:58 · Linear bias in attention layer (ALiBi) lecture slide · A Stanford ICME lecture slide explaining adding a bias to query-key attention scores. It illustrates with the sentence "a cute teddy bear is reading." where query m ("teddy bear") attends to key n ("cute"). The softmax formula adds bias(m,n), and ALiBi defines it as a linear, deterministic, unbounded function of distance, while the T5 bias is greyed out. - u194 Ideja za RoPE je, da v plasti pozornosti ne boste dodali odmika. Namesto tega boste neposredno spremenili poizvedbo in ključ. Kako ju bomo torej neposredno spremenili? Naredili boste to, da bosteAnd the idea behind RoPE is in the attention layer, you're not going to add a bias. What you're going to do is you're going to change the query and the key directly. And so how are we going to change them directly? What you're going to do is you're
- u195 zavrteli svojo poizvedbo. Zavrteli boste svoj ključ, vsakega v odvisnosti od položaja, na katerem je. Zakaj je to tako privlačno? Ker je lepo to, da ko zavrtite poizvedbo, kogoing to rotate your query. You're going to rotate your key, each of them as a function of the position that they're in. And why is it something that is very appealing? Well, because the nice thing is when you rotate the query, when
- u196 zavrtite ključ, pri izračunu formule samopozornosti dejansko dobite izraz, ki je funkcija razlike med n in m.you rotate the key, what you're actually doing, when you do the self-attention formula is you're actually bubbling up an expression that is a function of the difference between n and m.
- u197 Pogledali si bomo, kako to deluje. Nisem prepričan, ali je kdo med vami strokovnjak za geometrijo in rotacijske matrike. Vektor zavrtite tako, da vzamete ta vektor in imate rotacijsko matriko,So we're going to see a little bit how that works. So here, so I'm not sure if any of you is an expert at geometry and rotation matrices. But the way you rotate a vector is you take that vector and you actually have a rotation matrix
- u198 ki jo uporabite na njem. Morda bom to kar zapisal. Če imam tole. Predpostavimo, da imate neki vektor, recimo mu x. Imate torej, recimo, dve dimenziji —that you apply to that vector. So I'm going to maybe just write that down. If I do have this. So let's suppose you have some vector, let's call it x. So you have, let's say you have two dimensions--
1:03:57 · Lecturer at blank chalkboard in Stanford classroom · A still from a lecture video shows a person with short dark hair, glasses, a dark T-shirt and green trousers standing with their back to the camera. They raise a hand toward the upper left of a large, empty dark-gray chalkboard, as if about to write. A faint "Stanford" watermark is at the lower right, and the edge of a projected slide is partly visible at the top right. - u199 predpostavimo, da imate x in y. In predpostavimo, da je vaš vektor takšen. To pa je, recimo, polmer r. Tu je torej os x enaka x — oprostite, to je R, tu pa imate kot theta,let's assume you have x and y. And let's assume that your vector is like this. And this is let's say a radius of r. So here the x-axis is x-- sorry, it's R and here you have your theta angle,
- u200 kosinus theta. Tu pa imate vrednost y, ki je R sinus theta. Predpostavimo torej, da imate to. Vse, kar počnem, je, da izražamcosine of theta. And then here you have your y value, which is R sine theta. So let's assume you have this. So what I'm only doing is expressing
- u201 x kot funkcijo nekega kota theta, ki ga že ima. Pokazati vam želim, kaj se zgodi, če rotacijsko matriko pomnožite s tem vektorjem x. Predpostavimo, da imate rotacijsko matriko za, recimo, kot phi, ki je — kar prepisal bomx as a function of some angle theta that it already has. And what I want to show you is if you were to multiply the rotation matrix with this vector x. So let's assume you have a rotation matrix of let's say angle phi, let's assume, which is-- so I'm going to just copy
- u202 to, kar je na prosojnicah. Torej kosinus phi, minus sinus phi, sinus phi in nato kosinus phi. Predpostavimo, da svojo rotacijsko matriko dejansko pomnožitewhat is on the slides. So it's cosine of phi is minus sine of phi, sine of phi, and then cosine of phi. So let's assume you actually multiply your rotation matrix
- u203 z vektorjem x. Za tiste, ki imate radi množenje matrik in trigonometrične formule, je to najboljši primer, ker bom ravno to pogledal. Tu bi torej izvedli množenje matrik.with the vector x. So for those of you who love matrix multiplications and trigonometry formulas, this is the best case because I'm going to exactly see. So here you would do the matrix multiplication.
- u204 Torej R krat kosinus theta kosinus phi minus R kosinus theta — oprostite, minus R sinus phi sinus theta. Kaj je to? To je R kosinus vsote theta in phi. In uganili ste, druga komponenta je enaka, le s sinusom.So R times cosine of theta cosine of phi minus R cosine of theta-- sorry, minus R sine of phi sine of theta. What is this? It's R cosine of theta plus phi. And you guessed it, the other one is the same, but with sine.
- u205 Zakaj vse to pišem? Pokazati vam želim, da z množenjem vektorja z rotacijsko matriko vektor zavrtite. Zato imamo to formulo zapisano na prosojnici. Lepo pa je, da če svoj poizvedbeni vektor zavrtiteSo why am I writing all of this? What I want to show you is if you multiply your vector with the rotation matrix, you're rotating your vector. And this is the reason why we have this formula written on the slide. And the nice thing is, if you rotate your query vector
- u206 za neki kot v odvisnosti od m in svoj vektor ključa zavrtite v odvisnosti od njegovega položaja n, dobite rotacijsko matriko, ki je dejansko funkcija n minus m.by some angle as a function of m, and if you rotate your key vector as a function of its position n, then you obtain a rotation matrix that is actually a function of n minus m.
- u207 Podrobnosti vam bom prihranil. Če pa preprosto izvedete množenje, boste videli, da deluje. To je zelo lepo zato, ker je razširljivo na poljubne položaje. Ničesar se ne učite.So I will spare you the details. But if you just do the multiplication, you will see that it works. And so the reason why it is pretty nice is because this is extensible to any positions. You're not learning anything.
- u208 Mimogrede, povedal bom še nekaj: pokazal sem vam le dvodimenzionalni primer. Za posplošitev na, recimo, d-dimenzionalni primer bi to dejansko počeli po dvodimenzionalnih blokih. Rotacijo pa bi izvajali s koti, kiAnd by the way, one other thing I will say is I just showed you the 2D case. But in order to generalize that let's say d-dimensional case, you would actually do that by 2D blocks. And you would do the rotation with angles that
- u209 so funkcija indeksa. Torej glede vašega prejšnjega vprašanja: tudi tu bi imeli kote, ki bi bili funkcija, recimo, pri nižjem indeksu bi bil kot drugačen kot pri poznejšem indeksu. Super.are a function of the index. So to your earlier question, so here you would have also angles that would be a function, let's say if it's a lower index, it's a different angle compared to if it's a later index. Cool.
- u210 Lepo pri tej metodi pa je, da če pogledate velikostni red skalarnega produkta med poizvedbo in ključem v odvisnosti od oddaljenosti njunih položajev, vidite, da približno upada, ko sta m in nAnd the nice thing with this method is if you take a look at the order of magnitude of the dot product between the query and the key as a function of how far their positions are, then you will see that roughly it tends to decay as m and n
- u211 bolj narazen. Ni strogo monoton, ker je stvar bolj zapletena. Toda zelo na splošno upada in odraža to, kar želimo pri žetonih, ki so zelo daleč narazen.are farther apart. So it's not strictly monotonic because, well, it's more complicated than that. But at a very high level, it just decays and it just reflects what we want in tokens that are very far apart.
- u212 To je bil RoPE. Z drugimi besedami, izvirni članek o transformerju je uporabljal pozicijske vložitve, ki so se prištevale, v nasprotju z današnjo uporabo RoPE za kodiranje položaja.So that was RoPE. So in other words, the original transformer paper used position embeddings that were additive, which is in contrast with nowadays where people use RoPE as a way to encode position.
- u213 Tako ga torej uporabljajo. Ne uporabljajo pa prištevanja položaja, o katerem smo govorili prej. Zdaj bomo govorili o drugi komponenti, ki je nekoliko drugačna v primerjaviSo this is how people use it. And they don't use the additive position that we discussed before. So now we're going to talk about another component that is a little bit different compared
1:09:28 · Sparse attention: Longformer slide with empty attention grid · A Stanford lecture slide titled "Sparse attention: Longformer" shows an 8x8 grid of pink cells meant as an attention matrix. Rows and columns are labeled with the tokens [CLS], A, cute, teddy bear, followed by ellipses. No cells are highlighted yet, so the sparse pattern has not been revealed. A small inset shows the lecturer standing at the top right. - u214 Pozornost z drsečim oknom (SWA)Sliding Window Attention (SWA)
- u215 z izvirnim transformerjem, in to je plast pozornosti. Omenil sem, da je v kodirniškem delu vsak lahko pozoren na vsakega. V dekodirniškem delu je dani žeton lahko pozoren nase in na žetone pred seboj. Zato je naravno vprašanje, ki so si ga zastavili,to the original transformer, and this one is the attention layer. So I mentioned that in the encoder part, everyone can attend to everyone. In the decoder part, a given token can attend to itself and to tokens before it. So one natural question that people have asked
- u216 ali morate res biti pozorni na vse v vsaki plasti. To namreč zahteva veliko izračunov. Odgovor je, da morda tega ne potrebujete. Obstaja posebna različica,is, well, do you really need to attend to everyone at every layer? Because it's a lot of computations. And the answer is, well, maybe you don't need to do that. And in particular, there is a specific variation
- u217 ki se imenuje pozornost z drsečim oknom in je namenjena temu, da ste pozorni le do določenega položaja, ki je od vas oddaljen. Ne na vse, temveč le do določene meje. Temu pravijo tudithat is called the sliding window attention that is actually meant for you to attend to only up to a certain position that is farther away from you. Not everyone, but only up to a certain level. And so here it's something that people also
- u218 lokalna pozornost. Povedati vam želim, da bi morda — verjetno mi boste rekli: v redu, to težavo je imel že RNN. Zakaj torej to počnete? Zato želim poudariti nekaj, za kar upam, da bo smiselno.call local attention. And what I want to tell you is you may-- so probably, you will probably come back to me with saying, OK, the RNN actually had this issue. Well, why are you doing this? So I want to point out something that I hope will be making sense.
- u219 Vaš model ni samo en blok. Ni samo en blok dekodirnika. Dejansko vsebuje več blokov. Operacija pozornosti se torej ne zgodi samo enkrat, temveč večkrat. Če imate, recimo, zaporedje žetonov.So your model is not just one block. It's not just one block of the decoder. It's actually several blocks. So the attention operation is not just happening once. It is happening several times. So if you have, let's say, a sequence of tokens.
1:11:17 · Lecturer at blank blackboard, Stanford classroom · A man seen from behind, in a dark T-shirt and green-gray trousers, raises his hand with chalk to a large empty dark blackboard. A faint "Stanford" watermark is at the lower right, and part of a projected slide is at the top right edge. The board is still blank, so he appears to be about to start writing. - u220 Te žetone bom preprosto natančno ponovil tukaj in, recimo, tukaj. Predpostavimo, da lahko ta žeton sodeluje samo sam s seboj in z enim predhodnim žetonom.So I'm going to just replicate exactly these tokens over here and let's say over here. So let's assume that this token can only interact with itself and with one token from before.
- u221 Tu vidite samo sebe in predhodni žeton. Če pa upoštevate, da je podobno tudi ta žeton lahko pozoren nase in na predhodni žeton, lahko ta žeton dejansko vidi predstavitveHere you only see yourself and the token before. But if you consider that in a similar fashion this token can attend to itself and the token before, well, effectively, this token is able to see representations
- u222 žetonov, ki so onkraj te meje. Je to, kar govorim, smiselno? Ja. V redu. Z drugimi besedami, čeprav omejujete žetone, s katerimi lahko sodelujete,from tokens that are beyond the limit. Does what I'm saying making sense? Yeah. OK. So in other words, even though you are limiting yourself in the tokens that you're able to interact with,
- u223 lahko z več naloženimi bloki dejansko sodelujete z bolj oddaljenimi žetoni. Za tiste med nami, ki poznamo tudi področje računalniškega vida, torej če poznate konvolucijske nevronske mreže, je ideja nekoliko podobna receptivnim poljem.if you have several stacked blocks, then what you're actually able to do is to interact with further tokens. And for those of us who are also familiar with the vision world, so in case you're familiar with convolutional neural networks, it's a little bit the same idea as receptive fields.
- u224 Ko tu izvedete konvolucijo, je dani element dejansko funkcija številnih slikovnih pik, če greste nazaj po verigi. Gre torej za isto idejo. V redu, o plasti pozornosti vam želim povedati še nekaj.So here when you perform the convolution, a given element is actually a function of actually many pixels if you go back into the chain. So it's the same idea. OK, I want to tell you something else about the attention layer.
- u225 Pozornost z združenimi poizvedbami (GQA)Group Query Attention (GQA)
- u226 Mislim, da smo o tem na kratko govorili že prej med predavanjem. Ampak v redu, to bom znova uporabil. Predpostavimo, da smo spet pri modelu, ki vsebuje samo dekodirnik, kar je značilno za velike jezikovne modele.So I think we briefly discussed it earlier in the lecture. But OK, I'm going to reuse this. So let's assume that we're back with our decoder only model which is typically what LLMs are composed of.
- u227 Predpostavimo, da želite napovedati naslednji žeton. To je vaš zadnji napovedani žeton. Za napoved naslednjega žetona imate več plasti, toda zlasti v plasti pozornosti ste pozorni nase.And let's assume that what you want to do is to predict the next token. Well, this is your last predicted token. In order to predict the next token, you have a bunch of layers, but in particular in the attention layer, what you're doing is you're attending to yourself.
- u228 Pozorni ste na predhodni žeton, na žeton pred njim in na žeton pred njim. Predpostavimo, da napoveste nov žeton in da ste pri tem novem žetonu za napoved naslednjega žetona pozorni nase, na predhodnega in tako naprej. Vsakič, ko želite napovedati naslednji žeton, torejYou're attending to the token before, the token before that, the token before that. Let's assume you predict a new token and that the new token, in order to predict the next token, you're attending to yourself, you're attending to the one before you, and so on and so forth. So every time you want to predict the next token, what
- u229 izvajate to vzročno pozornost, pri kateri primerjate poizvedbo svojega žetona z vsemi ključi drugih žetonov. In vsakič, ko želite napovedati nov žeton,you're doing is this causal attention, where you're comparing the query from your token with all the keys from the other tokens. And every time you want to predict a new token,
- u230 ga znova primerjate s ključi prejšnjih žetonov. Lahko torej vsakič, ko izvedete to operacijo, izračunate vse prejšnje ključe ali pa ključe med dekodiranjem shranjujete.you again compare it to the keys of the previous tokens. So you could either compute all the previous keys every time you do that operation, or you could store the keys as you perform your decoding.
- u231 Ko na primer dekodiram tukaj, sem pozoren samo nase. Izračunal sem ključ. Ključ lahko shranite. Napoveste tega. Tu sem torej pozoren sem in na predhodnega — potrebujem torej ključ. Ključ lahko ponovno uporabim. Tu izračunam ključ, ki ga shranim. In ta postopek nadaljujem tako naprej.So, for instance, when I decode when I'm here, I attend only to myself. I computed the key. You can save the key. You predict this one. So here I attend to here and to the one before-- so I need the key. I can reuse the key. And I compute the key here that I save. And I'm continuing this process so on and so forth.
- u232 Težava pri tem je, da ključi zasedajo pomnilnik. Ko vaše dekodiranje postaja vse daljše, morate te ključe shranjevati. Če se spomnite, je plast pozornosti dejansko plast večglave pozornosti.So the problem with this is keys detect memory space. And as your decoding gets longer and longer, you need to store these keys. And so if you remember, the attention layer is actually a multi-head attention layer.
- u233 Nima torej samo enega ključa, temveč več ključev za isto plast in isti žeton. Zato so poskušali zmanjšati število ključev in vrednosti, ki jih mora ustvariti vsak žeton. Zato imamo to metodo.So it doesn't only have one key, it has actually several keys for the same layer for the same token. So that is the reason why people have tried saving up the number of keys and the number of values that each token needs to produce. And that's why you have this method.
- u234 Na primer idejo deljenja ključev in vrednosti med glavami. Te metode so zanimive zato, ker ključe za napoved naslednjega žetona vedno potrebujete, zato želite tu prihraniti pomnilnik.So, for instance, the idea of sharing keys and values across heads. So the reason why people are interested in such methods is because given that you always need the keys in order to predict the next token, you want to save memory in there.
- u235 Zato imamo številne metode, kot je pozornost z združenimi poizvedbami, ki med glavami deli projekcijski matriki ključev in vrednosti, ali pa pozornost z združenimi poizvedbami, ki je nekoliko pogostejša in pri kateri imate določeno število skupin, znotraj katerih delite matrike ključevAnd so that is the reason why you have a number of methods like group query attention, which shares the key and the value projection matrices across the heads, or the group query attention which is a little bit more common, where you have a certain number of groups where you share the key
- u236 in vrednosti. To je v nasprotju z izvirno plastjo večglave pozornosti, ki je imela eno glavo, kjer ste imeli vse projekcijske matrike, ki ste se jih morali naučiti. Vse to torej zato, da povem, da koand value matrices. And this contrasts with the original multi-head attention layer, which had one heads, where you had all the projection matrices that you had to learn. So all of that to say that given that you
- u237 ste v položaju, ko ves čas shranjujete ključe in vrednosti za žetone, ki ste jih dekodirali v preteklosti, želite, da jih ne bi bilo treba shranjevati preveč. Nočete zapolniti pomnilnika.are in this situation where you're always saving your keys and your values for tokens that you have decoded in the past, what you want is to not have to save too much of them. You don't want to saturate your memory.
- u238 Zato iščejo načine, kako to optimizirati. Eden od njih je preprosto zmanjšati število različnih projekcijskih matrik za ključe in vrednosti, ki se jih morate naučiti. Zato, mislim, nikogar ne skrbi poizvedba, ker poizvedboSo people are trying to find ways to optimize that. And one such way is to just reduce the number of different projection matrices that you need to learn for the keys and the values. And that is the reason why, I mean, no one cares about the query because the query,
- u239 uporabite enkrat in je nato ne potrebujete več. Je to smiselno? Danes torej precej uporabljajo GQA. Med vsem, kar smo videli, boste zelo pogosto videli RoPE. Precej pogosto boste videli lokalno pozornost z drsečim oknom.you use it once and then you don't need that. So does that make sense? So nowadays people use GQA quite a lot. So among everything we've seen, you will see a RoPE quite a lot. You will see local attention with sliding window quite a lot.
- u240 Precej pogosto boste videli GQA. In govoriti vam želim še o zadnji stvari,You will see GQA quite a lot. And there is one last thing that I want to talk to you about,
- u241 Predhodna normalizacija v primerjavi z naknadno normalizacijoPre-Norm versus Post-Norm
- u242 in sicer o normalizaciji. V izvirni arhitekturi transformerja. Če se spomnite, je to ob prvem branju članka nekoliko bolj podrobnost. Normalizacijo izvajajo tako, da najprej izvedejo operacijo podplasti, nato rezultat prištejejo vhodomwhich is the normalization. So in the original transformer architecture. So if you remember, so it's a little bit more of a detail when you first read the paper. But the way people do normalization is they first perform the sublayer operation and then they add to the inputs
1:18:13 · Post-Norm layer normalization in Transformers (lecture slide) · A Stanford lecture slide titled "Different kinds of layer normalization" presents the Post-Norm variant, where Output = LayerNorm(x + SubLayer(x)). A diagram shows a transformer block in which Multi-Head Attention and then an FFN each feed an addition (residual) step, followed by a Layer Norm, so normalization comes after the residual connection. A small inset shows the lecturer standing at a blackboard. - u243 in nato normalizirajo. Torej normalizirajo x plus podplast od x. Temu pravimo tudi naknadna normalizacija. Normalizirate torej po operaciji. Razlog, da so menili, da to morda ni najboljši način, pa je, da je tuand then they normalize. So they do normalization of x plus sublayer of x. So it's also called post-norm. So you're normalizing after the operation. And the reason why people thought it was maybe not the best way is because here
- u244 ideja rezidualne povezave omogočiti vhodu neposreden prehod, da gradient bolje teče. Tu pa je x dejansko znotraj normalizacije plasti. To ni najbolje. Zato danes ne normalizirajo po operaciji.the idea behind residual connection is that you want to let the input through just for the gradient to flow better. And so here the x is actually within the layer normalization. So it's not great. And so this is the reason why people nowadays, what they do is they don't normalize after the operation.
- u245 Dejansko normalizirajo pred njo. Najprej normalizirajo vhode in jih nato pošljejo v plast. Nato rezultat prištejejo x. Temu pravimo tudi predhodna normalizacija. To je način, da rezidualna povezava opravi svojo nalogo omogočanja pretoka gradienta. Zato boste tudi predhodno normalizacijo videli kot zelo pogosto metodo.They actually normalize before. So they first normalize the inputs and then they put it into the layer. And then they add it to x. It's also called pre-norm. And it's just a way for the residual connection to do its job of letting the gradient flow. So you will see pre-norm as also a very common method.
- u246 LayerNorm v primerjavi z RMSNormLayerNorm versus RMSNorm
- u247 In še zadnja stvar, obljubim, in sicer sama normalizacija plasti. V izvirnem transformerju normaliziramo po vseh aktivacijah tako, da najprej ponovno centriramo x, nato pa imamo člen gama in natoAnd one last thing, I promise, which is the layer normalization itself. So in the original transformer, here we're normalizing across all the activation by first recentering x and then having a term, gamma, and then
- u248 neki odmik beta, kar pomaga pri stabilnosti učenja in konvergenci. Preizkušali pa so tudi druge metode normalizacije. Zlasti so ugotovili, da normalizacija RMS — RMS pomeni koren povprečja kvadratov — dejansko opravi nalogo prav tako dobro.some bias beta, which helps with training stability and convergence. But people have tried with other normalization methods. And in particular, they have found that RMS norm-- RMS stands for Root Mean Squared norm, actually does the job just as well.
- u249 Tu vam x ni treba ponovno centrirati, temveč ga morate samo preskalirati in imeti le en faktor, ki se ga morate naučiti. Zato jo radi uporabljajo. Mislim, da so bili to vsi moji triki. Torej samo za povzetek.And here, you don't need to recenter x, you just need to rescale it and to have just one factor that you need to learn. And that is the reason why people tend to use it. And I think this was all the tricks I had. So just as a summary.
- u250 Prej so pri normalizaciji uporabljali naknadno normalizacijo in normalizacijo plasti, danes pa uporabljajo predhodno normalizacijo in normalizacijo RMS. Na kratko, danes torej RoPE, lokalna pozornost, gka GQA, predhodna normalizacija in normalizacija RMS.Before on normalization front, people used to do post-norm and layer norm, and nowadays people do pre-norm and RMS norm. So long story short, nowadays RoPE, local attention, gka GQA, pre-norm, and RMS norm.
- u251 S tem predajam besedo Shervinu.And with that, I'll give it to Shervin.
- u252 Napovedovanje naslednjega žetonaNext token prediction
- u253 Hvala, Afshin. Zdaj bomo nekaj časa skupaj govorili o napovedovanju naslednjega žetona. Kot je omenil Afshin, veliki jezikovni modeli uporabljajo avtoregresivni postopek, pri katerem začnete z danim naborom že obdelanih žetonov, nato pa ustvarjate drugeThank you Afshin. So now we're going to spend some time together to talk about next token prediction. And as Afshin has mentioned, LLMs they use this autoregressive process where you start with a given set of tokens that have been processed, and then you generate the others
- u254 enega za drugim. Recimo, da začnete samo z BOS. Nato ustvarite A in nato teddy, bear, is ter dokončate zaporedje. Zdaj je vprašanje, kako ustvarite naslednji žeton. Veste, da se vsi ti obdelajoone at a time. So let's say you start with just BOS. So you generate A and then teddy, bear, is, and then you complete the sequence. So now the question is, how do you generate the next token? So you know that all of these are processed
- u255 skozi te plasti dekodirnika. Imate mehanizem samopozornosti in nevronsko mrežo s povezavami naprej, ki se ponovita n-krat, ker imate n naloženih plasti dekodirnika. Na koncu pa se to z linearno plastjo projicira v prostor vašega besedišča za napoved naslednjega žetona.through these decoder layers. So you have the self-attention mechanism and the feedforward neural network that is repeated n times because you have n layers of decoder that are stacked. But then at the end, it is projected on a linear layer to predict the next token on the space of your vocabulary.
- u256 Izberete ga lahko na več načinov. Kaj bi bil naraven način? Ker imate verjetnostno porazdelitev, bi bila prva intuitivna misel lahko, da je verjetnostna porazdelitev že opravila veliko dela namesto mene.And there might be several ways to choose it. So what could be a natural way? So first, since you have a probability distribution, one piece of intuition could be the probability distribution has done a lot of work for me.
- u257 Pove, kateri žeton je najverjetnejši. Torej ga preprosto vzemimo. To je ena možnost. Toda ko računate žetone enega za drugim, poskušate neposredno optimizirati naslednji žeton. Ko pa ustvarite celotno zaporedje,It says, what is the most probable token? So let's just take it. So that could be one. But the thing is, as you compute tokens one after the other, you will try to optimize the next token immediately. But as you have generated the whole sequence,
- u258 vidite, da celotno zaporedje morda nima optimalne skupne verjetnosti. To je ena slabost tega pristopa. Morda bi se zato želeli bolj usmeriti v skupno verjetnost. Zato imamo tehnike, kot je iskanje s snopom,you see that the global sequence might not be with optimal joint probability. So this is one weakness of this approach. And you might be tempted to go the joint probability route a bit more. So this is why you have techniques like beam search
- u259 ki ne obravnava celotne skupne verjetnosti, ker bi bilo to računsko predrago. Spremlja pa k poti hkrati. Recimo, da želite izračunati naslednji žeton: namesto da bi izbrali samo naslednjega, ves čas upoštevate k poti.that doesn't do full joint probability because that would be too computationally expensive. But it does track k path at a time. So let's say you want to compute the next token, instead of only selecting the next one, you will consider k path all the time.
- u260 Tu imate torej začetek zaporedja. Tam imate an, ki sta dobra, kot dve najboljši možnosti. Nato ustvarite naslednjo verjetnostno porazdelitev in še naprej ohranjate k najboljših in tako naprej. Kdo mi lahko pove, katero slabostSo here you have beginning of sequence. You have an there that are good like the two best ones. And then you generate the next probability distribution, and then you keep on keeping the k best and so on. So who can tell me, what kind of weakness
- u261 vidite pri teh dveh tehnikah, ki je še nisem omenil? Ja. Več računanja. Ja, pri drugi, ne pa pri prvi. Iščem nekaj, kar je skupno obema tehnikama. Kaj lahko rečete o ponovljivostiyou see out of these two techniques that I haven't called out just yet? Yes. So there is a more computation. Yes, for the second one, but not for the first one. I'm looking for something that is common to both techniques. So what can you say about the reproducibility
- u262 tega, da vedno izberete žeton z največjo verjetnostjo? Vedno bo isti. Kaj pa iskanje s snopom? Recimo, da ponovite izračune ob istem času. Ali vsakič dobite isto pot ali se spremeni? Ja, odlično.of choosing always the highest probability token? It will always be the same. What can you say about beam search? Let's say you redo the computations at the same time. Do you get the same path each time or will it change? Yeah, great.
- u263 Torej ja. Ista pot in postopek je determinističen. Odlično. Tu vam želim približati, zakaj to morda ni najbolje, saj bi kot nekdo, ki se poklicno ukvarja z optimizacijo, lahko rekli: v redu, mene to ne moti.So yeah. Same path and it's deterministic. Great. And this is where I want to bring your intuition on why that may not be great, because as someone who optimizes things for a living, you might say, OK, I don't mind.
1:24:49 · Predicting next token with beam search · A Stanford ICME lecture slide explaining beam search as a second idea for decoding: keep the k most likely paths. A tree starting at [BOS] highlights the path a → cute → teddy/bear, with other branches faded. The slide notes the problem: more computation and still lacking creativity. A small inset shows the lecturer, and a transformer diagram sits on the left. - u264 Determinizem je lahko dober. Toda pokazati vam želim, zakaj bi vas to zanimalo kot uporabnika. Predpostavimo, da uporabljate klepetalnik katerega od naših priljubljenih velikih jezikovnih modelov in postavite določeno vprašanje, recimo pozdravno sporočilo: »Dobro, pa ti?« Recimo, da vaši prijatelji pošljejo enako sporočiloDeterminism might be good. But I just want to show you as a user why you would care about it. So let's suppose you are a chatbot user of all our favorite LLMs, and you ask a given question, like let's say a greeting message, "Good, and you?" And let's say your friends ask the same message
- u265 in dobite enak odgovor in tako naprej. Morda boste imeli občutek, da je klepetalnik robotski. Ne vem, kako je z vami, ampak robotski klepetalniki niso preveč privlačni, saj se zdi, da so še vedno močno načrtovani, medtem ko bi se vi kot človek morda odzvali nekoliko drugačeand you have the same answer, and so on, you might feel that the chatbot is robotic. And robotic chatbots, I don't know about you, but it's not so appealing because it feels like it's still heavily engineered, whereas you as a human, you might be tempted to respond a bit differently
- u266 na podobne pozive. To, kar sem povedal, je predvsem miselni poskus, saj se lahko v praksi kontekst velikega jezikovnega modela precej spreminja. Recimo, da smo danes 2. oktobra na Stanfordu. Če to vprašanje postavim čez eno uro, se bo kontekst nekoliko spremenil.to similar prompts. So what I said here is mostly a thought experiment, because in practice, the context of the LLM might change quite a bit. Let's say today we are the 2nd of October at Stanford. If I ask this question one hour from now, the context will change a bit.
- u267 Morda bo vključil moj novi čas in druge informacije. Zato to morda ne velja povsem strogo. Vseeno pa vidite to robotsko vedenje. Nedeterministično vedenje pa bi lahko kot možne izbire ponudilo podobno dobro zveneče odgovore, kar je odlično.It might put my new time and other pieces of information. So this might not strictly apply. But still you see this robotic behavior. Whereas non-deterministic behavior could give similarly well-sounding answers as potential choices, which is great.
- u268 Upam, da sem vas prepričal, da determinizem ni najboljši. Za nekatere primere uporabe je lahko dober. O tem bom govoril čez trenutek. Naraven naslednji korak za odpravljanje determinizma pa je vrnitev k tej verjetnostni porazdelitviSo I hope I convinced you that determinism is not the best. So it can be good for some use cases. I'll talk about it in a bit. And one natural next step to combat determinism is to go back to this probability distribution
1:26:41 · Predicting next token by sampling from probability distribution · A Stanford ICME lecture slide presenting the "3rd idea" for next-token prediction: sample the next token from the model's probability distribution P(w_{t+1}|C). A bar chart gives probabilities over candidate words, with "kind", "smart", "fluffy" and "gentle" highest and "airplane" and "where" lowest. On the left is the transformer decoder diagram with the Output Probabilities layer highlighted, and a small video inset shows the lecturer at a blackboard. - u269 in preprosto vzorčenje iz nje, saj imate verjetnostno porazdelitev in uteži. Vse naše računske metode nam omogočajo vzorčenje naslednje besede. Torej naredimo to. To lahko storite z dvema metodama, saj se morda ne želite ukvarjati s celotno porazdelitvijoand simply sample from it, because you have a probability distribution, you have weights. All our computational methods enable us to sample the next word. So let's just do that. And you can do so with two methods, because you might not want to deal with the whole distribution
- u270 ves čas. Morda želite izbirati med k najverjetnejšimi naslednjimi žetoni, torej top-k. Druga pogosto uporabljena tehnika pa je top-p, pri kateri želite izbrati žetone, ki imajo določeno verjetnostnoall the time. So you might want to select amongst top-k most probable next tokens. And the second technique that is used quite often is top-p where you want to select tokens that have a given probability
- u271 porazdelitev kumulativno. Obljubil sem, da vam bom povedal, kdaj je determinizem potreben. Na primer, če izvajate zahtevne naloge obdelave naravnega jezika, pri katerih potrebujete ponovljivost,distribution in cumulate. So I promised you that I would tell you when determinism is needed. So, for example, if you perform natural language tasks that are tricky and need reproducibility,
- u272 recimo če želite povzeti besedilo. Želite vedno enak izhod, kar je lahko dobro. Na enem od poznejših predavanj bomo govorili o vrednotenju, zlasti o velikem jezikovnem modelu kot sodniku, kjer želite doslednost med dodeljenimi ocenami. To sta torej dobra primera.for example, let's say you want to summarize a piece of text. You want the same output all the time, that can be good. In one of the later lectures, we're going to talk about evaluations and particularly LLM as a judge, where you want consistency between the ratings that you give. So these two are good examples.
- u273 V drugih primerih je morda najbolj privlačna ta nedeterministična pot. Zdaj se bom poglobil v podrobnosti tega, kar sem omenil na splošno, in poskrbel, da bo razumljivo. V zadnjih plasteh imate to linearno projekcijoIn the rest of the time, this non-deterministic path might be the most attractive. So now I'm going to go into the specifics that I mentioned on a high-level, but making sure that it makes sense. So in the last layers, you have this linear projection
- u274 iz d model, prostora vložitev vašega žetona v danem trenutku. Nato ga projicirate v prostor besedišča. Na podlagi tega uporabite operator Softmax, da ta števila pretvorite v verjetnostno porazdelitev.between d model, the embedding space of your token at a given time. And then you project it on the space of vocabulary. And then based on this, you apply this Softmax operator to convert these numbers into a probability distribution.
- u275 Zakaj vam to govorim? Ker želim predstaviti parameter, za katerega ste kot uporabniki morda že precej slišali — temperaturo T, ki pomaga uravnavati dobljeno verjetnostno porazdelitev. Kot vidite, ima običajni operator SoftmaxAnd why am I telling you that? It's because I want to introduce a parameter that you might have heard as users quite bit-- the temperature T, which helps modulate the probability distribution that you get. So here, as you see, so the regular Softmax operator
- u276 T enak 1. Formula, ki jo vidite na desni, torej velja pri T enako 1. T uvedete takole. Zanima me vaša intuicija o tem, kakšna bo potem verjetnostna porazdelitev. Recimo, da vzamete T večji od 1.has T equals 1. So the formula that you see on the right is T equals 1. You introduce T like so. I want to ask your intuition of how you feel the probability distribution to be then. So let's say you take T bigger than 1.
- u277 Če imate dano verjetnostno porazdelitev, kako mislite, da se bo spremenila? Ja, eden od komentarjev je: bolj ploska. Ja, odlično. Naj vprašam še obratno. Recimo, da imate zelo majhen t.If you have a given probability distribution, how do you feel the probability distribution will change? So yeah, the one comment is flatter. Yeah, great. And let me ask you the opposite. Let's say you have very small t.
- u278 Kaj vam pravi intuicija? Ja, komentar je: bolj ostra. Ja, odlično. Je vsem jasno? Če imate majhen T, bo visoki Xi bolj poudarjen. Pri drugih i-jih pa bo vsota spodajWhat is your intuition? Yeah and the comment is sharper. Yeah, great. So is it clear to everyone? Because if you have small T, then the Xi that is high will be more emphasized. And the for the other i's, the some at the bottom
- u279 prevladala. Imeli boste torej le en člen — en indeks, katerega verjetnost bo blizu ena, pri drugih pa bo blizu 0. Ko je T velik, se bodo vsi ti x v eksponentni funkciji, nekaj deljeno s T, znotraj eksponenta približevali 0. Vse bo torej bolj ali manj enakomerno.will take it over. So you will have just one term-- so you will have just one index that will have a probability close to one and the other ones will be close to 0. And when T is large, then all of these x exponential of something over T will tend to 0 within the exponential. So everything will be more or less uniform.
- u280 Prav to prikazujejo ti grafi. In še nekaj: determinizem je bolj zvezen kot pa zares binarna izbira. Ni se vam treba odločiti samo za vklop ali izklop. Temperaturo lahko prilagajate kot nastavitev.And this is exactly what these graphs show. And one thing, so this is a determinism is continuous more so than truly like binary choice. So you're not committed to either turn it on or off. You can adjust the temperature as a setting.
1:30:37 · Impact of temperature on probabilities (lecture slide) · A Stanford ICME lecture slide titled "Impact of temperature on probabilities". It lists "Small T" and "High T", each paired with a question mark, so the effects are left blank as questions for the audience. A small inset in the top right shows the lecturer standing in front of a blackboard. - u281 Želim pa povedati — govoril sem o determinizmu. Ali se res zgodi? Lahko bi mislili, da se, saj imate v arhitekturi dekodirnika naučene vložitve. V redu, te so med izvajanjem sklepanja deterministično določene. Gredo skozi mehanizem maskirane samopozornosti.And I want to say-- so I talked about determinism. Does it really happen? So you could think that it does, because when you look at your decoder architecture, you have embeddings that are learned. OK, these are deterministically set at inference time. It goes through the masked self-attention mechanism.
- u282 Imate fiksne uteži in fiksne operacije. Lahko bi mislili, da je to fiksno, nevronska mreža s povezavami naprej. Imate dane uteži, ki so fiksne. Množite. To bi moralo biti fiksno in tako naprej. Pri temperaturi 0 bi torej mislili, da je povsem deterministično. Vendar se izkaže, da ni, ker v praksi pogoni za sklepanje velikih jezikovnih modelovYou have fixed weights, fixed operations. You could think that's fixed, feedforward neural network. You have given weights that are fixed. You multiply. This should be fixed and so on. So with a temperature of 0, you would think that this is completely deterministic. But it turns out that not because in practice LLM
- u283 vašo zahtevo združujejo v paket z drugimi. Razlog, da pride do nedeterminizma, je povsem računski. V teoriji bi moralo biti še vedno deterministično. Vendar obstaja koncept invariantnosti glede na paket, ki v nekaterih primerih ni upoštevan.inference engines, they will batch your request among others. And the reason why nondeterminism comes into play is a purely computational one. In theory, it should still be deterministic. But there is this concept of batch invariance that is not respected in some cases.
- u284 Močno priporočam ta blog avtorja [NERAZUMLJIVO] kot odlično branje. Podrobno predstavi razlog. Če želite poenostavljeno razlago, gre za neasociativnost seštevanja števil s plavajočo vejico,And I strongly recommend this blog from [INAUDIBLE] as a great piece of reading. So he goes through the exact reason. And if you want me to break it down to you, it all goes to the floating points non-associativity with respect to the addition operation,
1:32:13 · Person drawing box-and-arc diagram on chalkboard · A person in a dark t-shirt and glasses, seen from behind and the side, draws with chalk on a dark chalkboard. On the board are four hand-drawn rectangles in a row, with many curved arcs looping over them and connecting them, and small tick marks beneath each box. A faint "Stanford" watermark appears at the lower right. - u285 pri kateri vrstni red seštevanja vpliva na rezultat. Recimo, da velikemu številu prištejete majhno število in nato to veliko število odštejete: lahko dobite 0.where the order of addition does matter on the result that you get. So let's say you add a big number to a small number and then you retract that big number, you might get 0.
- u286 Če pa to operacijo izvedete ločeno, dobite nazaj to majhno število. Vse je povezano s predstavitvijo števil s plavajočo vejico, ki so približna. Ta odnos torej velja v svetu števil s plavajočo vejico. Ja.Whereas if you do that operation separately, you will get that small number back. So it all has to do with the representation of floating point numbers that are approximated. So this relationship does apply in the world of floating points. Yeah.
- u287 Komentar je torej, da bi bilo treba tenzor računati neodvisno. Izkaže se, da se glede na izvedbo vrstni red operacij znotraj teh tenzorjev spremeni. Da, to je razlog. Blog torej vsebuje več informacij o tem, zakaj natankoSo the comment here the tensor should be computed independently. So it turns out that depending on the implementation, the order of operation within these tensors will change. Yes, that is the reason. So yeah, the blog has more information on exactly why
- u288 in kako zgraditi jedra, ki to upoštevajo, in je odlično branje. Še kakšno vprašanje? V redu, odlično. Govorili smo o dekodiranju v običajnem primeru. Včasih, zlasti v industrijskem okolju,and then how to build kernels that do apply this as great reading. Any other questions? OK, great. And so now we talked about decoding in the usual case. Sometimes, and more particularly in an industry setting,
- u289 želite s temi velikimi jezikovnimi modeli opravljati naloge, za katere bi sicer uporabili kompleksne sisteme. Morda želite ustvariti strukturiran izhod, kot je JSON. Vprašanje, ki si ga morda zastavite: recimo, da želite ustvariti podatekyou might want to use these LLMs to perform tasks you would have used complex systems for. So you might want to generate let's say structured output, such as JSON. And one question that you might ask yourself, let's say you want to generate a piece of data
- u290 v tej določeni obliki in vam je to pomembno. Če tega ne naredi pravilno, namreč nadaljnje razčlenjevanje odpove in imate težavo. Kako to storite? Prvi pristop, na katerega bi lahko pomislili, je, da velikemu jezikovnemu modelu preprosto naročite, naj to naredi v obliki JSON, in upate na najboljše.in this specific format and then this matters to you. Because if it doesn't do it right, then parsing fails downstream and you're in trouble. How do you do so? So one first approach that you could think about is just ask the LLM for it, do this in JSON format and hope for the best.
- u291 Pri današnjih modelih, tudi najlažjih, to običajno deluje dobro. Vendar ni 100-odstotno, vi pa želite 100 %. Kako lahko to dosežete? Obstaja koncept vodenega dekodiranja, pri katerem je nabor razpoložljivih žetonov za napoved v naslednjem koraku omejen,With today's models, even the lightest, this usually works well. But it's not 100% and what you want is 100%. So how can you do that? So there is a concept called guided decoding, where the span of available tokens to be predicted at the next step is restricted,
- u292 odvisno od skladnje jezika, v katerem želite dekodirati. Recimo, da uporabljate JSON. Veste, da mora biti prvi žeton določen simbol in tako naprej. Tako bi se lahko tega lotili.depending on the syntax of the language you want to decode this in. So let's say you are in JSON. You know That your first token must be a specific symbol and so on. And this is how you could deal with it.
- u293 V redu, upam, da je bilo vse razumljivo. Zdaj bomo govorili o zanimivem delu, in sicer o oblikovanju pozivov.OK, so I hope all made sense. And now we're going to talk about one exciting part, which is prompting.
- u294 Oblikovanje pozivovPrompting
- u295 Predstaviti želim nekaj izrazov, da bomo vsi poznali osnovno besedišče. Recimo, da želite velikemu jezikovnemu modelu poslati zahtevo. Običajno ne vnesete samo žetona BOS in mu prepustite ustvarjanja vsega, kar sledi.And I want to introduce some terms, so that we all know some basics of vocabulary there. So let's say you want to issue a request to an LLM. Usually, you do not put just the BOS token and let it generate everything afterwards.
- u296 Imate določen poziv. Tu bi bil moj poziv lahko plišasti medvedek. Iz njega želim ustvariti naslednje žetone. Vse jih bom torej vnesel kot vhod. Nato bo avtoregresivno izračunaval vsak žeton posebej.You have a given prompt. So here my prompt could be a teddy bear. And I want to generate the next tokens out of it. So what happens is that I will put all of them as input. And then autoregressively, it will compute each token one at a time.
- u297 Morda ste že slišali za koncept kontekstnega okna. Kje pride tu v poštev? Pri napovedovanju naslednjega žetona, ne glede na to, kje ste, je vse, kar je na vhodu, vaše kontekstno okno. Ko pogledate celotno napoved,And you might have heard of this concept called context window. Where does it come at play here? So at the stage of next token prediction, anywhere you are, what is as input is your context window. And when you look at your whole prediction,
- u298 ko je ta povsem končana, se vsi ustvarjeni žetoni imenujejo izhodni žetoni. Včasih bi morda rekli, da je kontekstno okno natanko tisto, kar kot uporabnik vnesete, vendar je dejansko več kot to, saj mora biti vsak ustvarjeni žetononce it's completely done, whatever tokens were generated are called the output tokens. So you might be tempted sometimes to say that the context window is exactly what you put as input as a user, but it actually is more than that, because every token that you generate
- u299 ponovno dodan na vhod. Zato morate to upoštevati, ko ob teh velikih številkah pomislite, da lahko vnesete karkoli. Gre za velike številke kontekstnega okna, kot bomo videli na prosojnici. To morate upoštevati. Povezano je torej z dolžino izhoda.needs to be put back at the input level, which is why when you think about these large numbers, you think I can input anything. These are large numbers as context window, as we'll see in the slide. You need to take that into account. So it's linked with output length.
- u300 Ja. Vprašanje je torej, zakaj potrebujemo fiksno dolžino konteksta, na primer največjo dolžino konteksta. Razlog je računski. Zelo kmalu bomo videli, zakaj daljši kontekst morda niti ni zaželen. Obstaja torej tudi intuitiven razlog.Yep. So the question is, why if you need to have a fixed context length, like a maximum context length? So the reason is a computational one. And we'll see very soon why it might not even be desirable to have higher context length. So there is also an intuition based one reason.
- u301 To bomo videli čez trenutek. Je razumljivo? Želim navesti nekaj velikostnih redov. Glede dolžine konteksta morda vsi veste za velikostni red milijona vhodnih žetonov, kar je standard v panogi.We'll it in seen in a second. That makes sense? So I want to give some orders of magnitude here. So in terms of context length, you might all know about that O of 1 million tokens as input, which is the industry standard.
1:37:28 · Orders of magnitude: LLM API model specs compared · A Stanford ICME lecture slide titled "Orders of magnitude" shows API page screenshots for three models: OpenAI's GPT-6.1 Sol, Anthropic's Claude Opus 5.5 and Google's gemini-3.1-pro-preview. All three have context windows of about 1 million tokens, with output limits of 128K tokens for the first two and 65,536 for Gemini. Pricing is listed for the first two: $2/$10 per million tokens for GPT-6.1 Sol and $4/$20 for Claude Opus 5.5. A small inset shows the lecturer standing in a room. - u302 Izhodnih žetonov pa je običajno velikostnega reda 100.000. To je veljalo do pred dvema dnevoma, ko sem moral predelati to prosojnico. Pravzaprav bomo morda kmalu tudi tam prešli na milijon. Ta novi veliki jezikovni model pa ni objavil največje vhodneAnd then as output tokens, it's usually in the order of magnitude of 100k. That was true until two days ago where I had to rework this slide. Actually, maybe soon, we're going to move into the million territory there as well. And this new LLM that came out didn't publish an input maximum
- u303 dolžine. Morda smo tam torej napredovali za en velikostni red. Toda to so uporabni velikostni redi. Da dobite še občutek, kaj pomeni žeton: običajno žeton predstavlja 3/4 besede, stran pa ima približno 500 žetonov.length. So maybe we might have gone one order of magnitude higher there. But these are some good orders of magnitude. And then to give you some intuition on what token means. So usually, a token is 3/4 of a word and a page is about 500 tokens.
- u304 Ko torej govorite o velikostnih redih: 100.000 žetonov je približno knjiga, milijon pa obsežna knjiga. Zdaj pa nazaj k vašemu vprašanju: ali je več vhodnih žetonov vednoSo when you talk about orders of magnitude, if you take 100k tokens, it's about a book, and a million, it's a large book. And now coming back to your question, is it the case that always having more tokens as input
1:38:38 · Token mental model and orders of magnitude, Stanford lecture slide · A Stanford ICME lecture slide titled "Discussion" gives rules of thumb for converting tokens to words and pages, then scales of token counts. Most of the text is faded, and only the closing question "Are more tokens always better?" is in full black. A small inset video shows the lecturer standing in front of a chalkboard. - u305 Razkroj kontekstaContext rot
- u306 bolje? Paziti morate na pojav, imenovan »razkroj konteksta«. Obstaja preizkus, imenovan igla v kopici sena, pri katerem nekam v kontekstno okno vstavite informacijo, ki vas zanima, naloga pa je njeno priklicevanje.is better? Well, you need to beware of a phenomenon that's called "context rot," where there is this test called needle in a haystack, where you put a piece of information that you care about somewhere in that context window and the task is a retrieval one.
- u307 Izkaže se, da ima veliki jezikovni model z daljšanjem konteksta vse več težav pri priklicu te informacije. Včasih težava izhaja iz samega modela. Zato boste ob izdajah modelov vedno videli, da se stopnja halucinacij zmanjšuje in tako naprej.And it turns out that as the context length goes higher, the LLM has more and more difficulty to retrieve that piece of information. So sometimes it's a problem that comes from the LLM itself. So you will always see in the model releases the hallucination rate that goes down and so on.
- u308 Toda tega ne morete povsem rešiti, saj je lahko konceptualno, ko informacijo pomešate med druge, okoli nje toliko šuma, da priklic natanko te informacije ni realistična naloga. Na splošno pa dodajanje vse več vhodnih podatkovBut this is not something that you could perfectly solve, because conceptually, when you mix a piece of information, among others, it might be the case that there is so much noise around that the task of retrieving exactly that piece of information is not realistic. And in general, putting more and more as inputs
1:39:25 · Lecture slide on "context rot" with GPT-4 needle-in-haystack test · A presenter in a dark T-shirt and green pants stands gesturing in a Stanford lecture room with chalkboards behind him. A projected slide titled "Prompting: risk of 'context rot'" shows a heatmap from the Needle in a Haystack pressure test of GPT-4 128K. Retrieval is mostly accurate (green), but it degrades (red/yellow cells) at long context lengths, roughly 73K–128K tokens, when the fact sits at about 10%–50% document depth. - u309 to tveganje povečuje. Zato pogosto slišite o zgoščevanju konteksta. Vsakič bi morali začeti nov klepet. Te stvari konceptualno še vedno veljajo. Zato nimamo neomejenega kontekstnega okna. To je tudi nekakšna dobra praksa.pushes that risk up, which is why in general you hear about context compaction. You should start a new chat every time. These things still apply conceptually. And this is why we are not here with unlimited context window. It's also like a good practice.
- u310 V redu, odlično. Zadnje minute bom namenil tehnikam za izboljšanje zmogljivosti, ne da bi spreminjali uteži modela. Obstaja širok koncept učenja v kontekstu, pri katerem namesto poučevanja s prilagajanjem utežiOK, awesome. And I'm going to spend the last minutes on techniques to improve performance without you changing any weights of your model. So there is a large concept called in-context learning, where instead of teaching in terms of weights tuning
1:40:16 - u311 velikega jezikovnega modela podate primere in rešitve tega, kar želite. Recimo, da model sprašujete o starosti svojega plišastega medvedka. Če ga vprašate brez primerov, v primerjavi s tem, da mu podate nekaj vprašanj in odgovorov, ki ponazarjajo pričakovani odgovor,your LLM, you give examples and solutions of what you want. So let's say you are in the task of asking your LLM about the age of your teddy bear. So if you just ask it in zero shot versus give some question answers of what answer you expect,
- u312 se bo model implicitno naučil oblike in morda celo sklepanja, ki ga mora izvesti. Danes boste videli, da se učenje z nekaj primeri uporablja vse manj, ker modeli za sklepanje postajajo vse boljši.the LLM will learn the format and maybe even the reasoning that it needs to go through implicitly. And these days, you will see few shot learning being less and less used because the reasoning models, they get better and better.
- u313 Slaba stran učenja z nekaj primeri pa je, da se model preveč prilagodi konkretnim primerom, ki mu jih podate, vi pa želite, da bi se bolj opiral na sklepanje. Zato boste videli tehnike prilagajanja pozivov, ki te primere pretvorijo v navodila. Takšna navodila običajno oblikujejo ročnoAnd the bad effects of few shot learning is that it will make your model overfit on the specific examples that you give it, whereas what you want is be more reasoning-based. So you will see some prompt tuning techniques that turn these examples into instructions, and people typically handcraft such instructions
- u314 in jih uporabijo namesto primerov. Druge očitne slabosti so tudi več vhodnih žetonov, kar poveča stroške in zakasnitev. Glede sklepanja pa bi lahko rekli: kaj če vanj vključimo nekaj sklepanja?and put them instead of examples. And then again, some other obvious downsides are also you have more input tokens, which increases cost and latency. So on that reasoning part, you might say, how about we put some reasoning in there?
- u315 Veriga misli (CoT)Chain of Thought (CoT)
- u316 Obstaja torej prelomni članek z naslovom Veriga misli, ki učenje v kontekstu dvigne na naslednjo raven tako, da model v teh pozivih z nekaj primeri uči, kako priti do rešitve.So there is this landmark paper called chain of thought, where it takes in-context learning to the next stage by teaching the model in these few short prompts how it gets there.
- u317 Avtorji so opazili, da se je model naučil poti sklepanja in da se je uspešnost na splošno izboljšala. Nočem pa, da bi verigo misli razumeli zgolj kot tehniko učenja v kontekstu. Je veliko več kot to.And the authors, they saw that the model learned the reasoning path, and overall it improved performance. And I don't want you to consider chain of thought to be purely an in-context learning technique. It's way more than that.
- u318 Govorili bomo tudi o modelih za sklepanje, pri katerih se uporabljajo žetoni razmišljanja in velja isti koncept. O tem bomo govorili takrat. Tehnika, ki bi jo morda uporabili zunaj sprotnega izvajanja, pa se imenuje samodoslednost. Kaj če namesto ene poti sklepanjaAnd we will talk about reasoning models where thinking tokens are used and the same concept applies. So we'll talk about it then. And one technique that one might be tempted to use offline is called self-consistency. So how about, instead of generating one reasoning path, I
- u319 ustvarim več poti? Lepo pri tem je, da postane izhod, ki vas zanima, recimo na področju aritmetike, stabilnejši. Z večinskim glasovanjem lahko pridete do odgovora, s katerim se strinja več ustvarjenih rešitev. Ja, na predavanjih o modelih za sklepanje bomo izvedeli večgenerate several ones? Then one nice thing is that it makes the output that you might be interested in, let's say in the arithmetic world, more stable. And by majority voting, you can get to an answer where more generations agree to. Yeah, we'll see in reasoning models lectures, more
- u320 o tem. To je vse, kar sem imel danes za vas. Želim vam lep konec tedna. Hvala. [APLavz]about these. And that's all I had for you today. And I hope you have a great weekend. Thank you. [APPLAUSE]
V okolici
BERT v odprti kodi: najsodobnejše predučenje za obdelavo naravnega jezika
Ekipa Google AI Language najavlja odprtokodno izdajo BERT, tehnike predučenja za obdelavo naravnega jezika. BERT je globoko dvosmeren model, vnaprej naučen na neoznačenem besedilu, ki ga je mogoče hitro dodatno učiti na majhnih podatkovnih zbirkah za posamezne naloge. Objava poroča o najboljših doslej doseženih rezultatih pri 11 nalogah obdelave naravnega jezika.
Prispevek
Izboljšanje razumevanja jezika z nenadzorovanim učenjem
En sam transformer, ki ni vezan na posamezno nalogo in je predhodno učen z jezikovnim modeliranjem na veliki količini neoznačenih besedil ter nato dodatno učen, dosega najboljše doslej znane rezultate pri številnih raznolikih jezikovnih nalogah. Največje izboljšave dosega pri zdravorazumskem sklepanju in bralnem razumevanju, kar avtor razume kot dokaz, da nenadzorovano učenje razvija ti sposobnosti. Delo prinaša tudi visoke računske stroške, omejitve učenja o svetu iz besedil in nezanesljivo posploševanje.
Prispevek
To besedilo je napisano z umetno inteligenco.
Objavljeno v: Zdaj