1. predavanje: Transformerji
Izvirni naslov vira: Stanford CME295 Transformerji in veliki jezikovni modeli | Jesen 2026 | Predavanje 1 – Transformerji
Transformerji so omogočili sodobne velike jezikovne modele z arhitekturo, ki jo je mogoče povečevati z več podatki, računskimi viri in parametri. Njihove osnove združujejo tokenizacijo in naučene vektorske vložitve s položajnimi informacijami, pozornostjo in nevronskimi mrežami s povezavami naprej, da oblikujejo kontekstualne predstavitve in ustvarjajo besedilo.
Video1 vir
- Potrjeno pri drugem viru: 1
- Le tu: 45
Kaj pravi
- Transformerji zaznamujejo prehod od specializiranih rekurentnih modelov k velikim jezikovnim modelom, ki jih je mogoče povečevati, pogovornim izdelkom in agentom. Besedilo se najprej pretvori v tokene: tokenizacija po besedah in po znakih imata nasprotne kompromise med velikostjo besedišča in dolžino zaporedij, medtem ko se metode podbesedne tokenizacije, kot je BPE, iz reprezentativnega korpusa naučijo pogostih delov besed. Naučene vektorske vložitve s pomočjo napovednih nalog zajamejo pomenske odnose, vendar statične predstavitve Word2vec ne upoštevajo konteksta in besednega reda. Rekurentne nevronske mreže ohranjajo vrstni red zaporedja, a imajo težave z oddaljenimi informacijami in stroški zaporednega učenja. Pozornost namesto tega tokene povezuje neposredno ter z naučenimi podobnostmi med poizvedbami in ključi utežuje vektorje vrednosti. Izvirni transformer združuje kodirnik, ki predstavi izvorno besedilo, in dekodirnik, ki avtoregresivno ustvarja prevode. Položajne informacije zagotavljajo vrstni red; samopozornost združuje informacije iz tokenov, nevronske mreže s povezavami naprej pa dodajajo nelinearne transformacije. Te interakcije izvajata pozornost s skaliranim skalarnim produktom in več glav. Navzkrižna pozornost dekodirnika dostopa do izhodov kodirnika, vzročno maskiranje pa preprečuje dostop do prihodnjih tokenov. Rezidualne povezave, normalizacija, naključno izpuščanje in glajenje oznak podpirajo učenje. Te komponente skupaj tvorijo arhitekturno osnovo sodobnih velikih jezikovnih modelov.
- Članek »Attention is All You Need« iz leta 2017 je predstavil arhitekturo transformerja. u47–49 ·
1 vir
Pravijo tudi
- Raziskava Attention Is All You Need
- Afshine navaja november 2022 kot čas izida ChatGPT in ta izid opisuje kot prelomnico v interakciji javnosti s pogovornimi velikimi jezikovnimi modeli. u51–52 · Predavatelj izrazi negotovost glede svojega spomina na mesec izida.
- Byte Pair Encoding se nauči besedišča tako, da večkrat združuje najpogostejše pare tokenov, dokler ne doseže izbrane velikosti besedišča. u89–94 ·
- Neznani token po ustaljenem dogovoru predstavlja besedilo, ki ga ni v besedišču tokenizatorja. u101–103 ·
- Po dogovoru za generiranje, ki ga opisuje Afshine, token za začetek zaporedja sproži generiranje, token za konec zaporedja, ki ga model izpiše, pa označuje zaključek. u104–106 · Predavatelj pozneje poudari, da dogovori o posebnih tokenih niso univerzalni.
- Afshine pravi, da besedišča sodobnih velikih jezikovnih modelov obsegajo več sto tisoč tokenov, in kot primer navede 200,000. u112–113 · Ocena se nanaša na tokenizatorje, ki obravnavajo angleščino in druge jezike, ne na določen model.
- Afshine opisuje podbesedno tokenizacijo kot najbolj priljubljeno raven tokenizacije, BPE pa kot najpogostejšo vrsto tokenizatorja v današnji uporabi velikih jezikovnih modelov. u112–113 · BPE je v predavanju že prej predstavljen kot podbesedni tokenizator.
- Pri Word2vec naloga zvezne vreče besed napoveduje besedo iz okoliškega konteksta, naloga skip-gram pa iz dane besede napoveduje okoliške besede. u125–127 · To sta nadomestni nalogi za učenje predstavitev, ne pa končni nalogi uporabe.
- V Afshinovi poenostavljeni mreži za učenje vektorskih vložitev imajo vhodni vektorji z eno enico in preostalimi ničlami ter izhodni verjetnostni vektorji velikost besedišča V, skrita predstavitev pa ima izbrano dimenzijo D, ki je običajno precej manjša od V. u135–136 ·
- LSTM poleg skritega stanja dodajo še stanje celice, da bi informacije ohranili dlje, vendar Afshine pravi, da imajo še vedno omejitve pri dolgoročnih odvisnostih. u164–166 ·
- Po Afshinovih besedah normalizacija po plasteh normalizira aktivacije in pomaga pri konvergenci učenja transformerja. u262 ·
- Glajenje oznak del ciljne verjetnosti dodeli elementom besedišča, ki niso določeni naslednji token. Afshine poroča, da so avtorji transformerja s to tehniko dosegli boljše vrednosti metrik strojnega prevajanja. u268–272 · 90% za ciljni token in preostalih 10% sta ponazoritveni vrednosti, ne navedeni eksperimentalni nastavitvi.
- Pri zaporedju dolžine n imajo transformerjeve matrike poizvedb, ključev in vrednosti n vrstic ter širine dQ, dK oziroma dV. Širini poizvedb in ključev se morata ujemati, da je mogoče matrično množenje poizvedb in ključev. u286–290 · Ustrezne naučene projekcijske matrike preslikajo iz d_model v vsakega od teh prostorov.
- Množenje Q s transponirano matriko K da matriko velikosti n krat n, katere elementi so skalarni produkti med poizvedbami in ključi posameznih tokenov. u291–292 · Tu je n dolžina zaporedja.
- Izračun pozornosti je softmax(QKᵀ/√dK)V. Shervine deljenje z √dK pojasni kot normalizacijo vpliva dimenzije ključev na varianco ocen pozornosti. u295–297 · Softmax pretvori ocene v uteži, katerih vsota je ena.
- Večglava pozornost vzporedno izvede h izračunov pozornosti, stakne njihove izhode in jih z izhodno projekcijo preslika iz h·dV nazaj v d_model. u296–299 ·
- Po Shervinovi razlagi izvirni transformer kodirniški blok ponovi šestkrat. u299–301 ·
- Navzkrižna pozornost dekodirnika vzame poizvedbe iz tokenov dekodirnika, ključe in vrednosti pa iz končnih izhodov kodirnika. Vsak dekodirniški blok prejme te končne predstavitve kodirnika. u305–306 ·
- Trikotna vzročna maska med učenjem blokira povezave samopozornosti dekodirnika do poznejših tokenov. Maskirane ocene so nastavljene na negativno neskončnost, zato njihove uteži po uporabi funkcije softmax postanejo nič. u314–316 · Maska tokenu preprečuje uporabo informacij, ki med generiranjem še ne bi bile na voljo.
- Za večjezične aplikacije tokenizator naučite na korpusu, v katerem so zastopani vsi jeziki, ki jih mora aplikacija obravnavati. u96–97 · Priporočilo je namenjeno tistim, ki se ukvarjajo z večjezičnostjo.
- Tokenizacija na ravni besed sama po sebi ne omogoča deljenja naučenih informacij med sorodnimi oblikami, kot sta »bear« in »bears«, niti ne zagotavlja podobnih predstavitev zanje. u70–76 · Skupni podbesedni koreni omogočajo ponovno uporabo informacij pri sorodnih besednih oblikah.
- BPE izboljša učinkovitost obdelave tako, da pogosto sopojavljajočim se delom dodeli žetone in s tem zmanjša število žetonov, potrebnih za besedilo, podobno njegovemu učnemu korpusu. u94–96 · Po predavateljevi razlagi manj žetonov pomeni, da model za obdelavo besedila porabi manj časa.
- Dopolnilni žetoni lahko izenačijo dolžino zaporedij in s tem omogočijo učinkovito obdelavo z vektorji, matrikami in tenzorji ujemajočih se dimenzij. u107–108 ·
- Učenje mreže na nadomestni nalogi napovedovanja besed lahko ustvari skrite predstavitve, ki zajamejo pomenske podobnosti in analogije, čeprav učenje teh razmerij ni izrecni cilj napovedovanja. u137–141 · Afshine naučene povezave ponazori s paroma Paris–France in Berlin–Germany.
- RNN težko uporabljajo oddaljene informacije, ker vedno znova spreminjajo en sam vektor skritega stanja, ki mora povzemati zaporedje. Afshine to omejitev pri dolgoročnih odvisnostih poveže s problemom izginjajočega gradienta. u160–169 · Informacije, potrebne za navezovanje na oddaljene dele zaporedja, v trenutnem skritem stanju morda niso več na voljo.
- Učenje RNN je počasno, ker je vsaka napoved naslednjega žetona odvisna od skritega stanja, ki nastane z zaporedno obdelavo predhodnih žetonov, enega za drugim. u170–171 · Zaporedna odvisnost je ena od omejitev, zaradi katerih iščemo alternative RNN.
- Podobnost med poizvedbo in ključem določa, koliko vrednost posameznega žetona prispeva k izhodu mehanizma pozornosti. Nastala predstavitev je utežena kombinacija vektorjev vrednosti, poizvedbe, ključi in vrednosti pa so pridobljeni z naučenimi projekcijami. u190–200 · Vloge poizvedbe, ključa in vrednosti ločujejo ocenjevanje relevantnosti od informacij, ki se združujejo.
- Rezidualne povezave izrazijo izhod plasti kot vsoto funkcije njenega vhoda in nespremenjenega vhoda, kar značilkam omogoča, da obidejo podplast. Afshine pravi, da to olajša vzvratno razširjanje napake in učenje v globokih arhitekturah. u257–261 · Afshine rezidualno plast predstavi kot spreminjanje obstoječe predstavitve, ne pa kot njeno popolno zamenjavo.
- Metoda dropout med učenjem namenoma z določeno verjetnostjo izpušča enote, da se model ne bi preveč zanašal na posamezne značilke. Afshine pravi, da to izboljša posploševanje. u267–268 ·
- Afshine predstavlja možnost povečevanja transformerja z več podatki, računskimi viri in parametri kot arhitekturno prelomnico, ki je omogočila sodobne velike jezikovne modele. u47–51 ·
- Tokenizacija razdeli besedilo na nedeljive enote, imenovane tokeni, ki jih je nato mogoče številčno predstaviti modelom. u58–62 ·
- Naučene predstavitve tokenov naj bi odražale odnose med tokeni, ne pa zgolj razločevale njihove identitete, da lahko modeli uporabljajo besedilo za napovedovanje ali generiranje. u120–125 ·
- Pozornost modelu omogoča neposreden dostop do predhodnih tokenov in učenje tega, kateri tokeni so pomembni, namesto da bi se pri ohranjanju predhodnih informacij zanašal izključno na skrito stanje. u174–179 ·
- Samopozornost izračuna predstavitev tokena v odvisnosti od drugih tokenov v njegovem zaporedju, namesto da bi token združila z rekurentnim skritim stanjem. u183–187 ·
- Izvirni transformer s kodirnikom oblikuje predstavitve izvornega besedila, z dekodirnikom pa te predstavitve uporablja pri ustvarjanju prevoda. Afshine to arhitekturo predstavlja kot osnovo sodobnih velikih jezikovnih modelov. u219–222 ·
- Shervine kot bistveni komponenti transformerja opredeli pozornost in nevronske mreže s povezavami naprej, pri čemer slednje vsebujejo večino njegovih parametrov in zmogljivosti. Preostale tehnike označi kot pripomočke pri učenju, poudari pa tudi kakovost podatkov. u311–313 ·
- Kako se softmax znotraj mehanizma pozornosti razlikuje od končnega softmaxa v transformerju? u317–319 · Softmax v mehanizmu pozornosti porazdeli uteži med ključe žetonov; končni softmax pa poda verjetnosti za besednjak, namenjene napovedovanju naslednjega žetona.
- Zakaj žeton za začetek zaporedja ni prikazan kot del ustvarjenega prevoda? u319–320 · Žeton za začetek zaporedja je vhodna oznaka, ki se uporablja za napoved prvega izhodnega žetona; izhodni žeton za konec zaporedja pa označi, kdaj naj se generiranje ustavi.
- Tokenizacija na ravni znakov omogoča majhen besednjak in se izogne neznanim besedam, če so njihovi znaki zajeti, vendar ustvarja daljša zaporedja in težje razložljive vložitve. u77–82 · Daljša zaporedja upočasnijo izračune modela.
- Podbesedna tokenizacija lahko izkoristi skupne korene in se iz podatkov nauči uporabnih delov besed, vendar zahteva učenje tokenizatorja in je močno odvisna od učnega korpusa. u83–88 · Afshine priporoča, da se učni podatki tokenizatorja uskladijo s predvideno uporabo.
- Pri nespremenljivi velikosti besednjaka lahko večjezični tokenizator za posamezen jezik ustvari daljša zaporedja, vendar lahko skupni izrazi v različnih jezikih koristijo naučenim predstavitvam. u114–117 · Afshine pravi, da skupni učinek na kakovost predstavitev ni jasen, in kot možen vir medjezikovnih sinergij navede kratice organizacij.
- Obravnavani pristop Word2vec besedi v različnih kontekstih dodeli isto predstavitev in v besednih vložitvah ne zajame besednega reda, čeprav ta vpliva na pomen povedi. u146–150 · Afshine omejitve ponazori z besedo »bank« v pomenu rečnega brega oziroma finančne ustanove ter s primerom, v katerem objema otrok ali pa plišasti medvedek.
- Če vsakemu žetonu omogočimo interakcijo z vsemi drugimi žetoni, s tem še ne ohranimo besednega reda. Transformer to omejitev odpravi z dodajanjem položajnih informacij vložitvam žetonov. u185–186 · Rešitev s položajnimi vložitvami je pojasnjena pozneje v u227–236.
- Naučene položajne vložitve v Afshinovem primeru ne morejo predstaviti položajev zunaj tistih, naučenih med učenjem. Vnaprej določene položajne predstavitve, ki temeljijo na frekvencah, ponujajo alternativo, kadar vhodi presegajo ta naučeni razpon. u229–234 · Afshine omejitev ponazori s 1,000 vhodnimi žetoni, pri čemer so vložitve naučene le do položaja 500.
- Transformerjeva razširljiva kombinacija pozornosti, položajnih informacij in izračunov v mrežah s povezavami naprej nad naučenimi predstavitvami tokenov zagotavlja arhitekturno osnovo sodobnih velikih jezikovnih modelov. Kako transformer pretvori besedilo v kontekstualne predstavitve in ustvarja izhod ter zakaj je njegova arhitektura omogočila sodobne velike jezikovne modele?
Kako utemeljuje
- thesis Scalable transformers underpin modern LLMs through contextual token computation How does the transformer turn text into contextual representations and generate output, and why did its architecture enable modern LLMs?
- theme Tokenization balances efficiency and coverage Tokenization makes text computationally usable, while subword methods balance vocabulary coverage, sequence length, and corpus dependence.
- theme Prediction learns useful but limited representations Word-prediction tasks learn semantic representations, but static embeddings fail to capture context and word order.
- theme Attention builds context through direct interactions Attention replaces reliance on recurrent memory with learned token interactions, supplemented by positional information.
- idea Attention accesses relevant earlier tokens directly
- argument Sequential hidden-state dependencies slow recurrent training
- idea Self-attention represents tokens through other sequence tokens
- theme Encoder and decoder coordinate generation The encoder represents source text while the decoder generates output using source representations and causally restricted self-attention.
- theme Scalable computation enables modern LLMs Attention and feedforward computation provide the core capacity, while supporting techniques make deep transformer training effective.
Vir, odlomek za odlomkom
Prepis, preveden z umetno inteligenco iz angleščine.
- u1 DobrodošliWelcome
- u2 Pozdravljeni vsi in dobrodošli pri predmetu CME 295, transformerji in veliki jezikovni modeli. Ime mi je Afshine in ta predmet bom poučeval skupaj s Shervinom, ki je zadaj. Preden začnemo, bi rad povedal nekaj besed o naju.Hello, everyone, and welcome to CME 295, transformers and large language models. My name is Afshine, and I'll be teaching this class with Shervine, who's in the back. So before we start, I just want to say a few words about ourselves.
- u3 S Shervinom sva brata dvojčka in imava zelo podobno izobrazbeno in poklicno pot. Oba sva obiskovala šolo v Franciji, imenovano Centrale Paris. Nato sva prišla v ZDA na podiplomski študij. Jaz sem šel na MIT, Shervine pa sem na Stanford, na oddelek ICME. Potem sva oba odšla v tehnološko industrijo.So Shervine and I are twin brothers, and we have very similar backgrounds. So we both went to a school in France called Centrale Paris. And then we came to the US for grad school. So on my end, I went to MIT. And then Shervine came here at Stanford in the ICME department. And then after that, we both went to the tech industry.
- u4 Najprej sva oba šla v Uber, nato v Google. Zdaj sva oba pri Netflixu. S Shervinom imava rada velike jezikovne modele oziroma LLM-je. Na področju LLM-jev delava, bi rekel, od začetka dvajsetih let tega stoletja.So we first both went to Uber, and then we went to Google. And now we're both at Netflix. So Shervine and I, we like LLMs. So we've been working in the field of LLMs, I would say since the early 2020s.
- u5 To je eden od razlogov, zakaj imava tako srečo, da lahko poučujeva ta predmet. V različnih oblikah ga poučujeva od leta 2021. Ker pa se je zanimanje za LLM-je povečalo, sva ga lani dejansko uvedla kot uradni predmet na Stanfordu.And so that's one of the reasons why we're so lucky to be teaching this class. We've been teaching it since 2021 under various formats. But as attention gained towards LLMs, we have actually made it an actual Stanford class since last year.
- u6 Ta izvedba je tretja. Če ste torej tukaj in se sprašujete, ali je predmet primeren za vas: njegov cilj je pojasniti, kako delujejo LLM-ji, zlasti pa razumeti temeljni mehanizem njihove arhitekture. Ogledali si bomo torej transformer —And this session is the third instance. And so if you're here wondering if this class is good for you-- so the goal of this class is to tell you how LLMs work and in particular, understand the underlying mechanism of its architecture-- so we're going to see the transformer--
1:31 · Welcome to CME 295 course goals slide · A Stanford lecture slide titled "Welcome to CME 295!" lists two course goals: understanding how Transformers work and relate to LLMs, and learning how LLMs are trained and used in applications. A small inset in the top right shows a person standing in a lecture hall. The slide has Stanford and ICME branding. - u7 pa tudi, kako se LLM-ji učijo, kako jih lahko uporabljamo, pri čem so dobri in pri čem niso. Upam, da boste pri tem predmetu dobili občutek za vse to. Kar zadeva ciljno občinstvo, bi rekel, da je precej široko.but also how LLMs are trained, how we can use them, what they're good at, what they're not good at. So hopefully, you'll be able to get a sense of all of that in this class. And in terms of the target audience, I would say it's a pretty wide audience.
- u8 Če želite postati raziskovalec, bi bil to lahko odličen predmet, ki vam razširi obzorja glede različnih tehnik, ki se uporabljajo, različnih področij uporabe in tako naprej. To je torej ena skupina.So in case you want to go and be a research scientist, I would say it could be a great class to just open up the set of things that you are able to see in terms of, what are the different techniques that are being used, what are the different applications, and so on. So I think that's one.
- u9 Druga skupina ste tisti, ki želite izvesti osebni projekt. Dandanes so programerski agenti povsod. Če želite preprosto vzeti neko orodje in nekaj narediti, bi verjetno morali vedeti, pri čem je programerski agent dober in pri čem ni. In tretjič, ne glede na vašo vlogo,The second one is if you want to do a personal project. So nowadays, coding agents are everywhere. And so if you want to just take one tool and just do something, you should probably know what the coding agent is good at and not good at. And third, I would say no matter your role,
- u10 je potreba po pismenosti na področju umetne inteligence vse večja. Obstaja izraz pismenost na področju UI. Ne glede na to, kje delate in kakšna je vaša vloga, postaja poznavanje delovanja teh orodij vse pomembnejše.there is a growing need of being literate in AI. So there's this term called AI literacy. So no matter where you work and your role, I would say just knowing how these tools work is becoming increasingly important.
- u11 Če se prepoznate v kateri od teh skupin, je ta predmet morda primeren za vas. Glede predznanja bi rekel, da je odlično, če imate nekaj osnov linearne algebre, če veste, kaj je matrika in kako množimo, poleg tega pa še nekaj osnov strojnega učenja.So if you feel like you're in one of these categories, this class may be good for you. And in terms of the prerequisites, I would say if you have some foundations in linear algebra, if you know what a matrix is, how we do multiplications, then that would be great-- along with some basics in ML.
- u12 Na primer, kaj je funkcija izgube, kaj je nevronska mreža in kaj je vektorska vložitev, čeprav bomo to obravnavali pri predmetu. Je pa dobro, da to poznate že prej. Je razumljivo?So for instance, what is a loss function, what is a neural network, what is an embedding, although we will be seeing that in the class. But it's good to have those, I would say, beforehand. Make sense?
- u13 Razlika v primerjavi z lansko izvedboDifference from last year’s edition
- u14 Prav, super. Morda veste, morda pa ne, da se ta predavanja snemajo. Zadaj lahko vidite kamero. Snemali smo jih že lani. Morda se torej sprašujete, kakšen smisel ima prihajati na predavanja, če so že posneta. Področje se razvija tako hitro,OK, cool. So you may or may not know that this class is being recorded. So you can see the camera in the back. It was actually recorded last year. So you may be wondering, well, what is the point in attending the lecture if it was already recorded? So the field is moving so quickly
3:43 · CME 295 welcome slide: goals and intended audience · A Stanford ICME lecture slide titled "Welcome to CME 295!" with the Goals section faded out and the Audience section highlighted. It says the course suits people interested in LLMs for career, project or curiosity reasons, and requires machine learning basics and linear algebra. A small inset shows the lecturer standing beside a blackboard. - u15 da se je od lani pojavilo ogromno novosti. Eden od ciljev tega predmeta je prav vključiti ves doseženi napredek. Naštel bom nekaj primerov. Napredek je bil pri naknadnem učenju. Na primer pri destilaciji politike,that there has been so many new things that have come up since last year. And actually, one of the goals of this class is to incorporate all the advances that have happened. So I'll name a few. So there has been some progress on the post-training side. So for instance, on policy distillation,
- u16 če ste že slišali zanjo, seveda pri agentih UI, torej programerskih agentih in podobno, ter pri novih paradigmah LLM-jev. Tradicionalno so napovedovali po en žeton naenkrat. Danes pa je vse več modelov, ki se stvari lotevajo drugače,if you've heard of it, of course, AI agents, so coding agents and so on, and new paradigms of LLMs. So traditionally, it was predicting tokens one at a time. But nowadays, there's been an increasing number of models that have approached things differently,
- u17 med drugim z vidika difuzije. Skratka, če obiskujete ta predmet in se pripravljate na izpite, si oglejte letošnja predavanja, ker bodo precej drugačna.so from the diffusion perspective, among other things. So long story short, if you're attending this class and you're preparing for exams, please look at this year's lectures because they will be quite different.
5:01 · Logistics slide: Friday class date and time · A Stanford University lecture slide titled "Logistics" with a maroon header. It lists the date and time of the class as Fridays from 3:30pm to 5:20pm. A small inset video frame in the top right shows a person standing in front of a chalkboard. - u18 Organizacija predmetaClass logistics
- u19 Glede organizacije: zelo sem vesel, da vas je v petek popoldne tukaj toliko. Predavanja bodo vsak petek od 15.30 do 17.20. Potekala bodo v tej učilnici. Predmet je ovrednoten z dvema kreditnima enotama.In terms of the logistics-- so I'm so happy to see so many of you on a Friday afternoon. So it will be every Friday from 3:30 to 5:20. It will be in this class. And then it is a two-unit class.
- u20 Izberete lahko številčno oziroma črkovno oceno ali način opravil/ni opravil. Vsa predavanja se snemajo. Posnetke bomo objavili najpozneje dva dni po predavanju. Če želite, jih torej lahko spremljate na daljavo ali pa pridete osebno.You can either choose it to take it as letter or credit, noncredit. So again, all the lectures are recorded. We'll make sure to post the recordings, at most, two days after the lecture has happened. So feel free to watch it remotely if you want or attend the class in person.
- u21 Pravzaprav bi vas zelo rada videla v živo, a izberite, kar vam ustreza. Pri predmetu ni domačih nalog, sta pa dva izpita: vmesni in zaključni. Vmesni bo zajemal prva štiri predavanja,Actually, we'd love to see you in person, so feel free to choose either way. And this class has no homeworks, but it has two exams. So one is the midterm, and one is the final. So the midterm will be about the first four lectures,
- u22 in bo čez en mesec, mislim? Ja, 23. oktobra. Zaključni izpit pa bo zajemal zadnjih pet predavanj. Skupaj bo torej devet predavanj. Štel bo 50 % skupne ocene. Ker to ni prvič,and it will be one month from now, I guess? Yeah, October 23. And the final exam will be on the last five lectures. So there will be nine lectures in total. And it will be accounting for 50% of the total. So given that it's not the first time
- u23 da izvajava ta predmet, sva na spletu že objavila, kako sta videti vmesni in zaključni izpit. Na spletni strani lahko pod zavihkom 2025 vidite, kaj pričakujeva na teh izpitih. Vključujejo vprašanja izbirnega tipa. Imamo tudi nekaj vprašanj z odprtimi odgovori.that we're giving this class, we have already posted online what a midterm looks like, what a final looks like. So if you go on the website, you can actually see in the tab 2025 what we would expect from these exams. So it's a multi-choice questions. We also have some free-form questions.
- u24 Takšna vprašanja bi torej postavila. Imate za zdaj kakšno vprašanje glede organizacije? Ja. Mimogrede, vprašanja bom vedno ponovil za tiste, ki spremljajo na daljavo. Vprašanje je, ali imamo govorilne ure.So this is the kind of question we would ask. Any questions on the logistics so far? Yeah. So I'm going to always repeat, by the way, questions just for people who are watching remotely. So the question is, are there office hours?
6:49 · Instructor presenting course logistics slide in Stanford lecture hall · A man in a maroon t-shirt and glasses stands in front of large chalkboards, gesturing with open hands while speaking. A projected Stanford ICME slide titled "Logistics" lists class details: 2 units, grading option, recorded lectures, and midterm and final exam dates with 50% weights each. - u25 Uradnih govorilnih ur nimamo. Bova pa s Shervinom po vsakem predavanju ostala tukaj, če boste želeli kaj vprašati. In to bomo pravzaprav videli tukaj, če imate kakšno — To bomo torej videli pozneje, če boste imeli vprašanja. Na voljo je tudi Ed, platforma, kjer lahko postavljamo vprašanja.So we don't have official office hours. However, Shervine and I will be staying after each class in case you want to ask any questions. And we're going to see it actually here in case you have any-- So we're going to see it later if you have any questions. There is also Ed, so platform where we can ask questions.
- u26 Z veseljem bova odgovorila nanje. Super. Glede gradiva: govoril sem o vmesnih izpitih in podobno. Vsi so — tisti od lani so na spletni strani.So yeah, we'd love to answer them. Cool. So in terms of the material-- so I was talking about the midterms and so on. So they're all-- so the ones from last year, they're on the website.
- u27 Na spletni strani je tudi učni načrt in tam bodo objavljeni posnetki. Prosojnice objavljamo en dan pred predavanjem, ker so lani nekateri prišli do naju in rekli,The website also contains the syllabus, and the recordings will be posted there. One thing that we're doing is that we're posting the slides one day before the lecture because last year, some people came to us and said,
- u28 da bi radi nanje pisali zapiske. Zato smo jih zdaj navajeni objavljati en dan pred predavanjem. Prenesete jih lahko s spletne strani. Kar zadeva gradivo, imamo tudi učbenik, in sicer tega: Super Study Guide, Transformers and LLMs.OK, we'd love to be able to annotate on the slides. So now, we took the habit of posting them one day before the lecture. So if you go on the website, you can retrieve them. So in terms of the material, we do have a textbook, which is this one, the Super Study Guide, Transformers and LLMs.
- u29 Mislim, da ima knjižnica nekaj izvodov, tako da si ga lahko tam izposodite. Dobite ga lahko tudi na spletu. Imamo tudi spletno stran. Poleg tega imamo še pregledni list, ki naj bi bil čim bolj ažuren. S Shervinom sva ga pravzaprav posodobila pred nekajI believe the library has a few copies, so you can borrow from there. You can also get it online. We got the website as well. And along with that, we also have a cheat sheet which aims at being the most up to date. So Shervine and I actually updated it just a couple
- u30 tedni. Njegov namen je strnjeno zajeti celotno vsebino. Morda je torej dober pripomoček za učenje tik pred posameznim izpitom. Vem tudi, da nas veliko prihaja iz različnih držav.of weeks ago. And that one aims at covering the whole content in a concise way. So maybe it's a good companion for studying right before each exam. And also, I know a lot of us are international people.
- u31 Če ne najdete prevoda v svoj jezik, se oglasite pri naju. Z veseljem bi sodelovala z vami. Trenutno je na voljo, mislim, v 15 jezikih, vključno z angleščino. Z veseljem bi videl še več jezikov. Super.In case you don't see your language being translated, feel free to come to us. We'd love to partner with you. So right now, it's available in, I believe, 15 languages, including English. So yeah, I'd love to see more languages as well. Cool.
- u32 Glede komunikacije: obvestila bomo objavljali na platformi Canvas. Dostopate lahko tudi prek Canvasa. Če pa nama želite kaj vprašati zasebno, lahko odgovoriva tudi prek poštnega seznama, kiIn terms of how we communicate-- so we will post announcements on Canvas. And you can also access it through Canvas. But if you have any questions that you want to ask us in private, we can also answer through the mailing list that
- u33 je na prosojnici, skupaj z najinima e-poštnima naslovoma na Stanfordu. Mislim, da sem z organizacijo končal. Je kakšno vprašanje? Je strašljivo?is on the slide, along with our Stanford emails. I think I'm done for the logistics. Is there any question? Is it scary?
- u34 Ker smo imeli samo eno vprašanje. Samo zanima me, ali vas še kaj skrbi. Je vse jasno, povsem jasno? Ja. Vprašanje je, ali bomo videli, kako se to povezuje s prakso v industriji. Odgovor je da.Because we had only one question. Just wondering if there's any that you may worry. Is everything clear, super clear? Yeah. So the question is, will we see how this ties back to what is practiced in the industry? The answer is yes.
- u35 Ena od stvari, ki jih bomo obravnavali, zlasti v drugem delu predmeta, je uporaba LLM-jev v različnih okoliščinah. Samo kot zanimivost: spomnim se, da so lani med izvajanjem predmeta objavili nekaj novosti. Zato sva vsebino sproti posodabljala.So one of the things we'll be seeing, especially in the second part of this class is how we can apply those LLMs in different settings. And so just as an anecdote, so last year, I remember there were some things that came up that were released as we were teaching the class. And so we updated the content as we went.
- u36 Prepričan sem, da bova enako naredila tudi tokrat. Odgovor je torej da. Ja. Vprašanje je, kaj priporočava za pripravo, glede na to, da ni domačih nalog in da vmesni in zaključni izpit štejeta vsak polovico. Odvisno je od tega, kako se običajno učite, a mislim, da je najboljše redno učenje.So I'm sure we'll do the same thing this cycle as well. So yeah, the answer is yes. Yeah. So the question is, what is the recommendation for preparation given that there is no homework, and then it's 50-50 midterm-final? I would say depending on how you usually study, I think, just studying regularly, I think, works best.
- u37 Najpomembneje je, da ste med predavanjem pozorni na stvari, ki jih obravnavamo. V učbeniku so lahko teme, ki jih ne bomo obravnavali, in teh na nobenem izpitu ne pričakujemo. Grobo rečeno se lahko na izpitu pojavi vse, kar povemo.I would say just paying attention to things that we're covering in the class, during the class, I think, is most important. So there may be topics that are in the textbook that we're not covering, and I would say those are not expected in either exams. So roughly speaking, anything we say can be in the exam.
- u38 Vprašanje je, ali imamo naloge za vajo. Da. Lani sva rekla ne. Zdaj pa da, imate tiste iz leta 2025. Vprašanja bodo sicer drugačna. Prav, odlično. Na voljo imamo samo dve uri oziroma eno uroSo question is, do you have any practice problems? So yes. So last year, we said no. But now yes, you have the 2025 ones. So yeah. But the questions will be different. So yeah. OK, great. So one thing is we only have two hours or one hour
- u39 in 15 minut na teden. Tako niti približno ne bomo imeli časa obravnavati vsega. Zato bo na vsaki prosojnici, o kateri bomo govorili, vedno — oziroma večinoma — čisto spodaj naveden vir, kiand 15 minutes per week. So we will have nowhere near the time to cover everything. So one thing that we'll be seeing in each of the slides that we'll be talking over is always-- I mean, most of the time-- a source at the very bottom of the slides that
- u40 ga lahko preverite, če vas zanima več podrobnosti. Če vas zanima tema, ki smo jo morda obravnavali le nekaj minut, pa bi radi izvedeli več, poglejte prosojnice. Super. Še nekaj: ko sem se pred nekaj leti začel ukvarjati s področjem obdelave naravnega jezika, NLP,is meant for you to check in case you're interested to learn more details. So feel free to refer to the slides in case you're interested in a topic that maybe we've covered for a few minutes, but you want to learn more. Cool. Another thing-- I mean, something that I personally have felt when I first started in the NLP field
- u41 sem osebno občutil, da je povsod ogromno kratic. To je lahko zastrašujoče. Upava, da boste, če vas te kratice danes preplavljajo, do konca predmeta imeli v glavi povezave med kraticami ina few years ago, there are so many abbreviations all over the place. And it can be intimidating. So our hope is that in case you're feeling overwhelmed today by these abbreviations, that by the end of this class, you'll have a mental mapping of which abbreviations correspond to what
- u42 pojmi, ki jih označujejo. To je najin cilj.concepts. So there is our goal.
- u43 ČasovnicaTimeline
- u44 Začeli bomo z vprašanjem, kako smo prišli do sem. Pred 10–15 leti, v desetih letih tega stoletja, je bilo področje, kot se spomnim, povsem drugačno.And with that, we're going to start by asking ourselves how we got here. So 10-15 years ago, in the 2010's, so I remember, the field was completely different.
12:42 · CME 295 Transformers & Large Language Models course title slide · A Stanford University title slide for CME 295, "Transformers & Large Language Models", with the Stanford logo and ICME branding on a white left half. The maroon right half lists the lecture outline, with "Introduction" highlighted as the current section. A small inset in the top right corner shows a person standing in a lecture room. - u45 Nismo imeli enega modela, ki bi počel vse. Običajno smo imeli en model za vsak primer uporabe. Na področju so prevladovale RNN, povratne nevronske mreže, ki si jih bomo pri tem predavanju na kratko ogledali. Imeli smo modele za posamezne primere uporabe,We didn't have one model that did everything. We had typically one model per use case. So the kind of model that was dominating the field was RNNs, Recurrent Neural Networks, which we'll briefly see in this lecture. And you had these use case specific models,
- u46 na primer za analizo sentimenta. Sprašujete se torej, ali je stavek oziroma ocena pozitivna, negativna ali nevtralna. Če ste želeli prevesti besedilo, ste imeli za to namenski model. Če ste v besedilu želeli prepoznati imena, kraje in podobno, ste imeli tudi za to namenski model.such as for sentiment extraction. So you ask yourself if a sentence, a review is positive, negative, or neutral. If you had a text you wanted to translate, you had a dedicated model for that. And if you had-- I don't know-- text, you wanted to identify names, locations, and so on, you would also have a dedicated model for that.
- u47 Tako je bilo v desetih letih tega stoletja. Uspešnost je bila v redu. Pravi preobrat pa je prineslo leto 2017. Takrat je izšel članek, o katerem bomo danes veliko govorili,So this was in 2010's. Performance was OK. But the thing that really made a true difference that was a turning point was 2017. So 2017, there's a paper that came out, that we're going to talk about at length today,
13:56 · Lecture slide: "Attention Is All You Need" paper, 2017 · A Stanford ICME lecture slide shows the title page and abstract of the 2017 Transformer paper by Vaswani et al. A vertical timeline on the left marks the 2010s and the year 2017. A small inset at top right shows a lecturer standing in a classroom. - u48 z naslovom »Attention is All You Need«. Predstavil je novo arhitekturo, ki je temeljila na paradigmi, ki se je izkazala za zelo dobro razširljivo. S tem mislim, da če modelu zagotovite več podatkov, več računskih virov in več parametrov,that's called "Attention is All You Need," that introduced a new architecture that relied on a paradigm, that proved to be very scalable. By scalable, I mean, if you give your model more data, more computes, and more parameters,
- u49 dejansko dosežete veliko večje izboljšanje uspešnosti, kot ste ga opažali prej. To bomo danes videli. Ta arhitektura se imenuje transformer. Na desni je prikaz, kako je predstavljena v izvirnem članku.you're actually able to see performance gains that are far greater compared to what you used to see before. And it's something that we're going to see today. So this architecture is called the transformer. And on the right, you have an illustration of how it's illustrated in the original paper.
- u50 Ogledali si bomo, kako deluje. Nato so ljudje to arhitekturo povečevali tako po velikosti modela kot po številu žetonov, na katerih so jo učili. Tako so se pojavili sodobni LLM-ji,We're going to see how it works. And from there, people have taken this architecture and just scaled it from a model size perspective but also from the number of tokens it's been trained on. And this is how modern-day LLMs have come into the picture,
- u51 LLM-ji, ki dejansko znajo — oziroma precej dobro tvorijo besedila in programsko kodo. Leta 2022 je izšel ChatGPT. Novembra, mislim, kot se spomnim. Ja. To je bila spet prelomnica,lLMs that actually know-- I mean, that actually generate texts pretty well, that generate code pretty well. And in particular, in 2022, ChatGPT got released. So I remember in November, I believe. Yeah. And again, it was a turning point
- u52 predvsem z vidika izdelka, ker ljudje pred tem niso bili zares vajeni interakcije s pogovornim robotom. Mislim, da je bila ta izdaja res prvi stik ljudi s tem vidikom. In mislim, da niti oseba oziroma podjetje, ki ga je predstavilo, verjetno nifrom more of a product perspective because before that date, people were not really used to interacting with the chatbot. So I believe that release was really the first time that people got introduced to that aspect. And I think even the person or the company who launched it probably didn't even
- u53 vedelo, kako veliko bo to postalo. To predvidevam zato, ker so imeli v tvitih ob izdaji modela, mislim, tipkarsko napako. To se mi zdi smešno, ker danes ob vsaki izdaji modela besedilo desetkrat pregledajo.realize how big it would get. I mean, I'm assuming because in their tweets that released the model, I believe they had a typo, which I find funny because nowadays, whenever there is a model release, there is 10 times review of what the wording is.
15:52 · Launch of ChatGPT, the "conversational" era, with Sam Altman tweets · A Stanford ICME lecture slide with a vertical timeline (2010s, 2017, 2022, with 2022 highlighted) next to Sam Altman's Nov 30, 2022 tweet announcing ChatGPT. On the right, four follow-up tweets describe language interfaces and assistants. The last tweet, circled in red, corrects a typo ("god" should be "got"). A small inset video shows the speaker standing at the top right. - u54 Predvidevam torej, da pri tej objavi ni bilo tako. Ampak ja, to je še ena prelomnica. In zdaj smo tu, leta 2026. Predvidevam, da vas veliko ali kar vsi skoraj vsak dan uporabljate programerske agente.So I'm assuming that this was not the case for the announcement here. But yeah. So that is also another turning point. And then here we are, 2026. I'm assuming a lot of you or all of you are interacting with coding agents almost on a daily basis.
- u55 Ogledali si bomo, kako smo prišli do te stopnje, kako smo od pogovornega LLM-ja oziroma pomočnika prišli do dejansko agentskega vedenja. To bomo obravnavali zlasti v drugem delu predmeta. Je za zdaj vse jasno?So we're going to see how we got to that stage, how we went from a conversational LLM, conversational assistant, to actually agentic behavior. So we're going to see that, especially in the second part of this class. So far so good?
- u56 Super. Zdaj bomo začeliCool. So with that, we're going to start
16:56 · Lecture slide "Agentic era!" showing AI coding tools · A still from a Stanford lecture video shows a man in a maroon T-shirt standing in a classroom, looking at a projected slide titled "Agentic era!". The slide has a timeline running from the 2010s through 2017 and 2022 to "Now". It lists four agentic coding tools: Anthropic's Claude Code, Cursor, OpenAI's Codex and Google's Antigravity. - u57 TokenizacijaTokenization
- u58 z enim temeljnim pojmom, tokenizacijo. Kaj je torej tokenizacija? Besedilo ni nekaj, kar bi modeli zares razumeli. Modeli razumejo števila.with one foundational concept, which is tokenization. So what is tokenization? So when we talk about text, text is not really something that models can understand. Models understand numbers.
- u59 Besedila ne razumejo. Prvi cilj je torej najti način, kako besedilo predstaviti v obliki, ki jo modeli razumejo, torej s števili. To naredimo tako, da besedilo najprej poskušamo razdeliti na enote,They don't understand text. So the first goal is to find a way to represent that text in forms of something that models can understand, so in forms of numbers. So the way that we do that is we first try to divide the text into entities
- u60 ki jih nato lahko predstavimo. Proces deljenja besedila na nedeljive enote imenujemo tokenizacija. V tem primeru imamo »Ljubek plišasti medvedek bere.« Ena možna tokenizacija je, da je »Ljubek« enathat we can then represent. And so the process of dividing the text into indivisible entities is what is called tokenization. So in this example, we have "A cute Teddy bear is reading." And one possible tokenization is to say that "A" is one
17:57 · Tokenization of a sentence into tokens · A Stanford lecture slide titled "Tokenization" shows the sentence "A cute teddy bear is reading." with an arrow pointing down to the sentence split into boxed tokens. "teddy bear" is kept as one token. A small inset video shows a presenter standing beside a chalkboard. - u61 nedeljiva enota. »Plišasti« je druga enota. »Medvedek« je lahko še ena enota. In tako naprej. Vsak tak element imenujemo žeton. Naš cilj je te žetone predstavitiindivisible unit. "Cute" is another unit. "Teddy bear" can be another unit. And so on and so forth. So each of these elements is called a token. And our goal is to represent these tokens
- u62 s smiselnimi matematičnimi predstavitvami. V tem primeru želimo vsak žeton predstaviti z vektorjem, vektorjem števil. Da lahko vhodno besedilo tokenizirate, morate vedeti, katere žetonewith mathematical representations that are meaningful. So in this case, we want each token to be represented by a vector, a vector of numbers. So in order for you to tokenize an input text, you need to know, what are the tokens that are
- u63 smemo uporabljati. Imamo nekaj, čemur pravimo besedišče, ki vsebuje vse možne žetone, ki jih lahko uporabite. Glede na izbrano besedišče lahko dobite različno dolga zaporedja. Z dolžino zaporedja tukaj mislimallowed for you to be using? And so we have something that's called a vocabulary which includes all possible tokens that you can use. And depending on the vocabulary that you choose, you may end up with different sequence length. So here, by sequence length, I mean
- u64 število žetonov, na katere ste razdelili besedilo. V tem primeru jih imamo 1, 2, 3, 4, 5, 6, šest žetonov. Kmalu bomo videli, da sta velikost besedišča in dolžina zaporedja tesno povezani, karthe number of tokens, by which you divided your text. So for instance, in this instance, we have 1, 2, 3, 4, 5, 6, six tokens. We're going to see in a second that there is a tight relationship between vocabulary size and sequence length, and that's something that
- u65 bo vplivalo na izbiro tokenizatorja. Je za zdaj jasno? Morda se zdaj sprašujete: vse to je lepo, ampak kako vem, kako naj tokeniziram besedilo? To je teoretični pojem, ampak kako to naredim?will inform which tokenizer we should be choosing. So far, so good? So now, you may be wondering, well, all of that is great, but how do I know how I tokenize my text? This is just a theoretical concept, but how do I do that?
- u66 Eden od naravnih načinov je, da rečete: besedilo bom tokeniziral po besedah. Presledek bom obravnaval kot ločilo med žetoni. Tukaj bi torej rekli »Ljubek plišasti medvedek bere.«So one natural way is for you to say, OK, so I'll just tokenize the texts with respect to words. So I'm going to consider space as being a delimiter between tokens. So here, I would say "A cute Teddy bear is reading."
- u67 Vsaka beseda v tem besedilu bi predstavljala žeton. Katere so prednosti in slabosti tega pristopa? Prednosti: zelo preprosto je, zlasti v angleščini, žeton preslikate v besedo. Je tudi razložljivo, sajSo every word in that text would actually represent a token. So what are the pros and cons of this approach? So pros, very simple, especially for the English language, you map a token to its words, very simple. It is also interpretable, as in you
- u68 veste, da predstavitev besede oziroma žetona ustreza določeni besedi. Toda vsaj v angleščini imamo veliko različic besed.know when you get a representation of a word that it corresponds-- or a representation of a token that it corresponds to a given word. However, at least in English, you have many variations of words.
20:39 · Word-level tokenization: pros and cons · A Stanford ICME lecture slide shows the sentence "A cute teddy bear is reading." split into seven tokens, one per word plus the final period. Below it, a smiley face lists the advantages (simple, interpretable) and a crying face lists the drawbacks (large vocabulary, ignores word roots, out-of-vocabulary risk). A small inset in the corner shows the lecturer standing near a board. - u69 Samostalnik je lahko na primer v ednini ali množini. Lahko imamo moško in žensko obliko. Različic je lahko zelo veliko. Zaradi tega lahko besedišče postane zelo veliko. To je ena slabost.So, for instance, a noun, you can have it as singular and plural. You can have the masculine form, the feminine form. You can have many, many variations. So your vocabulary size may get very large as a result of that. So that's one con.
- u70 Druga slabost, ki jo bomo kmalu videli, je, da pri učenju predstavitve posameznega žetona nič ne zagotavlja, da bosta dva žetona, ki predstavljata isto stvar, dobila enako predstavitev.The second con is, we're going to see in a second, that when we learn the representation of each token, there is nothing that guarantees us that two tokens that represent the same thing would get the same representation.
- u71 Če na primer vzamemo besedi »medved« in »medvedi«, sta to edninska in množinska oblika iste živali, medveda. Ne bi želeli, da sta predstavitvi teh dveh žetonov preveč oddaljeni,So, for instance, if you consider the word "bear" and the word "bears," these are the singular and plural of the same animal, which is a bear. And so you wouldn't want the representation of these two tokens to be too far from one another
- u72 ker predstavljata isto stvar. Pri takšni tokenizaciji pa težko, prvič, izkoristite znanje o podobnem žetonu in, drugič, zagotovite podobnost teh predstavitev.because they represent the same thing. Well, with this way of tokenizing your text, you would have a hard time, first of all, leveraging the knowledge that you have from the similar token, and second, just guaranteeing that these representations are similar.
- u73 Tretja slabost pa je, da se morate naučiti predstavitve vsake besede — ena beseda je en žeton — zato se lahko zgodi, da pri učenju tokenizatorja na določenem korpusuAnd then the third one is, well, given that you need to learn the representation of each of these words-- so one word is one token-- you may run into a case where if you train your tokenizer on a given corpus of text, that you actually
- u74 ne naletite na besedo, ki jo nato srečate med sklepanjem. Lahko vam torej manjkajo predstavitve, ki se jih niste mogli naučiti preprosto zato, ker med učenjem te besede niste srečali.do not have a given word that you then encounter at inference time. So you may actually be missing representations that you could not have had the chance to learn, just because you did not encounter that word at training time.
- u75 Zato obstaja tveganje besed zunaj besedišča, kar pomeni, da žetona med učenjem niste videli in zanj nimate predstavitve. Skratka, tokenizacija na ravni besed je preprosta,And therefore, you can run into the risk of out-of-vocabulary, meaning that a token is actually not something that you have seen at training time, and you don't have the representation for that one. So long story short, word-level tokenization is simple,
- u76 vendar ima nekaj slabosti. Ena je prav to, da ne morete izkoristiti besed s podobnimi koreni. Posledica sta veliko besedišče in tveganje besed zunaj besedišča.but it comes with a few cons. And one of the cons is really the fact that you are not able to leverage words of similar roots. And this leads to vocabulary being large and risk out-of-vocabulary.
- u77 Naslednje vprašanje je: ali lahko naredimo bolje? Obstaja bolj smiseln način tokenizacije? Naravna zamisel bi bila, da besedila ne delite po besedah, ampak po znakih. Imate določeno število dovoljenih znakov, vsajSo the next question is, OK, can we do better? Is there another way of tokenizing the text that could make more sense? So a natural thought could be, well, you don't divide by words, you divide by a character. You have a fixed number of allowed characters, at least
23:37 · Character-level tokenization of a sentence · A Stanford ICME lecture slide shows the sentence "A cute teddy bear is reading." being split by an arrow into individual character tokens. Each letter, space (shown as an underscore) and the final period gets its own box, so the sentence becomes 27 tokens. A small inset shows the lecturer standing at the right. - u78 v angleščini oziroma v kateremkoli jeziku. Tako ni več tveganja besed zunaj besedišča, ker boste v učni množici srečali vse črke abecede oziroma lahko poskusite to zagotoviti. S tem boste imeli tudi majhno besedišče.in English or in any languages. And so you are not running the risk out-of-vocabulary anymore because you will encounter all the letters in the alphabet in your training set, or you can try to do that. And by doing so, you will also have a small vocabulary.
- u79 Poleg tega bi bili odporni proti razlikam med velikimi in malimi črkami ter pravopisnim napakam, ki jih ljudje običajno delajo, ko — ne vem, ali se prepoznate v tem, jaz se. Ko tipkam na računalniku, včasih kaj napišem narobe. Ne bi želel, da bi bila predstavitevAnd you would also be robust to casing and misspellings that people usually make when-- I mean, I'm not sure if you recognize yourself, I do. So when I type-- I don't know-- on my computer, I sometimes misspell things. And I wouldn't want the representation
- u80 besede, ki sem jo nameraval napisati, drugačna od dejanske besede. Tako se ne bi zgodilo, da besede ne prepoznamo zgolj zaradi napačnega zapisa. Toda videli bomo, da je ob tem dolžina zaporedjaof a word I meant to write to be different from the actual word. And so here, we would not be going into the case of not recognizing a word just because it is misspelled. But we will see that if you do that, the sequence length is
- u81 veliko večja. Računska zahtevnost modela pa je odvisna od dolžine zaporedja. Če je zaporedje zelo dolgo, ga bo model dolgo obdeloval. Izračuni bodo torej veliko počasnejši.going to get much longer. And model complexity is a function of sequence length. So the sequence is very long. Then your model will take a long time to process the sequence. So it will make computations much slower.
- u82 Tudi same vektorske vložitve so veliko manj razložljive: če vam povemo, da ima črka A takšno predstavitev, je to morda precej bolj abstraktno kot predstavitev besede. To bomo kmalu videli.And the embeddings themselves, they're much less interpretable as in-- if we tell you the letter A has this representation, it's maybe much more abstract than talking about word representation. And we will see that in a second.
- u83 Je za zdaj razumljivo? Ja. Upam, da sem dovolj dobro utemeljil kompromis, da je vaša naslednja naravna zamisel nekaj vmes: ne besede, ne znaki, ampak deli besed. Kaj če bi torej besedilo tokeniziraliSo far, does that make sense? Yeah. So I hope I am motivating a trade-off enough that the next natural thought in your mind is to actually try something in between, so not word, not character, but in between, so subwords. So how about we tokenize the text
25:53 · Subword-level tokenization of an example sentence · A Stanford lecture slide titled "Tokenization: subword-level" shows the sentence "A cute teddy bear is reading." split into subword tokens by an arrow. Words like "teddy" and "reading" are broken into pieces ("ted" + "##dy", "read" + "##ing"), while the other words stay whole. A small video inset at top right shows a lecturer standing near a board. - u84 z uporabo znanja o besedah, ki se ga lahko naučimo iz učnega korpusa? Izločimo pogoste skupine črk in jih predstavimo z žetonom.by leveraging knowledge that we have about words that we can learn from some training corpus? And we divide common occurrences of letters, and we represent them with a token.
- u85 Na primer, pri »reading« bi »read« predstavili z enim žetonom in »ing« z drugim. Kaj če naredimo tako? Prednost je, da bi izkoristili korene besed. V mojem prejšnjem primeru bi imela »bear« in »bears« na primer skupen žeton »bear«.So for instance, for reading, we would represent "read" with a token and "ing" with another token. So how about we do that? So the good thing here is that we would leverage the root of words. So in my previous example, "bear" and "bears" would have the, for instance, "bear" token in common.
- u86 Druga prednost je, da se tega naučimo iz podatkov: način tokenizacije temelji na dejanskem zapisu besed. Slabost pa je dodatno delo. Pri tokenizaciji po besedah žetone preprosto dobimo z deljenjem po presledkih.And then the second thing is it would be actually learned from the data, as in the way you tokenize text is informed by how words are actually written. But then the con is, well, you need to do that extra work. So in the word-level case, you just need to produce tokens by just dividing based on space.
- u87 Tukaj pa bi — morate opraviti nekaj dodatnega dela. Način pridobivanja žetonov bo močno odvisen od vrste podatkov, ki jih imate pri učenju tokenizatorja. To je torej še ena slabost.So here, you would do-- you need to do some extra work. And then the way you obtain these tokens will be highly dependent on the type of data that you have when you do your tokenizer training. So that's another thing, another con.
- u88 Zagotoviti moramo, da so podatki, s katerimi se učimo tokenizacije, usklajeni s končnim ciljem. Tukaj bi rad nekaj povedal. Govoril sem o treh načinih tokenizacije besedila.So we need to make sure that the data that you use to learn how to tokenize things is actually aligned with your end goal. So I just want to say something here. So I talked about three ways of tokenizing texts.
- u89 Na ravni besed, znakov in delov besed. Med temi tremi je danes zaradi vseh omenjenih razlogov daleč najbolj priljubljena raven delov besed. Pogosto boste slišali kratico BPE. BPE je vrsta tokenizatorja na ravni delov besed,So word level, character level, subword level Among the three, subword level is by far the most popular nowadays, for all the reasons that I mentioned. And you'll hear the word or the acronym BPE a lot. So BPE is a type of subword tokenizer
- u90 ki pomeni Byte Pair Encoding oziroma kodiranje parov bajtov. Povezava do članka je na dnu prosojnice, če želite izvedeti več, jaz pa bom opisal bistvo delovanja. BPE se nauči, kateri žetoni naj bodo v besedišču, tako da začne z začetno množico žetonov,that stands for Byte Pair Encoding. So the paper is linked at the bottom of the slide in case you're interested to learn more, but I'll give you just the gist of how it works. So BPE learns what tokens should be in your vocabulary by starting from an initial set of tokens
- u91 poišče najpogostejše pare v učnih podatkih in uvede namenske žetone, ki združujejo žetona iz teh parov. Dal bom primer.and identifying the most frequent pairs in your training data and by coming up with dedicated tokens for merged tokens of these pairs. So for instance-- I'll give an example.
- u92 Predstavljajte si, da začetno besedišče vsebuje vse črke abecede. Imate recimo besedo »an«, kot v »an idea« ali »an amazing course«. »An« se pojavlja zelo pogosto.Let's imagine your initial vocabulary is all the letters in the alphabet. And you have, I don't know, the word "an," like "an idea," "an amazing course." So "an," that occurs very frequently.
- u93 Tukaj bo torej rekel: »a« in »an« se zelo pogosto pojavljata skupaj. Dodajmo žeton, ki ju združi. Novi žeton bo dodal v besedišče in postopek ponavljal, dokler ne doseže želene končne velikosti besedišča.So here, it will say, OK, "a" and "an" appear very frequently together. So let's actually add a token that merges the two. It will add that new token in the vocabulary, and then repeat the process until reaching a desired final vocabulary size.
- u94 To bo vaše končno besedišče. Lepo je, da se teh žetonov naučimo iz podatkov: stvari, ki se pojavljajo skupaj, prepoznamo in dodamo v besedišče. Tako bo zaporedje krajše. Besedila vam ne bo treba razstavitiAnd that will be your final vocabulary. So the nice thing is that these tokens are learned from the data, so things that appear together are actually identified and added to your vocabulary. So this will lead to your sequence length being shorter. So you will not have to decompose your text
- u95 na toliko žetonov. Model tako ne bo potreboval toliko časa za obdelavo besedila. Od tod učinkovitost. Če imate učni korpus z veliko besedami, ki jih srečujete v praksi, bo zaporedje žetonov,into that many tokens. So your model will not take that much time to process your texts. And so that's where the efficiency comes from. So if you have a training corpus that has, let's say, a lot of the words that you encounter in practice, then the sequence length of the tokens
- u96 ki ga dobite iz besedila z enakimi besedami kot v učnem korpusu, veliko krajše. Če delate z več jeziki, torej poskrbite, da je tokenizator naučenyou will get from a piece of text that uses the same words as what you had in your training corpus, will be much shorter. So in case you're doing multilingual work, then make sure that your tokenizer is trained
- u97 na korpusu, ki predstavlja vse jezike, ki vas zanimajo. To je en primer. Tega je bilo veliko, zato se bom za trenutek ustavil. Imate za zdaj kakšno vprašanje o tem delu? Da.on a corpus that represents all the languages that you're interested in. That's one example. So that was a lot. So I'll just pause for a second. Is there any questions so far on this part? Yes.
- u98 Vprašanje je, kakšna je povezava med BPE in n-gramom. N-gram je pravzaprav nekaj drugega. Ta pa, da, kot pravite, žetone iz korpusa uči z iterativnim združevanjem najpogostejših parov, dokler ne doseže želene končne velikosti besedišča.So the question is, what is the relationship between BPE and n-gram? So n-gram is actually something separate. And this one, yes-- to your point, it will learn the tokens from your corpus by merging the most frequent pairs in an iterative way until reaching a final desired vocabulary size.
- u99 Naslednje naravno vprašanje je: imate žetone, kako pa veste, kako jih predstaviti? Morda se to sprašujete. To bomo videli čez približno pet minut. Več o tem torej kmalu. Pravzaprav gledam na uro. Mislim, da zaostajam, zato bom verjetno nadaljeval.So next natural question is, OK, you have your tokens, then now, how do you know how to represent them? Maybe you're asking yourself this. And we will see that actually in about five minutes. So more on that in a bit. Actually, I'm looking at the time. I don't think I'm on time, so I'll probably move on.
- u100 Če imate vprašanja, me kar prekinite. Tokenizacija je res temelj vsega, kar bomo obravnavali od zdaj naprej. Doslej smo videli žetone, ki predstavljajo besedila, ki jih želimo tokenizirati.But if you have any questions, please feel free to interrupt me. Tokenization is really the building block of everything we'll see from here, so yeah. So far, we've seen tokens that represent texts that we want to tokenize.
- u101 Imamo pa tudi posebne žetone. Namenjeni so predstavljanju stvari, ki jih želimo izraziti v zaporedju. Eden takih je za primer, ko naletimo na izraz ali del besedila, ki ni v našem besedišču.But the truth is we also have some special tokens. And these special tokens are meant to represent things that we want to express in sequence. So one such token is whenever we encounter a term or a piece that is actually not something that is part of our vocabulary.
- u102 Običajno imamo namenski žeton, ki predstavlja ta del besedila zunaj besedišča, imenuje pa se žeton za neznano. To je en poseben žeton. Primer: »Teddy bear«. Predstavljajte si, da to napišem Teddy DI bear.So the convention is to have a dedicated token that represents this out-of-vocabulary piece of text, and it's called the unknown token. So it's one special token. So I give an example, "Teddy bear." Imagine if I write it Teddy DI bear.
- u103 V učnem korpusu pa takega zapisa nikoli nismo videli. Če vaše besedišče sestavljajo samo ti štirje žetoni, torej Teddy, cute, bear in unknown, bo Teddy bear tokeniziran kot žeton za neznano in nato bear.And in the training corpus, we've never seen such a spelling. Then if your vocabulary is only composed of these four tokens, so Teddy, cute, bear, and unknown, then Teddy bear will be tokenized as unknown token, and then bear.
- u104 To je en primer. Druga skupina posebnih žetonov: pogosto morate označiti začetek in konec zaporedja, in videli bomo, kako to naredimo. Imamo dve skupini posebnih žetonov.One example-- Another set of special tokens-- so a lot of the times, you need to indicate when the sequence is starting, when it is ending, and we'll see how we do that. So we have two sets of special tokens.
- u105 Ena je začetek zaporedja, BOS, druga pa konec zaporedja, EOS. Večinoma ju uporabljamo pri tvorjenju besedila. Ko želite na primer začeti tvorjenje, modelu po dogovoru podateOne is beginning of sequence, BOS, and then end of sequence, EOS. Those are mostly used when we want to generate text. So for instance, when you want to start the generation, the convention is to feed your model
- u106 žeton za začetek zaporedja, da svojemu žetonu — svojemu modelu nakažete, da želite tvoriti besedilo. Model bo ob koncu tvorjenja izpisal žeton za konec zaporedja in s tem sporočil, da je končal. Tako se to uporablja.with the beginning of sequence token, just to indicate to your token-- to your model that you want to generate text. Your model will then, at the end of its generation, just output the end of sequence token to just tell you that its generation is finished. So this is how it's used.
33:45 · Special tokens in tokenization: UNK, BOS, EOS · A Stanford ICME lecture slide titled "Special tokens" shows three token boxes: [UNK] (unknown, "out of vocabulary"), [BOS] (beginning of sequence) and [EOS] (end of sequence). [UNK] is greyed out, while [BOS] and [EOS] are highlighted in lavender. The example sentence "What a cute teddy bear!" is below, and a small inset shows the lecturer standing at the right. - u107 »Kako ljubek plišasti medvedek« bi bilo torej na primer: začetek zaporedja, »Kako ljubek plišasti medvedek« in konec zaporedja. Zadnji, ki ga morda srečate, pa je dopolnilni žeton. Namenjen je temu, da imajo zaporedja določeno velikost.So "What a cute Teddy bear" would be beginning of sequence, "What a cute Teddy bear" and end of sequence, as an example. And then the last one that you may encounter is the padding token. And that one is meant to make your sequences be of a certain size.
- u108 To se včasih uporablja zaradi učinkovitosti. Če želite, da so vsa zaporedja enako dolga, ker jih, kot bomo videli, lahko predstavimo z vektorji, matrikami in tenzorji — strojna oprema pa ima rada enake dimenzije — lahko uporabite dopolnjevanje.So this is sometimes used for efficiency perspectives. If you want all your sequences to be of the same length, because we'll see that we can represent that with vectors, matrices, tensors-- and hardware loves things that have the same dimension-- then padding can also be used.
- u109 Toda ta seznam nikakor ni izčrpen in ljudje uporabljajo številne različne dogovore. Takšen zapis BOS, EOS in takšen zapis dopolnjevanja niso univerzalni.But I want to say that this list is by no means exhaustive and that you also have a lot of different conventions that people take. So this way of writing, BOS, EOS, this way of writing padding, it's not universal.
- u110 Naj vas torej ne preseneti, če srečate različice. Danes imamo tudi pomočnike. Imate uporabnika in pomočnika. Tudi to ljudje predstavljajo s posebnimi žetoni. Še enkrat, seznam ni izčrpen.So just don't be surprised if you encounter different variations. And nowadays, you have things like assistants. So you have a user, assistant. And those are other things that people represent with special tokens. So again, this is not an exhaustive list.
- u111 Vedite le, da taki žetoni obstajajo in da naj bi modelu sporočali nekaj o besedilu, kar mora razumeti. Super. Toliko o tokenizaciji.But just know that such tokens exist, and they are meant to convey something about the text that the model should understand. Cool. That's it for tokenization.
- u112 Kakšno vprašanje? Da. Vprašanje je, kakšen je danes velikostni red besedišča pri LLM-jih. Odlično vprašanje. Gre za stotisoče. Videli boste torej nekaj v velikostnem redu stotisočev, 200.000, nekaj takega.Any questions? Yes. The question is, what is the order of magnitude of the vocabulary size for LLMs right now? So it's a great question. It is on the order of hundreds of thousands. So you will see something like hundreds of thousands, 200,000, something like this.
- u113 Ti tokenizatorji znajo obravnavati angleščino pa tudi druge jezike. Kot sem omenil, je danes najpogostejši tokenizator BPE. To si je torej dobro zapomniti. Ja.And these are tokenizers that are able to handle both English but also other languages. And as I mentioned, the most common type of tokenizer nowadays is the BPE one. So yeah, so these are the things that are good to have in mind. Yeah.
- u114 Vprašanje je, ali tokenizator zaradi podpore več jezikom postane nekoliko manj strokoven za posamezen jezik. Mislim, da je težko reči, ker so med jeziki lahko sinergije. Na splošno je torej težko reči.So the question is, having multiple languages be handled by your tokenizer, does that make your tokenizer a bit less of an expert in a given language? I think it is hard to say, I would say, because there may be some synergies between languages. So I would say it's hard to say in general.
- u115 Vendar pa se bo besedišče, katerega velikost določite ob izvajanju algoritma BPE, zapolnilo z žetoni različnih jezikov. Zato lahko dobite besedišče, ki vodi do daljših zaporedij, če vas zanima samo en jezik.But that being said, the vocabulary size that you fix when you run your BPE algorithm will be filled with tokens from different languages. So you may get a vocabulary that may lead you to longer sequence length if you're only interested in one particular language.
- u116 Z vidika učinkovitosti se torej morda kaj pozna. Z vidika predstavitev pa ni povsem jasno. Primer so kratice organizacij, o katerih ljudje morda govorijo v številnih jezikih.So from an efficiency perspective, maybe you'll see something. But then from a representation perspective, it's not super clear. So one example is acronyms of organizations that maybe something that people talk about in a bunch of languages.
- u117 Morda vam torej koristi učenje te predstavitve iz različnih besedil v različnih jezikih. So prednosti in slabosti. Odlično. Super.So you may benefit from learning that representation from different texts of different languages, so pros and cons. Great. Cool.
- u118 Word2vec (CBOW, Skip-gram)Word2vec (CBOW, Skip-gram)
- u119 Zdaj torej vemo oziroma smo se naučili, da lahko iz vhodnega besedila ustvarimo žetone ali besedilo predstavimo z žetoni. Naslednje naravno vprašanje je, kako predstaviti te žetone. To si bomo ogledali zdaj.So now, what we know, what we have learned is given an input text, we're able to generate tokens or represent that text with tokens. So the next natural question is how to represent those tokens. So this is what we're going to see now.
37:27 · Stanford CME 295 lecture on Transformers and LLMs · A lecturer in a maroon T-shirt stands in front of a large dark chalkboard in a Stanford classroom, with a projected slide above him. The slide shows the course title "CME 295 Transformers & Large Language Models" and an agenda in which "Word representation" is highlighted, indicating the current section of the lecture. - u120 Najbolj naiven način je reči, da je vsak žeton drugačen. To je skrajno očitno. Žetone pa lahko predstavimo s tako imenovanim kodiranjem one-hot. Recimo, da imam žeton »mehak«. Lahko rečem, da je to vektor (1, 0, 0).So the most naive way to do that is to say that each token is different. So it's extremely obvious. But you can represent your tokens by what we call one-hot encodings. So here, let's say I have the token soft. I can say, OK, it's the 1,0,0 vector.
- u121 Če to naredite za vse žetone, je slabost ta, da bodo pri skalarnem produktu vsi med seboj pravokotni. Je to dobro? Ne.And if you do that for all your tokens, well, the bad thing is they're all going to be orthogonal to each other if you take the dot product. So is it a good thing? No.
- u122 Ni dobro, ker vam nič ne pove o tem, kaj ti žetoni so in kako so povezani. Tega ne želite. Želite jih predstaviti tako, da predstavitev odraža njihovo medsebojno podobnost. To želite.It's not a good thing because it doesn't tell you anything about what these tokens are and how they're related to each other. So it's not what you want. What you want is to represent these tokens in a way that reflects how similar they are to one another. That is what you want.
- u123 Želite na primer, da je »plišasti medvedek« podoben »mehak«, ker so plišasti medvedki mehki, knjiga pa je morda neodvisna. Tega se želite naučiti. Želite se naučiti smiselnih predstavitev. In zakaj si jih sploh želite naučiti?So, for instance, you want "Teddy bear" to be similar to "soft" because Teddy bears are soft, but maybe book to be maybe independent. This is what you want to learn. You want to learn meaningful representations. And by the way, why do you want to learn meaningful representations?
- u124 Ker želite z besedilom nekaj narediti. Potrebujete ga kot vhod v model, da dobite neki izhod, na primer naslednje besede ali napoved razreda. Razumeti morate vsebino besedila, zato si želiteWell, it's because you want to do something with your text. You need to have it as input into your model in order to do something as output-- so for instance, generating the next words, predicting some class. So you need to understand what is in your text, which is the reason why what you want is
- u125 smiselnih predstavitev žetonov. To je poskušala doseči starejša metoda Word2vec. Zamisel je, da se teh predstavitev naučimomeaningful token representations. So this is what an earlier method called Word2vec tried to achieve. So here, the idea is to learn these representations
39:34 · Token representations: one-hot encoding versus learned embedding · A Stanford lecture slide compares naive one-hot encoding of tokens with learned embeddings. In one-hot encoding, "teddy bear", "soft" and "book" lie on orthogonal axes, so all dot products are 0. In a learned embedding, related words such as "teddy bear" and "soft" point in similar directions (inner product ~1), while "book" is nearly orthogonal to "teddy bear" (~0). A small video inset shows the lecturer standing at the upper right. - u126 prek tako imenovane nadomestne naloge. To je naloga, ki se je poskušate naučiti, ni pa vaš končni cilj. Naučiti se je poskušate, da dosežete nekaj drugega. Tukaj je nadomestna naloga na primer napovedovanjethrough what we call a proxy task. So a proxy task is a task that you're trying to learn, but it's not the task that you're trying to learn as an end goal. It is a task that you try to learn in order to achieve something else. And here, the proxy task is something like predicting
- u127 besede med nekaj kontekstnimi besedami — to je različica Word2vec z zvezno vrečo besed — ali napovedovanje besed okoli dane besede. To je različica skip-gram. Ogledali si bomo primer, da bo jasno.the word that is in between some context words-- so this is the continuous bag of words version of Word2vec-- or predicting words that are surrounding a given word. That is the skip-gram version. So we'll go through an example so that it becomes clear.
40:23 · Word2vec overview: CBOW and Skip-gram proxy tasks · A Stanford lecture slide introduces Word2vec as a neural network trained on a proxy task over billions of words to learn an embedding layer. It contrasts two proxy tasks using the sentence "A cute teddy bear is reading": CBOW predicts the middle words from surrounding context, while Skip-gram predicts surrounding words from the center words. A small inset shows the lecturer standing beside a board. - u128 Ali vsi veste, kaj je nevronska mreža? Ja. Prav. Tukaj sem prikazal zelo osnovno nevronsko mrežo. Lahko si jo predstavljate kot množenje vhoda z matriko, s katerim dobimo skrito predstavitev velikosti D, nato pa spet množenje z matriko za vrnitev na velikost V oziroma velikost besedišča.So, does everyone know what a neural network is? Yeah. OK. So I represented a very basic neural network. So you can think of it as an input matrix multiplication to get a hidden representation of size D and then again, matrix multiplication to go back to size V or vocabulary size.
- u129 Predpostavimo, da imamo stavek »A cute Teddy bear is reading.« Zaradi preprostosti predpostavimo, da želite iz besede »a« napovedati »cute«. Predstavljajmo si torej, da je nadomestna nalogaSo let's assume that you have the sentence "A cute Teddy bear is reading." And let's assume, for the sake of simplicity, that your goal is to predict "cute" from the word "a." So let's imagine that your proxy task is
- u130 napovedati naslednjo besedo. Zelo naivna predstavitev »a« je kodiranje one-hot. Predpostavimo, da ima besedišče šest elementov in da je »a« prvi žeton.to predict the next word. So here, "a," you're very naive representation of "a" is the one-hot encoding. So let's assume that you have a vocabulary size of six, and "a" is your first token.
- u131 »A« bi torej predstavili z (1, 0, 0, 0, 0, 0). To podate skozi mrežo. Predstavljajte si množenje matrike s tem vektorjem. Dobili bi skrito stanje velikosti 2, recimo dve števili, 0,2 in 0,9.So you would represent "a" with 1,0,0,0,0,0. You pass it through your network. So think of it as matrix multiplication with this vector. You would have a hidden state of size 2, to assume two numbers, 0.2 and 0.9.
- u132 Nato ga spustite skozi mrežo, torej še eno množenje z matriko. Dobite napovedi, katerih vsota je 1. Za normalizacijo lahko uporabite na primer softmax. Cilj je, da so te verjetnosti čim bližje oznaki, ki jo imate, torej napovedi besedeAnd then you pass it through your network, so again, another matrix multiplication. And then you have predictions that sum to 1. So you can use something like a softmax to normalize them. And your goal is to have these probabilities be as close to the label that you have, which is predicting the word
- u133 »cute«. Predpostavimo, da je »cute« druga beseda v besedišču. Predstavljena je torej z (0, 1, 0, 0, 0). Kot na prosojnici želite, da je 0,4 čim bližje 1. Zamisel je torej funkcija izgube, ki"cute." And so "cute," let's suppose that it's the second word of your vocabulary. So it is represented by 0,1,0,0,0. Your goal is, like on the slide, for the 0.4 to be as close as 1 as possible. So the idea is to have a loss function that
- u134 kaznuje to, da je verjetnost določene besede predaleč od besede, ki jo poskušate napovedati — če poznate izgubo navzkrižne entropije — nato pa posodobi uteži modela, da odražajo želeni rezultat.penalizes the fact of having a probability of a given word being too far from the word that you're trying to predict-- so in case you know the cross-entropy loss-- and then updates the weights of your model in order to reflect what you want.
- u135 Da bo jasno, bom šel skozi vse omenjene količine. Kodiranje one-hot, ki predstavlja žeton, ima velikost besedišča. Skrito stanje oziroma latentna predstavitev ima velikost D. D je parameter, ki ga lahko izberete,So just so that we're clear, I will just walk through all the quantities that we mentioned. So here, the one-hot encoding that represents the token is of the vocabulary size. The hidden state or also called latent representation is of size D. And D is actually a parameter that you can choose,
- u136 in je običajno precej manjši od velikosti besedišča. Napovedane verjetnosti besed: za vsak žeton imate eno verjetnost, zato se morajo ujemati z velikostjo besedišča. Velikost je torej V. Ujema se tudi z velikostjo kodiranja one-hot. Tukaj lahko poskušatetypically much smaller than the vocabulary size. And then the predicted word probabilities-- well, you have a probability per token, so it needs to match the vocabulary size. So it's of size V. And it also matches the size of the one-hot encoding. And this is where you're able to try
- u137 kaznovati odstopanja od besede, ki jo napovedujete. Recimo, da to naredite za »a«, da napoveste »cute«. Enako ponovite za »cute« in »Teddy bear«. Vzamete »cute« in ga predstavite s kodiranjem one-hot.to penalize for deviations from the word that you're trying to predict. So let's assume you do that for "a" trying to predict "cute." You repeat the same thing for "cute" for "Teddy bear." So you go "cute." You represent it with the one-hot encoding.
- u138 Spustite ga skozi mrežo. Dobite latentno predstavitev in spet verjetnosti. Primerjate jih z dejansko oznako za »Teddy bear«. Izračunate izgubo. Posodobite uteži glede na oddaljenost od oznake. To ponavljate skozi celoten korpus.You pass it through your network. You have a latent representation and again, probabilities. You compare that with the actual label that is representing "Teddy bear." Compute the loss. Update the weights given how far you are from the label. And you repeat that through your whole corpus.
- u139 Na koncu so avtorji ugotovili, da je latentna predstavitev, ki se je naučite na sredini mreže, dejansko smiselna: med naučenimi predstavitvami lahko izračunate mereWell, at the end of this, what the authors realize is that the latent representation that you learn in the middle of the network actually is making sense, as in you can compute similarity measures between
- u140 podobnosti. Vidite, da so predstavitve podobnih žetonov res podobne. V tem primeru je plišasti medvedek v odnosu do mehkobe to, kar je perzijska poezija v odnosu do umetnosti. Drug primer: Pariz je v odnosu do Francije to,the learned representations. And you see that representations of similar tokens are actually similar. So in this example, so Teddy bear is soft, what is Persian poetry to art. So another example is Paris is to France,
- u141 kar je Berlin v odnosu do Nemčije. Model se torej nauči teh lepih povezav. Tako dobite smiselne predstavitve besed. Ta metoda se je pojavila, mislim,what Berlin is to Germany. So you have these nice associations that are actually something that the model learns. So that gives you meaningful word representations. So that's a method that appeared, I believe,
- u142 na začetku desetih let tega stoletja. Mislim, da leta 2013, če se prav spomnim. Kdo mi lahko pove, kakšna je omejitev tega pristopa? Videli smo, da so naučene predstavitve besed smiselne.in the early 2010's. I believe it was 2013, if I remember correctly. So who can tell me what is a limitation of this approach? So here, the representation of the words that we learn-- we saw that they end up being meaningful.
- u143 Toda ali ima ta pristop kakšno omejitev? Ja. Eden od odgovorov je, da bi imeli težave, če naletite na nekaj, česar med učenjem niste videli. Da, to drži.But is there a limitation to this approach? Yeah. So one answer is that you would have trouble if you actually are not encountering something that you have seen during your training process. So yes, that is right.
- u144 Mislim, da to pravzaprav velja v večini primerov, ne samo v tem. To je ena omejitev. Je še kakšna — da, še kakšna? Odgovor je, da dimenzija raste z velikostjo besedišča. To je pravzaprav omejitev tokenizatorja,And I think that's right in actually most cases, beyond that case in particular. So that's one. Is there another-- yes, another limitation? So the answer here is the dimension scales up when the vocabulary size gets bigger. So actually, this is a limitation of your tokenizer
- u145 ker tokenizator določa velikost besedišča. Prav imate, da je to omejitev. Vendar ni značilna samo za ta pristop, saj morate vedno najti predstavitev vsakega elementa besedišča. Je torej omejitev, vendar omejitevbecause the tokenizer is the one that determines your vocabulary size. But you're right that this is a limitation. But it's not specific to that approach, as in you will always need to find a representation of each element in your vocabulary. So, I mean, it's a limitation but limitation
- u146 metod na splošno. Da. O, da. Odgovor je, da imajo besede lahko več pomenov. Točno tako. Ena omejitev je, da bo beseda, recimo »ljubek«, v tem stavku in v nekem drugem stavkuin methods in general. Yes. Oh, yes. So the answer is words can have multiple meanings. So exactly. So one limitation here is if the word, let's say "cute," is in this sentence versus in another sentence,
- u147 dobila enako predstavitev. Če prijazno rečete »ljubek plišasti medvedek«, ali pa nekdo sarkastično reče »o, kako ljubko«, lahko za besedo »ljubek« stojijo različni pomeni. Zelo klasičen primer je angleška beseda »bank«,they will both get the same representation. So if you say cute Teddy bear in a nice way versus someone who sarcastically says, oh, how cute, they may mean different things between the word-- behind the word "cute." So I think a very classic example is "bank,"
- u148 ki pomeni rečni breg ali banko, kamor greste. Gre za isto besedo, a drugačen pomen. Težava tega pristopa je, da bi bila predstavitev te besede enaka ne glede na stavek, v katerem je. Odlična pripomba.so river bank versus going to the bank. These are the same words but different meaning. So the problem with this approach is that the representation of this word would actually be the same regardless of the sentence that it is in. So great point.
- u149 Druga omejitev je, da vrstni red besed ni pomemben. Recimo, da rečemo »otrok objema plišastega medvedka« in »plišasti medvedek objema otroka«. Besede so povsem iste, pomenijo pa različne stvari. Pri tem pristopu bi dobili enake vektorske vložitveAnother limitation here is that the word order does not matter. So let's assume we're saying the child is hugging the Teddy bear, and the Teddy bear is hugging the child. These are the exact same words, but they mean different things. We would get the same embeddings with this approach
- u150 v obeh primerih. Vse to so omejitve, zato so to nekaj,in both cases. So these are all limitations, which is the reason why this is something
- u151 RNN, LSTMRNN, LSTM
- u152 kar so ljudje poskušali rešiti na različne načine. Eden od njih so RNN, ki so bile, kot smo že videli, prevladujoča vrsta modelov v desetih letih tega stoletja.that people have tried to resolve through different means. One such means is RNNs, which, as we previously saw, was the type of model that was dominating the models back in the 2010's.
- u153 RNN izračunavajo dodatno količino, ki je tukaj označena z A. Imenuje se tudi skrito stanje in poskuša zajeti pomen doslej videnegaAnd so here, RNNs, what they do is that they actually have an extra quantity that they compute, which here is represented with A. There is also called a hidden state that tries to encapsulate the meaning of the sentence seen
- u154 stavka. Ogledali si bomo primer. Vzemimo isti stavek: »Ljubek plišasti medvedek bere.« Besedo podate v RNN. Poskušala bi napovedati besedo »ljubek«. Nato pa ohrani to, čemurso far. So we're going to see that as an example. So let's assume we go with the same sentence. So a cute Teddy bear is reading. So here, you would actually put the word into the RNN. It would try to predict the word "cute." But then what it will do is keep what
49:13 · Stanford ICME slide: Recurrent Neural Networks (RNNs) beginning diagram · A lecture slide titled "Recurrent Neural Networks (RNNs)" on a maroon header, with the start of a diagram: a small white box labeled "A" with an arrow pointing up into a larger light-blue box. A small inset video in the top right shows a lecturer standing near a chalkboard. Stanford University and ICME branding appear at the bottom. - u155 pravimo skrito stanje, ki kodira pomen doslej videnega zaporedja. To bo vhod za naslednjo napoved. Kot vhod bomo imeli »ljubek« in tudi to skrito stanje, ki bo vplivalo na naslednjo predstavitev,we call a hidden state that encodes the meaning of the sequence seen so far. That will be an input to the next prediction. So we'll have "cute" as an input and then this hidden states as an input as well in order to inform the next representation,
- u156 in tako naprej. Tukaj torej ne upoštevate zgolj vektorskih vložitev posameznih žetonov. Upoštevate tudi vložitev doslej dekodiranega zaporedja. To vam omogoča upoštevanjeand so on and so forth. So here, what you're doing is you're not just considering embeddings of tokens on their own. You're also considering the embedding of the sequence decoded so far. And that allows you to take into a consideration
- u157 vrstnega reda besed v stavku. RNN so se takrat uporabljale za številne naloge. Pri razvrščanju bi na primer obdelovali po en žeton naenkrat in ohranjali sproti spreminjajoče se stanje, kithe order of the words in the sentence. And RNNs are actually models that were used in a bunch of tasks back in the day. So, for instance, for classifications, what you would do is process tokens one at a time and then keep a self-mutating state that
- u158 kodira pomen doslej videnega zaporedja. Pri analizi sentimenta bi poskušalo napovedati sentiment. Pri večrazrednem razvrščanju, če bi na primer želeli določiti, ali je beseda samostalnik ali glagol, pa biencodes the meaning of the sequence seen so far. And it would try to predict, let's say, a sentiment in the sentiment extraction case. In the multi-classification case, for instance, if you wanted to determine if a word was a noun or a verb, then you
- u159 uporabili predstavitve, ki ustrezajo posameznim vhodom in spet upoštevajo skrita stanja, ali pa preprosto tvorjenje. Toda ena omejitev RNN je —would actually leverage the representations corresponding to each input, which again, would take into consideration the hidden states or just generation. But one limitation of RNNs is that--
51:09 · Long Short-Term Memory (LSTM) overview slide with cell diagram · A Stanford lecture slide introducing LSTMs, noting they came from a 1997 paper and use a more structured approach in the cell's hidden state. The "General form" diagram shows an LSTM cell with previous and next cell states c and activations a, four gates (Γf, Γu, Γr, Γo), a candidate state c̃, and input x at time t. A small inset shows the lecturer standing near a board. - u160 Prav. Odlično je bilo, da ste upoštevali vrstni red besed v zaporedju. Težko pa si je zapomnila besede iz oddaljene preteklosti, ker je pomen zaporedja kodiralaOK. It was great you would consider the order at which the words would appear in a sequence. But it would have trouble remembering words that happened far in the past, because what it used to do was to encode the meaning of the sequence
- u161 v en sam vektor, ki se je nenehno spreminjal. Imeli smo torej težavo tako imenovane dolgoročne odvisnosti: če ste dva stavka za nečim, o čemer ste govorili prej,in one single vector that kept on being modified. So you had this issue of what we call long-range dependency, where if you end up two sentences after something that you have talked about prior to that
- u162 bi to težko razbrali zgolj iz trenutnega skritega stanja. To je lahko težava, ko se na primer sklicujete na nekaj iz preteklosti. Lahko rečete: »O, moj plišasti medvedek je tako ljubek.«would have trouble teasing that out just using the hidden state at that point. And that can be problematic, for instance, when you refer to something that happened in the past. So for instance, you can say, oh, my Teddy bear is so cute.
- u163 »Visok je 3 čevlje.« »On« se torej nanaša na nekaj iz preteklosti. Predpostavimo zdaj, da se ta »on« nanaša na nekaj iz oddaljene preteklosti. Potem imamo težavo, ali skrito stanje, ki gaIt is 3 feet tall. So "it" refers to something that is in the past. So now let's assume that "it" I'm using is referring to something that is far in the past. Then we have this problem of actually having the right set of information in the hidden state
- u164 upoštevamo, vsebuje prave informacije. Zato so obstajale različice RNN. Ena se je imenovala LSTM, Long Short-Term Memory oziroma dolgi kratkoročni spomin, in je poskušala rešiti to težavo,that we're considering. So this is the reason why there were some variations of RNNs. One such variation was called LSTM, Long Short-Term Memory, which tried to address this problem,
- u165 tako da ni ohranjala samo skritega stanja, ampak tudi drugo stanje, imenovano stanje celice, ki naj bi informacije prenašalo dlje. Toda tudi take različiceby not only keeping a hidden state but also another state called the cell state that was meant to carry information for longer. But the truth is even such variations
- u166 so imele omejitve in spet isto težavo. Če povzamemo dosedanje načine pridobivanja vektorskih vložitev: videli smo Word2vec, zelo preprost pristophad their limitations, which, again, had the same issue. So if we were to just recap the state of the ways we could obtain our embeddings so far, we saw Word2vec, which is a very simple approach
- u167 za izračun predstavitev besed. Težava pa je, da je predstavitev besede enaka tudi, če je beseda v drugem zaporedju. To je omejitev. Poleg tega, kot smo že omenili,to compute representations of words. But the problem is that if a word is, let's say, in a different sequence, then the representation is the same. So that is a limitation. And also as mentioned previously,
- u168 lahko ista beseda pomeni različne stvari, česar predstavitev prav tako ne izraža. Pri RNN pa težavo vrstnega reda besed rešujemo s skritim stanjem, ki zajema doslej videno zaporedje.the same word can actually mean different things. And so that is also not conveyed. And in the case of RNNs, we are actually addressing the word order problem by having a hidden state that encapsulates the sequence that is seen so far.
- u169 Toda imamo težavo dolgoročnih odvisnosti. Ta izhaja iz globlje težave, imenovane problem izginjajočega gradienta, ki pri povratnem razširjanju uvaja določene omejitve. Še nekaj, česar nismo omenili: pri RNNBut the problem is that we have this long-range dependency problem. That is actually coming from a deeper problem called the vanishing-gradient problem, which is a problem when you want to backpropagate, that just introduces some limitation. And another thing that we have not mentioned, but RNNs,
- u170 je težava, da za vsako napoved naslednjega žetona potrebujete skrito stanje, ki zajema vse, kar ste videli doslej. Zato morate za naslednjo napoved vedno obdelovati žetone enega za drugim.the problem is every time you want to predict the next token, you need to have the hidden state that encapsulates all the things that you have seen so far. So you always have to just go through tokens one at a time in order to make the next prediction.
- u171 Učenje takega modela je zato izjemno počasno. Za tisti čas je dajal dobre rezultate, a ne ravno neverjetnih. Zaradi vseh teh razlogov so v desetih letih tega stoletja ljudjeAnd when it comes to training such a model, it is just extremely slow. And it had great results at the time but not amazing either. So for all of these reasons, in the 2010's, people
- u172 preizkušali različne tehnike. Ena od njih je res izstopala, zdaj,tried different techniques. And there is one technique that really stood out now
- u173 PozornostAttention
- u174 ko gledamo nazaj, in imenuje se pozornost. Zamisel je naslednja. Namesto da se za zajetje pomena doslej videnega zaporedja zanašamo samo na skrito stanje, modelu omogočimo neposredne povezave z žetoni,from hindsight, but that is called attention. And the idea is as follows. Instead of solely relying on the hidden state to encapsulate the meaning of the sequence that you have seen so far, the idea is to let your model have direct connections from tokens
- u175 ki jih je videl v preteklosti. Z drugimi besedami, ne pravimo, naj se glede tega, kaj se je zgodilo prej, zanaša samo na skrito stanje. Pravimo, da ima lahko za napoved naslednjega žetona tudi neposredne povezave z že videnimi žetoni.that you have seen in the past. So in other words, we're not saying only rely on the hidden state to know what has happened in the past. We're saying you can also have direct connections to tokens that you have seen in the past in order to predict the next token.
- u176 Pri prevajanju na primer predpostavimo, da želite v francoščino prevesti »Ljubek plišasti medvedek bere.« Predpostavimo, da rečete — [GOVORI FRANCOSKO] In želite napovedati naslednjo besedo. Intuitivno bi bilo za to odlično vedeti, katero besedoSo in the translation example, so let's assume you want to translate in French, "A cute Teddy bear is reading." And let's assume you say-- [SPEAKING FRENCH] And you want to predict the next word. So intuitively, in order to predict the next word, it would be amazing to know what the word that you
- u177 želite prevesti. Pri tradicionalni RNN do te besede ne bi imeli neposrednega dostopa. Dostopali bi lahko samo prek skritega stanja. Tukaj pa želimo neposredno povezavo s prejšnjimi žetoni in modelu prepustiti, da se nauči, kateri so pomembni.want to translate is. So in the traditional RNN case, you would not have access to that-- direct access to that word. You would only have access to it via the hidden state. So here, the idea is to have a direct connection to previous tokens and let the model learn which ones matter.
- u178 Pri napovedovanju se nato opre na pomembne žetone. To je koncept pozornosti. Pozornost pomeni, da modelu omogočite neposredne povezave od določenega žetonaAnd here, for the prediction, to rely on the ones that matter in order to make the prediction. So this is the concept of attention. The concept of attention is letting your model draw direct connections from a given token
- u179 do nekaterih preteklih žetonov.to some tokens in the past.
- u180 Mehanizem samopozornostiSelf-attention mechanism
- u181 Ta pojem je zelo pomemben, ker je temelj tega, kar si bomo ogledali zdaj. Prej sem omenil članek »Attention is All You Need«, ki je izšel leta 2017.And this concept is very important because it is at the foundation of what we're going to see now. So I mentioned previously that there was this paper called "Attention is All You Need" that came out in 2017.
- u182 To je bila prelomnica, ker so ljudje videli, da omogoča zelo dobro povečevanje obsega in daje izjemne rezultate. Članek temelji na samopozornosti, ki je nekakšna pozornost na steroidih. Natančno si bomo ogledali, kaj s tem mislimo.That was a turning point because people saw that it was very scalable. It was giving you amazing results. Well, this paper relies on the concept of the self-attention, which is attention but on steroids. And we'll go through exactly what we mean by that.
- u183 Recimo, da imamo zaporedje »Ljubek plišasti medvedek bere.« Zdaj ne pravimo več, da bomo predstavitev dane besede izračunali kot funkcijo skritega stanja, ki zajema pomen dosedanjega zaporedja, in besede same.So let's assume you have the sequence "A cute Teddy bear is reading." So now the idea is to not say that we're going to compute the representation of a given word as a function of the hidden state that encapsulates the meaning of the sequence so far and the word itself.
- u184 Tega ne pravimo. Zdaj pravimo, da lahko predstavitev določenega žetona izračunamo tako, da jo izrazimo kot funkcijo vseh drugih žetonov v tem zaporedju. Prosim?We're not saying that. Now what we're saying is that in order to compute the representation of a given token, we can actually do that by expressing that representation as a function of all the other tokens in that sequence. Sorry?
- u185 Mislim, da ste izpostavili pomembno vprašanje: kako veste, kakšen je vrstni red besed, če pustite, da vse medsebojno delujejo z vsemi, če je bilo to vaše vprašanje. Če torej pustite, da žeton deluje z vsemi drugimi žetoni, dejansko izgubite pojem vrstnega reda besed.So I think you raise an important point, which is, how do you know the order of words if you just let everyone interact to everyone, in case that was your question. So if you let a token interact with all other tokens, you actually lose the concept of word order.
- u186 To je pravzaprav nekaj, kar obravnavamo pozneje. Torej si bomo ogledali prav ta del. Tukaj pa dejansko ne veste, kje so žetoni, ker imate neposredno povezavo. V tej povsem osnovni predstavitvi ne veste, kje so žetoni. Zato bomo pogledali, kako točno odpraviti to težavo.And it is actually something that is addressed later on. So we're going to exactly see that part. But here, you actually do not know where tokens are because you have a direct connection. In this very vanilla representation, you don't know where tokens are. So we're going to see exactly how you fix that issue.
- u187 Ampak ali je zamisel smiselna? Zamisel, da želite predstavitev žetona izračunati tako, da jo izrazite kot funkcijo vseh drugih žetonov v zaporedju, ali je ta zamisel smiselna? Približno?But does the idea make sense? The idea that in order to compute a representation of a token, you actually want to express that as a function of all the other tokens in the sequence, does this idea make sense? Roughly?
- u188 Ja, to bom razumel kot pritrditev. Torej bomo šli skozi primere. Shervine ima pozneje tudi podroben primer. Upam, da bo potem nekoliko bolj jasno. Obstaja nabor oznak, ki jih ljudje uporabljajo in ki jih bomoYeah, I'll take that as a yes. So we're going to go through examples. And actually, Shervine has a detailed example later on. So hopefully that will make a bit more sense. There is a set of notations that people use that we're
59:54 · Attention mechanism: concept of Query, Key, Value · A Stanford lecture slide titled "Attention mechanism" introduces the concept of Query, Key, Value. The sentence "a cute teddy bear is reading ." is shown as separate word boxes, with "teddy bear" highlighted in a dark dotted box and the other tokens greyed out. A small inset in the top right shows the lecturer standing in front of a blackboard. - u189 Poizvedba, ključ, vrednostQuery, key, value
- u190 zdaj uvedli. Te oznake so poizvedbe, ključi in vrednosti, Q, K in V. Poizvedba je torej entiteta, ki poskuša ugotoviti, o čem govori določen žeton.going to introduce now. So these notations are queries, keys, and values, Q, K, and V. So the query is the entity that is trying to determine what a given token is about.
- u191 Zamisel je, da želi najti žetone, ki so uporabni za sestavljanje smiselne predstavitve žetona, za katerega je odgovorna. Poizvedba za plišastega medvedka torej poskuša najti druge žetone, ki so pomembniAnd the idea is it wants to find tokens that are useful in order to construct a meaningful representation of the token that it is responsible for. So the query for Teddy bear, what it tries to do is to find other tokens that is relevant
- u192 za izračun smiselne predstavitve tega žetona. Zato bo pogledala, kako podobna je ta količina ključem zaporedja, ki so povezani z vsakim žetonom v zaporedju.in order to compute a meaningful representation of that token. So what it will do is see how similar that quantity is to keys of the sequence that are associated with each token in the sequence.
- u193 Ko ugotovi, v kolikšni meri je podobna posameznemu žetonu, bomo vsakemu od teh žetonov priredili vrednost. Z drugimi besedami, predstavitev plišastega medvedka želimo izraziti kot funkcijo vseh drugih žetonovAnd once it determines the magnitude at which it is similar to each token, we will associate a value to each of these tokens. So in other words, we want to express the representation of Teddy bear as a function of all the other tokens
- u194 v zaporedju. Zato bomo najprej določili uteži. Gre za uteženo povprečje. Potrebujemo uteži. Uteži določimo glede na to, kako podobna je poizvedba za plišastega medvedka posameznemu ključu. Dejanska vrednost pa bo preprosto vektor vrednosti, ki ustreza posameznemu žetonu.in the sequence. So what we will do is first determine the weights. So it's a weighted average. We want the weights. The weights are determined by how similar the query for Teddy bear is to each key. And then the actual value will be just the value vector corresponding to each token.
- u195 Torej bo nekako tako – če bi to zapisal, je to vsota nečesa, kar predstavlja podobnost. Torej Q in Ki, Vi. To je vaša poizvedba.So it will be something like-- if I were to write it, so it's like the sum of something that is representing the similarity. So Q and Ki, Vi. So this is your query.
1:01:45 · Lecturer standing at empty chalkboard in Stanford classroom · A still from a lecture video shows a person in a maroon t-shirt and khaki pants, seen from behind, standing at a large, mostly blank dark chalkboard. A white vertical line is drawn near the right side of the board. A projector screen at the upper right shows partial "Stanford Univers…" text, and a faint "Stanford" watermark is at lower right. - u196 Z nekimi operacijami podobnosti poskušate ugotoviti, kako podobna je vaša poizvedba vsem drugim ključem. Tukaj je kot primer skalarni produkt. In to povežete. To je torej skalar. To je skalar. In to povežete z Vi, ki je prav tako vektor.You're trying to determine how similar your query is to all the other keys with some similarity operations. So here's the dot product as an example. And you associate that. So this is a scalar. This is a scalar. And you associate that with Vi which is also a vector.
- u197 To se morda zdi nekoliko abstraktno, zato vam bom dal primer. Predpostavimo, da želimo vedeti, kaj najbolje opisuje plišastega medvedka. Poizvedba se lahko vpraša: v redu, kaj najbolje opisuje plišastega medvedka? Pogledate vse žetone. In rečete: o, »ljubek« pravzaprav kar dobro opisuje plišastega medvedka.So this may seem a little bit abstract, so I'll give you an example. So let's assume we want to know what best describes the Teddy bear. The query can be asking itself, OK, what best describes a Teddy bear? And you look at all the tokens. You're like, oh, "cute" actually describes the Teddy bear pretty well.
- u198 Morda bo torej skalarni produkt med ljubek, plišasti medvedek in K ljubek velik. Predpostavimo torej, da bo predstavitev, ki jo izračunate za plišastega medvedka, močno odvisna od »ljubek«. To so torej pojmi poizvedbe, ključa in vrednosti.So maybe the dot product between cute, Teddy bear, and K cute is going to be high. So the representation that you compute for Teddy bear is actually something that will depend heavily on cute, let's assume. So these are the concepts of query key value.
1:03:00 · Lecturer writing a summation formula on a blackboard · A man in a maroon t-shirt stands with his back to the camera, writing on a dark chalkboard in a lecture hall. The board shows part of an equation, a sum over i of an inner product with k_i times v_i, with a brace underneath labeled "scalar". A Stanford University watermark and a projector screen showing "Stanford Univers" are visible. - u199 Naslednje vprašanje je, kako jih dobite. Kako dobite poizvedbe, ključe in vrednosti? To so pravzaprav količine, ki se jih lahko naučite s projekcijskimi matrikami. Na začetku imate neki vhodni žeton,Now the next question is, how do you obtain those? How do you obtain queries key values? So these are actually quantities that you can learn with projection matrices. So you initially have some input token
- u200 ki predstavlja posamezni žeton. To predstavitev vzamete in jo prek projekcijskih matrik preslikate v prostor poizvedb, ključev in vrednosti.that represents each token. And what you do is you take that representation, and you project it on the space of queries, of keys, of values through some projection matrices.
- u201 Nato te količine uporabite za izračun smiselnih predstavitev žetonov. Ja. Odlično vprašanje. Vprašanje je, kaj je T. T je pravzaprav samo zato, da smo matematično natančni. T pomeni transponiranje.And then you use these quantities in order to compute meaningful representations of tokens. Yes. Amazing question. So the question is, what is the T? So T is actually just to be mathematically rigorous. So T is transpose.
- u202 Torej gre samo za to, da lahko to zapišete tudi kot QK transponirano. Še kakšno vprašanje?So it's just that this, you can also write it as QK transpose. Any other question?
- u203 Pozneje imamo podroben primer. Če je to približno razumljivo, je po mojem to odlično. To bomo videli čez trenutek. Izkazalo se je, da je to, kar sem opisal, nekaj, kar lahko zelo lepo – nekaj, kar lahko matematično izrazite z matrikami.So we have a detailed example later. So in case that roughly makes sense, I think that's great. We'll see that in a second. So it just turns out that what I described is something that is very nicely-- something you can express in mathematical terms with matrices.
- u204 Natančneje, operacijo, ki sem jo pravkar omenil, lahko izrazimo kot softmax poizvedbe in ključev. To skalirate z nekim faktorjem in pomnožite z vrednostmi. Pravzaprav imam morda dovolj časa, da vam povem, zakaj.So in particular, the operation I just mentioned is something that can be expressed as the softmax of the query and the keys. And you scale that by some factor times the values. And actually, I maybe have enough time for you to say why.
- u205 Predpostavimo, da imate – softmax je preprosto način, da dosežete, da je vsota koeficientov enaka 1. Približno to počne. Vprašanje pa je: če imate poizvedba ključ transponirano V – mislim, bolj ali manj s softmaxom in skaliranjem,So let's assume you have-- so the softmax is just a way for you to get the sum of the coefficients being equal to 1. So that's roughly what it does. But the question is, well, if you have query key transpose V-- I mean, more or less the softmax and the scaling,
- u206 zakaj vam to da tisto, kar smo videli zgoraj? Predpostavimo, da vaša matrika poizvedb vsebuje vse vaše poizvedbe, torej Q1, Qn. Torej je 1 prvi indeks vašega zaporedja.why does it give you the thing that we saw above? Well, let's assume that your query matrix has all your queries, so Q1, Qn. So 1 is the first index of your sequence.
- u207 Predpostavimo, da na prejšnjih prosojnicah rečemo, da je prvi indeks A. Recimo, da je A enak 1. Pika pa je, predpostavimo, n. Imamo torej poizvedbo za A pa vse do poizvedbe za piko. Enako naredite za K in V.So let's assume in the previous slides that we say the first index is A. Let's say A is 1. And then the dot is n, let's assume. So we have the query for A up until the query for the dot. And you do the same for K and V.
- u208 Če to matriko poizvedb pomnožite s Q transponirano, dobite K1, takole, Kn. In tukaj ste veseli nekaj linearne algebre.So if you multiply this query matrix times Q transpose, what you get is K1, like this, Kn. And so this is where you're glad some linear algebra.
- u209 Torej množenje matrik – naredite to krat to, kar je skalarni produkt Q1 K1. Drugi element pa je Q1 K2. Če to ponavljate, boste dobili matriko QIKJ.So matrix multiplication-- so you do this times this, which is the dot product of Q1 K1. And then second element is Q1 K2. So if you repeat this, you will have the matrix of the QIKJ.
- u210 Morda bom to zapisal tja gor. Zapisal bom točno to, kar je zgoraj. Torej imate –I'm going to maybe write that up up there. So I'm just going to write exactly what is above. So you have--
1:07:20 · Lecture on attention mechanism: query, key, value slide · A lecture hall still shows a man in a maroon shirt reaching up to a chalkboard while a projected Stanford ICME slide titled "Attention mechanism" is displayed. The slide illustrates the query, key, value concept with the sentence "a cute teddy bear is reading ." where the query for "teddy bear" connects to the keys of every word. The chalkboards carry handwritten notes on QK^T and inner products. - u211 Q1 K1. Vse do Q1 Kn. Nato to ponovite tukaj. To postavite sem. To ponovite tukaj. Če zdaj sem dodate V, dobite V1 Vn. Spet torej izvedete množenje matrik.Q1 K1. Up until Q1 Kn. And then you repeat that here. You put that here. You repeat that here. Now if you add a V in here, then what you obtain is V1 Vn. So again, you do your matrix multiplication.
- u212 Tukaj pa dobite – to krat to plus to krat to plus to krat to, vse do sem. Imate torej vsoto Q1 Ki Vi. In enako vse do vsote Qn, Ki, Vi.And here, what you get is-- this times this plus this times this plus this times this, up until here. So you have the sum of Q1 Ki Vi. And the same up until the sum of Qn, Ki, Vi.
- u213 Skratka, želel sem samo povedati, da lahko izražanje nečesa kot funkcije te operacije podobnosti in vrednostiSo long story short, I just wanted to say that the fact of expressing something as a function of this similarity operation and the values is something that you can represent
- u214 zelo dobro predstavite z matrikami. To formulo boste videli precej pogosto. Mislim, da je bilo o tem vprašanje na vmesnem izpitu. Torej namig: ta formula je lahko pomembna.very well with matrices. And you will see this formula quite often. So I believe there was a question on the midterm. So hint, this formula can be important.
- u215 Arhitektura transformerjaTransformer architecture
- u216 Zdaj ko vemo, kako je definirana samopozornost in kako deluje, bomo, upam, v naslednjih 17 minutah pogledali, kako se samopozornost uporablja v arhitekturi transformerja, ki je – ki je arhitektura, predstavljena v članku »AttentionAnd so now that we know how self-attention is defined, how self-attention works, now we're going to, hopefully in the next 17 minutes, see how self-attention is used in the transformer architecture, which is a-- which is the architecture that was introduced in the "Attention
- u217 is All You Need«. Zakaj se torej imenuje »Attention is All You Need«? No, avtorji so takrat, večina modelov je bila rekurentnih. Temeljili so na RNN. Stvari so torej računali rekurentno.is All You Need" paper. So why is it called "Attention is All You Need?" Well, the authors at the time, most models, were recurrent. They were based on RNN. So they used to compute things in a recurrent fashion.
- u218 Tukaj pa pravimo, da nam pravzaprav ni pomembno ohranjati skritega stanja z rekurzivnim prehajanjem skozi žetone. Tega ne počnemo. Namesto tega pustimo, da žetoni delujejo z vsemi žetoni prek neposrednih povezav, oziromaBut here, what we're saying is actually, we don't care about keeping a hidden state by recurring through tokens. We're not doing that. What we're doing instead is letting tokens interact with all tokens through direct connections, a.k.a.
- u219 prek samopozornosti, zato je pozornost vse, kar potrebujete. Ta članek je bil objavljen v kontekstu strojnega prevajanja. V tem kontekstu nas zanima prevajanje izvornega besedila, recimo v angleščini, v drug jezik, recimo v francoščino.through self-attention, which is why attention is all you Need. So this paper was released in the context of machine translation. So in this context, we're interested in translating a source text, let's say in English, over to another language, let's say in French.
- u220 V transformerju imamo dve komponenti. Na levi imamo tako imenovani kodirnik. Vloga kodirnika je izračunati smiselne predstavitve izvornega besedila, ki ga podamo kot vhod.And what we do is we have two components in the transformer. On the left, we have what we call an encoder. And the role of the encoder is to compute meaningful representations for the source text that is fed as input.
- u221 Drugi del transformerja pa se imenuje dekodirnik. Vloga dekodirnika je, da za tvorjenje prevoda uporabi smiselne predstavitve iz kodirnika skupaj z nekaterimi notranjimi vložitvami, ki jih izračunava.And we have a second part of the transformer which is called the decoder. And the role of the decoder is to use the meaningful representations from the encoder along with some internal embeddings that it is computing in order to generate the translation.
- u222 To je torej kontekst, v katerem je bil transformer predstavljen, in deloval je odlično. Je tudi temelj sodobnih velikih jezikovnih modelov, zato se osredotočamo nanj. Zato smo torej tukaj. Razlog, da sem te formule zapisal na tablo,So that is the context in which the transformer was released, and it performed great. And it is at the foundation of modern-day LLMs, which is the reason why we're focusing on this. So that's the reason why we're here. The reason why I wrote these formulas on the Blackboard
- u223 je, da je to po mojem verjetno najpomembnejša formula pri transformerjih. Zato je zelo pomembno, da si to predstavljate v smislu množenja matrik.is because I think this is probably the most important formula when it comes to transformers. So just visualizing this in terms of matrix multiplies is very important.
- u224 VhodInput
- u225 Zdaj bomo šli skozi vsako komponento transformerja in pogledali, kako se vse skupaj poveže. In gledam vas glede položajnih vložitev. O tem bomo govorili zdaj. Pri strojnem prevajanju kot vhod dobite besedilo v izvornem jeziku.So what we will do now is walk through each component of the transformer and see how this all comes together. And I'm looking at you with respect to the position embeddings. We're going to talk about this now. So for machine translation, what you get as input is a text in a source language.
- u226 Vaša naloga pa je prevesti ta izvorni jezik, to besedilo v izvornem jeziku, v ciljni jezik. Vaša prva naloga je torej razumeti, o čem govori izvorno besedilo. Tukaj imate vhodno vložitev,And your task is to translate that source language, that text in the source language into a target language. So your first task is to understand what your source text is about. So here, you have an input embedding
- u227 katere naloga je samo pretvoriti vhodno besedilo v žetone in nato vsakemu od teh žetonov prirediti neko vložitev, ki se je lahko naučite. Ta vložitev se nanaša samo na posamezni žeton. Nikakor ne upošteva konteksta.that is tasked with just converting this input text into tokens and then associating each of these tokens with some embedding that you can learn. This embedding is only with respect to each token. It is not context aware in any way.
- u228 Nato dodate vložitev, povezano s položajem žetona v zaporedju. In tukaj izvemo, kje se žetoni nahajajo. Torej seštejemo vložitev žetona in položajnoAnd what you do is you add an embedding that is associated with the position that the token is in the sequence. And this is where we know where tokens are located. So we add the token embedding and the position
1:13:24 · Positional encoding in the Transformer architecture (Stanford lecture slide) · A lecture slide titled "...with a trick!" explains positional encoding: position information is added to the inputs and can be learned or hardcoded. On the left is the faded Transformer architecture diagram with the positional encoding blocks highlighted at the encoder and decoder inputs. On the right are two heatmaps: a sinusoidal position-by-dimension pattern ranging from -1 to +1, and a position-by-position dot-product map with a strong diagonal. - u229 vložitev. Morda se sprašujete, kako dobimo položajno vložitev. Obstajajo različni načini. Načini, ki so jih ljudje – denimo avtorji – preizkusili, so pravzaprav dva. Eden je, da se vložitve naučimo.embedding together. And so the question you may have is, well, how do you obtain the position embedding? So you have different ways. The ways people-- like the authors have tried is actually two ways. One way is to learn the embedding.
- u230 Drugi način je, da imamo nekaj, kar je funkcija različnih frekvenc. Obstajajo prednosti in slabosti. Ampak želel bi samo – mislim, da je pristop z učenjem zelo naraven. Jasna slabost pa je, če imate vhodno besedilo, ki je daljšeThe second way is to actually have something that is a function of just different frequencies. So there are some pros and cons. But I just want to-- so I think the learning way is very natural. But a clear con is if you have an input text that is longer
- u231 od tistega, na katerem ste se učili med učenjem – če imate recimo 1.000 vhodnih žetonov, vendar ste se že – naučili ste se samo položajev, torej vložitev položajev, do recimo 500, potem nimate sreče. Višjih položajev ne morete predstaviti, zato je lahko poljubna, vnaprej določena predstavitevthan what you have learned at training time-- so if you have, let's say 1,000 tokens as input but you already-- you only have learned positions, like embeddings for positions, up to, let's say 500, then you're out of luck. You cannot represent positions greater than that, which is why the arbitrary, predefined representation can be
- u232 uporabna. Želim samo ponazoriti, zakaj je izbira različnih frekvenc lahko dober način za predstavitev nečesa, kot je položaj. Morda imate uro in opazite, da čas predstavljate z,useful. And I just want to illustrate why choosing different frequencies could be a good way to represent something like the position. So you may have a watch, and you may notice that you represent the time with,
- u233 recimo, tisto zadevo za ure, z minutami, sekundami. Vse se vrtijo z različnimi frekvencami. Če želite odčitati čas, recimo 4.49. Je 4, kar kaže urni del. Nato imate minute in nato sekunde.let's say an hour thingy, with the minutes, seconds. They all turn at different frequencies. So if you want to read the time, so for 4:49. It's 4, which is the hour piece. And then you have the minutes, and then you have the seconds.
- u234 Vsak od njih se vrti z drugačno frekvenco. Če jih združite, lahko natančno veste, koliko je ura. To je torej zamisel v ozadju vektorja elementov, ki se spreminjajo z različnimi frekvencami. To lahko dobite s funkcijama kosinus in sinus.And each of them they turn at different frequencies. And if you put them together, you can exactly know what time it is. So this is the idea behind having a vector of elements that vary with different frequencies. So you can obtain that with cosine and sine functions.
- u235 In to uporabljajo tukaj. Dobra lastnost teh predstavitev je, da so položaji, ki so blizu skupaj, zelo podobni. Tisti, ki so daleč narazen, pa so različni. To je torej ena lepa lastnost.And this is what people use here. So the good thing with these representations is that positions that are close to one another are very similar. And the ones that are far from one another are dissimilar. So this is one nice property.
- u236 To je en način predstavljanja položajev. Kakorkoli, morda preveč zahajam s teme. O položaju bomo več govorili naslednjič. Skratka, žetone lahko predstavimo skupaj z njihovimi položaji. Na tej stopnji smo torej sešteli vložitev žetona in položajno vložitev.So this is one way of representing the positions. Anyway, maybe I digress too much. We're going to talk more about position next time. But long story short, we can represent tokens along with their positions. So at this stage, what we did was add the token embedding and the position embedding.
- u237 Kodirnik transformerjaTransformer Encoder
- u238 Tukaj vstopimo v kodirnik. Kodirnik je komponenta transformerja, katere naloga je izračunati smiselne predstavitve žetonov. Tukaj imamo zelo pomembno vrsto plasti, imenovano plast pozornosti.And here, we come into the encoder. So the encoder is the component of the transformer which is tasked with computing meaningful representations of the tokens. So here, we have one very important type of layer called the attention layer.
1:16:27 · Transformer Encoder components and parameters (Stanford ICME lecture slide) · A lecture slide titled "Encoder" shows the Transformer architecture diagram from "Attention Is All You Need" with the encoder stack highlighted and the decoder faded. On the right it lists the encoder's components and the hyperparameters that define it. A small video inset in the top right shows a presenter standing by a chalkboard. - u239 Pravzaprav se imenuje plast samopozornosti. Kaj počne plast samopozornosti? Izračunava predstavitve žetonov kot funkcijo vseh drugih žetonov. In tukaj se zgodi ta stvar s poizvedbo, ključem in vrednostjo. To boste videli v primeru,It's actually called a self-attention layer. So a self-attention layer, what does it do? What it does is computes representations of tokens as a function of all other tokens. And this is where this query key value thing happens. So you're going to see that in the example
- u240 skozi katerega vas bo vodil Shervine. Zamisel pa je, da se naučimo projekcijskih matrik, s katerimi lahko žetone preslikamo v prostor poizvedb, ključev in vrednosti, kar jim nato omogoči medsebojno delovanje prek formule, ki smo jo videli.that Shervine will walk you through. But the idea is to learn projection matrices that will allow you to project your tokens into a space of queries, keys, and values, that will then allow them to interact through the formula that we saw.
- u241 To vam omogoča, da svoje žetone predstavite kot funkcijo drugih. Nato imate še drugo plast, imenovano nevronska mreža s prehodom naprej, ki vaši arhitekturi omogoča preslikavo predstavitev v višjedimenzionalne prostore, skupaj z neko aktivacijskoSo that allows you to represent your tokens as a function of others. And then you have another layer called the feedforward neural network, which is a way for your architecture to project representations into spaces of higher dimension, along with some activation
- u242 funkcijo, ki omogoča učenje nelinearnosti. Torej greste skozi kodirnik. Na koncu kodirnika dobite zelo smiselno predstavitev za vsak žeton. Ta je funkcija vseh drugih žetonov v zaporedju. Ko torej zdaj želite prevesti besedilo,function, which allows you to learn nonlinearities. So you go through the encoder. At the tip of the encoder, what you get is a very meaningful representation per token. That is a function of all other tokens in the sequence. So what you do is now, when you want to translate the text,
- u243 Dekodirnik transformerjaTransformer Decoder
- u244 vzamete posebni žeton, ki smo ga videli čisto na začetku, konec zaporedja – oprostite, začetek zaporedja. Svojemu modelu torej poveste: zdaj želim začeti generiranje. Začetek zaporedja podate kot vhod v dekodirnik. Dodate položajno kodiranje, kiso you take your special token that we saw in the very beginning, end of sequence-- sorry, beginning of sequence. So you tell your model, well, now I want to start the generation. So you input begin of sequence as an input to the decoder. You add the position encoding that
- u245 je povezano s tem žetonom, ki je prvi element zaporedja. Nato vstopite v dekodirnik, ki počne dve stvari. Prva je, da ima tudi mehanizem samopozornosti glede na sam žeton in vse žetone, kiis associated with that token, which is the first element in the sequence. And what you do is you enter the decoder, which does two things. The first thing is it also has an self-attention mechanism with respect to the token itself and all the tokens that
- u246 so bili ustvarjeni doslej. Vsak žeton torej poskuša izraziti kot funkcijo samega sebe in vseh doslej ustvarjenih žetonov. V primeru začetka zaporedja je to edini žeton, ki je bil doslej ustvarjen. To je to.was generated so far. So it tries to express each token as a function of itself and all the tokens that were generated so far. So in the beginning of sequence case, it's the only token that was generated so far. So that's it.
- u247 Nato imate drugo plast pozornosti, ki je drugačne vrste in kjer predstavitvam doslej ustvarjenih žetonov omogočite medsebojno delovanje z žetoni iz izvora,And then you have a second attention layer, which is a different kind, where you're actually letting the representations from tokens that were generated so far and let them interact with tokens from the source,
- u248 iz vhodnega izvora, iz izvornega jezika. Ne vem, ali na sliki vidite: ena puščica prihaja od tega, kar je bilo ustvarjeno doslej. Nato pa dve puščici prihajata iz kodirnika. Tista ena puščica od doslej ustvarjenega je poizvedba.from your input source, from the source language. So I'm not sure if you can see in the illustration, you have one arrow which is from what was generated so far. And then you have two arrows coming from the encoder. So the one arrow from the generator so far is the query.
- u249 Ključ in vrednost pa prihajata iz kodirnika, ker se sprašujete: kako lahko ta žeton izrazim kot funkcijo vseh žetonov vhodnega besedila? Mimogrede, ali je to smiselno? Ja.And the key and the value are coming from the encoder because you're asking yourself, how can I express this token as a function of all the tokens in the input text? By the way, does that make sense? Yeah.
- u250 V redu, odlično. In potem to naredite. Nato imate še eno plast, imenovano nevronska mreža s prehodom naprej, ki modelu spet omogoča, da se nauči načinov preslikave podatkov. Na koncu dobite zelo smiselno predstavitev besede, žetona, ki ste ga podali kot vhod.OK, great. And then you do that. And then you have another layer that's called the feedforward neural network that again, allows your model to learn ways to project your data. And then at the end, you get a very meaningful representation of the word that the token that you passed as inputs.
- u251 Tukaj imate torej na samem začetku začetek zaporedja. Na koncu dekodirnika pa imate zelo smiselno predstavitev tega žetona. Nato to predstavitev preslikate v prostor besedišča. In dobite verjetnosti, ki ustrezajo temu, kar je po vašem mnenjuSo here, in this case, in the very beginning, you have beginning of sequence. And at the end of the decoder, you have a very meaningful representation of that token. So what you do is you then project that representation on the space of vocabularies. And you get probabilities that correspond to what you think
- u252 naslednji žeton. Prevajanje tukaj torej pomeni samo ugotavljanje, kateri je naslednji žeton. Ugotovite torej, kateri je naslednji žeton. Nato na podlagi verjetnosti izberete ta naslednji žeton. In to ponavljate avtoregresivno.is the next token. And so here, translation is just figuring out what the next token is. So you figure out what the next token is. And then you choose what that next token is based on the probabilities. And then you repeat that in an autoregressive way.
- u253 Ta novi dekodirani žeton torej podate kot vhod dekodirnika. In ponovite natanko to, kar sem omenil. Imamo pet minut. Povedati vam moram še nekaj trikov, vendar se želim prepričati, da vsi sledimo.So you put that new decoded token as input of the decoder. And you repeat exactly what I mentioned. So we have five minutes. I have some tricks to tell you, but I want to make sure we're all on the same page.
- u254 Zato bom zdaj dal besedo vam, če imate do zdaj kakšno vprašanje. Mimogrede, obravnavali smo veliko stvari. To prvo predavanje je glede števila obravnavanih pojmov verjetno eno najtežjih, zato je povsem normalno, če se vam zdi, da smo videli veliko. Kakšno vprašanje o tem?So I'm just going to open the floor in case there is any questions so far. We've seen a lot of things, by the way. And this first lecture is probably one of the most difficult in terms of number of concepts we see, so completely normal if you feel like we've seen a lot. Any questions on this?
- u255 Ja. Vprašanje je torej – več puščic se združujeYep. So the question is-- there are multiple arrows merging
- u256 Računski trikiComputational tricks
- u257 v eno. To je zato, ker tega doslej še nismo videli. To je trik, ki si ga pravzaprav lahko ogledamo zdaj. Morda mislite na tole, rezidualne povezave. To je trik, ki modelu pomaga pri boljšem učenju. Te rezidualne povezave sointo one. So it's because we have not seen it so far. So this is a trick that actually we can see now. So you may be referring to this one, the residual connections. So this is actually a trick to help your model learn better. So these residual connections, they're
- u258 zelo uporabne v globokih arhitekturah, ker modelu omogočajo neposredno posredovanje značilk, namesto da bi jih spreminjala neka podplast. O tem rad razmišljam takole: namesto da bi na vsako plast gledali kot na nekaj, kar spremeni celoten vhod –very useful in architectures that are deep because they allow your model to pass in features directly instead of having them be modified by some sublayer. So one way I like to think about this is instead of thinking about each layer as something that modifies the whole input--
- u259 namesto da bi rekli, da moja plast preprosto spreminja vhod – predpostavimo, da je vaš vhod – predpostavimo, da je vaš vhod x. Namesto da rečete, da je izhod plasti neka funkcija x, pravite,so instead of saying my layer is just changing the input-- so let's assume your input is-- let's assume your input is x. Instead of saying that the output of a layer is some function of x, what you're saying
- u260 da je izhod vaše plasti neka funkcija x plus x. O tem rad razmišljam tako, kot da bi vzeli x in ga prilagodili, namesto da bi x povsem spremenili.is the output of your layer is some function of x plus x. And the way I like to think about it is it's as if you were taking x and modifying it, as opposed to changing completely x.
- u261 V praksi to pomaga pri vzvratnem razširjanju in modelu omogoča boljše učenje. To torej pomeni ta puščica. Ja.So in practice, doing that helps with back propagation and allows your model to learn better. So this is what this arrow is about. Yeah.
- u262 Ko smo že pri trikih, vam moram povedati še nekaj drugih. Eden je normalizacija aktivacij s tako imenovano normalizacijo plasti. Tudi to pomaga pri konvergenci. Morda ste v dekodirniku opazili besedo »maskirana«So speaking of the tricks, I have some other tricks to tell you. So one other is the fact of normalizing the activations with what we call layer normalization. So it also helps with convergence. You may have seen the word "masked"
- u263 samopozornost. Maskirana je zato, ker želite, da žetoni dekodirnika delujejo samo z žetoni, ki ste jih doslej dekodirali, saj ne morete delovati z žetoni, ki jih še niste dekodirali. Večglava pozornost – to, kar sem opisal s QKV,self-attention in the decoder. And the reason why it's masked is because you want your decoder tokens to only interact with tokens you have decoded so far, because you cannot interact with tokens you have not decoded yet. Multi-head attention-- so what I described with QKV, well,
1:24:31 · Multi-head attention in the Transformer (Stanford lecture slide) · A lecture slide titled "Computational trick: multi-head attention". On the left is the Transformer architecture diagram from "Attention Is All You Need" with the three Multi-Head attention blocks highlighted in orange. On the right, text says the idea is to run multiple self-attention layers in parallel, and compares this to multiple filters of a convolutional layer, shown with a small convolution graphic. A small inset at top right shows the lecturer standing near a blackboard. - u264 lahko naredite na različne načine. Naučite se lahko različnih projekcij. Za tiste med nami, ki poznate tudi modele računalniškega vida: kdo pozna – kdo ima tukaj izkušnje z računalniškim vidom? 1, 2, v redu.you can do it with in different ways. You can learn different projections. So for those of us who also are familiar with Vision-related models, who knows-- who has a Vision background here? 1, 2, OK.
- u265 Če torej poznate – pri konvolucijskih nevronskih mrežah lahko pri konvolucijski operaciji uporabite več filtrov, ki predstavljajo različne načine izvajanja konvolucije na vhodih. Različne glave pozornosti so torej tudi način,So in case you know-- when it comes to convolutional neural networks, when you do the convolution operation, you can use several filters, which are different ways of convoluting on your inputs. So having different attention heads is also a way
- u266 da se vaš model uči – da ima različne načine učenja iste stvari prek različnih projekcijskih matrik. Običajno imate h takih glav. Še en trik, izpuščanje – kdo je že slišal za izpuščanje? V redu, odlično.for your model to learn-- to have different ways to learn the same thing through different projection matrices. And so you typically have h such heads. So another trick, dropout-- who has heard of dropout? OK, great.
1:25:23 · Dropout as a computational trick in Transformers · A Stanford lecture slide titled "Computational tricks" explains dropout: randomly dropping neural net connections or units with a small probability, which gives better generalization. On the left, a faded Transformer architecture diagram has blue "D" markers showing where dropout is applied. On the right, two small network diagrams compare a standard neural net with the same net after dropout, where some units are crossed out and their connections removed. - u267 Ja, ta zamisel se ne uporablja samo v transformerju, ampak je široko uporabljena. To je tehnika, pri kateri med učenjem z neko verjetnostjo namerno izpustite nekatere enote, da se model ne bi preveč zanašal na določene značilke.Yeah, this is an idea that is not just applied in the transformer but widely used. So that one is a technique for which at training time, you intentionally drop some units with some probability in order for you to have your model to not rely too much on some features.
- u268 To modelu omogoča boljše posploševanje. In kaj imam še? Ja, glajenje oznak je še ena tehnika, uporabljena tukaj. Zamisel glajenja oznak je, da modelu naročite napovedovanje naslednjih besed. Namesto da bi rekli – recimo: kako lep dan.And that allows your model to generalize better. And then what do I have? Yeah, label smoothing is another technique that was used here. So the idea behind label smoothing is when you tell your model to predict the next words. Instead of saying-- let's say what a nice day.
- u269 Namesto da rečete: v redu, želim, da besedo »dan« napoveš s 100 %, vaš model pravi, da lahko napoveste besedo »dan« – pravzaprav ne s 100 %. Lahko imate tudi druge besede, saj lahko v jeziku stvari dopolnite na različne načine in so še vedno pravilne. Lahko torej rečete: kako lep dan, kako lepo predavanje,Instead of saying, OK, I want you to predict the word "day" 100%, your model is saying you can predict the word "day--" actually, not 100%. You can have also other words, because in language, you can complete things in different ways and still be valid. So you can say, what a nice day, what a nice class,
- u270 kako lep večer. Kakorkoli, glajenje oznak vzame te oznake in jih omehča tako, da reče: namesto da bi moral vaš model napovedati to oznako, v smislu, da morate ta model napovedati s 100 %,what a nice evening. Anyways, so label smoothing takes these labels, and it softens it by saying, OK, so instead of your model needing to predict that label, as in you need to predict that model 100%,
- u271 rečete: v redu, oznaka, ki sem jo želel napovedati, je morda, ne vem, 90 %. Preostalih 10 % pa so vse druge besede v besedišču. To modelu omogoča nekoliko boljše posploševanje. Avtorji so ugotovili, da to tudiyou say, OK, actually, the label that I wanted to predict is maybe, I don't know, 90%. And then the remaining 10% is all the other words, in the vocabulary. So it just allows your model to generalize a bit better. And authors have found that this also
- u272 izboljša metrike pri strojnem prevajanju. Za tiste, ki veste: BLEU je ena takih metrik. S tem pa predajam besedo Shervinu.improves metrics when it comes to machine translation. So for those of you who know BLEU is one such metric. And with that, I'll give it to Shervine.
- u273 Celovit primerEnd-to-end example
- u274 Hvala, Afshine. V tem zadnjem delu bo naš cilj vse, o čemer je govoril Afshine, povezati v en sam primer in natančno pogledati, kako ta izračun deluje na konkretnem primeru. Kot je omenil Afshine, je izvirni transformerThank you, Afshine. So in this last part, our goal is going to piece all that Afshine talked about together in one single example and see exactly how this computation works in a precise example. So as Afshine mentioned, the original transformer
- u275 namenjen strojnemu prevajanju. Vzeli bomo torej stavek v angleščini in ga poskusili prevesti v neki drug jezik. V primeru iz izvirnega članka o transformerju so vzeli francoščino in nemščino. Vzemimo torej to. In začnimo z našim najljubšim preprostim primerom,is in the business of machine translation. So what we're going to take is a sentence in English, and we're going to try to translate it into some other language. So in the example of the original transformer paper, they took French and German. So let's take that. And let's start with our favorite toy example,
- u276 torej »Ljubek plišasti medvedek bere.« Kot se spomnite, je prvi korak pri vsem tem tokenizacija. Afshine je omenil, da je to način poljubnega razdeljevanja teh besed na osnovne enote. Omenil je, da so podbesede optimalen način za to.so "A cute Teddy bear is reading." And as you recall, the first step in all of this is tokenization. And Afshine mentioned that it's a way to arbitrarily split these words into atomic entities. So Afshine mentioned subword is an optimal way to do it.
1:28:33 · Stitching all the pieces together with an example · A Stanford ICME lecture slide with a maroon title bar and an otherwise empty white body. At the bottom is a row of boxed tokens that spell the sentence "A cute teddy bear is reading." A small inset at top right shows the lecturer standing near a blackboard. - u277 Za ta primer pa bom izbral drugo delitev, da pokažem, da je poljubna. Recimo, da razdelimo takole. Kot je omenil Afshine, imamo tudi posebne žetone. Torej začetek stavka in konec zaporedja, ki ju dodate, da označite, kje se zaporedje začne in konča.But for the sake of this example, I'm going to take another split just to prove that it's arbitrary. So let's say we split it like this. As Afshine mentioned, we have also special tokens. So beginning of sentence and end of sequence that you put to characterize where your sequence starts and ends.
- u278 Poglejmo zdaj, kako jih kodiramo. V tej arhitekturi imamo iskalno tabelo, sestavljeno iz učljivih uteži. To imenujemo vložitve. Te se bodo naučile v procesu učenja. In kot je nekdo tukaj omenil,Now let's look at how we encode them. So we have, in this architecture, a lookup table that is made of learnable weights. So this is what we call embeddings. And these will be learned as part of the learning process. And as someone mentioned it here,
- u279 če želite izvajati pozornost tako, da upošteva kontekst in da veste, kje so drugi žetoni, potrebujete informacijo o položaju. Izvirni članek o transformerju to informacijo o položaju doda na začetku vhoda. Dodate jo torej s seštevanjem.if you want to perform attention in a way that's context aware and that you know where other tokens are positioned, you need that position information. And the original transformer paper puts this position information at the beginning of the input. So you add it additively.
- u280 Recimo, da velikost svoje vložitve imenujete D model. Potem bo vaša položajna vložitev, ki jo je Afshine opisal z zaporedjem sinusov in kosinusov različnih frekvenc, vektor enake dolžine, operacija pa je seštevanje. Na tej stopnji torej dobite vložitev,So let's say you call your embedding of size D model. Then your position embedding that Afshine described by a series of sines and cosines of different frequencies will be a vector of the same length and its additive operation. So at this stage, you end up with an embedding
- u281 ki je vsaj napol učljiva. Iskalna tabela, ki sem jo omenil, je vsekakor učljiva. Morda tudi položaji, odvisno od vaše zasnovne odločitve. To boste podali kot vhod kodirniku. Kaj se zgodi nato?that's at least half learnable. So the lookup table that I mentioned to you is at least learnable. Maybe the positions as well depends on your design choice. And this is what you will put as an input to your encoder. So what happens next?
- u282 Vsak žeton ima to predstavitev in lahko jo lepo predstavite v matrični obliki. Nadaljujmo s tem. Vstopili boste v kodirnik. Kot smo videli, bo prva komponenta kodirnika ta plast samopozornosti.Every token has this representation, and you can represent it in a nice matrix form. Let's go with it. And you're going to go into the encoder. And as we have seen, the first component of the encoder is going to be that self-attention layer.
- u283 Te vhode torej preslikate v prostor poizvedb. Za to imate projekcijsko matriko Wq. Dobite poizvedbe. Iste začetne vložitve preslikate v ključe.So you project these inputs into the space of queries. So for that, you have this Wq projection matrix. You get queries. With the same initial embeddings, you projected on keys.
- u284 Imate torej projekcijsko matriko Wk, ki se je boste naučili za preslikavo v ključe K. Enako naredite z vrednostmi V. V redu, odlično. Nato na tej podlagi uporabite omenjeno zelo pomembno formulo, formulo s softmaxom.So you have a Wk projection matrix that you will learn to project it into keys K. And you do the same with values V. OK, great. And then based on that, you apply the formula that we mentioned that is so important, that softmax formula.
- u285 Izvedemo te matrične produkte. Nato dobimo drugo matriko, ki ima enake dimenzije kot matrika V. Preden se poglobimo v podrobnosti, želim samo, da se uskladimoAnd we do this matrix products. And then we obtain another matrix that is of same dimension as the matrix V. So before we dive deeper into more specifics, I just want for us to get on the same page
- u286 glede dimenzij, saj smo govorili o številnih vložitvah. Stvari preslikavamo. Želim se samo prepričati, da govorimo isti jezik glede velikosti teh objektov. Vaše vhodno zaporedje – omenili smo, da je dolžine n. Ena od oznak za velikost teh vložitevon dimensions, because we talked about a lot of embeddings here. We project things. And I just want to make sure that we speak the same language as to what size are these objects. So your input sequence-- so we mentioned it's of length n. And one notation that people use to characterize these embedding
- u287 je D model. Projekcijske matrike Q, K in V pa naredijo naslednje: začnete v svetu D model in ga pretvorite v svet poizvedb, nato v svet ključev in nato v svet vrednosti.size is D model. And then what the projection matrices of Q, K and V do is respectively, you start from the D model world, and you turn it into the query world, and then key worlds, and then value world.
- u288 Zato je velikosti D model in DQ. Podobno D model Dk, D model DV za vsako projekcijsko matriko. Dobite te poizvedbe, ključe in vrednosti, ki imajo n vrstic, vendar so tokratSo this is why it's of size D model and DQ. And similarly, D model Dk, D model DV for each projection matrix. And you obtain these queries, keys, and values that are of size n rows but that are this time,
- u289 v teh prostorih poizvedb, ključev in vrednosti. Število stolpcev je torej DQ, DK in DV. Ker izvajate to množenje matrik, potrebujete omejitev, da je DQ enak DK. Tukaj sem zapisal DQ in DK samo zato,into these query, key, and value space. So the number of columns is DQ, DK, and DV. And since you do, this matrix multiply, you need these constraints that DQ is equal to DK. So here, I put DQ and DK just for the sake
- u290 da stvari pravilno poimenujem. Toda DQ mora biti že po zasnovi enak DK. In to dobite. Je za zdaj vse v redu? V redu, odlično. Zdaj se za trenutek ustavimo, vrnimo k temu primeru in poglejmo, kako deluje izračun matrika–matrika.of properly naming things. But DQ should be equal to DK by construction. And this is what you get. All good so far? OK, great. So now, let's pause a second and then go back to this example and see how the matrix-matrix computation work.
1:33:20 · Stitching pieces together: transformer query matrix Q for example sentence · A Stanford ICME lecture slide titled "Stitching all the pieces together with an example". On the left, a tokenized sentence is stacked vertically, with each token in its own box next to a tall gray rectangle labeled Q. The right side is empty, so this appears to be the first step of a build-up. A small inset shows the lecturer standing near a chalkboard. - u291 Kot je prej omenil Afshine, lahko vsak žeton predstavimo kot vrstično vložitev. To imate za Q. Če pogledate K transponirano, bo vsak stolpec vložitev določenega vektorja. Ko torej izvedete množenje matrik,So as Afshine was mentioning earlier, each token can be represented as a row embedding. And you have that for Q. If you consider K transpose, each column is going to be the embedding of a given vector. So when you do the matrix multiply,
- u292 dobite matriko velikosti n krat n, kjer bo vsaka celica neka podobnost. Tukaj je to na primer skalarni produkt med določeno poizvedbo in določenim ključem.you're going to end up with a matrix of size n by n, where each cell is going to be some similarity. Like here, it's a dot product between a given query and a given key.
- u293 Predpostavimo, da to tukaj pomnožite z V. Dobite naslednje: za vsako vrstico imate določeno poizvedbo. Preslikate jo v prostor ključev, ki jih imate v stavku. Dobite neko – torej želite dobiti neko verjetnostno porazdelitev po ključih.And let's suppose here, you multiply this by V. What you're going to end up with is for each row, you have a given query. You project it on the space of keys that you have in your sentence. So you get some-- so you want to get some probability distribution over keys.
1:34:13 · Attention example: QK^T score matrix and value tokens · A Stanford lecture slide titled "Stitching all the pieces together with an example". On the left is a QK^T matrix whose entries are query-key dot products between tokens, such as ⟨q_[BOS], k_[BOS]⟩ and ⟨q_A, k_A⟩. On the right the tokens of "A cute teddy bear is reading." are stacked, with [BOS] and [EOS] at the ends, next to a large gray block labeled V. A small inset shows the lecturer standing at the top right. - u294 Nato boste s temi utežmi utežili vrednosti. Potem boste vse to sešteli. Zdaj boste rekli: v redu, Shervine in Afshine, govorita o QK transponirano V, QK transponirano V. Formula ni taka.And then you're going to use these weights to weight the values. And then you're going to do a sum of all of this. Now you're going to say, OK, Shervine and Afshine, you talk about QK transpose V, QK transpose V. This is not what the formula is.
- u295 In imate prav. Formula je približno taka. Uporabimo softmax, da dobimo verjetnostno porazdelitev, katere vsota je 1 in ima lepe lastnosti. Nečesa še nismo omenili, a so to izbrali avtorji: normalizirali boste z nekim faktorjem, ker bo dimenzija decayAnd then you are right. The formula is approximately this. We take the softmax in order to get a probability distribution that sums to 1 and has nice properties. And one thing we haven't mentioned, but that the authors chose, is that you will normalize by some factor because the dimension decay will
- u296 vplivala na varianco, ki jo lahko dobite pri vsoti. Če torej želite, da je vse ustrezno normalizirano, lahko delite s standardnim odklonom. In to se zgodi tukaj. Kot smo omenili, je to večglavi postopek. Tega postopka torej ne izvedete enkrat, ampak h-krat.influence the variance that you might get as part of the sum. So if you want everything to be properly normalized, you can divide by the standard deviation. And this is what happens here. And so, as we mentioned, this is a multi-headed process. So you do not do this process once you do it h times.
- u297 Ta postopek učenja poizvedb, ključev in vrednosti poteka vzporedno. Na koncu nato združite vse te softmaxe QK transponirano, deljeno s kvadratnim korenom DK, krat V.So this process of learning queries, keys, and values is done in parallel. And then at the end, you concatenate all these softmax of QK transpose over square root of DK times V, together.
- u298 Nato imate še zadnjo projekcijsko matriko, ki ji rečemo W0 in ki te vložitve iz prostora HDV pretvori nazaj v D model. Mimogrede, v transformerju imate to lepo lastnost, da veliko operacijAnd then you have a last projection matrix that we call W0 that will turn these embeddings in a space HDV back into D model. So you have this nice property, by the way, in the transformer, where a lot of the operations
- u299 ohranja izvirno dimenzijo vložitev nespremenjeno. Začnete torej z D model, izvedete kup izračunov pozornosti in končate z D model. Nato vstopite v naslednjo plast, nevronsko mrežo s prehodom naprej. To je mreža z eno skrito plastjo,make the original dimension of embeddings invariant. So you start with D model, you do a bunch of attention calculations. You end up with D model. And then you go into the next layer, which is a feedforward neural network. That is a one hidden layer network
- u300 ki to predstavitev D model preslika v DFF1. Običajno je ta dimenzija večja od modela, da omogoča učenje kompleksnih predstavitev. Vse to izvedete veliki N-krat.that projects this D model representation into a DFF1. And then typically, you would have this dimension that is bigger than the model in order to allow for learning complex representations. And you do all of that big N time.
- u301 V izvirnem članku o transformerju je veliki N enak 6. To torej naredite večkrat. Na koncu kodirnika imate za vsak žeton predstavitev, ki ta žeton predstavlja na naučen način in ob upoštevanju konteksta. Je za zdaj vse v redu?So in the original transformer paper, big N is equal to 6. So you do that a bunch of times. And then at the end of the encoder, you have for each token, a representation that represents that token in a context aware and learned way. Is everything good so far?
- u302 V redu, super. Sprašujem zato, ker bomo prešli na dekodirnik. Želim se samo prepričati, da je vse razumljivo. Zdaj ko imamo to, kot smo omenili, je izvirni transformer namenjen strojnemu prevajanju. Zato morate začeti svoj prevedeni stavek.OK, awesome. So I'm asking because we're going to switch to the decoder. So I just want to make sure all make sense. So now that we have that, as we mentioned, the original transformer is in the business of machine translation. So you need to start the beginning of your translated sentence.
- u303 Eden od načinov, da vsilite njegov začetek, je ta nadomestni žeton. Dodate torej žeton BOS. Pogledate iskalno tabelo svojih vložitev. Imate začetno vložitev. Dodate ji položajno vložitev in jo nato podate dekodirniku.And one way to force the start of it is to have this is placeholder token. So you add this BOS token. Look at the lookup table of your embeddings. You have an initial embedding. You add your position embedding to it, and then you pass it to the decoder.
- u304 Imate to plast samopozornosti, za katero je Afshine omenil, da je maskirana plast samopozornosti, saj je to, kar se tukaj dogaja, vzročno. Vsak žeton gleda samega sebe in žetone pred seboj. Ko se to zgodi, imate še drugo plast pozornosti,And you have this self-attention layer that Afshine mentioned is a masked self-attention layer, because what happens here is that it's causal. Every token looks at itself and the tokens that precede it. And once that happens, you have another attention layer
- u305 imenovano navzkrižna pozornost, kjer je poizvedba žeton dekodirnika. Ključi in vrednosti pa so žetoni, ki prihajajo iz kodirnika. Pogledate torej sklad kodirnikov. Pogledate izhodno vložitev. In v vsaki plasti dekodirnika bo vsak blok dekodirnikathat's called cross-attention, where the query is the decoder token. And then the keys and the values are the tokens that come from the encoder. So you look at the stack of encoders. You look at the output embedding. And in every layer of decoder, every decoder block
- u306 dobil to zadnjo vložitev kot ključe in vrednosti. To izvedete in nato imate, tako kot v kodirniku, plast nevronske mreže s prehodom naprej, ki omogoča učenje kompleksnih značilk. Vse to steče. Nato imate neko linearno plast in potemwill get that last embedding as keys and values. So you do that, and then you have, just like in the encoder, a layer of feedforward neural network that allows for complex feature learning. And all of that goes. And then you have some linear layer and then
- u307 plast softmax, ki te predstavitve pretvori v verjetnostno porazdelitev po prostoru vaših besed – oziroma vaših žetonov v prostoru besedišča, da napoveste naslednjo besedo. Nato pa se tukaj zgodi – na naslednjih predavanjih bomo videli, katerea softmax layer that will turn these representations into a probability distribution over the space of your words-- or your tokens over the vocabulary space to predict the next word. And then what happens here is that-- we will see in the next lectures what
- u308 hevristike bi lahko uporabili za izbiro naslednje besede. Recimo pa, da tukaj izberemo maksimum. Izberete torej maksimum. Veste, katero besedo smo napovedali. Nato jo znova podate kot vhod dekodirniku. In ponovite popolnoma isti postopek. Tukaj torej vstavimo začetek zaporedja.could be heuristics to pick the next word. But let's say here, we pick the max. So you pick the max. You know what word we have predicted. And then you put it back as an input to the decoder. And you do the exact same process again. So here, we put beginning of sequence.
- u309 Dobite »un«. Nato dobite naslednji žeton [FRANCOŠČINA], ki ustreza »plišastemu medvedku«, in tako naprej. Na koncu dobite svoje zaporedje v ciljnem jeziku. To počnete, dokler ne pridete do žetona za konec zaporedja.You get "un." And then you get the next token [FRENCH] which is the equivalent of "Teddy bear," and so on. And then you get, at the end, your sequence in the target language. And then you do that until you hit an end of sequence token.
- u310 Takrat veste, da morate postopek prevajanja ustaviti. Tako torej začnemo s stavkom v nekem jeziku in končamo s stavkom v ciljnem jeziku. Kakšno vprašanje do zdaj? Ja.This is where you know that you should stop the translation process. So this is how we start from a sentence in a given language, and we end up in one in the target language. So any questions on this so far? Yep.
1:40:00 · Encoder-decoder translation example: English to French · A Stanford lecture slide titled "Stitching all the pieces together with an example" shows an encoder box on the left and a decoder box on the right. An English sentence, "A cute teddy bear is reading.", sits under the encoder. The French translation, "Un ours en peluche mignon lit.", sits above the decoder, and a small "encoded embedding" bar floats above the encoder. A lecturer is visible in a small inset at the top right. - u311 Pripomba je, da je vse skupaj videti zapleteno. Če bi morali strniti, kaj točno omogoča delovanje, kaj bi to bilo? Naslov članka »Attention is All You Need« nekoliko razkrije skrivnost uspeha. Tukaj je ključna plast pozornosti. Na naslednjih predavanjih bomo videli, da pravzapravThe comment here is it all looks complicated. If you were to boil down exactly what makes it work, what would it be? So "Attention is All You Need," the title of the paper, translates a bit the secret sauce. So the attention layer here is key. We're going to see in the next lectures that actually,
- u312 veliko teh stvari opustimo. Zanašamo se na podmnožico teh komponent, ki jih ponavljamo znova in znova. Ta plast pozornosti je torej ključna. Druga stvar pa je ta nevronska mreža s prehodom naprej, v kateri je večina parametrov mreže. Če bi torej natančno izračunali parametrea lot of these things are dropped. And we rely on a subset of these components that we repeat again and again. So this attention layer is the key. And then the second thing is this feedforward neural network where most of the parameters of the network reside. So if you were to calculate exactly the parameters
- u313 svojega modela, bi ugotovili, da ti vsebujejo večino zmogljivosti. In tukaj poteka učenje. Če bi vprašali mene, torej ti dve stvari, vse drugo pa so samo triki za boljše učenje in izboljšanje vsega skupaj, nato pa seveda še kakovost podatkov, ki je dodatna raven kompleksnosti.of your model, you realize that these contain most of the capacity. And this is where the learning happens. So if you were to ask me, these two, and then the rest are just tricks to better learn to improve all of it, and then, of course, the quality of the data, which is another layer of complexity.
- u314 Ja. Vprašanje je, ali lahko poveste več o maskiranem delu. To je računski trik, pri katerem imate trikotno matriko, ki maskira nekatere povezave vaše plasti samopozornosti. Med učenjem preprečuje vzpostavljanje povezav,Yeah. So the question is, can you talk more about the masked part? So it's a computational trick where you have a triangular matrix that will mask some connections of your self-attention layer. And at training time, it prevents connections
- u315 ki jih ne bi smeli poznati. Ja, to je bistvo. Ja, točno tako. Vprašanje je torej, kako je to povezano s softmaxom. Imate minus neskončnosti. In potem bo to 0. Softmax minus neskončnosti bo 0. Tako je povezano.that you shouldn't know to be made. So yeah, that's the gist of it. Yeah, exactly. So yeah, the question is how it relates to softmax? So you have minus infinities. And then this will be 0. Softmax of minus infinity will be 0. This is how it relates.
- u316 Ja. Ampak to so bolj računski triki. Mislim, da si je predvsem treba zapomniti, da pozabite na vse povezave med določenim žetonom in vsemi, ki so mu sledili. Mislim, da je to dovolj dober miselni model. Ja.Yeah. But these are more computational tricks. I think the main thing to have in mind is to forget about all connections from a given token and all the ones that succeeded. I think that's good enough as a mental model. Yeah.
- u317 V redu, super. Ja. Vprašanje je o različnih uporabah softmaxa. Tisti, ki se uporabljajo v plasteh samopozornosti in navzkrižne pozornosti, imajo drugačno funkcijo kot tisti v zadnji plasti. Na tiste v plasti pozornosti glejteOK, awesome. Yeah. The question here is on various uses of softmax. So the ones that are used in the self-attention layers and the cross-attention layers have a different function than the one at the last layer. You should see the ones in the attention layer
- u318 kot na projekcijo poizvedbe v prostor ključev. Torej preslikavamo predstavitev določenega žetona, torej med žetoni, medtem ko ima zadnja plast softmax drugačno funkcijo. Ta poskuša napovedati naslednji žeton. V nekem smislu torej ja, razumem –as a projection of the query over the space of keys. So what we do is projecting the representation of a given token, so cross tokens, whereas the last softmax layer has a different function. It's one that tries for you to predict the next token. So in some sense, yeah, so I do get the--
- u319 mislim, da je odlično opažanje, da to funkcijo uporabimo večkrat, vendar za različne stvari. Mislim, da je bilo – ja. Vprašanje je, zakaj prevod nima začetka zaporedja. Ga ima. Ja, to je prvi žeton tukaj. A, ja.I think it's a great point that we're using several times, this function, but it's for different things. I think there was-- yeah. So the question is, why is the translation not having beginning of sequence? It does. Yeah, it's the first token here. Oh, yeah.
1:43:17 · Transformer decoder walkthrough: stitching pieces together with an example · A Stanford ICME lecture slide shows a transformer decoder as a stack of layers inside a large box. An encoded embedding from a faded encoder, whose input is "A cute teddy bear is reading.", feeds the decoder. The decoder starts with a [BOS] token and outputs the first token "Un", which looks like the start of a translation. A small video inset shows the lecturer pointing at the screen. - u320 Prvi žeton tukaj je torej nadomestni žeton za napovedovanje naslednjega žetona za njim. Zato se ne pojavi na izhodu dekodirnika. Je samo vhod dekodirnika. Tisto, kar dobite na izhodu dekodirnika in na kar morate biti pozorni, pa je konec zaporedja, ker se morate tam ustaviti.So the first token here is a placeholder for you to predict the next token that comes after it. So it doesn't come at the output of the decoder. It's just the input of the decoder. And then what you get as the output of the decoder that you should watch out is end of sequence because this is where you should stop.
- u321 Ja. V redu, super. Ob vsem tem vam želim povedati, da je to, kar smo danes predstavili, šele začetek. Na tej točki smo šele v letu 2017. In kot gotovo veste, je bilo veliko uporab te tehnologije, ki zdaj poganjaYeah. OK, awesome. And then with all that, I want to tell you that what we presented today is just the beginning. We're just in 2017 at this point. And there has been, as I'm sure you know, many uses of this technology that now powers
- u322 vse te klepetalnike, ki jih uporabljamo. Na naslednjih nekaj predavanjih bomo obravnavali, kako take modele učimo. V drugem delu predmeta pa se bomo lotili tega, kako lahko poganjajo agente, s katerimi danes komuniciramo in jih uporabljamo, ter kako jih lahko uporabimo v različnih sistemih.all these chatbots that we use. So we're going to cover how we train such models in the next few lectures. And then in the second part of the class, we will tackle how these can power the agents that we interact and use today and how it can be used in several systems.
- u323 S tem se vam zahvaljujem za pozornost. In upam, da boste imeli lep konec tedna.And with that, thank you for your attention. And I hope you have a great weekend.
V okolici
Attention Is All You Need
Članek predlaga Transformer, arhitekturo za pretvarjanje zaporedij, ki temelji izključno na mehanizmih pozornosti ter ne uporablja rekurence in konvolucij. Poroča o najboljših dotlej doseženih rezultatih strojnega prevajanja na nalogah WMT 2014 iz angleščine v nemščino in iz angleščine v francoščino ob le delčku dotedanjih stroškov učenja ter o dobrih rezultatih pri sestavniškem razčlenjevanju angleških povedi. Avtorji trdijo, da uporaba zgolj pozornosti omogoča večjo vzporednost izvajanja in hitrejše učenje.
Raziskava1 vir
Učinkovito ocenjevanje vektorskih predstavitev besed
Članek predstavlja dve preprosti log-linearni arhitekturi, CBOW in Skip-gram, za učenje vektorskih predstavitev besed iz zelo velikih besedilnih korpusov. Opredeli testno zbirko besednih razmerij, pri kateri vektorji z vektorsko aritmetiko odgovarjajo na skladenjska in pomenska vprašanja, ter poroča o točnosti, času učenja in rezultatu pri dopolnjevanju povedi.
Raziskava
To besedilo je napisano z umetno inteligenco.
Objavljeno v: Zdaj