OctSum
00:00 / 56:15

Matthew Berman · 56:15

Speaker 0

This is Jeremy Berman from Anthropic. He's a researcher there, and no, we are not related. And we sat down and he explained exactly how large language models get built, everything from pre-training to post-training reinforcement learning. And so if you ever wanted to learn about this stuff, here's the right video for you. I hope you enjoy this video. I hope you learn a lot. And of course, if you want to see other videos like this, let me know down in the comments. If you have any questions, also just drop a comment. I'll try to answer them.

这是来自Anthropic的Jeremy Berman。 他是那里的一名研究员,而且不,我们没有亲戚关系。 我们坐下来聊,他详细解释了大语言模型是如何构建的,从预训练到后训练的强化学习,全都讲到了。 所以如果你一直想了解这方面的内容,这就是适合你的视频。 希望你喜欢这个视频。 希望你能学到很多东西。 当然,如果你想看更多类似的视频,请在评论区告诉我。 如果你有任何问题,也欢迎在评论区留言。 我会尽量回答。

Speaker 1

my goal is really to give an intuitive, high-level overview on how we're able to build intelligence and intelligent systems, really from just a file with numbers and a relatively small python program. so i'm going to break this up into seven, what i hope to be intuitive parts. what are neural networks? how they're trained? what are large language models? what is pre-training? What is post training? How did we get them to think? And can they discover new things?

我的目标是提供一个直观、高层次的概述,讲解我们如何构建智能以及智能系统,其实只需要一个存放数字的文件和一个相对较小的 Python 程序。 所以我会把它分成七个部分,希望每一部分都能让大家直观理解。 什么是神经网络? 它们是如何被训练的? 什么是大语言模型? 什么是预训练? 什么是后训练? 我们是如何让它们学会思考的? 它们能发现新事物吗?

Speaker 0

And this is all the same techniques or basic versions of what the modern large language model landscape looks like. So ChatGPT, Claude, this is all kind of what they are doing to make these incredible models.

这些都是相同的技术,或者说是现代大语言模型领域基础版本的技术。 所以ChatGPT、Claude,基本上就是在做这些事情,才打造出了这些出色的模型。

Speaker 1

Yes, yes, exactly. I think you know there are a lot of each in each one of these sections. You could do a whole deep dive for hours. I'm going to try and stay high level and intuitive, but of course you know ask any questions and maybe we could do you know a follow up video for for the ones that are most interesting.

是的,是的,没错。 我想你知道每个部分里都有很多内容。 你完全可以用几个小时做一次完整的深入剖析。 我会尽量保持在高层次、直观的角度来讲,不过你当然可以随时提问,也许我们可以针对其中最有趣的几个内容,再做一期后续视频。

Speaker 0

And I just want to give you your props for a second because you are self taught. You are a self-taught AI researcher, and so like this is the starting point for anybody who wants to follow that same journey.

我想先给你点个赞,因为你是自学成才的。 你是一名自学成才的人工智能研究者,所以这正是任何想走同样道路的人的起点。

Speaker 1

Yes, I would say really just follow your intuitions. Like you know, there are a few parts to training these things, and you can go as deep as you need to in each one. You know, kind of find what you get obsessed about, and then just follow that into rabbit hole. i think this is very self-teachable even today.

是的,我觉得真正要做的就是跟随你的直觉。 比如,训练这些东西有几个组成部分,你可以在每一个部分中深入到你需要的程度。 你知道的,就是找到你最着迷的方向,然后顺着它钻进兔子洞里去。 我认为即便在今天,这也是非常适合自学的领域。

Speaker 0

cool. all right, let's do it.

好的。 好,我们开始吧。

Speaker 1

to start off with what are neural networks, i want to start by giving a real-world example.

首先,什么是神经网络?我想先举一个现实世界的例子。

so let's say we have a sheet of apartments in new york. they have inputs and then they have the price. so an input would be the location, so soho, the square footage, and the number of baths. very simple example, toy example. and so the idea is we need to find the pattern, the function that maps these inputs, location, square foot, and number of baths to the price in new york. and so as you can see, we have a set of inputs, and then we have the actual price to the right. and so a classic neural network is really like a way to build a function. so you can imagine you could build a function to do this, right? like you could have a function that takes in the square footage, the bath, you could code it up, and then you could get pretty close. to the right answer for the price. but is there a way that we could teach the computer to build this function for us? and for a toy example, this seems okay, whatever, who cares, we can code up our own example. but you'll see as we start to model really, really complicated things, it's very useful. and in fact, we couldn't do it otherwise to actually have the model.

比如说,我们有一张纽约公寓的表格。 它们有输入,还有价格。 所以一个输入是位置,比如SoHo,还有面积和浴室数量。 非常简单的例子,一个玩具式的示例。 我们的思路是要找到规律,也就是那个将这些输入(位置、面积和浴室数量)映射到纽约房价的函数。 如你所见,我们有一组输入,右边是实际的价格。 所以,经典的神经网络本质上就是一种构建函数的方式。 所以你可以想象,你可以编写一个函数来完成这件事,对吧? 比如,你可以有一个函数,输入建筑面积和浴室数量,你可以把它编写出来,然后就能得到相当接近的结果。 也就是对价格给出接近正确的答案。 但是,有没有办法让计算机为我们构建这个函数呢? 以这个玩具示例来说,这样做似乎还可以,无所谓,我们可以自己编写一个示例。 但你会发现,当我们开始对非常非常复杂的事物进行建模时,这种方法就非常有用了。 事实上,如果没有这种方法,我们根本无法真正得到这个模型。

Speaker 0

build the function for us. and jeremy, when you say function, you literally mean kind of the old technique might be, okay, if square footage is between 1,000 and 2,000, and if the baths is between one and two, price it around here. and so you basically have to hard code all of this logic yourself, which, you know, if we have seven examples as shown here, maybe it's not so bad. but what if we have thousands, tens of thousands, or millions?

为我们构建这个函数。 杰里米,你说的函数,是不是指老式的方法,比如:如果建筑面积在1000到2000之间,并且浴室数量在一到两个之间,那么价格就定在这个范围附近? 所以你基本上得自己硬编码所有这些逻辑,如果像这里展示的那样只有七个例子,也许还不算太糟。 但如果我们有成千上万、甚至上百万个例子呢?

Speaker 1

exactly. millions. and then what if instead of three inputs, we have a thousand inputs, right? a real estate broker has hundreds of inputs in their head, right? the finishings when it was built. and what the real estate broker is doing is that they're pattern matching, right? they're saying, okay, i have a pattern match. i have a general idea of what each of these mean. and so i can now map this property to how much it should cost. but what we're trying to do is do this, have the computer build this function for us automatically in kind of a black box. so what does this really mean? well, here you can see this is a very basic formula. and let's just say we have inputs of location, the size, the baths, the location, and we have our answer. so what we can do is we can have these knobs. and the way the knobs work is you multiply the size by a certain parameter, by a certain value. let's randomize it at first. it's randomized to 0.25, right? we multiply the bathrooms by 0.05. we multiply the location by 0.15. we do all of this. we add it up together, and we should have an output. and this output gives us a price. now, we just randomly initialized these variables here, right? so what we get out, and you can see in these examples, for soho it predicts 942 k 742 860. these are all wrong because really what we're after is the green, but we could actually adjust these dials right. And eventually we can actually get pretty close.

没错。 上百万。 而且,如果不是三个输入,而是一千个输入呢,对吧? 房地产经纪人脑子里有数百个输入因素,对吧? 建造时所用的装修材料。 而房地产经纪人所做的,其实是模式匹配,对吧? 他们会说,好,我有一个模式匹配。 我对每个因素的含义都有大致的概念。 因此,我现在可以将这处房产与它应有的价格对应起来。 但我们想做的是,让计算机自动构建这个函数,就像一个黑箱一样。 那么这到底意味着什么呢? 嗯,你可以看到这是一个非常基础的公式。 假设我们有输入:位置、面积、浴室数量、位置,还有我们的输出结果。 所以我们可以设置这些旋钮。 旋钮的工作方式是:把面积乘以某个参数,也就是某个特定的数值。 我们先随机初始化它。 它被随机设为0.25,对吧? 我们把浴室数量乘以0.05。 我们把位置乘以0.15。 我们对所有这些都这样做。 我们把它们加起来,就应该得到一个输出。 这个输出给出的是一个价格。 现在,我们只是随机初始化了这些变量,对吧? 所以我们得到的结果,你可以在这些例子中看到,对于soho,它预测为942k、742、860。 这些都是错的,因为我们真正追求的是绿色的结果,但我们实际上可以调整这些旋钮。 最终我们确实可以非常接近目标。

Speaker 0

And can you can you explain in basic terms what the actual what you're multiplying by the knob? What does that represent?

你能用通俗的语言解释一下,你用旋钮乘的那个东西实际上是什么吗? 它代表什么呢?

Speaker 1

Yeah. So the knob is actually really just a random number in this case from zero to one. And it's like a black box. You are, you know, taking your inputs, which are you're turning your inputs into numbers, and then you're multiplying it by these random numbers or knobs. and there is some combination of knobs that will get you really close to always getting the right answer. now, let's say we can't possibly do it with three knobs, right, with three numbers. so when i'm turning this knob, the number is moving, right, as you can see here, and it's adjusting the output. let's say we can't get perfect with these three knobs. well, you can actually just add more knobs or more layers or more parameters to build an even more complex function. until eventually you reach the green.

好的。 所以在这种情况下,这个旋钮实际上就是一个从零到一的随机数。 它就像一个黑箱。 你就是把输入拿过来,把输入转换成数字,然后乘以这些随机数或旋钮。 而总会有某种旋钮的组合,能让你几乎每次都得到正确答案。 现在,假设我们不可能只用三个旋钮,对吧,也就是三个数字来做到这一点。 所以当我转动这个旋钮时,数字在移动,对吧,如你在这里看到的,它在调整输出。 假设我们用这三个旋钮无法达到完美。 那么,你其实可以直接增加更多旋钮、更多层或更多参数,来构建一个更复杂的函数。 直到最终达到绿色。

Speaker 0

and tell me if this is a right way to describe what these knobs are doing. but it's kind of assigning almost an importance value to each of those inputs. so maybe the size of your apartment is super important to the price output. Or maybe actually, how many baths you have is really, really important. Maybe the location is less important. Is that a good way to describe it? Where each of these different knobs is kind of adjusting how important our little formula, our little algorithm, is taking into account each of these factors.

告诉我这样描述这些旋钮的作用是否正确。 但它其实是在为每个输入分配一种几乎像重要性的数值。 所以也许公寓的面积对价格输出非常重要。 或者,也许浴室的数量真的非常、非常重要。 也许位置的重要性较低。 这样描述好吗? 这些不同的旋钮各自在调整我们这个小公式、小算法在考虑每个因素时的重要程度。

Speaker 1

Yeah, that's a great way to put it. Now this is an extremely simple example where the number of bathrooms isn't in some way intertwined with the location. And so let's say Soho might be not desirable to have a large place. this is a very simple example, just for demonstration purposes, but you're exactly right. in this simple example, it's basically saying how much do we weight each one, how much do we multiply each one. but you can imagine we can generate, we can add more terms such that you also divide by the size in a new knob, assuming the location is a certain thing. so we can build arbitrarily large complex functions just by adding more knobs. and changing the ordering of the knobs. and this would be an example of basically just one layer of a network, because we just have this simple function. but you can imagine that this output, all of these knobs, produce one number, and that number gets fed into a whole new set of knobs, and a whole new set of knobs. and so you have this function inside of a function inside of a function. which is ultimately what neural networks are, and again at each layer you have a whole new set of knobs that you can twist and turn, and the point is really to minimize this number right here. So this is the average on average each prediction is off by, and so what we're trying to do is minimize this number. So you can see that if we're just doing this by hand in this simple example, we can get relatively close. And um and so this is really the intuition yeah behind neural networks. It's really just turning knobs uh that that create arbitrary functions that get you closer and closer to minimizing what we call loss, which is um the difference between what the output is and or what what your model predicted and what actually exists in the world.

