神经网络是ai
Sometimes it seems like practically every time I ask how a cool piece of new technology works, I get a two letter response: AI.
有时,几乎每次我问到一项很酷的新技术是如何工作时,我都会收到两个字母的答复:AI。
But then, if I try to ask how AI (artificial intelligence) works, I’m told that it’s complicated and takes a lot of linear algebra and multivariable calculus to understand.
但是,然后,如果我试图问问AI(人工智能)是如何工作的,我被告知它很复杂,需要大量线性代数和多变量演算来理解。
For any curious person, this is annoying! It’s fun to look into the inner workings of complex systems that affect our lives. Being told you need to read two math textbooks to understand the basics of something is discouraging.
对于任何好奇的人,这很烦人! 研究影响我们生活的复杂系统的内部运作很有趣。 被告知您需要阅读两本数学教科书以理解某物的基础,这令人沮丧。
Fortunately, in the case of neural networks, it’s not true!
幸运的是,在神经网络的情况下,事实并非如此!
You definitely don’t need a deep understanding of linear algebra and multivariable calculus to understand the basics of neural networks. Now don’t get me wrong: complex math is essential for understanding neural networks at a deep level and creating your own neural networks from scratch.
您绝对不需要深入了解线性代数和多变量演算来理解神经网络的基础。 现在不要误会我的意思:复杂的数学是在一个深层次的理解神经网络,并从头开始创建自己的神经网络是必不可少的。
But that’s not why most of us ask how AI works. If you just want to get a better feel for what’s going on behind the scenes of things people call “AI”, you don’t even need to know what linear algebra or multivariable calculus is.
但这不是我们大多数人问人工智能如何工作的原因。 如果你只是想获得什么事情的事情幕后更好的手感被人们称为“AI”,你甚至都不需要知道什么线性代数和多变量微积分是 。
Reading and understanding this article will make you more knowledgeable about neural networks than 99% of people. If you want to create your own neural networks and become more knowledgeable on the topic than 99.99% of people, then go learn some math.
阅读和理解本文将使您比99%的人更加了解神经网络。 如果您想创建 自己的神经网络,并且比99.99%的人对本主题的知识更丰富,则可以学习一些数学。
After reading this article, you’ll be able to explain to anyone the structure of a neural network and how neural networks “learn” as they’re exposed to new data!
阅读本文后,您将可以向任何人解释神经网络的结构,以及神经网络在暴露于新数据时如何“学习”!
A neural network is the name for the computer program that’s the “brain” of an AI system. But before talking about neural networks, we’ll first look at what AI is, in a broad sense.
神经网络是计算机程序的名称,它是AI系统的“大脑”。 但是在谈论神经网络之前,我们将首先从广义上看一下什么是AI。
It’s weird that it’s so hard to define a technology that’s supposed to be all around us.
奇怪的是,很难定义一种应该存在于我们周围的技术。
Self-driving cars use AI to not run into stuff. Speech-to-text systems use AI to transcribe words. My phone’s handwriting keyboard uses AI to make sense of my sloppy pointer finger calligraphy.
自动驾驶汽车使用AI不会碰到东西。 语音转文本系统使用AI来转录单词。 手机的手写键盘使用AI来识别草率的指尖书法。
While these might all seem like super different tasks, all these systems have a key thing in common.
尽管这些看起来都像是超级不同的任务,但所有这些系统都有一个共同点。
Broadly speaking, an AI program is a computer program that finds patterns and does cool things with these patterns.
广义上讲,AI程序是一种计算机程序, 可以找到模式并使用这些模式进行酷炫的事情 。
This doesn’t sound that impressive until you realize that humans pretty much just do the same thing.
在您意识到人类几乎只是在做同一件事之前,这听起来并不令人印象深刻。
Think about any complex, human-y thing that humans like to do. Let’s take having a conversation with someone. At a fundamental level, conversations work because each person finds patterns coming from the other person, then does cool things with these patterns. Each person’s ears and brain work together to find patterns of vibrations in the air. The brain then converts these vibration patterns into words with meanings, which is a pretty cool thing to do. Each person’s eyes and brain work together to find patterns of movements in the other person’s face. The brain then converts these tiny movements into emotional signals, which is also a pretty cool thing to do.
想一想人类喜欢做的任何复杂的,人性化的事情。 让我们与某人交谈。 从根本上讲,对话之所以有效,是因为每个人都找到了另一个人的模式,然后用这些模式去做一些有趣的事情。 每个人的耳朵和大脑共同工作,以发现空气中的振动模式。 然后,大脑将这些振动模式转换为具有含义的单词,这是一件很酷的事情。 每个人的眼睛和大脑共同工作,以寻找另一个人脸上的运动方式。 然后,大脑将这些微小的运动转换为情感信号,这也是一件很酷的事情。
No matter how complicated a task is, any task can be reduced to finding patterns and using these patterns to do cool things. Of course, most tasks involve insanely large numbers of patterns, but they’re ultimately still based on patterns.
无论任务多么复杂,任何任务都可以简化为寻找模式并使用这些模式来完成一些很酷的事情 。 当然,大多数任务都涉及大量的模式,但最终它们仍基于模式。
A self-driving car AI system learns to recognize objects on the road, like signs and road markings. The system then uses these patterns to construct an internal model of the road and steer safely.
自动驾驶汽车AI系统学习识别道路上的物体 ,例如标志和道路标记。 然后,系统使用这些模式来构建道路的内部模型并安全转向。
Speech-to-text systems learn to recognize common speech sounds, and they combine patterns of these sounds into words. In other words, these systems are built to recognize patterns of patterns.
语音转文本系统学会识别常见的语音 ,并将这些语音的 模式组合成单词。 换句话说,构建这些系统是为了识别模式的模式 。
At its core, the challenge of making really good AI is trying to make systems that can accurately recognize patterns of patterns (of patterns of patterns of patterns…) in the real world.
从本质上讲,制作出出色的AI的挑战是试图使系统能够准确识别现实世界中的模式模式(模式模式的模式……)。
If that idea makes sense to you, then you understand the essence of AI.
如果这个想法对您有意义,那么您就了解了AI的本质。
Now is also a good time to clear up the difference between two commonly discussed forms of AI: artificial narrow intelligence and artificial general intelligence.
现在也是清除两种常见形式的AI之间的区别的好时机:人工狭义智能和人工通用智能。
Artificial narrow intelligence (ANI) is a pattern recognition based AI system that is designed to do a specific task. This is the kind of AI that’s all around us today. Examples of ANI include fingerprint scanners, automatic credit card fraud detection systems, and every other application of AI discussed above. These systems are built to recognize patterns in specific situations, and the state-of-the-art ones are damn good at it.
人工智能(ANI)是一种基于模式识别的AI系统,旨在执行特定任务。 如今,我们周围都是这种AI。 ANI的示例包括指纹扫描仪,自动信用卡欺诈检测系统以及上述AI的所有其他应用程序。 这些系统旨在识别特定情况下的模式,而最先进的系统则擅长于此。
Artificial general intelligence (AGI) is where things start getting really crazy. AGI is designed to match or exceed the intelligence of a human. This means that an AGI system should be able to learn to recognize any pattern that a human could learn to recognize. As of 2020, AGI does not exist yet. Most experts agree that we’ll probably have AGI sometime between decades and centuries from now, but at the moment, we’re still working on it.
人工智能(AGI)是事情开始变得疯狂的地方。 AGI旨在匹配或超越人类的智力。 这意味着AGI系统应该能够学会识别人类可以学会识别的任何模式。 截至2020年,AGI尚不存在 。 大多数专家都同意,从现在起几十年至几个世纪以后,我们可能会使用AGI,但目前,我们仍在努力。
Here, we’ll be talking specifically about ANI. The general principles we’ll explore here would totally be relevant to an AGI system as well, but they’ve only ever been implemented in ANI.
在这里,我们将专门讨论ANI 。 我们将在这里探讨的一般原理也将与AGI系统完全相关,但是它们仅在ANI中实现。
Now that we understand the basics of AI, we can start getting into neural networks.
既然我们了解了AI的基础知识,就可以开始进入神经网络了。
A neural network is the name for the computer program that’s the “brain” of an AI system. Neural networks are designed so that they get smarter as they see more and more data.
神经网络是计算机程序的名称,它是AI系统的“大脑”。 神经网络的设计使其在看到越来越多的数据时变得更加智能。
To understand this process of a neural network “getting smarter,” we’ll look at a classic application of neural networks: handwritten digit recognition.
为了理解神经网络“变得越来越聪明”的过程,我们将研究神经网络的经典应用:手写数字识别。
The University of California, Irvine, assembled a famous dataset of handwritten numbers from 0–9. The dataset contains images of numbers volunteers wrote by hand, and these images are paired with the actual number each one is supposed to be.
加利福尼亚大学欧文分校收集了一个著名的0-9手写数字数据集。 数据集包含手写的志愿者数字图像,这些图像与每个人应该是的实际数字配对。
To make it easier for normal people’s computers to work with, each image was scaled down to 8x8 pixel resolution. Here’s what the actual scaled-down images look like:
为了使普通人的计算机更容易使用,每个图像均缩小到8x8像素分辨率。 实际的缩小图像如下所示:
Not too hard for a person to figure out. Just stand about 20 feet back so the images get all blurry. It’s pretty clear that the first one is a 0, the second one is a 3, and the third one is a 7 written by some nerd who crosses their 7s.
一个人想起来并不太难。 只需向后站立约20英尺即可使图像变得模糊。 很明显,第一个是0,第二个是3,第三个是一个7的书呆子,书呆子写的是7。
But if I asked you to write a computer program to identity which is which, then that’d be a good challenge. That’s a perfect thing to use a neural network for.
但是,如果我要求您编写一个计算机程序来标识身份,那将是一个很好的挑战。 使用神经网络是一件完美的事情。
Just like a human baby, a neural network can’t just recognize these images right away. First, we have to train the neural network.
就像人类婴儿一样,神经网络不能立即识别这些图像。 首先,我们必须训练神经网络。
As we talk about training, just pretend the neural network is a person. This makes the verbs in the rest of this section make a lot more sense. In the next section, we’ll get into how a neural network does all this neat stuff without actually being a person.
当我们谈论培训时,只是假装神经网络是一个人。 这使本节其余部分的动词更有意义。 在下一节中,我们将探讨神经网络如何在不真正成为人的情况下完成所有这些巧妙的工作。
To train the neural network, we start by showing it an image and telling it what that image is supposed to be. So basically, “neural network, this thing is a 0.”
为了训练神经网络,我们首先向它显示图像并告诉它该图像应该是什么。 所以基本上就是“神经网络,这个东西是0。”
Then we do it again. “Neural network, this thing is a 3.”
然后我们再做一次。 “神经网络,这个东西是3。”
And we keep doing that over and over again until we’ve shown it lots of images of every number. But don’t show it every image we have. The images and solutions that we show it are called the training data.
而且,我们会一遍又一遍地做下去,直到我们给它展示了每个数字的大量图像为止。 但是,请不要显示我们拥有的所有图像。 我们显示的图像和解决方案称为训练数据 。
After it’s seen a bunch of images, we say that the neural network has been trained. The next step is to test the trained neural network.
看了一堆图像之后,我们说神经网络已经训练好了 。 下一步是测试经过训练的神经网络。
To test the neural network, we show it one of the images that it hasn’t seen yet and ask the neural network what number it thinks it is. “Neural network, what do you think this is?”
为了测试神经网络,我们向它显示尚未看到的图像之一,并询问神经网络它认为它是多少。 “神经网络,您认为这是什么?”
If it identifies the image correctly, as a 5 in this case, we keep track of that. If it identifies the image incorrectly, we keep track of that too. We keep showing the neural network images that it hasn’t seen yet and making it identify them until we’ve run out of images. The images that we show the neural network during the test phase are called the testing data.
如果它正确地识别出图像,在这种情况下为5,我们将对其进行跟踪。 如果它不能正确识别图像,我们也将对其进行跟踪。 我们将继续显示尚未看到的神经网络图像,并使其识别它们,直到我们用完图像为止。 我们在测试阶段显示的神经网络图像称为测试数据 。
The neural network’s accuracy score is the percentage of images it correctly identifies. We want to get this neural network’s accuracy score as close to 100% as possible.
神经网络的准确性得分是其正确识别的图像的百分比。 我们希望使该神经网络的准确性得分尽可能接近100%。
There are several parts of the neural network that we can adjust to improve the accuracy score, which we’ll explore later on. After we tweak the neural network a bit, we train it once again, then test it again, and calculate a new accuracy score. We keep repeating this process, changing the neural network a little each time, until we’re satisfied with how it performs!
我们可以调整神经网络的多个部分以提高准确性得分,我们将在稍后进行探讨。 在稍微调整了神经网络之后,我们再次对其进行训练 ,然后再次对其进行测试 ,然后计算出新的准确性得分 。 我们不断重复这个过程,每次都稍微改变一下神经网络,直到对它的性能感到满意为止!
For challenges like this one that involve classifying things, this is how basically all neural networks get smarter over time.
对于像这样涉及到事物分类的挑战,这基本上就是所有神经网络随着时间变得越来越聪明的方式。
But there’s still one thing that you’re probably confused about, for good reason.
但是,出于充分的理由,您可能仍然对一件事感到困惑。
The neural network isn’t a person. How is it looking at stuff and identifying patterns like a person would?
神经网络不是人。 它如何看待事物并像人一样识别模式?
Before we get into how the neural network identifies patterns, let’s first figure out how it “looks at” stuff at all.
在研究神经网络如何识别模式之前,我们首先要弄清楚它是如何“看待”事物的。
The pixelated numbers in this dataset are really just a bunch of light and dark colored boxes. We immediately see them as numbers, but that’s only because we have a really well trained neural network living inside our heads. For a neural network that doesn’t know anything yet, we need an easier way of representing these images.
该数据集中的像素化数字实际上只是一堆浅色和深色框。 我们立即将它们视为数字,但这仅仅是因为我们的大脑中生活着一个训练有素的神经网络。 对于尚不了解的神经网络,我们需要一种表示这些图像的简便方法。
Let’s say we have some random image like this:
假设我们有一些像这样的随机图像:
If we wanted to, we could represent the shades of the boxes as numbers instead of colors. 0 could stand for white, 1 could stand for black, and numbers in between 0 and 1 could stand for shades between white and black. Here’s what that would look like:
如果需要,我们可以将框的阴影表示为数字而不是颜色。 0代表白色,1代表黑色,0到1之间的数字代表白色和黑色之间的阴影。 如下所示:
[[0.5, 0.75, 0.5],[0, 1, 0],[0.5, 0.75, 0.5]]If we know that this is supposed to be a 3x3 square image, we wouldn’t even need to put the numbers on separate lines. We could just make one list of numbers, like this:
如果我们知道这应该是3x3的正方形图像,我们甚至不需要将数字放在单独的行上。 我们可以只列出一个数字,像这样:
[0.5, 0.75, 0.5, 0, 1, 0, 0.5, 0,75, 0.5]This list is a lot easier for a neural network to handle! We could follow this same set of steps for any image, including the number images we already have. This means that the image of the number 5 above would look like this to a neural network:
对于神经网络来说,这个列表要容易得多! 对于任何图像,包括已经拥有的图像,我们都可以遵循相同的步骤。 这意味着上面的数字5在神经网络中看起来像这样:
[0.0, 0.125, 1.0, 1.0, 1.0, 0.875, 0.3125, 0.0, 0.0, 0.5625, 1.0, 0.6875, 0.375, 0.5, 0.1875, 0.0, 0.0, 0.5625, 1.0, 0.125, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1875, 1.0, 0.8125, 0.0625, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 0.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.75, 1.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0625, 0.6875, 1.0, 0.375, 0.0, 0.0, 0.0, 0.25, 1.0, 1.0, 0.5, 0.0, 0.0, 0.0]Neural networks see images as a list of numbers, just like this.
就像这样,神经网络将图像视为数字列表 。
Now that we understand how neural networks see images, we’ll look at the structure of a very simple neural network.
既然我们了解了神经网络如何看待图像,我们将研究一个非常简单的神经网络的结构。
A neural network is simply made up of neurons connected to other neurons. If every circle is a neuron, and every line is a connection, here’s what that looks like for a simple neural network:
神经网络仅由连接到其他神经元的神经元组成 。 如果每个圆都是神经元,每条线都是连接,那么简单的神经网络就是这样:
This is called a feedforward neural network, and it’s the type of neural network we’ll explore here. There are tons of different types of neural networks, but feedforward neural networks are the simplest to understand.
这称为前馈神经网络,这是我们将在此处探讨的神经网络的类型。 有许多不同类型的神经网络,但是前馈神经网络最容易理解。
Each of those neurons on the far left is called an input neuron. That neuron on the right is called the output neuron.
最左侧的每个神经元称为输入神经元 。 右侧的神经元称为输出神经元。
The word “neuron” sounds really fancy and sciencey, but a neuron is really just a box that holds a number.
“神经元”一词听起来确实很花哨和科学,但是神经元实际上只是一个装有数字的盒子 。
This neural network might look pretty useless, but it’s actually very simple to input any one of our images into it.
这个神经网络可能看起来毫无用处,但是实际上将我们的任何图像输入到其中都很简单。
First, increase the number of output neurons to the number of pixels in the image. Because it’s an 8x8 image, the number of pixels in the image equals 8 X 8, which equals 64. So we need 64 input neurons.
首先,将输出神经元的数量增加到图像中的像素数量。 因为它是8x8图像,所以图像中的像素数等于8 X 8,等于64。因此我们需要64个输入神经元。
Remember that “list representation” of an image that we made above? Because each number in the list representation we made above represents a pixel, the list is also 64 numbers long.
还记得我们上面制作的图像的“列表表示”吗? 因为我们在上面所做的列表表示中的每个数字都代表一个像素,所以列表也有64个数字长。
From here, we can put each number in the list inside its own input neuron.
从这里,我们可以将列表中的每个数字放入其自己的输入神经元内。
Each input neuron represents a single pixel of the image. And just like that, we’ve fed the neural network an entire image!
每个输入神经元代表图像的单个像素。 就像这样,我们已经为神经网络提供了完整的图像!
Of course, the neural networks needs to actually do something with the image to be useful.
当然,神经网络实际上需要对图像做些有用的事情。
This is where the action starts. Don’t worry about the purpose of passing information between neurons just yet. We’ll talk about that in just a moment! For now, focus on understanding how information is passed between neurons.
这是动作开始的地方。 现在不用担心在神经元之间传递信息的目的。 我们将在稍后讨论! 现在,重点关注理解信息如何在神经元之间传递。
To figure out what number should be in the output neuron, we add up all the input neurons connected to it.
为了弄清楚输出神经元中应该有多少个,我们将与其连接的所有输入神经元相加 。
As an example, let’s say a neural network with 5 input neurons looks like this:
例如,假设具有5个输入神经元的神经网络如下所示:
To figure out what value should be in the output neuron, we add up all the input neurons that are connected to the output neuron. The result would look like this.
为了弄清楚输出神经元应该有什么值,我们将所有连接到输出神经元的输入神经元相加。 结果看起来像这样。
But addition alone isn’t quite enough for a working neural network. We also need to give each connection a certain weight.
但是单靠加法还不足以使神经网络正常工作。 我们还需要给每个连接一定的权重 。
When a connection between an input neuron and the output neuron is weighted, the input neuron’s number is multiplied by the connection’s weight before being added to the next layer. Let’s see that in action. Below, the numbers in green are the weights of each neuron’s connection.
当对输入神经元和输出神经元之间的连接进行加权时, 输入神经元的数量将乘以连接权重,然后再添加到下一层。 让我们看看实际情况。 下面的绿色数字是每个神经元连接的权重。
Below, we can see the results of the multiplication in green as well.
在下面,我们还可以看到绿色的乘法结果。
The sum of the weighted input neurons is stored in the output layer.
加权输入神经元的总和存储在输出层中。
So now we have two different parameters we in this system that we can mess with: the value of the input neurons, and the weights of each connection.
因此,现在我们在该系统中可以使用两个不同的参数:输入神经元的值和每个连接的权重。
There’s just one more thing we need to do to this output neuron. All the input neurons have a value between 0 and 1, but the output neuron’s value right now is way above 1. To keep things consistent, we’ll put the output neuron’s number into a mathematical function called the sigmoid function that spits out a number between 0 and 1, no matter what the input is.
我们只需要对输出神经元做一件事。 所有输入神经元的值都在0到1之间,但是现在输出神经元的值远高于1。为了保持一致,我们将输出神经元的数字放入一个称为Sigmoid函数的数学函数中,该函数会散出一个数字在0和1之间,无论输入是什么。
This way, the output neuron’s range always matches the input neurons’ range. This will become important later. Putting the output neuron’s value into the sigmoid function and replacing the output neuron’s original number with the result is called transforming the output neuron. In the context of neural networks, a function like this that transforms values is called an activation function.
这样,输出神经元的范围总是匹配输入神经元的范围。 这将在以后变得很重要。 将输出神经元的值放入S形函数中,并用结果替换输出神经元的原始编号,称为转换输出神经元。 在神经网络的上下文中,像这样的转换值的函数称为激活函数 。
This whole weighting process still probably seems pretty arbitrary. But weights are very useful, and you’re ready to understand why!
整个加权过程似乎仍然很随意。 但是权重非常有用,您已经准备好理解原因了!
It’s actually possible to make a simple classification system with just the concepts we’ve already covered! Let’s say you want to make a system that can distinguish between the number 1 and the number 0.
实际上,仅使用我们已经介绍的概念就可以创建一个简单的分类系统! 假设您要创建一个可以区分数字1和数字0的系统。
To make seeing the boundaries of each image a little easier, I’ve added in border lines.
为了使查看每个图像的边界更容易一些,我添加了边框线。
Looking at the 1 and the 0 next to each other makes a very important detail clear: 1s usually have very dark pixels in the middle of the image, while 0s usually have very light pixels in the middle of the image.
彼此相邻的1和0可以很清楚地看到一个非常重要的细节:1s通常在图像中间有非常暗的像素,而0s通常在图像中间有非常亮的像素。
If we can get our neural network to recognize this, then we have a pretty good shot at classifying 1s and 0s correctly.
如果我们能够使神经网络识别这一点,那么我们就可以正确地对1和0进行分类。
Fortunately, we have the perfect tool for this: weighting.
幸运的是,我们有一个完美的工具: 加权 。
Each input neuron represents a pixel. The darker a pixel is, the closer its neuron’s value is to 1. The lighter a pixel is, the closer its neuron’s value is to 0. By weighting each input neuron’s connection to the output neuron, we can effectively give every pixel a weight. This is an important concept, so spend a second thinking about this to make sure it makes sense.
每个输入神经元代表一个像素。 像素越暗,其神经元的值越接近1。像素越浅,其神经元的值越接近0。通过对每个输入神经元与输出神经元的连接进行加权, 我们可以有效地赋予每个像素权重 。 这是一个重要的概念,因此请花点时间思考一下以确保它有意义。
With weighting, we can make some pixels more important in calculating the output neuron’s value, and we can make some pixels less important.
通过加权,我们可以使某些像素在计算输出神经元的值时更重要,而可以使某些像素的重要性降低。
Say we gave all the neurons that correspond to pixels in the middle of the image a positive weight. Let’s say we also gave all the input neurons that correspond to pixels around the edges of image a negative weight. This means that dark pixels in the middle of the image make the output neuron’s value go up, while dark pixels on the edges of the image make the output neuron’s value go down.
假设我们给所有与图像中间像素相对应的神经元一个正权重 。 假设我们还给所有与图像边缘周围像素相对应的输入神经元负权重 。 这意味着图像中间的暗像素使输出神经元的值上升,而图像边缘的暗像素使输出神经元的值下降。
Now let’s imagine what would happen if we put an image of the number 1 into our weighted neural network. Images of the number 1 (like the one above) tend to have a ton of dark pixels in the middle of the image. Because the pixels are really dark, the numbers in the neurons that represent these pixels will be close to 1. We have these middle neurons’ connections weighted positively, which means that the value of the output neuron will be large and positive. Once the output neuron’s number has been transformed with the sigmoid activation function, the output neuron’s number will be super close to 1. (If the transformation aspect is confusing, take another look at the graph below.)
现在让我们想象一下,如果将数字1放入加权神经网络中,将会发生什么情况。 编号为1的图像(如上面的图像)在图像中间往往有大量的暗像素。 因为像素真的很暗,所以表示这些像素的神经元中的数字将接近1。我们将这些中神经元的连接加权为正 ,这意味着输出神经元的值将为正且较大。 一旦使用S型激活函数对输出神经元的数量进行了变换 ,则输出神经元的数量将超级接近1。(如果变换方面令人困惑,请再看下面的图。)
In contrast, let’s imagine what would happen if we put an image of the number 0 into our weighted neural network. Images of the number 0 tend to have more dark pixels at the edges of the image. Dark pixels on the edges of the image mean that the input neurons that represent the edge pixels will have values that are close to 1. Since these edge neurons’ connections are negatively weighted, the value of the output neuron will also be negative. Once the output neuron’s number has been transformed with the sigmoid activation function, the output neuron’s number will be close to 0.
相比之下,让我们想象一下如果将数字0的图像放入加权神经网络会发生什么。 数字0的图像在图像边缘往往有更多的暗像素。 图像边缘上的暗像素表示代表边缘像素的输入神经元的值将接近1。由于这些边缘神经元的连接被负加权,因此输出神经元的值也将为负。 一旦使用S型激活函数对输出神经元的数目进行了转换 ,输出神经元的数目将接近0。
With this system, images of the number 1 tend to make the output neuron’s value very close to 1, while images of the number 0 tend to make the output neuron’s value close to zero.
使用此系统,数字1的图像趋于使输出神经元的值非常接近1,而数字0的图像趋向于使输出神经元的值接近零。
This gives us a simple classification rule.
这给了我们一个简单的分类规则。
If the output neuron’s value is quite close to 1, then the image is a 1. If the output neuron’s value is quite close to 0, then the image is a 0.
如果输出神经元的值非常接近1,则图像为1。如果输出神经元的值非常接近0,则图像为0。
You may be wondering how the network defines “quite close” when it comes to the output neuron’s value. This is where training comes in! If we ran a bunch of pictures of 1s and 0s through this neural network, it would become clear that second layer neuron values that are larger than a certain number (not necessarily 0.5) mean that the image is probably a 1.
您可能想知道网络在输出神经元的值方面如何定义“非常接近”。 这就是训练的源头! 如果我们通过该神经网络运行一堆1s和0s的图片,则很明显,第二层神经元值大于某个数字(不一定是0.5)意味着该图像可能是1。
However, this super simple neural network structure has a major limitation. If we tried to test it with a new image, we’d get the number inside the output neuron, but the neural network wouldn’t actually make a guess. From here, another program or a person would have to look at the output neuron’s value and see whether it seems high enough to be a 1 or low enough to be a 0.
但是,这种超简单的神经网络结构具有很大的局限性。 如果我们尝试用新图像对其进行测试,我们将获得输出神经元内部的数字,但是神经网络实际上不会做出猜测。 从这里开始,另一个程序或一个人将不得不查看输出神经元的值,并查看它看起来足够高到等于1还是足够低到等于0。
Fortunately, there’s a pretty simple solution to this issue.
幸运的是,有一个非常简单的解决方案。
The neural network we just imagined weighted the middle pixel neurons’ connections positively and the outer pixel neurons’ connections negatively.
我们刚刚想象的神经网络对中间像素神经元的连接进行正加权,而对外部像素神经元的连接进行负加权。
But there’s no reason we had to weight the middle neurons’ connections positively and the outer neurons negatively. If we wanted to, we could have weighted the outer neurons positively and the middle neurons negatively.
但是我们没有理由要对中神经元的连接进行正加权,而对外神经元进行负加权。 如果我们愿意,我们可以对外部神经元进行加权,而对中神经元进行加权。
This inverse weighting would mean we get inverse results. An image of a 0 would cause the output neuron’s value to be close to 1, while an image of a 1 would cause the output neuron’s value to be close to 0.
这种相反的加权将意味着我们得到相反的结果。 图像为0会使输出神经元的值接近1,而图像为1会使输出神经元的值接近0。
If we wanted the neural network to automatically make a guess during testing without having to actually look at the output neuron’s value, we could put a neural network with our original weighting next to a neural network with inverse weighting.
如果我们希望神经网络在测试过程中自动进行猜测而不必实际查看输出神经元的值,则可以将原始加权的神经网络放在具有反向加权的神经网络旁边。
We would put the same image into both neural networks. If the original-weighted neural network’s output neuron had a higher value, then the image would be classified as a 1. If the reverse-weighted neural network’s output neuron had a higher value, then the image would be classified as a 0.
我们会将相同的图像放入两个神经网络。 如果原始加权神经网络的输出神经元具有较高的值,则图像将被分类为1。如果反向加权神经网络的输出神经元具有较高的值,则图像将被分类为0。
Another way of expressing this idea is a neural network with two output neurons! This is simply putting the two neural networks above on top of each other.
表达此想法的另一种方法是具有两个输出神经元的神经网络! 这只是将两个神经网络放在彼此之上。
If the top neuron’s value is higher, then the image is classified as a 1. If the bottom output neuron’s value is higher, then the image is classified as a 0.
如果顶部神经元的值较高,则图像被分类为1。如果底部神经元的值较高,则图像被分类为0。
It’s important to highlight that each neuron’s connection to each output neuron has its own weight.
重要的是要强调每个神经元与每个输出神经元的连接都有其自身的权重。
It’s totally allowed for neuron A’s connection to neuron B to be weighted super heavily, even if neuron A’s connection to neuron C is weighted super lightly. Or A–B could be positively weighted, and A–C could be negatively weighted. Connections between two neurons are weighted, but neurons themselves are not.
完全允许将神经元A与神经元B的连接加权得非常重,即使将神经元A与神经元C的连接加权得很轻也是如此。 或者,可以将A–B加权为正,而将A–C加权为负。 两个神经元之间的连接被加权,但神经元本身不被加权。
This is closer to how real neural networks classify images. Each classification possibility has its own output neuron, and whichever output neuron has the highest number is the classification that the neural network guesses.
这更接近于真实的神经网络如何对图像进行分类。 每个分类可能性都有自己的输出神经元,而输出神经元中数量最多的是神经网络猜测的分类。
In this case, 1 and 0 each have their own output neuron. If the 1 output neuron’s value is higher, then the neural network guesses 1. If the 0 output neuron’s value is higher, then the neural network guesses 0.
在这种情况下,1和0各自具有自己的输出神经元。 如果1个输出神经元的值较高,则神经网络猜测1。如果0个输出神经元的值较高,则神经网络猜测0。
If things are making sense so far, then you now understand the structure of a very simple binary classification neural network!
如果到目前为止一切都有意义,那么您现在就可以了解一个非常简单的二进制分类神经网络的结构!
But there is an aspect of this neural network that we haven’t addressed in much detail.
但是,该神经网络的一个方面尚未详细介绍。
How exactly do you set the weights of each connection?
您如何精确设置每个连接的权重?
We have the basic idea of how it’s done: depending on which output neuron we’re talking about, the connections between the middle input neurons and the output neuron we’re talking about are weighted either positively or negatively to identify the hole in the middle of the 0 or the line in the middle of the 1.
我们有一个基本的操作思路:根据我们正在谈论的输出神经元,正输入或负输入对中间输入神经元和正在讨论的输出神经元之间的连接进行加权,以识别中间的Kong0或1中间的行。
But really, that’s pretty vague. I mean, it’s not like somebody goes in and manually sets the weights for each connection. This would be tedious for even an 8x8 image, and it would be insanely hard for a 100x100 image!
但是实际上,这非常模糊。 我的意思是,这并不像有人进来手动设置每个连接的权重。 即使是8x8的图像,这也很繁琐,而对于100x100的图像,这将非常困难!
The answer lies in a concept called the loss function.
答案在于称为损失函数的概念。
If our neural network were perfect, we know what we’d want it to do. If we showed it a 0, we’d want the 0 output neuron’s value to be exactly 1, and we’d want the 1 output neuron’s value to be exactly 0.
如果我们的神经网络是完美的,我们知道我们想要它做什么。 如果我们将其显示为0,则希望0输出神经元的值正好为1,而我们希望1输出神经元的值正好为0。
This would mean the neural network is telling us that it is sure it’s seeing a 0 when it actually is seeing a 0.
这意味着神经网络告诉我们,当它实际看到0时,它肯定看到了0。
Of course, it’s basically impossible to reach this level of perfection. But it is possible to quantify how far away we are!
当然,要达到这种完美水平基本上是不可能的。 但是可以量化我们有多远!
For each image, we do this by finding the difference between the ideal value and the observed value of each output neuron, then squaring this result. We add these squared values together to get our result.
对于每个图像,我们通过找到每个输出神经元的理想值和观察值之间的差,然后对该结果求平方来实现。 我们将这些平方值相加在一起得出结果。
The function that produces this result is called the loss function. People always want to minimize losses, and we want to minimize the result of our loss function to make the neural network as accurate as possible.
产生此结果的函数称为损失函数 。 人们总是希望使损失最小化,而我们希望使损失函数的结果最小化,以使神经网络尽可能准确。
But how do we know how to minimize the loss function?
但是我们如何知道如何使损失函数最小化?
Let’s start by understanding the function that produces the observed value of one output neuron. Remember, this value is generated by multiplying each input neuron by the weight of its connection to the output neuron we’re working with, and adding these products all together. Using a bit of math, we could write that process like this:
让我们首先了解产生一个输出神经元观察值的函数。 请记住,该值是通过将每个输入神经元与我们正在使用的输出神经元的连接权重相乘,然后将这些乘积加在一起而生成的。 使用一点数学,我们可以这样编写该过程:
And the ideal value is simple to find for each output neuron. If we want the test image to be classified as the output neuron’s image, the ideal value is 1. If we don’t want the test image to be classified as the output neuron’s image, the ideal value is 0. One reason we use the sigmoid function is so that we can make the ideal value a nice 0 or 1, instead of trying to take a wild guess.
对于每个输出神经元,很容易找到理想值 。 如果我们要将测试图像分类为输出神经元图像,则理想值为1。如果我们不想将测试图像分类为输出神经元图像,则理想值为0。 sigmoid函数的作用是使我们可以将理想值设为0或1,而不是尝试大胆地猜测。
If the ideal value is 1, we just subtract 1 from the equation above. The expanded form of the difference between the observed value and the ideal value in this case looks like this:
如果理想值为1,则只需从上式中减去1。 在这种情况下,观察值与理想值之间的差的展开形式如下所示:
The loss function for a single output neuron is the square of this big thing. In this case, this is the loss function of the output neuron that indicates if the image represents a 1.
单个输出神经元的损失函数就是这个大问题的平方。 在这种情况下,这是输出神经元的损失函数,指示图像是否代表1。
To get the loss function for an entire image, you repeat this process for each output neuron. If the output neuron you’re working with corresponds to the actual image shown, then the ideal value is 1. Otherwise, the ideal value is 0.
要获得整个图像的损失函数,请对每个输出神经元重复此过程。 如果您正在使用的输出神经元与所示的实际图像相对应,则理想值为1。否则,理想值为0。
At the end, you add together the loss function for each output neuron.
最后,将每个输出神经元的损失函数加在一起。
This gives you the loss function for the entire image. The lower this value, the better the neural network did for the image.
这为您提供了整个图像的损失功能 。 该值越低,神经网络对图像的效果越好。
But we’re not quite done. This is just the total loss function for one image.
但是我们还没有完成。 这只是一张图像的总损失函数。
This is where things start getting crazy.
这是事情开始变得疯狂的地方。
To find the total loss for all images, we repeat this entire process for every image in the entire set of training data. At the end, we add together the loss functions for each image to get a single mind-bogglingly massive loss function for the whole neural network on the entire training set. The lower this gargantuan loss function is, the better the neural network is doing!
为了找到所有图像的总损失,我们对整个训练数据集中的每个图像重复整个过程。 最后,我们将每个图像的损失函数加在一起,以获得整个训练集上整个神经网络的令人难以置信的庞大损失函数。 这个巨大的损失函数越低,神经网络的性能就越好!
The reason we don’t just minimize the loss function for a single image is because we need to make sure the neural network can classify different kinds of images. If we just tried to minimize the loss function for a single image of the number 1, the neural network would find this easy. The best way for it to minimize this image’s loss function would be to simply classify every single image as a 1, no matter what. What a smartass.
我们不仅仅将单个图像的损失函数最小化的原因是,我们需要确保神经网络可以对不同种类的图像进行分类。 如果我们只是试图最小化数字为1的单个图像的损失函数,则神经网络会发现这很容易。 最小化此图像损失函数的最佳方法是,无论如何,都将每个图像简单地分类为1 。 真是个聪明人。
We want to force the neural network to classify images as either 1s or 0s based on their appearance, so we add together the loss functions for each image to make the neural network take all images into consideration.
我们要强制神经网络根据图像的外观将图像分类为1s或0s,因此我们将每个图像的损失函数加在一起,以使神经网络考虑所有图像。
Now that we’ve explored what the loss function is, we can take a look at how the computer minimizes it.
现在我们已经研究了损失函数是什么,我们可以看一下计算机如何将其最小化。
The loss function that we just unpacked has three inputs:
我们刚刚解包的损失函数具有三个输入:
The value of each input neuron 每个输入神经元的值 The ideal value of each output neuron (1 or 0, depending on the neuron) 每个输出神经元的理想值(1或0,取决于神经元) The weights of each neuron’s connection with each output neuron 每个神经元与每个输出神经元的连接权重The value of each input neuron depends on the image the neural network is being fed, so we can’t change that. The ideal value of each output neuron also depends on the image, so we can’t change that either.
每个输入神经元的值取决于正在馈入神经网络的图像,因此我们无法更改它。 每个输出神经元的理想值也取决于图像,因此我们也不能更改它。
But we can do whatever we want to with the weights!
但是我们可以做任何我们想做的事情!
The weights are the component that the computer adjusts to minimize the loss function.
权重是计算机调整以最小化损失功能的组成部分。
To understand a bit about how this works, let’s look at a 2D function.
为了稍微了解一下它是如何工作的,让我们看一下2D函数。
Let’s say we start at a random point on this curve, and we want to find our way to the bottom.
假设我们从这条曲线上的一个随机点开始,然后我们想找到到达底部的方法。
But here’s the catch: we can’t actually see the rest of the function. We can see just enough to figure out whether the function is going up or down where we are, but no more.
但是这里有个问题:我们实际上看不到该函数的其余部分。 我们可以看到刚刚够弄清楚功能是否或进入上下我们在哪里,但没有更多。
That’s not a big problem, though. If we’re trying to get to the bottom, we can just hop down a little.
不过,这不是一个大问题。 如果我们试图达到最低点,我们可以跳下一点。
And if we’re not down yet, we just hop down again.
如果我们还没有失望,我们只是再次跳下去。
And again.
然后再次。
If we realized we hopped too far and found the curve pointing the other way like that, we know we hopped over the bottom, which is awesome! Then we take a smaller hop the other way.
如果我们意识到跳得太远,发现曲线指向了相反的方向,我们就知道我们跳到了底部,这太棒了! 然后,我们以另一种方式进行较小的跳跃。
At this point, we know we’re pretty close to the bottom.
在这一点上,我们知道我们已经接近底部。
The computer does something similar to minimize the loss function!
计算机会执行类似的操作以最大程度地减少损失功能!
The computer adjusts one weight at a time, while leaving the others constant. On the graphs above, the vertical axis is the value of the loss function, and the horizontal axis is the value of the weight that’s being adjusted.
计算机一次调整一个重量,而其他重量保持恒定。 在上面的图表中,垂直轴是损失函数的值,水平轴是要调整的权重的值。
But just like the example above, the computer only calculates enough of the loss function to see the slope of the function.
但是,就像上面的示例一样,计算机仅计算出足够多的损失函数即可看到函数的斜率。
That’s okay for the computer though! Just like we did, the computer uses the slope of this graph to decide which direction to adjust the weight. If the slope is really steep, the computer adjusts the weight a lot, and if the slope isn’t that steep, the computer adjusts the weight just a little.
那对电脑来说还可以! 就像我们所做的一样,计算机使用此图的斜率来决定调整权重的方向。 如果坡度确实很陡,则计算机会大量调整重量;如果坡度不是那么陡,则计算机仅会稍微调整重量。
After the computer adjusts one weight, it moves onto the next weight and repeats the same process. It keeps doing this for the weight of every single connection in the entire network!
计算机调整完一个砝码后,它将移至下一个砝码并重复相同的过程。 对于整个网络中每个连接的重量,它都会继续这样做!
After all the weights are adjusted, the computer looks at all of the training data again to figure out where the new weights put it on the loss function graph. The computer then minimizes adjusts the weights more to further minimize the loss function, creating another new set of weights.
调整完所有权重后,计算机会再次查看所有训练数据,以找出新权重将其放在损失函数图中的位置。 然后,计算机将最小化调整权重更多,以进一步最小化损失函数,从而创建另一组新的权重。
This process continues, potentially thousands of times, until the programmers tell the computer to stop or the computer is satisfied that it’s minimized the loss function.
该过程可能会持续数千次,直到程序员告诉计算机停止运行或计算机对它已将损失函数降至最低感到满意为止。
And this all happens automatically during a single training session!
在一次培训中,所有这些都会自动发生!
In short, training a neural network involves adjusting the weights of each connection between input and output neurons to minimize the loss function.
简而言之,训练神经网络需要调整输入和输出神经元之间每个连接的权重,以使损失函数最小化。
If that sentence makes sense to you, then you have a solid grasp on the basics of neural network training!
如果这句话对您有意义,那么您就对神经网络训练的基础有了扎实的掌握!
There’s just one more piece of the puzzle we’ll add now.
现在,我们将添加另外一个难题。
So far, we’ve been working with a neural network that only has two output neurons: one that corresponds to an image of a 0, and another that corresponds to an image of a 1.
到目前为止,我们一直在使用只有两个输出神经元的神经网络:一个对应于0的图像,另一个对应于1的图像。
But by now, you may have guessed that it’s possible to add an output neuron for every possible number from 0–9.
但是到现在,您可能已经猜到,可以为0–9中的每个可能数字添加输出神经元。
This neural network operates just like the one we’ve been discussing! The only difference is that it can be trained on the entire dataset, and it can identify any number from 0–9.
这个神经网络的运行就像我们一直在讨论的那样! 唯一的区别是,可以在整个数据集上对其进行训练,并且可以识别0–9之间的任何数字。
When training begins, the neural network sets random values for the weights of each connection. Over multiple cycles of optimization, the neural network gradually adjusts the weights to minimize the loss function and maximize accuracy.
训练开始时,神经网络会为每个连接的权重设置随机值。 在多个优化周期中,神经网络逐渐调整权重以最小化损失函数并最大化准确性。
But there’s another, even cooler aspect of neural networks that we haven’t even discussed yet.
但是神经网络还有另一个甚至更酷的方面,我们还没有讨论过。
So far, we’ve been linking input neurons directly to neurons that try to identify an entire number.
到目前为止,我们一直在将输入神经元直接链接到试图识别整数的神经元。
But what would you guess happens if we put a whole line of neurons in the middle of the network? This line of neurons is called a hidden layer.
但是,如果我们将整个神经元线放在网络中间,您会猜怎么办? 这行神经元称为隐藏层 。
For each input neuron, the hidden layer acts like an output neuron. For each output neuron, the hidden layer acts like an input neuron.
对于每个输入神经元, 隐藏层的作用类似于输出神经元。 对于每个输出神经元,隐藏层的作用类似于输入神经元。
A beautiful thing occurs here. Following the optimization process we discuss above, the neurons in the hidden layer naturally learn to identify subsections of numbers! These small subsections can be things like lines, curves, and dashes that work together to form a full number, just as pixels work together to form lines, curves, and dashes. Often, the subsections of numbers that hidden layers identify are shapes that look nothing like part of a number to the human eye, but rather have only subtle mathematical relevance to the shape of a complete number.
美丽的事情在这里发生。 在上面讨论的优化过程之后,隐藏层中的神经元 自然学会识别数字小节 ! 这些小部分可以是像直线,曲线和破折号这样的东西,它们可以一起形成一个整数,就像像素可以一起形成折线,曲线和破折号一样。 通常,隐藏层所标识的数字子部分的形状在人眼看来并不像数字的一部分,而是与整数的形状仅具有微妙的数学相关性。
In other words, the neural network uses pixels to identify small parts of numbers. It then uses these small parts of numbers to identify entire numbers.
换句话说,神经网络使用像素来识别数字的一小部分。 然后,它使用数字的这些小部分来标识整个数字。
Let’s just stop and take a moment to realize how epic that is.
让我们停下来花一点时间来了解那是多么的史诗 。
Unleashing the equations and optimization procedures we’ve discussed above naturally causes hidden layers of neurons to identify subsections of numbers. The laws of mathematics alone identify deep patterns, without any human intervention.
释放我们上面讨论的方程式和优化程序, 自然会导致神经元的隐藏层识别数字的各个部分。 仅数学定律就能确定深层模式,而无需任何人工干预。
And you don’t have to stop at just one hidden layer. Two, three, or hundreds of hidden layers can be added to models for different results. Each hidden layer can also contain different numbers of neurons. The possibilities for messing around with hidden layers are endless.
而且您不必仅停留在一个隐藏层。 可以将两个,三个或数百个隐藏层添加到模型中以获得不同的结果。 每个隐藏层还可以包含不同数量的神经元。 搞乱隐藏层的可能性是无限的。
If you’re wondering how a programmer can improve a model’s accuracy once it’s been trained, adjusting hidden layers is a common thing to try. (It’s also worth mentioning that there are dozens of completely different neural network structures, each with their own fascinating and unique characteristics.)
如果您想知道程序员在训练后如何提高模型的准确性,那么尝试调整隐藏层是很常见的事情。 (还值得一提的是,有数十种完全不同的神经网络结构,每种结构都有其独特的独特魅力。)
Hidden layers are the way in which neural networks learn to recognize patterns of patterns (of patterns of patterns of patterns…), as we discussed in the beginning of the article. In the digit classification problem, hidden layers let the neural network identify patterns of numbers from patterns of number subcomponents from patterns of pixels.
正如我们在本文开头所讨论的,隐藏层是神经网络学习识别模式模式(模式模式的模式……)的方式。 In the digit classification problem, hidden layers let the neural network identify patterns of numbers from patterns of number subcomponents from patterns of pixels.
The possibilities for utilizing neural networks extend far beyond handwriting recognition. Neural networks can be relevant to any activity that involves recognizing patterns. They can be relevant to cooking, flying planes, building houses, optimizing supply chains, writing AI-generated papers, growing peas, teaching languages, and almost any other activity that you could possibly think of.
The possibilities for utilizing neural networks extend far beyond handwriting recognition. Neural networks can be relevant to any activity that involves recognizing patterns. They can be relevant to cooking, flying planes, building houses, optimizing supply chains, writing AI-generated papers, growing peas, teaching languages, and almost any other activity that you could possibly think of.
That’s why it seems like AI is in every single new technology you ask about.
That's why it seems like AI is in every single new technology you ask about.
Patterns are at the core of everything.
Patterns are at the core of everything.
Note: If you want to learn more about neural networks and AI, there are tons of high-quality resources online. Andrew Ng’s coursera courses on machine learning and deep learning are great places to start.
Note: If you want to learn more about neural networks and AI, there are tons of high-quality resources online. Andrew Ng's coursera courses on machine learning and deep learning are great places to start.
翻译自: https://medium.com/@a.jeremymah/behind-the-eyeballs-of-ai-how-neural-networks-work-207c31e0b1ff
神经网络是ai