What AI Is
A-Level Computer Science Topic 18 13:11 English narration · English + 中文 subtitles burned in
Chapters
Transcript
Nobody ever wrote the rules for telling a cat from a dog.
从来没有人写下过"怎么分辨猫和狗"的规则。
No programmer sat down and typed "if it has pointed ears and whiskers".
没有哪个程序员坐下来敲出"如果它有尖耳朵和胡须"。
And yet your phone does it instantly, on photos it has never seen before.
然而你的手机却能瞬间做到,而且是在它从没见过的照片上。
That is the shift: instead of programming the answer, we show the machine thousands of labelled examples and let it find the pattern itself.
这就是那个转变: 我们不再把答案编进程序,而是给机器看成千上万张带标签的样例,让它自己找出规律。
That is machine learning — and it is why AI suddenly got good.
这就是机器学习——也正是人工智能突然变强的原因。
What artificial intelligence actually is, under the hood.
人工智能在底层究竟是什么。
Today: how AI, machine learning and deep learning nest together, what an artificial neuron does, the three ways machines learn, how training works, and the difference between predicting a number and a category.
今天我们讲:人工智能、机器学习和深度学习是如何层层嵌套的、 一个人工神经元在做什么、机器学习的三种方式、训练是怎么进行的, 以及预测一个数字和预测一个类别之间的区别。
Let's begin.
让我们开始吧。
First, three words people mix up.
先说三个常被混淆的词。
Artificial intelligence is the whole field: any system doing tasks that would normally need human intelligence.
人工智能是整个领域:任何完成通常需要人类智能的任务的系统。
Inside it sits machine learning — algorithms that learn patterns from data instead of being programmed step by step.
在它里面是机器学习——从数据中学习规律,而不是被一步一步编写好的算法。
And inside that sits deep learning, which uses neural networks with many layers.
再往里是深度学习,它使用带有很多层的神经网络。
They are nested, not separate.
它们是层层嵌套的,而不是彼此并列的。
A large part of AI sits on a graph — nodes joined by edges — and the syllabus names four places it shows up.
人工智能有很大一部分建立在图上——由边连接起来的结点——考纲点名了它出现的四个地方。
Pathfinding: roads form a graph, and the shortest route is a graph search, using Dijkstra's algorithm or A-star.
路径搜索:道路构成一张图,最短路线就是一次图搜索,用迪杰斯特拉算法或者 A 星算法。
Game playing: each board position is a node and each move an edge, so the whole game is a tree, searched by minimax with alpha-beta pruning.
博弈:每一个棋局是一个结点,每一步棋是一条边,于是整局棋就是一棵树, 用带 alpha-beta 剪枝的极小化极大算法来搜索。
State-space search: a planning problem is moving between states by applying operators until you reach a goal.
状态空间搜索: 一个规划问题就是通过施加算子在状态之间移动,直到到达目标。
And knowledge representation: a semantic network has concepts as nodes and relationships as edges — dog IS-A animal — while a knowledge graph stores facts about the world for search engines and assistants.
还有知识表示:语义网络以概念为结点、以关系为边——狗是一种动物—— 而知识图谱为搜索引擎和助手存储关于世界的事实。
The standard tools for walking any of these are breadth-first and depth-first search.
遍历这些图的标准工具,是广度优先搜索和深度优先搜索。
Here is a single artificial neuron in full, and the four steps are exactly what an exam asks you to describe.
这是一个完整的人工神经元,而这四个步骤正是考试要你描述的东西。
It takes several input values.
它接收若干个输入值。
It multiplies each by a weight — and the weights are the thing that gets learned.
它把每一个乘以一个权重——而权重正是被学习出来的那个东西。
It adds them all up, together with a bias term, which shifts the sum and lets the neuron fire at something other than zero.
它把所有乘积连同一个偏置项加起来,偏置项让这个和发生平移, 使神经元不必非要在零处才被激发。
Then it applies an activation function, a NON-LINEAR function such as ReLU.
然后它施加一个激活函数, 一个非线性函数,比如 ReLU。
That non-linearity matters more than it looks: without it, stacking layers would collapse back into one big linear function and depth would buy you nothing.
这个非线性比看上去重要得多: 如果没有它,把很多层叠起来会退化成一个大的线性函数,加深就毫无收益。
Finally it outputs the result, which feeds neurons further on.
最后它输出结果,去喂给后面的神经元。
Neurons sit in layers: an input layer, one or more hidden layers where the useful internal patterns are learned, and an output layer.
神经元按层排列:一个输入层,一个或多个隐藏层——有用的内部模式就是在那里学出来的—— 以及一个输出层。
With many hidden layers it is a deep neural network, and training one is deep learning.
隐藏层很多时,它就是一个深度神经网络,训练它就叫深度学习。
Why does depth help?
深度为什么有帮助?
Because the lower layers learn simple patterns — edges in an image, phonemes in speech — and the higher layers combine those into abstract concepts.
因为较低的层学到简单的模式——图像里的边缘、语音里的音素—— 而较高的层把这些组合成抽象的概念。
That is why ANNs can learn straight from raw data, from pixels and audio and text, without anyone hand-designing the features first.
这正是人工神经网络能够直接从原始数据学习的原因, 从像素、音频和文本直接学,不需要谁事先手工设计特征。
And that is exactly what drove the breakthroughs in image recognition, speech recognition, machine translation and game playing.
而这也正是图像识别、语音识别、机器翻译和博弈这些突破背后的原因。
So what is a neural network?
那么神经网络到底是什么?
Start with one artificial neuron.
先从一个人工神经元说起。
It takes several input numbers, multiplies each by a weight, adds them all up together with a bias, then passes that total through an activation function — and the result is its output.
它接收几个输入数字, 把每个乘上一个权重,再连同一个偏置一起全部加起来,然后把这个总和送进一个激活函数—— 得到的结果就是它的输出。
One neuron is simple.
单个神经元很简单。
The power comes from stacking them in layers: an input layer, one or more hidden layers where the useful patterns get learned, and an output layer.
真正的力量来自把它们一层层地堆起来: 一个输入层、一个或多个学习有用规律的隐藏层,以及一个输出层。
With many hidden layers, we call it deep.
隐藏层很多时,我们就叫它深度网络。
There are three ways a machine can learn.
机器学习有三种方式。
Supervised learning uses labelled data — thousands of photos already tagged cat or dog — and learns the mapping from input to label.
监督学习使用带标签的数据——成千上万张已经标好"猫"或"狗"的照片—— 并学会从输入到标签的映射。
Unsupervised learning gets no labels at all; it finds structure by itself, like grouping similar customers into clusters.
无监督学习完全没有标签;它自己去发现结构, 比如把相似的顾客聚成一簇一簇。
And reinforcement learning has an agent that acts, gets a reward or a penalty, and gradually learns a policy that earns the most reward — how a program learns to play a game, or to drive.
而强化学习里有一个智能体,它采取行动、 得到奖励或惩罚,并逐渐学出一套能拿到最多奖励的策略——程序就是这样学会玩游戏、或者学会开车的。
Machine learning is the umbrella term for any algorithm that learns from data, and it splits into three paradigms.
机器学习是任何从数据中学习的算法的统称,它分成三种范式。
Supervised learning uses data that carries labels — images tagged cat or dog — and the algorithm learns the mapping from input to label.
监督学习使用带标签的数据——被标注为猫或狗的图片——算法要学的是从输入到标签的映射。
It covers classification, when the answer is a category, and regression, when it is a number.
它涵盖分类,也就是答案是一个类别时;以及回归,也就是答案是一个数字时。
Unsupervised learning has no labels at all; the algorithm has to find structure by itself, for instance clustering similar customers together without anyone saying which group is which.
无监督学习完全没有标签;算法必须自己找出结构, 比如把相似的顾客聚成一类,而没有任何人说过哪一类是什么。
And the third is reinforcement learning.
第三种是强化学习。
Use machine learning whenever writing explicit rules would be impractical — spam filters, recommendations, fraud detection.
凡是写明确的规则不现实的时候,就用机器学习—— 垃圾邮件过滤、推荐系统、欺诈检测。
Deep learning is a subset of machine learning that uses deep neural networks.
深度学习是机器学习中使用深度神经网络的那一部分。
But an exam answer that says "use deep learning" for everything is wrong, and here is why.
但如果一份考卷答案对什么问题都说"用深度学习",那是错的,原因如下。
It needs lots of data and lots of compute — GPUs — because there are millions of weights to fit, and fitting them badly is worse than not fitting them at all.
它需要大量数据和大量算力——需要图形处理器——因为有上百万个权重要拟合, 而拟合得不好比根本不拟合还糟。
For small datasets, simpler machine-learning methods often do better: fewer parameters means less to overfit.
对小数据集来说,更简单的机器学习方法往往更好: 参数更少,可过拟合的余地也更小。
So the honest answer to "what should I use" depends on how much labelled data you actually have, not on which technique sounds most advanced.
所以"我该用什么"这个问题的诚实答案, 取决于你实际拥有多少带标签的数据,而不是哪种技术听起来更先进。
Reinforcement learning works differently from both of the others.
强化学习的工作方式和前两种都不同。
An agent acts in an environment.
一个智能体在环境中行动。
Each action changes the state and returns a reward.
每一个动作都会改变状态,并返回一个奖励。
The agent's goal is to learn a policy — a strategy for choosing actions — that maximises the total reward over time.
智能体的目标是学出一个策略—— 一套选择动作的方法——使长期的总奖励最大。
Notice what is missing: there are no labels up front.
注意这里缺少了什么: 一开始根本没有标签。
Nobody tells the agent the right action; it finds out by trial and error, and by the reward arriving later.
没有人告诉智能体正确的动作是什么; 它是靠试错、靠稍后才到来的奖励自己摸索出来的。
That is why it suits sequential-decision problems where the consequence of a move only becomes clear much later — games, robot control, autonomous driving.
这正是它适合序贯决策问题的原因——那些一步棋的后果要很久以后才显现的问题: 博弈、机器人控制、自动驾驶。
A self-driving car is a real example: Lidar and camera sensors build a live picture of the road, and a learned policy decides how to steer.
自动驾驶汽车就是一个真实例子:激光雷达和摄像头 传感器构建道路的实时画面,学到的策略决定如何转向。
A humanoid robot puts many of these abilities into one body — it uses AI to see faces, understand speech and move its arms in a lifelike way.
人形机器人把许多这类能力 放进一个身体——它用人工智能看人脸、理解语音,并以逼真的方式移动手臂。
How does training actually work?
训练究竟是怎么进行的?
Four steps, repeated over and over.
四个步骤,一遍又一遍地重复。
Forward pass: feed an example through the network and see what comes out.
前向传播:把一个样例送进网络,看看输出是什么。
Compute the error, using a loss function — a single number saying how wrong it was.
用损失函数算出误差——一个数字,表示它错得有多离谱。
Backward pass: send that error backwards through the network, working out how much each weight contributed to it.
反向传播:把这个误差沿网络往回送, 算出每一个权重对它贡献了多少。
Then update every weight by a small step that reduces the error.
然后按一个能减小误差的小步长,去更新每一个权重。
Repeat over thousands of examples and the error shrinks — that is backpropagation with gradient descent.
在成千上万个样例上重复,误差就会不断缩小——这就是配合梯度下降的反向传播。
Training adjusts the weights so the outputs match the targets, and the standard method is backpropagation with gradient descent.
训练就是调整权重,让输出与目标相符,而标准方法是带梯度下降的反向传播。
Four steps per training example.
对每一个训练样本有四步。
One, the forward pass: feed the input through to the output.
第一,前向传播:把输入一路送到输出。
Two, compute the error using a loss function — a single number saying how wrong the output is.
第二,用损失函数算出误差——一个数字,表示输出错得有多离谱。
Three, the backward pass: propagate that error backwards through the network, using the chain rule to find each weight's gradient, meaning how much it contributed to the error.
第三,反向传播:让这个误差沿着网络倒着传回去,用链式法则求出每个权重的梯度, 也就是它对误差贡献了多少。
Four, update the weights by a small step, whose size is the learning rate, in the direction that reduces the error.
第四,沿着能减小误差的方向, 把权重更新一小步,步长由学习率决定。
Repeat over many examples and many passes, called epochs, until the error stops shrinking.
在许多样本上、许多轮上反复进行, 每一轮叫做一个训练轮次,直到误差不再下降。
And that is where the name comes from: the error flows from the output BACK towards the input, so every weight's gradient is found in a single sweep.
而名字的由来正在于此: 误差从输出端向输入端倒着流,于是一趟扫下来就求出了每一个权重的梯度。
This picture is what step four is actually doing.
这张图正是第四步在做的事。
Plot the error against a weight and you get a curve with a minimum.
把误差对某个权重画出来,就得到一条有极小值的曲线。
The gradient tells you which way is downhill, and the update takes a small step in that direction.
梯度告诉你哪个方向是下坡,而更新就是朝那个方向迈一小步。
Repeat and you walk down towards the minimum error.
不断重复,你就一步步走向误差的最小值。
The learning rate is the size of each step, and it matters both ways: too small and training takes forever; too large and you overshoot the minimum and can bounce around without ever settling.
学习率就是每一步的大小, 而它太大太小都有问题:太小,训练会慢得没完没了; 太大,你会越过最小值,可能一直来回震荡而始终安定不下来。
And one practical point worth knowing: after training is finished, using the model is cheap — a new input needs only ONE forward pass to get a prediction.
还有一个实用的要点值得知道:训练结束之后,使用这个模型是很便宜的—— 一个新输入只需要一次前向传播就能得到预测。
All the expense is in the training.
全部的开销都在训练上。
Some tasks predict a number rather than a category — a house price, tomorrow's temperature — and that is regression.
有些任务预测的是一个数字而不是一个类别——房价、明天的气温——这就是回归。
Linear regression fits a straight line, or in more dimensions a hyperplane: y equals m-one x-one plus m-two x-two and so on, plus a constant c.
线性回归拟合一条直线,在更高维时是一个超平面: y 等于 m 一 x 一 加 m 二 x 二,依此类推,再加上一个常数 c。
The coefficients are chosen to minimise the sum of SQUARED errors against the training data, and the squaring is what makes a few large misses count much more than many small ones.
这些系数的选择,是让对训练数据的误差平方和最小, 而取平方使得少数几个大偏差远比许多个小偏差更受重视。
Those dashed vertical gaps in the picture are exactly the errors being squared and added.
图中那些竖直的虚线段,正是被取平方再相加的那些误差。
Use it when the relationship looks roughly linear and you want a model you can interpret.
当关系看上去大致是线性的、而你又想要一个能解释的模型时,就用它。
For curved data, use polynomial, decision-tree or neural-network regression — the same idea every time: define a model, define a loss, adjust the parameters to minimise it.
对弯曲的数据,就用多项式回归、决策树回归或神经网络回归—— 每一次的思路都一样:定义一个模型,定义一个损失,调整参数使它最小。
Exam scenarios almost always use the same pattern: a deep-learning model trained on labelled data, often several combined into a pipeline.
考试的情景题几乎总是用同一个套路:一个在带标签的数据上训练出来的深度学习模型, 而且常常是好几个串成一条流水线。
Three examples.
三个例子。
Customer identification at an automated shop: the system is trained on labelled face images; a camera captures a face; image recognition extracts a representation; that is matched against registered customers, and the closest match identifies the person.
无人商店里的顾客识别: 系统在带标签的人脸图像上训练;摄像头拍下一张脸;图像识别提取出一个表示; 拿它与已注册的顾客比对,最接近的那个就确定了这个人是谁。
Reading text from images: image recognition finds the text regions, optical character recognition extracts the characters, machine translation converts them, and text-to-speech reads them aloud — four models chained.
从图像中读出文字:图像识别找出文字区域,光学字符识别提取出字符, 机器翻译把它们转换过来,文本转语音再把它们读出来——四个模型串在一起。
And checkout item-detection: object detection, trained on labelled product images, sees which items go into the basket.
还有结账时的商品识别:在带标签的商品图像上训练出来的目标检测模型, 看出哪些商品被放进了购物篮。
In every case, by the time a user interacts with it the model is fast, because it is only doing a forward pass.
在每一种情形里,等到用户与它打交道的时候, 模型都很快,因为它只是在做一次前向传播。
The intelligence is in the patterns learned during training.
智慧都在训练时学到的那些模式里。
For each task, say whether it needs regression or classification, and what the output layer of an ANN would look like.
对下面每一个任务,说出它需要的是回归还是分类,以及人工神经网络的输出层会是什么样子。
First: predict tomorrow's temperature.
第一:预测明天的气温。
Second: decide whether an email is spam.
第二:判断一封邮件是不是垃圾邮件。
The method is to ask what KIND of thing is being predicted.
方法是问:被预测的是哪一类东西。
A temperature is a number on a continuous scale, so this is regression, and the output layer is a single neuron holding that value.
气温是连续尺度上的一个数字, 所以这是回归,输出层就是一个神经元,装着那个数值。
Spam or not-spam is a category, so this is classification, and the output gives a probability per class.
垃圾邮件还是非垃圾邮件是一个类别,所以这是分类,输出给出每一类的概率。
Both are supervised learning: each needs labelled examples to train on, and in both cases training adjusts the weights by backpropagation to reduce the error.
两者都是监督学习:都需要带标签的样本来训练, 而且两种情形下,训练都是用反向传播调整权重以减小误差。
And the deciding question is simply number or category — not how difficult the task feels.
而做判断的那个问题很简单:是数字还是类别——而不是这个任务感觉有多难。
One last distinction the exam loves.
最后一个考试很喜欢考的区分。
If the answer is a number — tomorrow's temperature, a house price — that is regression, and the output layer is a single neuron holding that value.
如果答案是一个数字——明天的气温、一套房子的价格—— 那就是回归,输出层是一个装着那个数值的神经元。
If the answer is a category — spam or not spam — that is classification, and the output gives a probability for each class.
如果答案是一个类别——垃圾邮件还是非垃圾邮件—— 那就是分类,输出给出每个类别的概率。
Both are supervised learning; the deciding question is simply: number, or category?
两者都属于监督学习; 决定用哪个的问题很简单:是数字,还是类别?
Three marks to lock in.
三个要拿稳的分。
First, distinguish machine learning, deep learning and reinforcement learning, and give an example of each.
第一,分清机器学习、深度学习和强化学习,并各给一个例子。
Second, describe a neural network — input, hidden and output layers with weighted connections — and how backpropagation adjusts the weights to cut the error.
第二,描述一个神经网络——输入层、隐藏层和输出层,以及带权重的连接—— 并说清楚反向传播如何调整权重来减小误差。
Third, supervised uses labels, unsupervised does not; regression predicts a number, classification a category.
第三,监督学习用标签,无监督学习不用; 回归预测一个数字,分类预测一个类别。
Nail these, and this topic is yours.
掌握这些,这个专题就是你的了。