是的,你这样说非常好。 现在这是一个极其简单的例子,其中浴室数量与位置之间并没有以某种方式相互关联。 那么假设,SoHo可能并不适合有很大的住所。 这只是一个非常简单的示例,仅用于演示,但你说得完全正确。 在这个简单的例子中,基本上是在说我们给每一项赋予多大的权重,也就是我们把每一项乘以多少。 但你可以想象,我们可以生成、可以添加更多的项,比如再加一个新的旋钮,使其也除以某个大小,假设位置是某种特定的东西。 所以我们只需不断添加更多旋钮,就能构建任意复杂的函数。 还可以改变旋钮的排列顺序。 这基本上就是网络中一层的示例,因为我们这里只有这一个简单的函数。 但你可以想象,所有这些旋钮的输出会产生一个数字,而这个数字又会被输入到一整组新的旋钮中,然后又是一整组新的旋钮。 因此,你会得到一个函数套着一个函数,再套着一个函数。 这正是神经网络的本质。而且同样,在每一层,你都有一整组新的旋钮可以拧来拧去,其目的就是要最小化这里的这个数字。 这就是平均每次预测的偏差,所以我们要做的就是最小化这个数字。 所以你可以看到,如果在这个简单的例子中我们手动去做,就能相当接近目标。 嗯,这就是神经网络背后的直观理解,是的。 它本质上就是转动旋钮,从而构造出任意函数,使我们不断接近最小化所谓的损失。损失指的是模型的输出,也就是模型所预测的结果,与现实世界中实际情况之间的差距。

Speaker 0

Right? So if the actual sales price of that apartment in Soho. is $2 million and we predict or the model predicts it's $1 million. that's way off. and we want to continue to adjust those knobs until we get closer.

对吧? 假设那套位于苏荷区的公寓实际售价是…… 200万美元,而我们预测或者模型预测它是100万美元。 这差得太远了。 我们就要继续调整那些旋钮,直到越来越接近。

Speaker 1

exactly. yes. and you just want to keep adjusting. so we will come back to this example, actually. let me now go back to the slides.

没错。 是的。 你只需要不断地调整。 所以实际上我们之后还会回到这个例子。 现在让我回到幻灯片。

this is just a general quick level intuition. what exactly are knobs and what are they doing? Now here's the actual example. If this were a neural network, we don't really need to focus into what all these numbers are. But if you wanted to actually see, we would turn the location into numbers as an input layer. We would turn the size into a number. We turn the bathrooms into a number, and then each of these connections. is the actual knob. It's the number. It's the weight. And so, uh, latitude has a weight that goes into, uh, and in this case there are three, um, there are three intermediate layers. So we can construct a function, um, and what you're doing is you're basically, you're filling in, this is a number, this is a number, this is a number, this is a number. You're multiplying this number by this number. Plus this number by this number, plus this number by this number, and I know it gets very complicated, which is why this is really... yeah.

这只是一个通俗快速的直观理解。 旋钮到底是什么?它们起什么作用? 现在来看实际的例子。 如果这是一个神经网络,我们其实不需要深究这些数字都代表什么。 但如果你想真正看清楚,我们会把位置转换成数字,作为输入层。 我们会把面积转换成一个数字。 我们把卫生间数量也转换成一个数字,然后每一条连接线…… 就是实际的旋钮。 它就是那个数字。 它就是权重。 所以,嗯,纬度有一个权重连接到,嗯,在这个例子中有三个,嗯,有三个中间层。 所以我们可以构造一个函数,嗯,你基本上要做的是填入数值:这是一个数字,这是一个数字,这是一个数字,这是一个数字。 你要把这个数字乘以那个数字。 再加上这个数字乘以那个数字,再加上这个数字乘以那个数字。我知道这会变得非常复杂,这也是为什么这真的是……是的。

Speaker 0

this looks intimidating, but I think the way to think about it is what we did on that previous slide with the knobs. It's just a much more sophisticated version of that.

这看起来很吓人,但我认为理解它的方式,就是我们在上一张幻灯片中对旋钮所做的事情。 它只是那种思路的一个复杂得多的版本。

Speaker 1

yes, yes, exactly. at the end of the day, we are just turning knobs and we are building these functions. and as you can see, these are functions that are now relatively complicated, even though we're just turning knobs. now, as you can see, it would get very time consuming to have to go in and individually tune each knob. you know, ok, we tune these knobs and then we run these examples and then we see that we're off by this amount. ok, well, let's adjust this knob. let's adjust this knob. You know, there's there you can do it by hand, but um the great the great invention really of neural networks is we can actually do this. We can have the computer calculate a lot of how we should tune these knobs automatically. And I will now get to that. But just before. I know this seems relatively simple, right? Our neural networks really just, they're just numbers, and then it's a Python script generally that really just describes how these numbers are ordered and wired. And that is really it. So, you know, what is a language model? A language model is really just a download from Hugging Face, which has the numbers and. the numbers are the brain, it's actually the parameters. So when we say there's a 2 trillion parameter model, that means they're basically 2 trillion numbers. And then we have a python function that describes the wiring of all of these numbers, which will ultimately build the compute graph. which we will then run the inputs through, and then we will get our output. But it is really, really as simple as just tuning knobs. I said before that there's a better way than just hand tuning these, right? So if you've heard of PyTorch or JAX or TensorFlow, these are called autograd engines. And at the end of the day, really what they're doing is they are keeping track. of all of the parameters, all of the numbers, and all of the computations that those numbers are involved in. and then they are keeping track, and then they are you know at the end you get your value which is how much you are off by. So in this case we were off by you know around 0.2 million dollars. And then what the autograd engine, what pytorch is doing, it's keeping track of all of the calculations and it knows what each parameter, it actually knows how much each parameter. if you were to wiggle it, if you were to update it by zero or by zero, how much it would affect the ultimate loss. so how much if we wiggle this size, how much should it ultimately affect this position? so the way it does this is that ultimately we are just creating a function, we are creating a very complicated function that ends up outputting the loss, but it's a function. and what we can do is we can take the derivative of each parameter. So with respect, so we can take the derivative of this ultimate loss, how much we are off by with respect to each single parameter. And so you can imagine we have this size weight.

对,是的,没错。 归根结底,我们只是在转动旋钮,并由此构建这些函数。 如你所见,这些函数现在相当复杂,尽管我们只是在转动旋钮。 如你所见,如果要逐个进入并手动调整每个旋钮,会非常耗时。 好,我们调整这些旋钮,然后运行这些示例,接着发现我们偏差了这么多。 好,那我们调整这个旋钮。 我们调整这个旋钮。 你知道,手动调整当然可以,但神经网络真正伟大的发明在于,我们其实可以让它自动完成这件事。 我们可以让计算机自动计算出该如何调整这些旋钮。 我现在就来讲这个。 不过在此之前。 我知道这看起来相对简单,对吧? 我们的神经网络其实就是一些数字,而通常只需要一个Python脚本来描述这些数字如何排列和连接。 差不多就是这样。 那么,什么是语言模型? 语言模型实际上就是从Hugging Face下载的一个文件,里面包含这些数字,以及…… 这些数字就是大脑,它们其实就是参数。 所以当我们说一个模型有2万亿参数时,意思就是它基本上有2万亿个数字。 然后我们有一个Python函数来描述所有这些数字的连接方式,最终会构建出计算图。 我们将把输入送入这个计算图运行,然后得到输出。 但它真的非常非常简单,就像转动旋钮一样。 我之前说过,有比手动调整这些旋钮更好的方法,对吧? 所以如果你听说过 PyTorch、JAX 或 TensorFlow,它们被称为自动求导引擎。 归根结底,它们真正做的是记录跟踪。 记录所有参数、所有数字,以及这些数字所涉及的所有计算。 然后它们会记录下来,最后你会得到一个数值,也就是我们偏差了多少。 所以在这个例子中,我们大约偏差了20万美元。 然后自动求导引擎,也就是 PyTorch 所做的,是跟踪所有的计算,它知道每个参数,实际上它知道每个参数的影响有多大。 如果你稍微调整它,比如把它更新为零或者别的数值,它会对最终损失产生多大影响。 那么,如果我们调整这个尺寸,它最终应该对这个位置产生多大影响? 它的做法是:最终我们只是在构造一个函数,一个非常复杂的函数,它最终输出损失值,但它仍然是一个函数。 我们可以做的是,对每个参数求导数。 也就是说,我们可以对这个最终损失(即我们偏差了多少)关于每一个单独参数求导。 你可以想象我们有这样一个尺寸权重。

Speaker 0

which is multiplied. Jeremy, sorry, let me interrupt for a second. There was a lot of terms thrown out. Maybe you can just use the most basic terms and then go deeper.

它被相乘。 Jeremy,抱歉,我打断一下。 你刚才抛出了很多术语。 也许你可以先用最基本的术语说明,然后再深入。

Speaker 1

Yes, yes. Taking a step back. we are ultimately just building a function that takes in the inputs, it multiplies these inputs by a variety of numbers which are the knobs, and then we get an output, and we can tell how different that output is from what we expected. with just this information, we can then. determine what the effect of changing one of these knobs is. On the final loss, in other words, if we were to shift this. this parameter, this knob. how much, what is the effect on the final loss? and we can do this per parameter. and so let's say we shift this and the effect actually on the loss is something like three. so for every one change we make in the size, the loss is, let's say, increased by three. so now we actually know, well, if we want to minimize the loss, right? well, we can just make this number a bit smaller, and if we make this number a bit smaller, we are going to decrease the amount we're off by, and we can do this per parameter. and so what pytorch is really doing is it's saying for each of these knobs. What is the effect of each of these knobs on the final result, such that we can now know how to slightly adjust each knob to get closer to the actual number that we're trying to get to?

好的,好的。 退一步说。 我们最终只是在构建一个函数,它接收输入,用各种数字(也就是旋钮)乘以这些输入,然后得到一个输出,我们可以判断这个输出与我们预期的相差多少。 有了这些信息,我们就可以接着…… 确定改变其中某个旋钮会产生什么影响。 换句话说,对于最终损失而言,如果我们把这个值移动一下。 这个参数,这个旋钮。 移动多少,它对最终损失有什么影响? 而且我们可以逐个参数地进行这一操作。 假设我们移动了它,结果对损失的实际影响大约是三。 也就是说,尺寸每改变一个单位,损失就大约增加三。 那么现在我们就知道了,如果想要最小化损失,对吧? 那我们只需把这个数字调小一点,而如果把这个数字调小一点,我们与目标的偏差就会减小,而且可以逐个参数地这样做。 所以PyTorch实际上做的是,针对这些旋钮中的每一个进行计算。 每个旋钮对最终结果有什么影响,这样我们就能知道如何稍微调整每个旋钮,使结果更接近我们想要达到的实际数值。

Speaker 0

And PyTorch is traditional software. It is a piece of software. that kind of manages this entire pipeline for us.

而PyTorch是一种传统软件。 它是一个软件程序。 它为我们管理整个流程。

Speaker 1

exactly right. pytorch is tracking the effect of this knob on ultimately on the outcome of the prediction, and so at the end of the day, it will tell us how much. A change in this knob will affect the loss, and once we know how much, what is the effect of this parameter on the final loss, we can then inch it either in a positive direction or negative direction. We can add 0.1 or subtract 0.1, and that will get us closer to the actual prediction. And so this is, and we do that for every single parameter. So every parameter, every knob is moved slightly such that if you were to run. The inputs again, you would get closer to the right answer the next time.

