This 1-Hour Andrej Karpathy Lecture Explains Modern AI Better Than Most Courses

This 1-Hour Andrej Karpathy Lecture Explains Modern AI Better Than Most Courses

从注意力机制到提示词编程:读懂现代AI

TechXOps9 位订阅者

105 分钟阅读AI

【AI前沿】从软件1.0到软件3.0:Transformer如何改变编程与人工智能? 这场斯坦福讲座由安德烈·卡帕西主讲,串联起神经网络、Transformer与大语言模型的发展脉络。他从软件1.0的手写算法谈到软件2.0的训练数据,再提出软件3.0:用提示词指挥模型执行任务。讲座拆解了注意力机制如何推动Transformer取代循环网络,也展示模型如何处理文本、图像与语音,以及模拟终端、程序和应用。读者将借此理解GPT背后的关键设计,认识提示词编程的能力与局限,并获得搭建AI应用所需的基础视角。 🎙️ 主讲人介绍 安德烈·卡帕西(Andrej Karpathy):人工智能研究者与工程师,曾在斯坦福、OpenAI和特斯拉工作;本场讲座回顾软件与AI的演进,并讲解Transformer和大语言模型。 核心议题:软件1.0、2.0与3.0的演进、神经网络与数据驱动编程、注意力机制与Transformer架构、GPT的提示词编程与虚拟系统、Transformer的多模态应用、模型能力、局限与未来方向。 关键词:Andrej Karpathy、Transformer、注意力机制、GPT、提示词编程、软件3.0

章节 1:从软件1.0到神经网络编程

📝 本节摘要:

Karpathy回顾自己在斯坦福、OpenAI和特斯拉的工作,以及业余编程项目,随后提出软件2.0:用数据集训练神经网络,而不是手写所有规则。传统软件仍然负责训练与部署等环节,两种范式叠加使用,推动图像识别、棋类和语音识别等任务的发展。

[原文] [Andrej Karpathy]: I was here as a PhD student at Stanford about seven years ago. Then I went to OpenAI, then I went to Tesla, and then I came back to OpenAI as of one week ago. So, I'm just spinning up again at OpenAI. Here at Stanford, I worked on early neural networks for connecting images and natural language. Some neural networks that look like today's CLIP, if some of you are familiar with it, or early image captioners and so on. At OpenAI, I worked on generative models of images and a bunch of other reinforcement learning.

[译文] [Andrej Karpathy]: 大约七年前,我还是斯坦福的博士生,在这里学习。之后我去了 OpenAI,又去了特斯拉;一周前,我刚回到 OpenAI,现在正重新熟悉那里的工作。在斯坦福时,我研究的是早期的图像与自然语言连接神经网络,比如一些类似如今 CLIP 的网络,以及早期的图像描述模型。在 OpenAI,我研究了图像生成模型和其他一些强化学习项目。

[原文] [Andrej Karpathy]: Here, as you can see, there are generated images. They are 32-by-32-pixel images, and you can see some textures. We were all very proud of them six years ago. But today, you have Stable Diffusion, Midjourney, and DALL-E. I think things have changed a lot. It's pretty incredible. But this was amazing state of the art at the time. And at Tesla, I worked on Autopilot. So, when you see the cars on the road and the traffic lights and everything like that in the instrument cluster, my team would create the neural networks that make these predictions.

[译文] [Andrej Karpathy]: 如你所见,这里展示的是生成图像,尺寸为 32×32 像素,能看出一些纹理。六年前,我们为这样的成果感到非常自豪。如今则有 Stable Diffusion、Midjourney 和 DALL-E,变化实在太大了,令人惊叹。不过在当时,这已经是非常出色的前沿成果。在特斯拉,我参与了自动驾驶辅助系统 Autopilot 的研发。仪表盘上显示道路上的车辆、红绿灯等信息时,背后负责做出这些预测的神经网络就是由我的团队开发的。

[原文] [Andrej Karpathy]: But I suspect the reason I was invited to give a keynote here is not any of that stuff, but the fact that I love to hack. I do a lot of things on the side. For example, I wrote a library for training neural networks in JavaScript a while ago. It was called ConvNet.js. At the time, a lot of people were like, “Why?” And I was always like, “Why not?”

