第一章:AI世界的大门——什么是大语言模型?
你有没有想过,当你对着手机说「Hey Siri,今天天气怎么样?」或者让小爱同学帮你播放歌曲时,背后是谁在帮助你呢?
Have you ever wondered who helps you when you say "Hey Siri, what's the weather today?" or ask Xiao Ai to play a song for you?
---
🌍 初识人工智能:身边的AI小助手
当科技走进你的生活
Imagine waking up every morning. The first thing you might do is check your phone. You ask your phone a question, and it answers you right away. When you watch videos on Douyin (TikTok) or YouTube, it somehow knows what you might like to watch next. When you shop online, it suggests things you might want to buy. These magical helpers are all powered by a technology called Artificial Intelligence, or AI for short.
每天清晨,当你睁开眼睛做的第一件事,可能就是拿起手机。你对着手机问一个问题,它立刻就能回答你。当你在抖音或YouTube上看视频时,它好像能猜到你接下来想看什么;当你网上购物时,它会推荐你可能喜欢的商品。这些神奇的小帮手,都有一个共同的名字——人工智能,英文叫 Artificial Intelligence,我们通常简称它为 AI。
Artificial Intelligence is like giving computers a brain. Just like how you learn from school, from books, and from experiencing the world, AI systems learn from massive amounts of data. They can recognize faces, understand speech, translate languages, and even create art and stories. AI is changing our world in remarkable ways, and understanding it will help you become a smart citizen in the future.
人工智能就像是给计算机装上了一个大脑。就像你们在学校里学习、从书本里获取知识、通过体验世界来成长一样,AI系统也是通过海量的数据来学习的。它们能识别人脸、理解语言、翻译文字,甚至能创作图画和故事。人工智能正在以惊人的方式改变着我们的世界,了解它将帮助你成为未来世界的小主人。
🔍 什么是人工智能?
Let's start with a simple question: What does it mean for a machine to be "intelligent"? Intelligence is the ability to learn, understand, and make decisions. When you solve a math problem, you use your intelligence. When you figure out how to ride a bike, you use your intelligence. When you understand a joke and laugh, you use your intelligence.
让我们从一个简单的问题开始:让机器变得「聪明」意味着什么?智能是指学习、理解并做出决策的能力。当你解决一道数学题时,你使用的是你的智能;当你学会骑自行车时,你使用的是你的智能;当你理解一个笑话并笑出来时,你使用的也是你的智能。
Artificial Intelligence, or AI, is the science of making machines intelligent. It's about creating computer programs that can perform tasks that typically require human intelligence. These tasks include:
人工智能(AI)是让机器变得智能的科学。它指的是创建能够执行通常需要人类智能才能完成的任务的计算机程序。这些任务包括:
感知(Perception)——就像你的眼睛可以看到图片、耳朵可以听到声音一样,AI可以通过摄像头「看」,通过麦克风「听」。这就是为什么你的手机能认出你的脸(人脸识别技术),也能听懂你说话的内容(语音识别技术)。
学习(Learning)——就像你通过做练习题来提高数学能力一样,AI通过分析大量数据来提高自己的能力。数据就像AI的「练习题」,数据越多,AI学得越好。
推理(Reasoning)——就像你通过已知的条件来推导答案一样,AI可以分析信息并得出结论。比如,当你问AI「今天要不要带伞?」时,它会分析天气数据来给你建议。
决策(Decision-making)——就像你在早餐时选择吃面包还是鸡蛋一样,AI也可以在分析后做出选择。比如,导航软件会分析路况,为你选择最快的路线。
📱 日常生活中的AI应用
AI is not just science fiction——it's all around us! Let's look at some examples of AI that you might encounter every single day.
人工智能并不只是科幻小说里的概念——它就在我们身边!让我们来看看你每天可能都会遇到的一些AI应用。
| 场景 | AI应用 | AI如何工作 | |------|--------|-----------| | 你说「Hey Siri」 | 语音助手 | AI识别你的声音,理解你说的话,然后执行命令 | | 你刷短视频 | 推荐系统 | AI分析你喜欢的内容,推荐更多相似的视频 | | 你拍照时对人笑 | 人脸识别 | AI检测并识别你的脸部特征 | | 你玩翻译软件 | 机器翻译 | AI理解一种语言,转换成另一种语言 | | 你在游戏中与电脑对战 | 游戏AI | AI分析你的动作,做出相应的反应 |
让我们详细看看几个最常见的例子:
智能语音助手:当你对着手机或智能音箱说「小爱同学」或「Hey Siri」时,一个AI程序就开始工作了。它首先需要「听到」你说的每一个字(这叫语音识别,Speech Recognition);然后要「听懂」你想表达的意思(这叫自然语言理解,Natural Language Understanding);最后要「决定」该如何回应你(这叫自然语言生成,Natural Language Generation)。整个过程只需要不到一秒钟!
推荐系统:你有没有注意到,当你打开某个视频软件时,它好像总能找出你感兴趣的内容?这背后的秘密就是推荐系统(Recommendation System)。想象一下,你喜欢看关于机器人的视频,AI会记录下这个偏好,然后找到其他也喜欢机器人视频的人都在看什么。如果你和另一个用户的喜好很相似,AI就会把他喜欢的视频推荐给你。这就是为什么推荐系统有时会被称为「比你更懂你」的AI。
人脸识别:当你用手机自拍时,有没有注意到手机能自动框出你的脸?这就是人脸识别(Face Recognition)技术。AI会分析你脸上的特征——比如眼睛之间的距离、鼻子的形状、脸的轮廓等——然后和存储的数据进行比对。即使你换了发型或者戴了眼镜,AI通常也能认出你来。
---
📚 大语言模型:会说话的人工智能
🧠 什么是大语言模型?
Now that we understand AI in general, let's talk about a very special kind of AI that's at the heart of this book: Large Language Models, or LLMs.
现在我们对人工智能有了基本了解,接下来让我们来认识一种非常特别的人工智能——这本书的核心内容:大语言模型,英文是 Large Language Models,简称 LLMs。
The word "large" in Large Language Model doesn't just mean "big" in size. It means these models have been trained on enormous amounts of text data—billions of sentences, paragraphs, and entire books! The word "language" tells us these models specialize in understanding and generating human language. And "model" refers to a mathematical representation that has learned patterns from data.
大语言模型中的「大」不仅仅指体型庞大。更重要的是,这些模型是通过海量的文本数据训练出来的——数十亿个句子、段落,甚至整本书!「语言」一词告诉我们,这些模型专门处理人类语言的理解和生成。而「模型」则是指从数据中学习模式的一种数学表示。
A Large Language Model is like a super reader who has read more books than anyone else in history. It has absorbed knowledge from websites, books, articles, and all kinds of written text. Because of this, it has learned how humans use language——how words fit together, what sentences mean, and even how to have conversations.
大语言模型就像一个超级读者,它阅读的书籍比人类历史上任何人都多。它从网站、书籍、文章和各种书面文本中吸收知识。正因如此,它学会了人类如何使用语言——词语如何搭配、句子是什么意思,甚至如何进行对话。
📖 语言模型:预测下一个词的艺术
To understand how LLMs work, we need to understand a key concept: Next Token Prediction, or predicting the next word.
要理解大语言模型是如何工作的,我们需要了解一个关键概念:下一个词预测,英文叫 Next Token Prediction。
When you speak or write, you probably don't think about each word one by one. But if you pause and think, you'll realize that language follows patterns. For example, if I say "The sky is...", you probably know the next word is likely "blue." If I say "I need to brush my...", you probably guessed "teeth." We make these predictions automatically all the time.
当你说或写东西时,你可能不会一个字一个字地思考。但如果你停下来想一想,你会发现语言是有规律的。比如,我说「天空是……」,你可能知道下一个词是「蓝色的」。我说「我需要刷我的……」,你可能猜到了是「牙」。我们一直在自动做出这些预测。
LLMs are masters at this kind of prediction. During training, these models are given huge amounts of text and practice predicting what comes next. They start by making random guesses, but over time, through millions of examples, they learn the patterns of language. They learn which words often go together, which phrases make sense, and which sentences are grammatically correct.
大语言模型是这种预测的大师。在训练过程中,这些模型会获得大量的文本,并练习预测接下来会出现什么。它们一开始会随机猜测,但经过数百万个例子的练习,它们学会了语言的规律。它们学会了哪些词经常一起出现,哪些短语是合理的,哪些句子在语法上是正确的。
Here's a simple way to think about it: Imagine you're playing a game where someone says the beginning of a sentence, and you have to guess the next word. If you've read millions of sentences, you'd be pretty good at it! LLMs have essentially played this game with the entire internet, which is why they can generate such natural-sounding text.
有一个简单的理解方式:想象你在玩一个游戏,别人说出一个句子的开头,你要猜下一个词。如果你已经读过数百万个句子,你会非常擅长这个游戏!大语言模型基本上就是和整个互联网玩了这个游戏,这就是为什么它们能生成如此自然的文本。
🔄 下一个词预测的原理
Let's look at the technical side of how next token prediction works. This is where things get a bit more complex, but we'll explain it in a way that's easy to understand.
让我们来看看下一个词预测的技术原理。这里会稍微复杂一点,但我们会用简单易懂的方式解释。
The core of an LLM is something called a neural network, which is inspired by how the human brain works. The human brain has billions of neurons (nerve cells) that are connected to each other. When you learn something new, the connections between neurons change. Neural networks in AI work in a similar way——they have artificial "neurons" that form connections, and these connections change as the model learns.
大语言模型的核心是神经网络,它的设计灵感来自人脑的工作方式。人脑有数十亿个相互连接的神经元(神经细胞)。当你学习新东西时,神经元之间的连接会发生变化。人工智能中的神经网络也是类似的方式工作——它们有「人工神经元」,这些神经元形成连接,并且随着模型的学习而改变。
When an LLM processes text, it converts each word (or more precisely, each token) into a list of numbers called a vector. A token can be a whole word, part of a word, or even a punctuation mark. The model then processes these vectors through many layers of artificial neurons, each layer extracting different features and patterns from the text.
当大语言模型处理文本时,它会把每个词(更准确地说,每个标记,即token)转换成一个数字列表,这叫做向量。一个标记可以是一个完整的词、一个词的一部分,甚至是一个标点符号。然后,模型会通过多层人工神经元来处理这些向量,每一层都会从文本中提取不同的特征和模式。
At the end of this process, the model produces a probability distribution over all possible next tokens. This means it calculates how likely each possible word is to be the next word in the sequence. The word with the highest probability is then selected as the next token.
在这个过程的最后,模型会对所有可能的下一个