完全正确。 PyTorch会追踪这个旋钮对最终预测结果的影响,因此归根结底,它会告诉我们这个旋钮的变化会在多大程度上影响结果。 一旦我们知道了这个参数对最终损失的影响有多大,就可以把它朝正方向或负方向微调。 我们可以加0.1,也可以减0.1,这样就能更接近实际预测值。 这就是我们对每一个参数所做的操作。 因此每个参数、每个旋钮都会被轻微移动,使得如果你再运行一次…… 再次输入这些数据,你会在下一次更接近正确答案。

Speaker 0

And it's not guessing at this stuff. It actually has to run the calculation and figure out how the different knob turns will affect the final output, how it will affect the loss.

而且它对这些东西并不是在瞎猜。 它实际上必须进行计算,弄清楚不同的旋钮调整将如何影响最终输出,以及如何影响损失。

Speaker 1

Right. And the way it does this is ultimately uses the chain rule from calculus. I think it's probably we shouldn't get into this and there are videos that can describe this. Yeah, a little too deep. I think it's good to just take for granted, take for granted that PyTorch will basically give you this information. So you.

对。 而它这样做,最终用的是微积分中的链式法则。 我想我们大概不应该深入讲这个,有一些视频可以解释这一点。 是的,有点太深了。 我觉得最好就把它当作理所当然,认为PyTorch基本上会给你提供这些信息。 所以你。

Speaker 0

yeah. I'm sorry, I cut you off.

嗯。 抱歉,我打断你了。

Speaker 1

Please finish that. No, so if we take for granted that PyTorch will give us this information, what we have, we have the amount we were off by given our current knobs, and then we know that if we just adjust the knobs, Um, according to how much PyTorch says they will affect the loss, so in the right direction. So if, if this knob, if we increase this knob, the loss will go down. We should increase it, and if we decrease, and vice versa, right? If, if the loss, if PyTorch tells us, oh, actually, uh, when this, when this gets larger, the loss grows, as in our inaccuracy grows. Oh, well, let's make it a bit smaller. and the amount that we inch up or down by is determined by the learning rate.

请继续说完。 好,那么如果我们理所当然地认为PyTorch会给我们这些信息,我们就有了:在当前旋钮设置下我们偏差了多少,然后我们知道,只要按照PyTorch所说的旋钮对损失的影响程度去调整旋钮,方向就是正确的。 所以,如果这个旋钮,如果我们增大这个旋钮,损失就会下降。 那我们就应该增大它,反之则减小,对吧? 如果损失,如果PyTorch告诉我们,哦,实际上,当这个值变大时,损失增加,也就是我们的误差增大。 哦,那我们就让它小一点。 而我们每次向上或向下调整的幅度,由学习率决定。

Speaker 0

And somebody who's just learning this for the first time doesn't necessarily need to know what's happening under the hood of pytorch.

对于第一次学习这个内容的人来说,他并不一定需要知道PyTorch底层到底发生了什么。

Speaker 1

Totally, it does it automatically. And I'll actually, I have some code, very simple code, that will show you the few lines, the only lines where this is all done automatically for you. And what this looks like in practice, I just have a quick. so i'm going to hit auto train here. and as you can see, it's automatically updating. let's reset auto train. so it's automatically adjusting those knobs, right? so that we are minimizing the amount that we are off by. and so it looks like possibly the best we're going to get is around being off by, you know, $0.07 million. and that's actually because we only have a simple linear function here. this is a very simple function. but if you add more layers to your neural network, as in you have functions inside functions inside functions inside functions, each with their own knobs, and we have activation functions, which change it so that you can represent more complicated relationships, which we won't get into. You can actually, you can represent any function with a neural network. which is a really cool property. It's called a universal function approximator because you just add more layers, you add more knobs, and you can get to any function. So in theory, we can actually get this loss to zero if we added a ton of knobs and a ton of layers.

完全正确,它是自动完成的。 我其实有一些代码,非常简单,会给你看那几行关键代码,也就是整个过程自动完成的唯一几行。 实际操作是什么样的呢,我快速演示一下。 那我现在点击这里的自动训练。 你可以看到,它在自动更新。 好,我们重置自动训练。 所以它会自动调整那些旋钮,对吧? 这样我们就能把偏差尽量缩小。 看起来我们能达到的最好结果大约是偏差 700 万美元,也就是 0.07 百万美元。 这其实是因为我们这里只用了一个简单的线性函数。 这是一个非常简单的函数。 但如果你给神经网络增加更多层,也就是函数套函数、再套函数,每一层都有自己的旋钮,并且加入激活函数,让它能表示更复杂的关系(这一点我们不展开讲),那就不同了。 实际上,神经网络可以表示任何函数。 这是一个非常酷的特性。 它被称为通用函数逼近器,因为你只需增加更多层、更多旋钮,就能逼近任何函数。 所以理论上,如果我们增加大量旋钮和大量层,就真的可以把这个损失降到零。

Speaker 0

Awesome. And and and you're like what you have just described is the basic unit of all AI today.

太棒了。 你可能会想,你刚才描述的就是今天所有人工智能的基本单元吗?

Speaker 1

Yes, exactly. This is called back propagation. Yes, this is how we are able to. update our knobs in a directed fashion to minimize the difference between what is actually in the world that we want to model and what our model gives us.

是的,没错。 这就叫反向传播。 是的,正是通过它,我们才能够…… 以有方向的方式调整我们的参数,使我们想要建模的现实世界情况与模型给出的结果之间的差异最小化。

Speaker 0

Now the important ingredients going into this is you need the inputs. You actually need to know, okay, where's the home located? What's the size? How many baths? and then you also need to know the real world answer. what did that apartment actually sell for?

其中,关键的输入要素是:你需要有输入数据。 你需要知道,比如这套房子位于哪里? 面积有多大? 有几个卫生间? 然后你还需要知道现实世界中的真实答案。 这套公寓实际卖了多少钱?

Speaker 1

yes, exactly. right.

对,没错。 对。

and, you know, there are various, there's a lot to cover in this, i think, for now. yeah, this is the intuition behind it. and we could, of course, go deeper. and as a final point to this, i'm going to show some code. Very simply, that actually does this in PyTorch. So you don't need to know. I don't want people, no one should be scared off by this code. This is just turning these inputs into numbers. These are the labels. So this is the home prices. And then this is the training. This is it. This is the training. And so here is our prediction. So we run, we run the model, we run the function, we calculate what the predictions are. This is our loss that we were just describing. This is how off we were. And now all we need, this means that we're just zero. We're starting a new step. So forget everything that we've. we've done before, we're going to loss backwards, which means we're going to calculate for each of the parameters what is their effect on the loss, and then we are going to take a step according to our learning rate, which says given that now we know the directions that we should be making parameters larger or smaller and the amount, let's do that. and now we can test. and so i'll just run this quickly. again, you really don't need to know what's happening, but this is just an example of literally, it's this much. this is what pytorch gives us.

还有很多内容需要讲,我觉得目前先讲到这里。 是的,这就是其背后的直观理解。 当然,我们还可以讲得更深入。 最后一点,我会展示一些代码。 非常简单,它实际上用PyTorch实现了这一过程。 所以你不需要理解这些。 我不希望大家被这段代码吓到,谁都不应该因此却步。 这只是把这些输入转换成数字。 这些是标签。 这些是房价。 然后就是训练过程。 就是这样。 这就是训练过程。 那么这里就是我们的预测。 所以我们运行模型,运行这个函数,计算出预测结果是什么。 这就是我们刚才描述的损失。 这就是我们偏差有多大。 现在我们只需要做的是,这意味着我们要把梯度清零。 我们要开始新的一步。 所以忘掉我们之前做过的所有操作。 我们要进行损失的反向传播,也就是为每个参数计算它对损失的影响,然后根据学习率迈出一步。既然我们已经知道了每个参数应该增大还是减小,以及调整的幅度,那就这样做吧。 现在我们可以进行测试了。 那我就快速运行一下。 同样,你其实不需要知道里面发生了什么,但这只是一个例子,说明代码量真的就这么少。 这就是PyTorch为我们提供的便利。

Speaker 0

this would be a lot of code. if this seems a little bit complicated, what's really nice is claude and ChatGPT. these systems are extremely good at writing and explaining code. so you can literally have it write this code for you. adjust it for you, explain each line in detail. so if you want to go a little bit deeper, that's a great way.

如果要自己写,代码量会非常大。 如果你觉得这些有点复杂,非常好的一点是Claude和ChatGPT。 这些系统在编写和解释代码方面极其出色。 所以你完全可以让它们帮你编写这段代码。 还可以让它们帮你调整代码,并逐行详细解释。 所以如果你想深入了解一些,这是个很好的方法。

Speaker 1

yes, definitely. yes. so this ran, and here is what we are seeing.

是的,绝对是。 是的。 所以这个运行了,下面是我们看到的结果。

again, this is not how you would want to train this in production. this is just a toy example. and so for each of our optimization steps, right, each tuning of the knob, and actually in this case, we are taking training steps. so 1,000 steps, 1,000 tunings. and we are getting results for every 100, just so that we don't have 1,000 outputs. so at step zero, right, randomly initialized knobs, our loss is eight, and our prediction for an upper west side, and this loss is using a mean squared error. the larger the loss, the worse it is. it is basically taking the literal difference in prices and turning it into a loss, which we won't get into here. but the larger it is, the worse the prediction was. and so how does it.

再说一次,这不是你在生产环境中训练它的方式。 这只是一个玩具示例。 所以对于我们的每一步优化,对,每一次调节旋钮,实际上在这个例子中,我们是在进行训练步骤。 所以是1,000步,1,000次调节。 我们每100步获取一次结果,这样就不会有1,000个输出。 所以在第0步,对,旋钮是随机初始化的,我们的损失是8,而我们对上西区房价的预测,这个损失使用的是均方误差。 损失越大,结果就越差。 它基本上是取价格的实际差值,并将其转化为损失,这里就不深入讨论了。 但差值越大,预测就越差。 那么它是怎么做到的呢?

Speaker 0

how does it know to head in the right direction? so like it could just test a bunch of those in a bunch of the knobs randomly, but it seems like it's kind of you know heading towards the correct answer. how does it know to continue towards that correct answer?

它怎么知道朝着正确的方向前进? 比如它可以随机测试大量旋钮的组合,但看起来它似乎正朝着正确答案前进。 它怎么知道要继续朝着那个正确答案前进?

Speaker 1

yeah, so. when we do loss dot backwards, what pytorch is doing is it's saying for each parameter i know where it was involved in calculating the final result and i know how off the final result was from what i wanted to get, which is actually calculated here. so here's the predictions, what we actually said here is minus the actual labels. we're going to square it, take the mean, which is generally how i won't get into this, but this is a way of turning those into numbers that are useful for pytorch. And so what this loss stop algorithm is saying is for each of these parameters, what effect if I were to make them larger, if I were to increase the knob, what effect would they have on the loss? Would it make the loss larger or would it make the loss smaller? And now that we've calculated this, so what actually happens in each of these parameters, which is a compute graph, we have a dot grad, which tells it the effect of that parameter moving up. on the loss and we do the step which then nudges that parameter either makes it larger or smaller according to the direction of what is called the gradient, but really in terms we are making it smaller or larger to decrease the loss if we were to run this again. So we are nudging it in the direction that will minimize the loss. And again, it knows that because it knows how each parameter, how each knob is related to the final loss. It's kept track of this the whole time, and so it can tell, yeah, if we make it larger, what is the effect on the loss? We've now kind of have an overview of how general non-language model neural network works, which is you have specific inputs, they are of specific. you know, numbers, and then they output a specific number. and we can basically calculate, given this output, how close we are to the expected output. language models are totally different beasts. they are much more general.