[译文] [Andrej Karpathy]: 不过我猜,邀请我来这里做主题演讲,并不是因为那些工作,而是因为我喜欢动手折腾。我业余做了很多项目。比如,前些年我写了一个用 JavaScript 训练神经网络的库,叫 ConvNet.js。当时很多人问:“为什么要这么做?”我总是回答:“为什么不呢?”

[原文] [Andrej Karpathy]: I did it for the lols. I was also the reference human for ImageNet. I spent about—actually, about one week—classifying images in ImageNet manually myself into 1,000 categories. That includes about 200 breeds of dog, and that was really fun. So, when you see human-coded human accuracy on ImageNet, that's me for that one week. I wrote activity-tracking apps. For example, I could see how much I coded. I created a hacking streak if I was coding for a while. I tracked my caffeine levels and everything, so that's pretty cool.

[译文] [Andrej Karpathy]: 我做那个项目纯粹是图个乐。我还曾是 ImageNet 的人工参照标注者。我花了大约——准确地说,大约一周——亲自把 ImageNet 的图像手动分到一千个类别里,其中包括大约两百种狗。这过程特别有意思。所以,你看到 ImageNet 上人工标注的准确率时,那一周的标注者就是我。我还写过活动追踪应用,比如用来查看自己写了多少代码;如果连续写代码一段时间,就记录一段编程连胜。我还会追踪咖啡因摄入量等等,挺有意思的。

[原文] [Andrej Karpathy]: Archive Sanity Preserver helps you find papers that are very interesting based on other ones that you like. I blog a bunch, and so a bunch of my blog posts became kind of popular over time. “The Unreasonable Effectiveness of Recurrent Neural Networks” is one of them. More recently, I'm also a YouTuber and influencer. I have a bunch of YouTube videos about transformers, GPTs, and so on. You're welcome to look at those, and repositories like minGPT and nanoGPT and so on.

[译文] [Andrej Karpathy]: Archive Sanity Preserver 能根据你喜欢的论文,帮你找到其他有意思的论文。我写过不少博客,其中一些文章后来也挺受欢迎,比如《循环神经网络的非凡效能》。近来我也做 YouTube 视频,算是个网红。我在 YouTube 上发布了不少关于 Transformer、GPT 等主题的视频,也欢迎大家看看 minGPT、nanoGPT 之类的代码仓库。

[原文] [Andrej Karpathy]: So, I love to hack, and I love this event. I hope you'll have a lot of fun. Now, I kind of feel like there has actually never been a more interesting time to hack than today. So, why? By the way, these are all images generated by DALL-E, and you'll notice that all of these hackers have hoodies. I thought that this was the dress code, so I brought one as well. So, why is it so interesting to hack today?

[译文] [Andrej Karpathy]: 我喜欢动手折腾,也很喜欢这次活动,希望大家玩得开心。我觉得当下可能是最适合动手创造的时代。为什么这么说?顺便一提,这些图片都是 DALL-E 生成的,你们会发现里面所有黑客都穿着连帽衫。我还以为这是着装要求,所以也带了一件。那么,为什么今天动手编程这么有意思?

[原文] [Andrej Karpathy]: I kind of feel like programming is changing very rapidly. This is all happening right now, and it's interesting and exciting. You're all explorers looking at the new vistas available, and you get to explore them. I think that's fascinating. So, let me double-click on that. What do I mean by it? What do you think of when you hear “programming”? What is programming about? Some of you might think of writing code, something that looks like this. You're giving instructions to a computer about what it should do. Maybe you're thinking about writing C++ code, giving instructions to the computer.

[译文] [Andrej Karpathy]: 我觉得编程正在飞速变化,这一切此刻都在发生,既有趣又令人兴奋。你们都是探索者,眼前出现了新的天地,可以亲自去探索,我觉得这很吸引人。让我展开说说,这是什么意思?听到“编程”时,你会想到什么?编程究竟是在做什么?有些人可能会想到写代码,比如这种形式:告诉计算机应该做什么。也许你想到的是写 C++,向计算机下达指令。