是的,所以。 当我们调用 loss.backward() 时,PyTorch 做的是:对于每个参数,它知道该参数在计算最终结果时参与了哪些运算,也知道最终结果与我们想要得到的结果相差多少,这个差值是在这里计算的。 所以这里是预测值,我们实际上在这里做的是预测值减去真实标签。 我们对其平方后取平均值,这通常是怎么做的,我不会深入讲,但这是一种把它们转换为PyTorch可用数值的方法。 所以这个损失最小化算法的意思是:对于这些参数中的每一个,如果我把它变大,也就是把旋钮调大,会对损失产生什么影响? 是会让损失变大,还是让损失变小? 现在我们已经计算好了,那么在每个参数上实际发生的是什么呢?这是一个计算图,我们有一个 dot grad,它告诉我们该参数向上移动时的影响。 对损失的影响。然后我们执行更新步骤,让该参数根据所谓梯度的方向变大或变小,但实际上,从效果来说,如果我们再运行一次,我们就是要让它变小或变大,以减少损失。 所以我们是朝着能使损失最小化的方向调整它。 而它之所以知道这一点,是因为它清楚每个参数、每个旋钮与最终损失之间的关系。 它一直都在记录这些信息,所以它能够判断:是的,如果我们把它变大,对损失会有什么影响? 我们现在大致了解了通用的非语言模型神经网络的工作方式,即你有特定的输入,它们是具体的 你知道的,数字,然后它们输出一个特定的数字。 我们基本上可以根据这个输出计算出它与期望输出的接近程度。 语言模型则完全不同。 它们的通用性要强得多。

but what's interesting is we can take the same document, the same data, and we can build a language model that will also predict the price. but we do it with language. and so the inputs, oops, the inputs. Are now the actual words on this document, really in reality their tokens, which are fractions of words or multiple words put together. But for now, simplify. Let's just say they are words. And so the model, the training data as input, will be words as a sequence. So at first, it will just use soho. It'll predict this comma. So comma, it should predict 1,200.

但有意思的是,我们可以使用同一份文档、同一份数据,构建一个同样能预测价格的语言模型。 但我们是用语言来实现的。 所以输入,哎呀,输入是…… 现在是这份文档中的实际词语,实际上是它们的词元(token),即词的片段,或者多个词组合在一起。 但目前先简化一下。 我们就假设它们是词语。 因此,模型的训练数据作为输入,将是按序列排列的词语。 所以一开始,它只会使用 soho。 它会预测这个逗号。 所以逗号之后,它应该预测1,200。

Speaker 0

So and so. Sorry, real quick. So. we're looking at the same data, right? soho, 1200, two bath, which before were individual inputs. but now we're looking at it as just like pure text, which it's just like, here's a string of text. let's continue and look what the next potential token or word is.

就是这样那样。 抱歉,快速插一句。 所以。 我们看的是同样的数据,对吧? Soho、1200、两卫,之前这些是各自独立的输入。 但现在我们把它当作纯文本来看,就像这是一串文字。 我们继续看下一个可能的词元或单词是什么。

Speaker 1

yes. yeah. and fundamentally, at a high level, neural networks. Are finding patterns in your data and they are really becoming your data. So the idea is they are learning to output given the data that it's already seen and the patterns it has ingested. What is the most likely next word such that I am being faithful to the data that you presented me with? So in essence, neural networks really are just the data that you are putting into it. So if we only feed it this type of document and let's say this document is 1 million lines. Um, it's all it knows how to only make sense of these types of words, but it should at the end of the day actually understand the patterns in the data such that it can also output, um, a next a word which in this case will be the prediction for the price of the of the unit.

是的。 对。 从根本上讲,在高层次上,神经网络…… 正在数据中寻找模式,并且它们实际上正在成为你的数据。 所以其思路是,它们学习根据已经见过的数据和已经吸收的模式来输出结果。 在忠实于你提供给我的数据的前提下,最可能的下一个词是什么? 因此,本质上,神经网络其实就是你输入给它的数据。 所以如果我们只喂给它这种类型的文档,假设这份文档有100万行。 嗯,它只知道如何理解这类词语,但归根结底,它应该真正理解数据中的模式,从而也能输出一个下一个词,在这个例子中就是该单元价格的预测。

Speaker 0

And Jeremy, when we're so the previous model we're running is very different from what a large language model is. First, can you remind me what the previous model is called?

Jeremy,我们之前运行的模型与大型语言模型非常不同。 首先,你能提醒我之前的模型叫什么名字吗?

Speaker 1

The previous model was just a neural network.

之前的模型只是一个神经网络。

Speaker 0

okay. can neural networks or are neural networks more accurate when you're looking for a very specific answer versus like a text-based answer?

好的。 当你要寻找一个非常具体的答案时,神经网络是否更准确,还是相比基于文本的答案,它们更准确?

Speaker 1

right. so the real answer is with enough data and compute, they should converge to the same thing, which is finding the correct function for to map your data and finding the patterns. In the limit, these should converge. However, with finite resources, if there's a problem where you're just wanting to output the price of something, you would certainly prefer to just have a normal neural network. A language model is in the subgroup of neural networks, like a language model is a deep neural network. But the point is, neural networks. we'll get the gist of the thing. these are two flavors of neural networks, but fundamentally what is happening under the hood is knobs are adjusting to map inputs to outputs, and if you do it for a long enough time with the same data, they should converge to the same answer. As you can tell, language is a whole new beast, right? Because there are so many more degrees of freedom with language than there are with numbers, or you know, with specific numbers that mean a certain thing. So compute for compute, you will always prefer to do just a normal neural network. But the underlying, you know, the truth is they will both converge to the correct answer, which is to find the function, the correct function, the correct pattern from input to output.

对。 所以真正的答案是:只要有足够的数据和算力,它们最终应该会收敛到同一结果,也就是找到正确的函数来映射你的数据并发现其中的规律。 在极限情况下,它们应该会收敛。 然而,在资源有限的情况下,如果问题只是要输出某个东西的价格,你肯定更倾向于直接使用普通的神经网络。 语言模型属于神经网络的一个子类,比如语言模型就是一种深度神经网络。 关键在于,神经网络。 我们会理解这件事的大意。 这些是神经网络的两种类型,但从根本上说,其内部运作的是:参数(旋钮)不断调整,以将输入映射到输出;如果用相同的数据长时间训练,它们应该会收敛到同一个答案。 如你所见,语言是一个全新的挑战,对吧? 因为与数字相比,或者与那些代表特定含义的具体数字相比,语言的自由度要多得多。 因此,就同等算力而言,你总是更倾向于使用普通的神经网络。 但从根本上说,二者都会收敛到正确答案,也就是找到从输入到输出的正确函数、正确规律。

Speaker 0

And because there's so much more flexibility with a language model, that makes it take much more data, much more input data to converge to the same level of accuracy as a as kind of the previous neural network we were just looking at would be right.

而且由于语言模型的灵活性大得多,要达到与我们刚才讨论的前一种神经网络相同的准确度,它需要多得多的输入数据才能收敛。

Speaker 1

That's generally correct. Yes. Okay. Um, yeah, there's a there's a lot of nuance with what you said, but but absolutely right. There are so many degrees of freedom. There are so many complicated relationships now that we're in language space. that, yeah, you're going to need a lot more parameters and a lot more compute to make sure that it really grasps the pattern.

大体上是正确的。 是的。 好的。 嗯,你说的这些有很多细微之处,但绝对正确。 自由度实在太多了。 现在我们进入了语言空间,各种复杂的关系也随之多了起来。 是的,要让它真正掌握其中的模式,你需要多得多的参数和大得多的算力。

Speaker 0

cool.

很好。

Speaker 1

so, yeah, but ultimately, you know, language models are just a new flavor of neural networks, but much more general. and so what's really cool is, okay, we care about predicting the next price. sure, we can use a language model for it. but the beauty is we can dub any text.

所以,是的,归根结底,语言模型只是神经网络的一种新形式,但通用性要强得多。 真正酷的地方在于,好,我们关心的是预测下一个价格。 当然,我们可以用语言模型来做这件事。 但妙处在于,我们可以把任何文本都拿来用。

train any language model on any amount of text, like the entire internet, and now it'll soak up the patterns of the internet. and ultimately, if you train it well, it will be able to predict the next word as an autocomplete of a given text, and it will reflect the data that you gave it. so if you train it on the entire internet, and then you ask it to just start generating next words, it will generate the most likely words. Given the input which is the internet, and so it is finding all of these patterns, and it is really what its data is ultimately. And I think you know, one obvious question as well. It was easy to calculate the loss, the how off we were when we were just outputting numbers at the end, but with language, you're outputting a word at the end. How are we supposed to compare 1.2 million to 1.5 million? These are two words. Well, the trick is language models don't output the final layer of a neural network when we're predicting. Just the price is just one. It's just the price. It's the number. With language models, you actually, um, the final layer or the number of words that you could possibly predict next, and each of them is assigned a probability of how likely the model thinks that token that next word should be. And now you can compare the probabilities. So let's say the right answer is 1.2 million, and as we're training, the language model thinks this is only 10% likely, but the real answer is it's 100% likely because it actually happened. For the real world, says 1.2 million is the right answer. So now we tune our knobs to turn what was 10% likely. We want to inch it towards 100%, so we want to make this more likely, 1.1 or 1.2 million more likely slightly. we're going to nudge all of the input knobs to make 1.2 just a bit more likely, which by definition makes everything else a bit less likely. and this is how we're training these neural networks. here is a real example of using Qwen to 0.5 b, which is 500 million. knobs numbers. and we have two models here. we're going to take a base model, which is a pre-trained model from Qwen, and we're going to start with this. and so what the base model says is, again, we've taken all of the internet, and we now have this model, and we can now generate completions from it. we have now created an autocomplete from the internet. so all it knows to do is complete text. that are similar to those that it is seen in in training, so we can actually just take it for a spin here. this should already be loaded. cool okay, so what i'm doing here is just two examples. i'm giving it an input of zero, so it's basically saying i'm asking it, and then i'm asking it to generate 100 new words. and so what we would expect is it's going to generate words that are in what it's been trained on. It thinks it's most likely randomly, so we can tell that this model Qwen has been trained on a lot of code because the first thing it outputs are code just auto completing from the internet, and then the second thing is this weird chinese thing. So it's obviously also been trained on text that looks like this, so we can it's safe to assume that a lot of the training data. in the quen model that it's been trained on, this base model, looks like this. now, it's autocomplete. so i can actually say, matthew berman said, and now it's going to generate 100 tokens that follow set. and we get to just see what's in this weird mind of this model that has seen basically all of the internet. Matthew Berman said in his interview that a good book should be a good story with main character. I don't think you said this. I don't remember saying that. I don't think you said anything. But the point is, this is an autocomplete. It's repeating what it thinks, given all of the inputs that it's been trained on, what are likely things that should follow. And that is really all that this is doing.

在任意数量的文本上训练任何语言模型,比如整个互联网,它就会吸收互联网上的各种模式。 最终,如果训练得好,它就能像自动补全一样,根据给定的文本预测下一个词,并且会反映你提供给它的数据。 所以如果你用整个互联网训练它,然后让它开始逐词生成,它就会生成最可能的词语。 以互联网作为输入,它就会发现所有这些模式,而它最终就是它的数据本身。 我想,还有一个显而易见的问题。 之前只输出数字时,计算损失很容易,也就是计算我们的预测偏差有多大;但对于语言,你最终输出的是一个词。 我们该如何比较120万和150万呢? 这是两个词。 其实诀窍在于,语言模型在预测时并不输出神经网络的最后一层。 价格只是一个。 就是价格。 就是那个数字。 对于语言模型来说,你实际上,嗯,最后一层,或者说你可能预测下一个的所有词的数量,其中每一个词都被赋予一个概率,表示模型认为该词作为下一个词的可能性有多大。 现在你可以比较这些概率了。 比如说正确答案是120万,而在训练过程中,语言模型认为它的可能性只有10%,但实际上它的可能性是100%,因为它确实发生了。 就现实世界而言,120万是正确答案。 于是我们调整旋钮,把原本10%的可能性提高。 我们希望让它一点点趋向100%,所以我们要让这个答案更可能出现,把120万或110万的可能性稍微提高一些。 我们要微调所有输入旋钮,使120万的可能性略微提高,而根据定义,这也会使其他所有选项的可能性略微降低。 这就是我们训练这些神经网络的方式。 这里有一个使用Qwen 0.5B的真实例子,也就是5亿参数的模型。 旋钮的数量。 这里我们有两个模型。 我们先取一个基础模型,也就是Qwen的预训练模型,我们从它开始。 基础模型的表现是这样的:同样,我们已经用上了整个互联网的数据,现在得到了这个模型,并可以用它生成补全内容。 我们已经用互联网创建了一个自动补全工具。 所以它只会做一件事:补全文本。 与它在训练中见过的内容相似的文本,所以我们可以直接在这里试一试。 这个应该已经加载好了。 好的,我在这里只做两个例子。 我给它的输入是0,也就是说我是在提问,然后让它生成100个新词。 因此我们预期它会生成在训练中见过的词语。 它认为最可能是随机的。所以我们可以看出,这个Qwen模型训练时用了大量代码,因为它输出的第一件事是代码,只是从互联网上自动补全,然后第二件事是这种奇怪的中文内容。 所以它显然也训练过类似这样的文本,因此可以安全地假设,训练数据中有大量这类内容。 在Qwen模型所训练的这个基础模型中,数据大致是这样的。 现在,它是自动补全。 所以我可以直接写:Matthew Berman说,然后它就会生成接下来的100个token。 我们可以看看这个几乎看过整个互联网的模型,其怪异的“大脑”里到底装着什么。 Matthew Berman在采访中说,好书应该是一个有主角的好故事。 我不认为你说过这话。 我不记得自己说过那句话。 我不认为你说过任何话。 但关键在于,这就是一个自动补全工具。 它只是在重复,根据它所训练的全部输入,判断接下来可能会出现什么内容。 这基本就是它所做的全部事情。

But it's fun to play around with. So again, it's autocomplete. You can put anything you want in here. And then it will output something interesting. And if you remember.

不过,玩一玩还是很有趣的。 所以,再说一遍,它就是自动补全。 你可以在这里输入任何你想要的内容。 然后它会输出一些有趣的东西。 如果你还记得的话。

Speaker 0

yeah, real quick, Jeremy, so I think one interesting thing to point out is that this Qwen model was trained probably a while ago, and maybe the reason why it's making something up about what I said is because it has no information about it. Nothing in the training data told it what I have said. Now, if. As part of the training data, it took some of my YouTube videos, transcribed them, and put them in the training data. It would know what I said.

好的,Jeremy,简单说一下。我觉得有一点值得指出:这个Qwen模型可能是很久以前训练的,它之所以会编造关于我所说内容的东西,可能正是因为它对此毫无信息。 训练数据中没有任何内容告诉它我说过什么。 现在,如果。 作为训练数据的一部分,它提取了我的一些YouTube视频,将其转录成文字,并放入了训练数据中。 它会知道我说过什么。

Speaker 1

That is true. However, I'll note that a pre-trained model might not have been trained to output necessarily things that are coherent or correct or not hallucinated, but it will definitely sound more like you. if it has been trained on data that you've actually said, it might not give verbatim things that you've said. so it's definitely been trained on einstein and these might be correct quotes, but also what you'll see is this is a bit. Incoherent, right? The answer to this question is in the text. My understanding is this is like incoherent, right? This is this is auto complete. It's just it's just producing what it thinks is most likely. But this is actually not very useful. It might be useful, you know, for this amount. Maybe if you want to write an email, it's seen a lot of emails that can give you the gist of what a good email might be. but this is also not very useful. so if you remember, you know, the pre-ChatGPT days, generally these were base models. and the base models aren't trained to be helpful. they aren't trained to necessarily tell the truth. they are just trained to autocomplete whatever is given to them. and so this is pre-training. pre-training is, okay, we have this incredible neural network where we can... we can train it on anything we want, any text we want, and it will have the gist, the patterns of this text, and it will predict things that it thinks are likely given the text that it's been trained on, with no guarantee that it's correct. it's just what's, what's more likely, what's, what's likely, what's likely, what's likely given the text that's been trained on. So the question is, how do you turn this into a chatbot or something useful? So one idea could be, well, what if we actually... actually, if I say like user, what is one plus one? assistant. so people figured out that because it's just autocomplete, what we can do is we can actually like figure out interesting things to pre-fill it with such that then it starts out outputting, completing more of what we want it to. so what i just did is i kind of tricked it. i said, okay, there's a, this is a text we want you to complete. a user says, what is one plus one? then the assistant colon. and we're kind of tricking it into becoming an assistant, right? it's taking all of what it knows about assistants online. and then it's going to autocomplete it. and so user, what is 1 plus 1? assistant, 1 plus 1 equals 2. okay, so now, you know, it goes on to something incoherent. but okay, we actually have an answer. and this is really cool. we just turned this, you know, this autocomplete engine into something that could possibly be useful. and this is something that researchers found. and so they're thinking, wait, okay, so if we come up with some sort of format, We can trick the model into being an assistant by basically having complete, and if it were to complete the document, it would do what we want. This is the actual Qwen 2 formatting. So they came up with something called im_start, im_end, and start. And we can actually just run this and it will autocomplete as an assistant, but it hasn't been trained to know when to stop. So it's just going to continue and continue. It's not necessarily a helpful assistant, but it is now assuming the role at least right here. of the assistant. like this is a correct answer.

这是真的。 不过,我要指出,预训练模型未必是经过训练、一定会输出连贯、正确或没有幻觉的内容的,但它确实会更像你说话的风格。 如果它是基于你实际说过的数据训练的,它可能不会逐字给出你说过的内容。 所以它肯定是在爱因斯坦的内容上训练过的,这些可能是正确的引语,但你也会看到,这有点…… 不连贯,对吧? 这个问题的答案就在文本中。 我的理解是,这就像是不连贯的,对吧? 这就是自动补全。 它只是在生成它认为最可能的内容。 但这实际上并不十分有用。 你知道,在某些情况下它可能还是有用的。 比如你想写一封邮件,它见过很多邮件,所以能给你一个好邮件大致是什么样子的概念。 但这同样也不是很有用。 所以,如果你还记得ChatGPT出现之前的时代,那时候通常使用的是基础模型。 而基础模型并不是为了提供帮助而训练的。 它们也不一定是为了说实话而训练的。 它们只是被训练来自动补全给定的任何内容。 所以这就是预训练。 预训练是这样的:我们有一个非常厉害的神经网络,可以用任何我们想要的文本来训练它,它会掌握这些文本的大意和规律,并根据它所训练过的文本,预测它认为可能的内容,但不保证预测是正确的。 它只是在判断什么更可能,什么更可能,什么更可能,什么在它所训练的文本基础上更可能。 那么问题来了,怎样才能把它变成聊天机器人或者其他有用的东西呢? 所以一个想法是,如果我们真的……其实,如果我说像这样:用户,一加一等于几? 助手。 所以人们发现,因为它只是自动补全,我们可以找到一些有趣的内容来预先填充它,这样它就会开始输出,补全更多我们想要的内容。 所以我刚才做的其实是某种欺骗。 我说,好的,这里有一段文本,我们希望你把它补全。 一个用户问:一加一等于几? 然后是助手:”。 我们其实是在诱导它变成一个助手,对吧? 它会调用它在网上所了解的关于助手的一切。 然后它就会自动补全下去。 于是是:用户,一加一等于几? 助手,一加一等于二。 好,然后它接着就会说出一些不连贯的内容。 但好吧,我们确实得到了一个答案。 这真的很酷。 我们把这个自动补全引擎变成了一个可能很有用的东西。 而这正是研究人员发现的一点。 于是他们想,等等,好,如果我们设计某种格式,就可以通过基本上写出一个完整的文档,来诱导模型扮演助手;而如果它要补全这个文档,它就会做我们想要的事。 这就是Qwen 2实际使用的格式。 所以他们想出了一套叫做 im_start、im_end 和 start 的标记。 我们其实可以直接运行,它就会以助手的身份自动补全,但它并没有经过训练,不知道什么时候该停下来。 所以它会一直继续、继续下去。 它不一定是一个乐于助人的助手,但至少在这里,它现在已经承担了这个角色。 助手的角色。 就像这是一个正确的答案。

Speaker 0

and when you say continue and continue, it's literally just indefinitely predicting whatever the next token is, whatever the next word is.

而当你说继续、继续下去时,它其实就是在无止境地预测下一个标记,也就是下一个词。

Speaker 1

right. and this is, i gave it 200 tokens. so for the next 200 tokens, predict what you think is the right thing to do. right.

对。 这里我给它设定了200个标记。 所以接下来的200个标记,它会预测它认为正确的做法。 对。

Speaker 0

and it doesn't notice. if you said 10,000, it would continue till that number as well. okay.

而它并不会察觉到这一点。 如果你设定的是10,000,它也会一直续写到那个数字。 好的。

Speaker 1

got it. yes. yes, and with language models, remember it's predicting a sequence. so for each new word, it adds that word to the sequence and then predicts the next one, adds that next word to the sequence and then predicts the next one. So we've noticed this, researchers noticed this, and they're like, ok, so we can now trick it into thinking it's an assistant. So what if we just create a bunch of data? For how we want the assistant to behave with our formatting, and then the model again, which will learn the formatting that we're telling it to learn, and it will become an assistant.

明白了。 是的。 是的,而对于语言模型,要记住它预测的是一个序列。 所以对于每一个新词,它把该词加入序列,然后预测下一个词;再把这个下一个词加入序列,然后预测再下一个词。 所以我们注意到了这一点,研究人员也注意到了,于是他们想:好,那我们现在就可以骗它,让它以为自己是一个助手。 那如果我们直接创建一大批数据会怎样? 数据内容是我们希望助手在我们的格式下如何表现,然后模型再次学习我们告诉它要学习的格式,于是它就会变成一个助手。

And so this is what we do, and this is the start of post-training, which is we're taking this base model, which is kind of a model of the world that can assume all of these various personas. It doesn't know it's an assistant, it has been trained to be an assistant, and we're filling it with a bunch of data. maybe we start by having humans literally like write user queries and then write assistant queries and then we're training on it. and then we're going to say we generate 100,000 examples of an assistant auto-completing. and we're also going to include in these examples a stop token, which means this is when the assistant stops. and now the assistant learns, okay, my role, it's starting to gain an ego here. my role is an assistant and when i'm done responding to the user in a good way as seen in the data, i should emit a stop token and when the program sees the stop token, it stops generating. And so now I'm going to use the instruction model, which has been trained with this data to know that it's an assistant. It now has an ego and it should know how to stop. And as you can see here, why is the sky blue? The sky appears to be blue when sunlight, however, when light so when we look up at the sky, the clouds, different colors and refracted options in the air. Great. So this is a pretty, pretty good response. And so comparing this, this response to this response is really the difference between an instruct model and a pre-trained or base model. And this probably in the Qwen 2 series was mostly really done with generating a bunch of data of good assistant messages with this formatting, and the model learns to learns the patterns and learns to be an assistant. And what is key here is every message. So this is what you might be familiar with when you actually like write to a language model, right? You have a role, user, content, wise sky blue. Under the hood, the model is actually just generating this format and giving it to the model, so it's trickery. Right? Like you are just pre-filling the model with what it's things that it's been trained on, and then it can respond in a similar way. So these are this and this are equivalent. These are the exact same. So we've turned this auto completion engine into an auto completion engine that now understands, has been trained to see a lot of assistant messages and knows now what good assistance sound like and can do it. And if you ever want to see what is actually being sent to the model, the actual tokens that the model is taking as input, you can just. you can use the tokenizer, you can input the messages and it will give you literally what the model sees. So when you write why is the sky blue, what the model is really saying is a system by default message, and then it is why is the sky blue, and it starts the assistant, so it knows to complete after assistant.