[原文] [Andrej Karpathy]: Maybe you're thinking about Donald Knuth and The Art of Computer Programming. This is programming as it was for the last maybe 70 years or so, unchanged on a high level, I would say, in terms of giving instructions to the computer and designing an algorithm. And this has gotten us really far. Spelling out these instructions allowed us to develop software like, say, Linux. This is a diagram of Linux. It's a very complicated software engineering project with lots of moving pieces, and these are all kinds of profilers and debuggers for its different pieces. So, it's gotten us really far, but not quite all the way. We started to see the cracks in what we could achieve in this paradigm when we got to other problems, like computer recognition—for example, image recognition. So, just recognizing that

[译文] [Andrej Karpathy]: 也许你会想到 Donald Knuth 和《计算机程序设计艺术》。过去大约七十年里,编程在宏观上一直是这个样子:给计算机下指令、设计算法。我认为,这种方式已经带我们走了很远。把指令明确写出来,让我们得以开发 Linux 这样的软件。这张图展示的是 Linux:一个复杂的软件工程项目,包含许多相互关联的部分,图中还有针对不同部分的各种性能分析器和调试器。这种方式成就巨大,但还不够。遇到其他问题时,我们开始看见这种范式的局限,比如计算机视觉,尤其是图像识别。要识别出

[原文] [Andrej Karpathy]: there's a cat in images is a very difficult problem. You can't actually write an algorithm to recognize a cat in an image because the cat can take on many different forms. You can't write a very good chess-playing game just by giving explicit instructions to a computer. You probably can't write an Autopilot system just by giving instructions to a computer alone. And we're probably not going to build AGI, artificial general intelligence, by spelling it out for a computer. So, that's not enough.

[译文] [Andrej Karpathy]: 图像里有一只猫,是个非常难的问题。你无法靠编写算法来识别图像中的猫,因为猫可以有各种不同的样子。只给计算机明确的指令,也写不出很强的下棋程序;大概也无法仅靠指令写出自动驾驶系统。我们恐怕也不能靠把规则逐条写给计算机,就造出通用人工智能(AGI)。所以,传统方式还不够。

[原文] [Andrej Karpathy]: I think we realized that we needed a new way to program computers. I've given it a new term: I call it Software 2.0. It's a new programming paradigm, and it's basically neural networks. But neural networks are not just another classifier competing with, say, a random forest. Neural networks are a new programming stack, and you program them slightly differently. You program them by accumulating data sets and iterating on them, something I call a data engine. You then compile your data set into a binary. The compilation is neural network training, and the binary is the neural network weights. This is the final program, written in weights, and you can't write it by hand. It comes out of optimization based on your data

[译文] [Andrej Karpathy]: 我认为,我们意识到需要一种新的计算机编程方式。我给它起了个新名字,叫“软件 2.0”。这是一种新的编程范式,本质上就是神经网络。但神经网络不只是另一种分类器,和随机森林之类的模型竞争。它是一套新的编程技术栈,编程方式也略有不同:不断积累数据集并反复迭代,我把这称为“数据引擎”。然后把数据集编译成二进制文件:编译过程就是训练神经网络,二进制文件则是神经网络的权重。最终程序由这些权重构成,不能靠手写得到,而是通过基于数据的优化产生。

  1. 章节 2:大语言模型学会生成与执行任务
  2. 章节 3:提示词让模型模拟虚拟系统
  3. 章节 4:用提示词编程通用型语言模型
  4. 章节 5:软件范式演进与提示词编程
  5. 章节 6:Transformer 如何处理图像、语音与多模态数据
  6. 章节 7:从特征工程到统一的 Transformer 架构
  7. 章节 8:从序列模型到注意力机制的起源
  8. 章节 9:Transformer 的架构优势与上下文学习
  9. 章节 10:用图上的消息传递理解注意力
  10. 章节 11:注意力机制与纳米GPT实现
  11. 章节 12:解码器结构与注意力信息传递
  12. 章节 13:因果注意力的掩码与文本生成
  13. 章节 14:Transformer为何高效且可作为通用计算机

正在加载后续章节…