我们就是这样做的,这也是后训练的开始:我们拿来这个基础模型,它某种程度上是一个对世界的模型,能够扮演各种不同的角色。 它并不知道自己是助手,它只是被训练成了助手,而我们正在用大量数据来填充它。 也许我们一开始会让人类真正地撰写用户提问,然后撰写助手的回答,接着用这些数据进行训练。 然后我们会说,我们生成10万个助手自动补全的示例。 我们还会在这些示例中加入一个停止标记,也就是助手何时应该停止输出。 现在助手学会了:好,我的角色是这样,它开始在这里产生一种“自我”了。 我的角色是助手,当我以数据中所示的良好方式回应完用户后,我应该输出一个停止标记,而程序看到停止标记时就会停止生成。 因此,现在我要使用这个经过此类数据训练、已经知道自己是助手的指令模型。 它现在有了“自我”,也知道该如何停止。 如你在这里所见,提问是:天空为什么是蓝色的? 当阳光照射时,天空看起来是蓝色的;然而,当光线……当我们抬头看天空时,云层呈现不同颜色,光在空气中发生折射和散射。 很好。 所以这是一个相当,相当不错的回答。 因此,将这个回答与那个回答相比较,正体现了指令模型与预训练或基础模型之间的真正区别。 在Qwen 2系列中,这很可能主要是通过生成大量具有这种格式的优质助手消息数据来完成的,模型由此学习这些模式,并学会成为一个助手。 这里关键的是每一条消息。 所以这就是你在真正给语言模型写东西时可能熟悉的格式,对吧? 你有一个角色,user,content,wise sky blue。 在底层,模型实际上只是在生成这种格式并把它交给模型,所以这是一种技巧。 对吧? 就像你是在用模型曾经训练过的内容来预先填充模型,然后它就能以类似的方式回应。 所以这个和这个是等价的。 这两者完全相同。 因此,我们把这个自动补全引擎变成了一个现在能够理解、并经过训练能看到大量助手消息的自动补全引擎,它现在知道好的助手听起来是什么样的,也能够做到。 如果你想看看实际发送给模型的内容,也就是模型作为输入接收的真正token,你只需要…… 你可以使用分词器,输入消息,它会字面上告诉你模型看到的内容。 所以当你写下“天空为什么是蓝色的”时,模型实际看到的是一条默认的系统消息,然后是“天空为什么是蓝色的”,并且开始了助手的部分,所以它知道要在assistant之后进行补全。

Speaker 0

And I just want to interject, if people want to try this, it is effectively free to do what you're doing. You can use Google Colab for free. Qwen is an open weights model you can download for free. So and we'll drop all the links to all this stuff down below.

我想插一句,如果大家想尝试这个,做你正在做的事情实际上是免费的。 你可以免费使用Google Colab。 Qwen是一个可以免费下载的开放权重模型。 所以,我们会把所有相关链接放在下面。

Speaker 1

yep, this is all free. i don't have a special plan. i'm using a t4 for free on google collab. cool. yep. okay, so this is the start of post-training, which is really exciting. we have an assistant model, and this is, you know, gpt-3. there are a lot of things i'm glossing over, but this is the general gist is we've turned an auto-complete engine and we've tricked it with more data into thinking that it's an assistant.

是的,这一切都是免费的。 我没有什么特别的付费计划。 我在Google Colab上免费使用的是T4。 不错。 嗯。 好的,这就是后训练的开始,这真的很令人兴奋。 我们有了一个助手模型,你知道的,这就是GPT-3。 有很多细节我在这里略过了,但大致的要点是:我们把一个自动补全引擎,通过更多的数据,骗得以为它是一个助手。

and it's now developed this assistant persona. and this is really cool and interesting. but now there's kind of a separate problem, which is the models can produce interesting things, but they are making obvious errors. if you asked it, i don't know if you remember, asking it math, it will seem very confident. it will return to you the answer without thinking. Right. So here's an example. What is, you know, 398 times 923 plus 2901, right? And the result of multiplication of this is 37,000, which is wrong. The right answer is 370,000. So this model totally got it wrong, right? And the. but it wasn't assistant, right? it generated it correctly. it knew to stop. so now there's this new issue, which is the models are just blurting out whatever they think, right? they're not actually thinking. and if i were to ask you this, you would think about it, think step by step, actually solve it, thinking. One thing that researchers discovered is maybe all you need to do is first prefill the assistant with let's think step by step, and then ask it again, and then all of a sudden you actually don't necessarily always get the right answer, but it is now actually thinking step by step, and it's getting closer. So now.

它现在已经发展出了这种助手人设。 这真的很酷,也很有意思。 但现在又出现了另一个问题:这些模型能产生有趣的东西,但它们会犯明显的错误。 如果你问它(我不确定你是否还记得),让它做数学题,它会表现得非常自信。 它会直接把答案返回给你,而不经过思考。 对。 所以这里有一个例子。 你知道的,398乘以923再加上2901等于多少,对吧? 这个乘法的结果是37,000,这是错的。 正确答案是370,000。 所以这个模型完全算错了,对吧? 而且, 但它当时并不是助手,对吧? 它生成的内容是正确的。 它知道该停下来。 所以现在出现了一个新问题:模型只是脱口而出它们所想的,对吧? 它们其实并没有在思考。 还有,如果我问你这个问题,你会思考它,一步一步地思考,真正去解决它,思考。 研究人员发现的一件事是,也许你只需要先用“让我们一步一步地思考”来预填充助手的回复,然后再问一次,突然之间,你不一定总能得到正确答案,但它现在确实在一步一步地思考,并且越来越接近正确答案。 所以现在。

Speaker 0

by the way, the discovery of let's think step by step. seems like very obvious, but it was kind of a recent discovery. It was wasn't it post ChatGPT becoming really publicly available, publicly known that people figured out, oh, literally just ask it to think step by step and you get better answers. Because I remember when I was making videos. In the early days of model reviews, I would manually type think step by step to get better answers from the models.

顺便说一下,“让我们一步一步地思考”这个发现。 看起来很显而易见,但它其实是最近才出现的发现。 是不是在ChatGPT真正公开可用、广为人知之后,人们才发现,哦,只要让它一步一步地思考,就能得到更好的答案? 因为我记得我在做视频的时候。 在模型评测的早期,我会手动输入“一步一步地思考”,以从模型那里得到更好的答案。

Speaker 1

Yeah, this um, it's unclear what was happening at the labs at this time, but in public, this is definitely true. And there are multiple ways to do it. There's one to like first force the assistant to start with this text, which is what we're doing here. There's also one where you prompt it to think step by step, which also yields better results. and yes, this is relatively recent again. I think probably the labs had figured out pretty quickly, but I agree publicly this was. this was relatively new and now all of a sudden we're getting quite close. now i'm going to transition.

是的,嗯,当时实验室里发生了什么不太清楚,但在公开层面,这确实是真的。 而且有多种方法可以做到这一点。 一种是先强制助手以这段文字开头,也就是我们这里正在做的。 还有一种是提示它一步一步地思考,这同样会带来更好的结果。 而且,没错,这同样是相对较新的事情。 我想实验室可能很快就想明白了,但我同意,在公开层面,这是。 这相对较新,而现在我们突然变得相当接近了。 现在我要过渡到下一个话题。

Speaker 0

and the first public publicly available model to use this new thinking was a one. is that right?

而第一个公开可用、采用这种新思考方式的模型是 o1。 是这样吗?

Speaker 1

right? it was a one. yes.

对吧? 是 o1。 是的。

Speaker 0

By OpenAI.

由OpenAI提供。

Speaker 1

yes. So you know, we were living in this non-thinking paradigm, and part of why the non-thinking was the case is because on the internet you get a lot of the outcomes of thinking, right? You see blog posts which had a lot of thinking, but you know, by humans to build the blog post, but you don't see the thinking with code, right? You see the final finished code, but you don't see the thinking, all the thinking that came into writing these these piece of code. And so the internet generally lacks thinking data. And not only that, even if it had thinking data, this is the model learning to think, but not for itself, kind of imitating what it thinks thinking should be. Now, in the limit, if you had enough of this data and a large enough model, it's very possible it would grasp fundamentally the patterns of thinking, and you could tell it to think like Einstein, and it would think for itself. But practically, what we found is that we can actually train the model to think for itself, to actually try out problems and learn from trial and error, which is called reinforcement learning.

是的。 要知道,我们一直处于这种非思考的范式中,而之所以会如此,部分原因在于互联网上你看到的大多是思考的结果,对吧? 你会看到一些博客文章,里面有大量思考,但那是人类为了写博客而进行的思考,而你看不到代码背后的思考过程,对吧? 你看到的是最终完成的代码,却看不到思考过程,也就是编写这段代码时所有的思考。 因此,互联网上通常缺乏思考数据。 不仅如此,即便有思考数据,这也只是模型在学习如何思考,而不是为了它自己,更像是在模仿它认为思考应该是什么样子。 从极限来看,如果有足够多的此类数据和足够大的模型,它very可能最终掌握思考的根本模式,你甚至可以让它像爱因斯坦那样思考,而它会自己去思考。 但在实践中,我们发现可以训练模型自己思考,让它真正去尝试问题,并通过试错学习,这被称为强化学习。

And this is what led to O one. Yeah, so O one was the first public model that had thinking, and it was this. I remember what it came out, it was just incredible. It was doing really well on things like Arc. It could code much better. It was just a whole new way of being able to use these language models. It was hallucinating less. and we didn't really know how it worked publicly until DeepSeek came out with r1, the famous deepseq r1 paper, which showed how you can do this with reinforcement learning. so i'm going to gloss over quickly around the next stage, which is using reinforcement learning to train the model to think for itself and to, through trial and error, update itself. How DeepSeek was able to train this model, I think for itself, is called GRPO, is the method they use, group relative policy optimization. But what this really means is, okay, so we have this math problem, right? Let's have the model try to answer this math problem 100 times. Actually, let me take a step back. Maybe the naive approach is: let's have the model try and answer a problem 100 times, and let's tell it to think step by step. And every time it gets it right, let's add this to the training data and train on this, so reinforce the times when it thought well, and we'll just throw out the bad examples. So this is a naive approach which actually does work. It's called rejection sampling. there are a few problems with this. one is that you don't learn from negative examples, and then two, there's a lot of noise in every rollout, in every response. there's of the random tokens that don't actually matter, they're kind of noisy, but you're also uploading them again, you're training on them. GRPO is a way of learning from negative examples as well, and also with scale canceling out a lot of the noise that you have this stable training of the model trying out problems for itself and learning. So the way it works, the model answers a problem 100 times, and then you score each problem based on how well it did one, how well it followed your desired formatting for thinking. and then two whether it got to the right answer, and then you take the average score of all of these groups, and then you subtract its score from the average, and this is called the advantage. this is basically how much this solution was better than the average solution the model is producing.

这正是O1诞生的原因。 是的,O1是第一个公开、具备思考能力的模型,就是这样。 我记得它发布时,真的令人难以置信。 它在ARC等任务上表现非常出色。 它的编程能力好得多。 这是使用语言模型的全新方式。 它的幻觉也少了很多。 直到DeepSeek发布R1,以及著名的DeepSeek R1论文,我们才公开了解它是如何运作的,该论文展示了如何利用强化学习实现这一点。 所以我将快速略过下一阶段,即利用强化学习训练模型自己思考,并通过试错不断更新自身。 DeepSeek是如何训练这个模型自己思考的呢?我认为其所用的方法称为GRPO,即组相对策略优化(group relative policy optimization)。 但这real意味着什么呢,好,我们有这样一道数学题,对吧? 让模型尝试回答这道数学题100次。 其实,我先退一步说。 也许最直接的做法是:让模型尝试回答一个问题100次,并告诉它要一步一步地思考。 每次它答对了,就把这个加入训练数据并用它来训练,也就是强化它思考得好的那些时候,而把糟糕的例子直接丢弃。 所以这是一种朴素的方法,但它实际上确实有效。 这叫做拒绝采样。 这种方法存在几个问题。 一是你无法从负面例子中学习;二是每一次推演、每一次回答中都存在大量噪声。 其中有很多随机的、实际上并不重要的token,它们算是噪声,但你仍然会把它们再次强化,并在上面训练。 GRPO是一种既能从负面例子中学习的方法,同时通过规模化的方式抵消掉大量噪声,从而让模型自己尝试解决问题并从中学习的训练过程变得稳定。 它的工作方式是:模型对一道题回答100次,然后根据两个方面给每个回答打分:一是它做得有多好,即是否遵循了你期望的思考格式; 二是它是否得出了正确答案。接着,你计算这一组所有回答的平均分,再用每个回答的分数减去这个平均值,这个差值被称为优势(advantage)。 这基本上衡量的是这个解法比模型所产生的平均解法好多少。

Speaker 0

and then jeremy, just to clarify, this is all within the category of post training. this is not happening within kind of what people think of chain of thought or kind of the thinking aspect of the model. this is separate.

然后,Jeremy,补充说明一下,这一切都属于后训练的范畴。 这并不是发生在人们通常所理解的思维链,或者说模型思考能力那一层面上的事情。 这是另外一回事。

Speaker 1

Yeah, this is this is training the model to learn to think on its own from from its own synthetic data. Yeah, got it. And so um with this now, each each time you answer a problem, you know its relative score, how well was it relative to if it you know answered 100 times, and then you use this number. to update the model to be more or less like that response over time. So for every token in a role in an answer that was really good, so we have a really good answer, right? It was like a one of one. It was a great answer. We make every token in that response more likely based on how good it was relative. And same thing if it's a bad example, we make every token in that rollout in that answer. A bit less likely, and so we are just tuning the dials to shift the model to make it more likely to answer correctly and less likely to answer incorrectly. But if you think about this on a high level, ultimately, right, this is just changing the data that we are using to train these models to be more correct. And this actually has an added benefit. So this is called on policy training. Policy is the model and this is the model. Generating its own training data on policy and reinforcing. And this is in many ways better than taking someone else's thinking and updating on someone else's thinking because the model generated this this answer itself with its own circuits. and so if you want to make this answer more likely, well, you know the model's already capable of answering like this. so you can just twist the knobs just a little bit to make it just a little bit more likely to output this token, where next word, versus if it's someone else's thinking, you are making all of that other person's thinking more likely, but you don't know what words you're making less likely by doing this. you might start to forget or degrade in other capabilities in a way that with reinforcement learning you don't as much because the updates are generally nicer when you are there, you are being less destructive to the knobs when it is your own thinking because you generated it, you just need to tweak it slightly. so this was a breakthrough and it allowed the models fundamentally to learn from trial and error and to teach itself new things.

是的,这就是训练模型,让它利用自己生成的合成数据,学会自主思考。 嗯,明白了。 所以,现在每次你回答一个问题时,你都知道它的相对得分,也就是相对于它回答100次的情况,它表现如何,然后你就用这个数值。 以便随着时间推移,让模型的输出或多或少地接近那个好的回答。 所以,对于一个很好的回答中的每一个token,也就是说我们得到了一个非常好的回答,对吧? 它简直是独一无二的。 这是一个很棒的回答。 我们会根据它相对而言有多好,提高该回答中每一个token的生成概率。 同样,如果是一个糟糕的例子,我们就会降低那次展开(rollout)中、那个回答里每一个token的生成概率。 让它们稍微不那么可能出现。因此,我们只是在调节这些参数旋钮,使模型更有可能正确作答,更不可能错误作答。 但如果从高层次来看,归根结底,这其实就是在改变我们用来训练这些模型的数据,使其更加正确。 而这实际上还有一个额外的好处。 所以这被称为同策略(on-policy)训练。 策略(policy)就是模型本身,这就是模型。 模型在同策略下生成自己的训练数据,并进行强化。 在很多方面,这比采用别人的思考过程并根据别人的思考进行更新要好,因为这个回答是模型自己用自己的电路生成的。 因此,如果你想让这个回答更有可能出现,你知道模型本来就有能力这样回答。 所以你只需稍微调整旋钮,让它输出这个token、也就是下一个词的概率略微提高。而如果是别人的思考过程,你实际上是在提高那个人思考过程的整体概率,却不知道这样做会让哪些词的概率降低。 你可能会开始遗忘或削弱其他能力。而在强化学习中,由于你是在自己的思考上更新,更新通常更温和,对旋钮的破坏性更小,只需略作调整,所以这种问题没那么严重。 因此,这是一项突破,它从根本上让模型能够从试错中学习,并自己教会自己新东西。

and now we're in this regime where if you can build an environment such that you can have the model answer many times and you can verify whether the answers are correct. then you can build this regime and the model will start to hill climb, it will start to improve on this task with limited degradation, degradation to the other things that the model knows. of course there's still degradation. yeah.

现在我们进入了这样一种阶段:如果你能构建一个环境,让模型多次作答,并且能够验证答案是否正确。 那么你就能建立这种机制,模型就会开始爬坡式地优化,在这个任务上不断改进,同时对模型已掌握的其他能力造成的退化也有限。 当然,仍然会有一些退化。 嗯。

Speaker 0

well jeremy, i wanted to ask you why are these pre training and post training phases separate because it sounds like reinforcement learning is so powerful. why can t that just be done from the beginning. And like maybe you can just kind of from a very high level explain why there needs to be two phases.

好的,Jeremy,我想问你,为什么预训练和后训练这两个阶段是分开的?因为听起来强化学习非常强大。 为什么不能从一开始就直接这样做呢? 你能不能从很高的层面解释一下,为什么需要两个阶段?对吧?

Speaker 1

right? So there are papers that try and merge the two, and I think it is totally possible that they will be merged, and I'm sure many people are working on this. But I think maybe just on a high level, fundamentally, when you're pre-training, you're taking off policy traces, as in you are taking the world's data, right? And you are building a next token, a next word predictor from the world's data. Once you give the model an ego, a personality now. If you give it data, it will start to imitate and become that thing. And so you can't, if you were to then go back to pre-training data, let's say, oh, I have this really great code corpus set of code, and I want to train the model after it's already been assistant post-train. What will happen is the model will start to adopt the style of the data that it's training on, and so it will start to lose the ability to be an assistant. It will start to respond in code, maybe. And then it will also take it for granted. Once you have to be very careful that you are making sure that once you give it an ego, you give it the assistant model, you really can't at least, you know, publicly. There's no, it is difficult to then train it on data that it did not produce. So yeah, if you were to train it on a code corpus, it would start to then talk like code. It would start to take that code for granted. but there are a lot of interesting, there are a lot of interesting experiments going on to build and reinforcement learning to all parts of the stack.

对吧? 确实有一些论文尝试把两者合并,我认为这完全有可能实现,我相信很多人都在研究这个问题。 但我觉得从根本上讲,大致来说,在预训练时,你使用的是离策略(off-policy)的轨迹,也就是说,你是在利用全世界的数据,对吧? 你用世界的数据构建一个下一个词元、下一个词的预测器。 一旦你赋予模型一个自我、一种人格, 如果你给它数据,它就会开始模仿并变成那种东西。 所以,如果你在模型已经完成助手式后训练之后,再回头使用预训练数据,比如说,哦,我有一个非常好的代码语料库,我想在模型已经完成助手后训练之后用它来训练模型, 结果会是,模型会开始采用它所训练数据的风格,因此它会逐渐失去作为助手的能力。 它可能会开始用代码来回应。 然后它还会把这一点视为理所当然。 一旦你赋予它自我,给它助手模型的身份,你就必须非常小心,至少,你知道,在公开场合,你really不能再随意这样做了。 要让它在不是它自己生成的数据上进行训练,是很困难的。 所以,是的,如果你用代码语料库训练它,它就会开始像代码一样说话。 它会把那些代码视为理所当然。 但是,有很多有趣的实验正在进行,目的是把强化学习应用到整个技术栈的各个环节,这方面有很多有意思的地方。

Speaker 0

very cool.

非常酷。

Speaker 1

finally, i'll just end with, you know, i think for a long time, first of all, we're in a very interesting moment, which is language models, you know, to my knowledge, haven't come up with, you know, super important novel discoveries that have been world-changing at this moment, but they are now starting to crack unsolved human math problems, for example. and one of the main criticisms of language models is, well, if they're just next word predictions, and they've been trained on a distribution, and by definition there's nothing new in this distribution because we've taken things that we've already know to train these models. are they really going to be fundamentally capable of escaping the model that they've been trained on and developing new knowledge? I think the answer to this is yes, because ultimately reasoning is the process of making these unlikely, true and interesting things more likely. And so if you think, you know, Einstein when he's coming up with general relativity. At first, the idea of general relativity wasn't a likely thing for him to just come up with because he hadn't thought through and built up, built all of the assumptions into abstractions to be able to deduce general relativity. But it was over time through reasoning that he was able to mold the, you know, his thinking and ultimately the data itself that he's been trained on such that he was able to get there. and models, i think, are the same way, right? as long as we continue to train them to reason really well over long horizons, i don't think there's a reason why they shouldn't be able to develop new knowledge and escape the distribution. because fundamentally, when they are reasoning for themselves, and we are now teaching them to reason for themselves, what this means is they are slowly building new abstractions on the fly until they're able to deduce new things. Um, you know, time will tell, but my money is on on the fact that that models will continue to get much better and they will end up um discovering new things.

最后我简单总结一下,我想说的是,我们正处于一个非常有趣的时刻。据我所知,语言模型还没有提出真正改变世界的重要新发现,但它们已经开始攻克一些未解决的人类数学难题了。 对语言模型的主要批评之一是:如果它们只是在做下一个词的预测,并且是在某个分布上训练的,那么按定义,这个分布里不会有任何新东西,因为我们训练这些模型用的都是人类已经知道的东西。 它们真的能从根本上突破训练数据的局限,发展出新知识吗? 我认为答案是肯定的,因为归根结底,推理就是让那些不太可能出现、但为真且有趣的事情变得更有可能的过程。 比如你想想爱因斯坦提出广义相对论的时候。 起初,广义相对论这个想法对他来说并不是一个很可能会自然冒出来的东西,因为他还没有经过思考,没有把所有假设逐步构建成抽象概念,从而推导出广义相对论。 但随着时间推移,通过推理,他得以塑造自己的思维,乃至他所接受训练的数据本身,最终才得以抵达那里。 我认为模型也是如此,对吧? 只要我们继续训练它们进行长程的出色推理,我认为就没有理由说它们不能发展出新知识、跳出训练分布。 因为从根本上说,当它们为自己推理时——而我们现在正在教它们自己推理——这意味着它们会在运行中不断构建新的抽象概念,直到能够推导出新的东西。 嗯,时间会证明一切,但我押注的是,模型会持续变得强得多,最终会发现新的东西。

Speaker 0

Well, Jeremy, I want to just say thank you so much for sharing all this. Um, I I learned a lot. It it really shows that. It you know, it seems a little bit intimidating, but if you start from the fundamentals and you build off of that, you can really learn it, you can apply it, you can experiment with this stuff yourself. And if you want to make this into a career, you can absolutely do that. It does not require a PhD. Certainly a lot of work, a lot of hard work, putting your head down, learning it, but it is very, very possible. So I just want to say thank you again.

好的,Jeremy,我想说,非常感谢你分享这一切。 嗯,我学到了很多。 确实如此。 它看起来可能有点令人生畏,但如果你从基础开始,逐步深入,你真的可以学会它,应用它,并亲自尝试这些东西。 如果你想把它发展成一份职业,你完全可以做到。 这并不需要博士学位。 当然,这需要大量工作、努力投入、埋头苦学,但这是非常、非常有可能的。 所以我想再次说声谢谢。

Speaker 1

No, thank you. Thank you.

不,谢谢你。 谢谢你。

Overview

视频由Anthropic研究员Jeremy Berman讲解大语言模型从基础原理到训练流程的完整脉络,内容分为七个部分。他先用纽约公寓价格预测的例子说明神经网络本质上是通过调整大量参数(“旋钮”)来拟合函数,再说明自动求导框架(如PyTorch)如何计算每个参数对损失的影响并逐步修正。随后视频讨论语言模型如何把同样的思路应用于文本,通过预训练学习海量文本的统计规律,再经后训练把自动补全模型转变为助手,并通过强化学习让模型在试错中学会推理。最后,视频探讨模型能否突破训练分布、发现新知识。整体以直观、由浅入深的方式呈现,适合希望理解现代大模型训练方法、并以此作为自学入门路线的观众。

Chapters

00:31 视频框架与学习路线

视频的目标是用一个数字文件和一个较小的 Python 程序,给出构建智能系统的直观高层概览。内容被划分为七个部分:什么是神经网络、如何训练、什么是大语言模型、什么是预训练、什么是后训练、模型如何学会思考,以及模型能否发现新事物。讲者指出,这些技术是现代大语言模型(如 ChatGPT、Claude)所用方法的基本版本。每一部分都有很深的细节可以展开,但讲者选择保持高层直观。讲者还强调,这一领域对自学者仍然可行,应当顺着兴趣深入。

直观的高层概述开场
七个部分的框架说明
神经网络主题
神经网络训练主题
大语言模型主题

02:13 神经网络即可调旋钮组成的函数

以纽约公寓数据为例,输入包括位置、面积和卫生间数量,输出是价格,目标是找到从输入映射到价格的函数。传统做法是人工硬编码规则,但数据量达到百万级、输入达到上千维时并不可行。神经网络的做法是给每个输入乘以一个参数(即“旋钮”),参数初始随机,求和得到预测价格,再与真实价格比较得到损失。参数的大小可以理解为各输入的重要程度。通过增加参数和层数,网络可以构造任意复杂的函数,而训练的目标就是不断调整旋钮以最小化损失。神经网络本质上就是由数字和描述其连接方式的 Python 脚本构成。

纽约公寓数据表
输入特征与价格列
位置、面积、卫生间等输入字段
简单示例数据
输入到价格的映射函数

09:16 自动求导与反向传播

人工逐个调整旋钮效率低,神经网络的关键突破在于让计算机自动计算每个参数应如何调整。PyTorch、JAX、TensorFlow 等自动求导引擎会记录所有参数及其参与的计算过程,并在得到损失后计算每个参数对最终损失的影响,即对损失求导。随后,每个参数沿着降低损失的方向按学习率微小更新,这一过程称为反向传播。讲者以简单的线性模型为例,展示自动调整后损失可以降到约 0.07 百万美元,并指出加入更多层和激活函数后,神经网络可以逼近任意函数,即所谓通用函数逼近器。训练需要输入数据和真实标签两类要素。

开始讲解具体示例,适合展示神经网络输入与连接结构的示意图
输入数值与各连接权重(旋钮)的网络结构示意
当前预测与真实值的误差数值(损失)
自动训练过程中参数(旋钮)被自动调整的界面变化
自动训练后能达到的最小误差结果

19:59 训练代码的基本结构

讲者展示了一段简单的 PyTorch 训练代码,它把输入转换为数字,把房价作为标签,然后依次执行前向计算得到预测、计算损失、清零旧梯度、执行 loss.backward() 计算各参数的梯度,并按学习率更新参数。讲者强调,这段代码只是玩具示例,不是生产环境的训练方式,初学者不必理解 PyTorch 的底层细节,可以借助 Claude 或 ChatGPT 逐行解释代码。

标签数据:房价数值展示
损失值与预测误差的可视化结果
代码运行后的输出结果

21:53 训练过程与损失变化

示例训练共进行 1000 步,每 100 步输出一次结果。第 0 步时参数随机,均方误差损失约为 8,预测值与真实值相差很大。损失越大表示预测越差,模型通过梯度信息朝正确方向调整参数,而不是随机尝试。讲者还提到,神经网络与语言模型在本质上都是通过调整参数将输入映射到输出,只要数据和计算足够,两者最终都会收敛到相同的函数映射。语言模型本身只是从 Hugging Face 下载的一组参数数字,加上描述其连接方式的代码。

第0步随机初始化参数时的损失值数据

24:52 语言模型:下一个词的预测

大语言模型的输入是文本的词元(token)序列,训练目标是预测下一个词。与数值预测不同,语言模型的输出层对所有可能的下一个词给出概率分布,训练时增大真实词的概率,从而计算损失。讲者指出,这类模型的自由度远高于数值任务,因此需要更多数据和计算才能收敛。模型实际上吸收的是训练数据中的模式,它输出的内容受训练数据分布的约束。

文档数据行中的房屋特征(soho、1200、two bath)以纯文本形式展示

29:29 预训练:从互联网文本到自动补全

预训练即用海量文本(理论上可以是整个互联网)训练神经网络,让它学会文本中的模式并预测下一个词。讲者以 Qwen 0.5B 基础模型为例演示:模型输出的代码和中文文本说明它的训练数据中包含大量代码。基础模型只会自动补全文本,并不以真实性或有用性为目标。例如,它会编造讲者“说过”的话,因为其训练数据中可能没有相关信息,但输出听起来很像讲者的风格。基础模型生成的内容连贯性差,实用价值有限。

语言模型对候选下一个词的概率分布
正确答案1.2 million的概率对比,模型仅给出10%
Qwen 0.5B基座模型的使用界面
基座模型自动续写输出的代码片段
输入提示后模型生成的续写文本结果

33:38 通过提示格式把自动补全模型变成助手

既然基础模型只做自动补全,研究者便设计特定的文本格式,例如在“用户:1加1等于几?助手:”之后让模型继续补全,从而诱导它扮演助手角色。Qwen 2 使用 im_start、im_end 等特殊标记来区分角色。但这种方式的模型不知道何时停止,会无限生成。这一发现说明,只要设计合适的文本格式,就可以把自动补全引擎转换成有用的助手雏形,这是后训练的开端。

模型输出内容不连贯的结果画面
Qwen 2 聊天格式中的 im_start 等特殊标记展示

38:38 后训练:指令数据与停止标记

后训练的核心是用大量高质量的助手式对话数据继续训练模型,数据可以由人工撰写,或由模型生成约 10 万条示例。这些示例包含结束标记,使模型学会在回答完毕后停止生成。讲者以“天空为什么是蓝色的”为例,对比基础模型与指令模型的输出,后者给出的回答明显更像一个有用的助手。消息中的角色和内容最终都被转换为模型可以读取的特定格式,因此把对话输入模型时,模型实际接收的是这些格式化的标记序列。讲者还说明,这些实验可以在 Google Colab 的免费 T4 GPU 上完成。

基座模型概念说明
填充数据的说明
人工编写用户查询
生成10万条示例
停止标记概念

42:14 直接回答的问题与逐步思考

指令模型虽然能给出流畅回答,但在数学等问题上会自信地直接输出错误答案,例如将 398 乘以 923 再加 2901 的结果算错,因为它只是“说出”而不是“思考”。研究者发现,只要在助手回答前预填“让我们一步一步思考”,或在提示中要求逐步推理,模型给出的答案就明显更接近正确。讲者回顾了公开场合中这一技巧的流行过程,也指出其问题在于互联网文本中多为结果而缺少思考过程,模型模仿的只是人们对思考的表面形式。

数学题原式:398 乘 923 加 2901
模型给出的错误结果 37,000
正确答案 370,000 的对比

45:59 强化学习与 GRPO:模型自我试错

OpenAI 的 o1 是首个公开提供思考能力的模型,其训练方式直到 DeepSeek R1 论文公开后才为外界所知。讲者以 GRPO(群体相对策略优化)为例说明:对同一道数学题,模型作答约 100 次,按格式规范和答案正确性打分,计算每次得分相对群体平均分的优势值,随后提高高优势回答中各个词元的概率,降低低优势回答中的概率。相比仅保留正确样本的拒绝采样,GRPO 同时利用负样本,并通过群体平均抵消噪声,使训练更稳定。讲者强调,这种训练是在模型自己生成的数据上进行的,相比模仿他人的思维过程,更不易破坏模型已有能力。

O1 模型相关讲解的起点
O1 作为首个公开带思考能力模型
O1 发布时的整体印象
O1 在 Arc 等基准上的表现
O1 编程能力提升

51:05 预训练与后训练为何分阶段

讲者解释,预训练使用的是离策略(off-policy)数据,即世界上已有的文本;一旦模型被赋予助手人格,再用其他分布的数据(如代码语料)继续训练,模型会逐渐采用该数据的风格并丧失助手能力,因此两阶段通常分开,尽管已有研究尝试将二者合并。关于模型能否产生新知识,讲者认为可以:推理的本质是让原本不太可能但正确且有价值的内容变得更可能,模型通过长程推理不断构造新的抽象,因此理论上可以突破训练分布。讲者认为,语言模型已开始解决一些未解决的数学问题,但这一结论仍需时间验证。讲者还表示,学习这一领域并不一定需要博士学位,但需要大量实践。

模型采用训练数据风格的代表性说明(无明确视觉证据,取核心段落锚点)

Conclusions

08:33 神经网络本质上是通过调整大量参数(旋钮)来拟合输入到输出映射的函数,训练的目标是最小化预测与真实值之间的损失。

15:09 自动求导引擎(如 PyTorch)通过反向传播计算每个参数对损失的影响,使参数能沿降低损失的方向自动更新,无需人工逐个调整。

29:38 语言模型的预训练以预测下一个词为目标,从海量文本中学习模式,但基础模型只做自动补全,不保证内容真实或有用。

35:24 后训练通过助手格式和指令数据,把自动补全模型转变为能够理解角色并在合适位置停止生成的助手模型。

40:02 指令数据中的结束标记让模型学会何时停止生成,这是把基础模型变为可用助手的关键细节之一。

43:21 让模型逐步思考可以明显改善其在数学等问题上的正确率,而直接输出答案容易出错。

45:45 强化学习让模型在自身生成的样本上通过试错学习,相比模仿他人思维,这种训练对已有能力的破坏更小。

48:05 GRPO 通过群体平均得分计算优势值,既能利用负样本,又能抵消噪声,从而使模型稳定地学习推理。

52:22 由于预训练与后训练的数据来源和风格不同,把已形成助手人格的模型再用其他分布的数据训练,容易导致其丧失助手能力。

54:17 讲者认为,只要模型能被训练得在长程推理中构造新抽象,就有可能突破训练分布、发现新知识。