Video
Đăng bởi Ban biên tập OpenER ·
Tác giả giữ toàn bộ bản quyền (All Rights Reserved) — không phải giấy phép mở. Bạn vẫn xem và học miễn phí trên OpenER; muốn tái sử dụng cần xin phép tác giả.
PROFESSOR
OK. Welcome, everyone. Welcome to the 22nd lecture of CS 188. A couple of announcements.
Được rồi. Chào mừng các em. Chào mừng đến với bài giảng thứ 22 của CS 188. Có vài thông báo.
Actually, the same ones as last lecture. Your project four is due tomorrow at 4:00 PM. Your homework 10, actually has been released, I hope, and will be due on Tuesday.
Thực ra giống như bài trước. Project bốn hạn nộp là 4 giờ chiều ngày mai. Bài tập về nhà 10 thì đã được đăng rồi, thầy hy vọng vậy, và hạn nộp là thứ Ba.
And then your midterm, perhaps the most important thing to keep in mind, is going to be next week Thursday.
Còn bài thi giữa kỳ, có lẽ là điều quan trọng nhất cần nhớ, sẽ diễn ra vào thứ Năm tuần sau.
There will be a prep page coming out later today or tomorrow with a practice midterm two and also a list of office hours and sections dedicated to midterm two.
Trang ôn tập sẽ được đăng hôm nay hoặc ngày mai, có đề thi thử giữa kỳ hai và danh sách giờ làm việc cùng các buổi thực hành dành riêng cho giữa kỳ hai.
Any questions about logistics?
Có câu hỏi nào về các vấn đề tổ chức không?
OK. So today's topic is Optimization and Neural Nets. In general in 188, we try to cover topics that are pretty timeless.
Được rồi. Chủ đề hôm nay là Tối ưu hóa và Mạng nơ-ron. Nói chung trong CS 188, chúng ta cố gắng đề cập những chủ đề khá là trường tồn với thời gian.
So that if 20 years from now, you decide after 20 years of no AI you get back into AI, that the materials you covered are still relevant. I think we do that pretty well.
Để nếu 20 năm nữa, các em sau 20 năm không làm AI lại quay về với AI, thì kiến thức đã học vẫn còn dùng được. Thầy nghĩ chúng ta làm việc đó khá tốt.
It happens to be that today the material we cover also is the fashion of the day.
Tình cờ là hôm nay nội dung chúng ta học cũng đang là mốt của thời đại.
So not only what we think of as a timeless topic, but also the most fashionable topic in AI for the past five years, and maybe for another five years to go.
Nên nó không chỉ là một chủ đề trường tồn, mà còn là chủ đề thịnh hành nhất của AI trong năm năm qua, và có thể là năm năm nữa.
Who knows how long? So we'll cover both the most fashionable topic and what we think of as a timeless topic today.
Ai biết được bao lâu? Vậy hôm nay ta sẽ học cả chủ đề thịnh hành nhất lẫn một chủ đề mà ta cho là trường tồn.
So it's a lot more mathematical than most of what we've done in 188. So that was already the case in the last lecture.
Nó mang tính toán học nhiều hơn hầu hết những gì ta đã làm trong CS 188. Bài trước đã là như vậy rồi.
So I'm going to rework through some of the things we covered last lecture to make sure we have the right foundation, and then from there build up to neural networks.
Nên thầy sẽ làm lại một số nội dung của bài trước để đảm bảo ta có nền tảng đúng, rồi từ đó xây dựng lên mạng nơ-ron.
So reminder. What are linear classifiers? Linear classifiers have inputs, which we call feature values, which might come in, let's say here, here, here, and so forth.
Nhắc lại nhé. Bộ phân loại tuyến tính là gì? Bộ phân loại tuyến tính có các đầu vào, mà ta gọi là giá trị đặc trưng, giả sử đến từ đây, đây, đây, và cứ thế.
Each feature has a weight, which is how much attention you pay to that feature. It could be a positive weight or a negative weight.
Mỗi đặc trưng có một trọng số, cho biết mức độ ta chú ý đến đặc trưng đó. Trọng số có thể dương hoặc âm.
And the weighted sum of the inputs is the activation of the unit. So mathematically, we have a weighted sum happening here.
Và tổng có trọng số của các đầu vào là độ kích hoạt của đơn vị. Về mặt toán học, ở đây ta có một tổng có trọng số.
i is indexing over the different input channels. And so we have, let's say, feature 1, 2, 3, and so forth all indexed by i, weighted some of those features.
i là chỉ số chạy trên các kênh đầu vào khác nhau. Vậy ta có, giả sử, đặc trưng 1, 2, 3, và cứ thế, đều đánh chỉ số theo i, rồi lấy tổng có trọng số của các đặc trưng đó.
In shorthand notation, it's this dot product notation. Then if the activation is positive, bigger than 0, we might say it's the positive class.
Viết tắt thì là ký hiệu tích vô hướng này. Nếu độ kích hoạt dương, lớn hơn 0, ta có thể nói đó là lớp dương.
If it's smaller than 0, we might say it's the negative class. Pictorially, it might look something like this. So that's a linear classifier.
Nếu nhỏ hơn 0, ta có thể nói đó là lớp âm. Hình ảnh minh họa có thể trông như thế này. Đó là một bộ phân loại tuyến tính.
Then last time we said, well, if all we do is this kind of deterministic decision making, it's not always obvious what is the optimal choice of w.
Lần trước ta nói, nếu chỉ đưa ra quyết định tất định như vậy, thì không phải lúc nào cũng rõ w tối ưu là gì.
It's harder to define, and there might not be one that gets everything right. So we transition to a probabilistic decision-making process, where we said, OK, we still have an activation just like before.
Khó định nghĩa hơn, và có thể không có w nào làm đúng tất cả. Nên ta chuyển sang quá trình ra quyết định theo xác suất, trong đó ta vẫn có một độ kích hoạt giống như trước.
That hasn't changed. We call it z. And it's the inner product of the weight factor with the feature factor that's coming in. It's very positive.
Điều đó không đổi. Ta gọi nó là z. Nó là tích vô hướng của vectơ trọng số với vectơ đặc trưng đi vào.
We want the probability of the positive class to go to 1. If it's very negative, we want the probability of the positive class going to 0.
Nếu z rất dương, ta muốn xác suất của lớp dương tiến về 1. Nếu rất âm, ta muốn xác suất của lớp dương tiến về 0.
So the question is, can we find a function that maps a real number that can be anywhere between negative infinity and positive infinity to the range 0-1?
Vậy câu hỏi là, có hàm nào ánh xạ một số thực nằm ở bất kỳ đâu giữa âm vô cùng và dương vô cùng về khoảng từ 0 đến 1 không? Thực ra có nhiều hàm như vậy.
In fact, there are many such functions that can do this. The one that we picked is sigmoid. What's key about it is that it's monotonically going from 0 to 1.
Hàm mà ta chọn là sigmoid. Điểm mấu chốt là nó đơn điệu đi từ 0 đến 1. z càng lớn thì càng gần 1.
The higher z becomes, the closer to 1. The more negative z becomes, the closer to 0. There were some questions after lecture. Could you use another function there?
z càng âm thì càng gần 0. Sau bài giảng có một số câu hỏi. Có thể dùng hàm khác ở đó không? Chắc chắn là được.
You definitely can. The key properties is this transition from 0 to 1 that's monotonic. One reason people use this one a lot is because when we optimize, we'll need to take derivatives.
Tính chất then chốt là sự chuyển từ 0 sang 1 mang tính đơn điệu. Một lý do nhiều người hay dùng hàm này là vì khi tối ưu hóa, ta cần lấy đạo hàm. Và hàm này tình cờ có đạo hàm thuận tiện.
And this one happens to also have convenient derivatives. And it's convenient to compute in itself. So there's some practical reasons why you might want to pick this one.
Bản thân nó cũng tính toán dễ dàng. Nên có một số lý do thực tế để chọn hàm này.
But for what we've covered so far, the main reason you'd pick something like this, it goes from 0 to 1 as you go from negative infinity to positive infinity.
Nhưng với những gì ta đã học đến giờ, lý do chính để chọn hàm như vậy là nó đi từ 0 đến 1 khi đầu vào đi từ âm vô cùng đến dương vô cùng. Đó là hàm sigmoid.
So that's the sigmoid. Then the question was, what's the best w when we're going to make probabilistic decisions? Well, we've seen that principle in a previous lecture when covering naive Bayes.
Rồi câu hỏi là, w tốt nhất là gì khi ta đưa ra quyết định theo xác suất? Ta đã thấy nguyên lý đó ở bài trước khi học naive Bayes.
It's the parameter vector that maximizes the likelihood of the data. In this case, the maximum likelihood estimation comes down to maximizing the conditional probability of the label yi.
Đó là vectơ tham số làm cực đại khả năng (likelihood) của dữ liệu. Trong trường hợp này, ước lượng hợp lý cực đại quy về cực đại hóa xác suất có điều kiện của nhãn yi.
So we have a data point i, which consists of a label yi, and an input xi. And our model will predict the distribution over possible labels.
Ta có điểm dữ liệu i, gồm nhãn yi và đầu vào xi. Mô hình của ta sẽ dự đoán phân phối trên các nhãn có thể có.
And we want the probability placed on the correct label, the one that's in the data. yi to be as high as possible. There's a log in front of that.
Và ta muốn xác suất đặt vào nhãn đúng, nhãn có trong dữ liệu, tức yi, càng cao càng tốt. Phía trước có một hàm log. Hàm log không làm thay đổi việc ta muốn giá trị cao hay thấp.
The log does not change things in terms of whether we want it to be high or low. It's just a monotonic transformation.
Nó chỉ là một phép biến đổi đơn điệu. Và đây là tổng các log xác suất của tất cả dữ liệu .
And what this is is a sum of log probabilities of all the data points; outputs given the inputs. And the score here, the value achieved, depends on w.
. dữ liệu; tức là các đầu ra cho trước các đầu vào. Và điểm số ở đây, giá trị đạt được, phụ thuộc vào w.
Different choices of w will achieve different sums of log probabilities. And what we'd like to find is a w that maximizes this, because that would be the w that best explains the data.
Các lựa chọn w khác nhau sẽ cho ra các tổng log xác suất khác nhau. Và ta muốn tìm một w làm cực đại giá trị này, vì đó sẽ là w giải thích dữ liệu tốt nhất.
Diving into the specifics under the p, the probability of the positive label, given the input xi and some weight w, is this thing over here.
Đi vào chi tiết bên trong p, xác suất của nhãn dương, cho đầu vào xi và một trọng số w nào đó, chính là biểu thức ở đây.
It's the linear classifier calculation, the dot product between weight vector and feature vector.
Đó là phép tính của bộ phân loại tuyến tính, tích vô hướng giữa vectơ trọng số và vectơ đặc trưng.
And then the sigmoid is applied to that, which is the remainder of that expression, 1 over 1 plus e to the negative activation.
Sau đó áp dụng hàm sigmoid lên kết quả đó, tức là phần còn lại của biểu thức: 1 chia cho 1 cộng e mũ âm của giá trị kích hoạt.
And then the probability of the other class is 1 minus the probability of the first class when there's only two classes. Any questions about this?
Còn xác suất của lớp kia là 1 trừ xác suất của lớp thứ nhất, khi chỉ có hai lớp. Có câu hỏi nào về phần này không?
This notation will keep coming back and back and back the entire lecture.
Ký hiệu này sẽ cứ xuất hiện lặp đi lặp lại suốt bài giảng.
OK. That's two class. How about multiclass? So this is two-class logistic regression.
Được rồi. Đó là trường hợp hai lớp. Còn nhiều lớp thì sao? Đây là hồi quy logistic hai lớp.
Multiclass, we could say, well, we can not have a weight vector per class. And the weight vector points in the direction that you think the data points for that class inhabit.
Với nhiều lớp, ta có thể nói: ta sẽ có một vectơ trọng số cho mỗi lớp. Vectơ trọng số chỉ theo hướng mà bạn nghĩ các điểm dữ liệu của lớp đó nằm ở đó.
So then to the multiclass linear classification, you'd say, well, let's look at each weight vector for each possible class i. We can compute the dot product with a feature vector, which describes the input.
Vậy với phân loại tuyến tính nhiều lớp, bạn sẽ xét từng vectơ trọng số cho mỗi lớp i có thể có. Ta tính tích vô hướng với vectơ đặc trưng mô tả đầu vào.
And then we can see which one maximizes that dot product. And that's the label we assign. But again, that's a deterministic decision rule.
Rồi xem lớp nào làm cực đại tích vô hướng đó. Và đó là nhãn ta gán. Nhưng đó lại là một quy tắc quyết định tất định.
And if things are not perfectly linearly classifiable, then it becomes less clear what your right choice is.
Và nếu dữ liệu không thể phân loại tuyến tính hoàn hảo, thì không còn rõ lựa chọn đúng là gì.
And so we're again going to define an objective function that characterizes how good a choice of weight vectors is. So we're going to turn it this into probabilities.
Vì vậy ta lại định nghĩa một hàm mục tiêu đo mức độ tốt của một lựa chọn các vectơ trọng số. Ta sẽ biến nó thành xác suất.
How do we turn — let's say if we have a three-class problem, we have three activations, z1, z2, z3, into probabilities.
Làm sao để biến — giả sử bài toán có ba lớp, ta có ba giá trị kích hoạt z1, z2, z3, thành xác suất?
This is the equation we're going to be using, which is called a softmax. Let's again interpret this. The first three numbers are the original activations, just the results of the inner products.
Đây là công thức ta sẽ dùng, gọi là softmax. Ta cùng diễn giải nó. Ba số đầu là các giá trị kích hoạt ban đầu, chính là kết quả của các tích vô hướng.
And then these are the softmax activations. Let's imagine z1 is a lot bigger than z2, and z1 is also a lot bigger than z3.
Còn đây là các giá trị kích hoạt softmax. Giả sử z1 lớn hơn z2 rất nhiều, và z1 cũng lớn hơn z3 rất nhiều.
Remember, an exponential looks like this and grows very quickly as you move further on that horizontal axis.
Nhớ rằng hàm mũ có dạng thế này và tăng rất nhanh khi bạn đi ra xa hơn trên trục hoành.
So if z1 is a lot bigger than z2 and a lot bigger than z3, what will happen? e to the z1 will be way, way, way bigger than e to the z2.
Nếu z1 lớn hơn z2 và lớn hơn z3 rất nhiều, thì chuyện gì xảy ra? e mũ z1 sẽ lớn hơn e mũ z2 cực kỳ nhiều.
And e to the z1 will also be a lot bigger than e to the z3.
Và e mũ z1 cũng lớn hơn e mũ z3 rất nhiều.
And what will happen is — and what we have at the bottom here — e to the z1 will dominate.
Và điều xảy ra là — ở phần dưới này — e mũ z1 sẽ chiếm ưu thế.
And we'll have — it's really a big difference — a probability close to 1 on the class label 1, and close to 0 on the others.
Và ta sẽ có — chênh lệch rất lớn — xác suất gần 1 cho nhãn lớp 1, và gần 0 cho các lớp còn lại.
No matter exactly how these numbers, the z1, z2, z3, are configured, what happens here is they all get turned into a positive number, because exponentiating makes it positive.
Dù các số z1, z2, z3 cụ thể ra sao, thì tất cả đều được biến thành số dương, vì lấy hàm mũ thì ra số dương.
And by dividing by the sum of all three, we normalize. And so these three numbers that we get out will always sum to 1, will always be positive.
Và chia cho tổng của cả ba, ta chuẩn hóa. Nên ba số thu được luôn có tổng bằng 1 và luôn dương.
And the more you're activated, the higher your probability will be in this resulting softmax.
Giá trị kích hoạt càng cao thì xác suất trong kết quả softmax càng cao.
Now, what z1, z2, z3 will be for a given data point will depend on our choices of the weight factors w for class one, w for class two, w for class three, altogether w.
Còn z1, z2, z3 của một điểm dữ liệu sẽ phụ thuộc vào lựa chọn các vectơ trọng số w cho lớp một, w cho lớp hai, w cho lớp ba, gộp lại là w.
What we'd like to find is the best w.
Điều ta muốn là tìm w tốt nhất.
So again, we can use the same principle of maximum likelihood estimation, which is the principle where we say we want to maximize the likelihood of the data we have overall choices of parameter vector available to us.
Vậy ta lại dùng cùng nguyên lý ước lượng hợp lý cực đại, tức là nguyên lý ta muốn cực đại hóa khả năng của dữ liệu đang có trên mọi lựa chọn vectơ tham số có thể.
So in this case, maximize the likelihood of data. Because we're interested in classification, making a decision will mean maximizing the likelihood of the labels condition on the input.
Ở đây là cực đại hóa khả năng của dữ liệu. Vì ta quan tâm đến phân loại, việc ra quyết định nghĩa là cực đại hóa khả năng của các nhãn có điều kiện theo đầu vào.
Remember, in naive Bayes, you maximize the likelihood of both x and y together. That's a different optimization.
Nhớ rằng trong naive Bayes, bạn cực đại hóa khả năng của cả x và y cùng nhau. Đó là một bài toán tối ưu khác.
Here we're just interested in y given x, and we'll try to find w's that are maximally good to optimize this objective over here. Underneath what's happening?
Ở đây ta chỉ quan tâm y cho trước x, và sẽ cố tìm các w tốt nhất để tối ưu hàm mục tiêu ở đây. Bên dưới đang diễn ra điều gì?
These probabilities are all softmaxes. That is you had activations, which is weight vector for, let's say, the label class in a product with the feature vector exponentiated at the top.
Các xác suất này đều là softmax. Nghĩa là bạn có giá trị kích hoạt, là vectơ trọng số của, giả sử, lớp nhãn đó nhân vô hướng với vectơ đặc trưng, rồi lấy mũ ở tử số.
And then at the bottom, you normalize by looking at all possible class labels. And you look at the inner product of the weight vector for each possible class label with the feature vector exponentiated.
Còn ở mẫu số, bạn chuẩn hóa bằng cách xét tất cả các nhãn lớp có thể. Bạn xét tích vô hướng của vectơ trọng số của từng nhãn lớp có thể với vectơ đặc trưng, rồi lấy mũ.
Sum it altogether to normalize. That's multiclass logistic regression. And that's what we'll be building up most directly in this lecture. Any questions about this?
Cộng tất cả lại để chuẩn hóa. Đó là hồi quy logistic nhiều lớp. Và đó là thứ ta sẽ xây dựng trực tiếp nhất trong bài giảng này. Có câu hỏi nào về phần này không?
OK. Then what we want to do now in this lecture is find a way to solve for w.
Được rồi. Việc ta muốn làm tiếp theo trong bài này là tìm cách giải ra w.
The naive way to solve for w is to assume that you have infinite computes, and you try every possible w. And if you do have infinite compute, that is actually a possibility.
Cách ngây thơ để giải w là giả sử bạn có năng lực tính toán vô hạn, và thử mọi w có thể. Và nếu bạn thật sự có tính toán vô hạn, thì đó thực sự là một khả năng.
You can just cycle through every possible w. And then figure out which one maximizes the score.
Bạn cứ duyệt qua mọi w có thể. Rồi xem w nào cực đại hóa điểm số.
And that would give you the same answer as we're hoping to find with the procedure we're going to describe. But the procedure we'll describe in this lecture will not require infinite compute.
Và nó sẽ cho cùng đáp án mà ta hy vọng tìm được bằng quy trình mà chúng ta sắp mô tả. Nhưng thủ tục mà ta mô tả trong bài này sẽ không đòi hỏi khả năng tính toán vô hạn.
So we've actually seen something similar before. When solving CSPs, we have to find assignments to variables. Think of w as a vector with each entry being a variable.
Thật ra ta đã thấy một thứ tương tự trước đây. Khi giải CSP, ta phải tìm phép gán giá trị cho các biến. Hãy coi w là một vectơ mà mỗi phần tử là một biến.
And we're trying to find an assignment to each entry in the vector w. With CSP, the score would have been how many of the constraints are satisfied. The more constraints satisfied, the better.
Và ta đang cố tìm một phép gán cho từng phần tử của vectơ w. Với CSP, điểm số sẽ là số ràng buộc được thỏa mãn. Thỏa mãn càng nhiều ràng buộc thì càng tốt.
And we saw something called local search, which was fairly scalable, where we said we start with a random assignment of the variables. And then we just do a random perturbation of a variable.
Và ta đã thấy một phương pháp gọi là local search, khá dễ mở rộng, trong đó ta nói rằng ta bắt đầu bằng một phép gán ngẫu nhiên cho các biến. Rồi ta chỉ cần nhiễu loạn ngẫu nhiên một biến.
And we see maybe if it's better. More constraints are satisfied. Let's keep it. Less constraints satisfied, maybe let's reject it, and repeat.
Và xem nó có tốt hơn không. Nhiều ràng buộc được thỏa mãn hơn. Thì ta giữ lại. Ít ràng buộc được thỏa mãn hơn thì ta bác bỏ nó, rồi lặp lại.
So that could be a starting point. And it's, philosophically speaking, the starting point for this lecture. You could just pick a random w, and then perturb an entry.
Đó có thể là điểm khởi đầu. Và nói về mặt triết lý, đó chính là điểm khởi đầu cho bài giảng này. Bạn có thể chọn một w ngẫu nhiên, rồi thay đổi nhẹ một phần tử.
See if it's better or worse. If it's better, keep it. If it's worse, go back to what you had before, and repeat. That's actually an algorithm you could run.
Xem nó tốt hơn hay tệ hơn. Nếu tốt hơn, giữ lại. Nếu tệ hơn, quay về cái trước đó, rồi lặp lại. Đó thật sự là một thuật toán bạn có thể chạy.
And you might find a pretty decent w if you run it long enough. Some trickiness, though. What we have here is not a discrete domain for the variable.
Và bạn có thể tìm được một w khá tốt nếu chạy đủ lâu. Tuy nhiên có chút rắc rối. Ở đây miền giá trị của biến không rời rạc.
We have continuous domains. So when we pick another value for a variable, there is infinitely many choices.
Ta có miền liên tục. Nên khi chọn một giá trị khác cho biến, có vô hạn lựa chọn.
And so we need to maybe be a little more clever about how we're going to pick a reassignment. When we have infinitely many choices, then went back.
Vì vậy ta cần khéo léo hơn một chút trong cách chọn phép gán lại. Khi có vô hạn lựa chọn, thì hãy nhớ lại.
We did CSPs, and there might have been three colors to choose from to color a map. So how do we do this efficiently?
Hồi học CSP, có thể chỉ có ba màu để chọn khi tô màu bản đồ. Vậy làm sao làm việc này hiệu quả?
One of things that is actually pretty interesting here is that even though it seems like continuous is our enemy, in that it makes it infinite, and there is so much more to choose from and to search over, actually, it'll help us a lot, because the beauty about continuity is that you can actually locally get some signal and see in which direction things are getting better, and which direction they're getting worse.
Một điều khá thú vị là dù có vẻ liên tục là kẻ thù, vì nó làm cho vô hạn, và có quá nhiều thứ để chọn và tìm kiếm, thật ra nó sẽ giúp ta rất nhiều, vì điểm hay của tính liên tục là ta có thể lấy cục bộ một tín hiệu và biết hướng nào mọi thứ đang tốt lên, và hướng nào đang tệ đi.
Whereas with CSPs, you have to make a discrete change. It doesn't give you as much local signal as we will get here.
Còn với CSP, bạn phải thay đổi rời rạc. Nó không cho bạn nhiều tín hiệu cục bộ như ta sẽ có ở đây.
So even though for now it looks like, oh, no, continuous is bad, you'll see actually it's a good thing for our optimization process.
Nên dù bây giờ trông có vẻ, ôi không, liên tục là xấu, bạn sẽ thấy thật ra nó là điều tốt cho quá trình tối ưu hóa của ta.
Let's start with a very simple continuous optimization, one dimensional. We have a function g of w. And we'd like to find where this function is maximized.
Hãy bắt đầu với một bài tối ưu liên tục rất đơn giản, một chiều. Ta có một hàm g của w. Và ta muốn tìm chỗ hàm này đạt cực đại.
If it's really a one dimensional function, you could just plot it like we did here. That's effectively having the infinite compute. You evaluate the function everywhere.
Nếu thật sự là hàm một chiều, bạn có thể vẽ đồ thị như ta làm ở đây. Về bản chất, đó là có khả năng tính toán vô hạn. Bạn tính hàm ở mọi điểm.
You look at it, and you say, oh, wow, this looks good. What's w? This is my w star, the best possible choice.
Bạn nhìn và nói, ồ, chỗ này trông tốt. w là bao nhiêu? Đây là w sao của tôi, lựa chọn tốt nhất có thể.
So sure, if your real problem is 1D, just do that, and you're good to go. I'm not advocating against doing that.
Nên nếu bài toán thật của bạn là 1D, cứ làm vậy, là xong. Tôi không phản đối việc làm đó.
But what we want to do now is we want to build some intuition from the 1D case that we can reuse in the higher dimensional cases.
Nhưng điều ta muốn làm bây giờ là xây dựng trực giác từ trường hợp 1D để dùng lại cho các trường hợp nhiều chiều hơn.
And in the higher dimensional cases, the intuition I've just plotted and looked at is just not going to work out. So what else can we do rather than just plotting and looking at it?
Và với trường hợp nhiều chiều, trực giác vừa vẽ ra rồi nhìn sẽ không còn dùng được. Vậy ta còn có thể làm gì ngoài việc vẽ rồi nhìn? theo cách đó?
Let's say we randomly initialize. And this is our w0, random initialization. We can look at the function value gw. You might say, well, it's good enough.
Giả sử ta khởi tạo ngẫu nhiên. Và đây là w0 của ta, khởi tạo ngẫu nhiên. Ta có thể xem giá trị hàm g(w). Bạn có thể nói, thế là đủ tốt rồi.
I call it done. My log likelihood has achieved a high enough score. But you can also look around and say, what if I change it? Can it become any better?
Tôi coi như xong. Log likelihood của tôi đã đạt điểm đủ cao. Nhưng bạn cũng có thể nhìn quanh và hỏi, nếu tôi thay đổi thì sao? Nó có tốt hơn được không?
Maybe you can perturb it by a small amount h to the right and to the left.
Có thể bạn nhiễu loạn nó một lượng nhỏ h sang phải và sang trái.
So it would be a w0 plus h over here, achieving this — well, this value here, and maybe a w0 minus h achieving this value over here.
Vậy ta có w0 cộng h ở đây, đạt giá trị này, và w0 trừ h đạt giá trị ở đằng này. đạt được giá trị này ở đây.
You might say, well, moving to the right seems better than moving to the left, because the value went up and we're trying to maximize the log likelihood.
Bạn có thể nói, đi sang phải có vẻ tốt hơn đi sang trái, vì giá trị tăng lên và ta đang muốn cực đại hóa log likelihood.
So then let's step in that direction and maybe repeat this process. Now you could probably do this.
Vậy ta bước theo hướng đó và có thể lặp lại quá trình này. Bạn hoàn toàn có thể làm vậy.
You could — then again, if you did exactly minus h and plus h, you would end up here and here. And then you'd choose to go here. Next time you'd end up here.
Nếu bạn dùng đúng trừ h và cộng h, bạn sẽ tới đây và đây. Rồi bạn chọn đi tới đây. Lần sau bạn tới đây.
Next time here. And then maybe next time if you're lucky, you land right on the top. And after you do that, you look in both directions. You'll see it doesn't get better.
Lần sau nữa tới đây. Và rồi lần sau, nếu may mắn, bạn đáp ngay đỉnh. Sau đó, bạn nhìn cả hai hướng. Bạn thấy nó không tốt hơn nữa.
You call it done. You found a local optimum. It doesn't mean you've found the global optimum. In this case, we did.
Bạn coi như xong. Bạn đã tìm được một cực trị cục bộ. Điều đó không có nghĩa là bạn đã tìm được cực trị toàn cục. Trong trường hợp này thì có.
But you could imagine if you started, let's say, here and you did the same procedure, you'd end up somewhere over here. We'll be OK with that in the optimizations that we're doing.
Nhưng bạn có thể hình dung nếu bạn bắt đầu, chẳng hạn, ở đây và làm cùng thủ tục, bạn sẽ kết thúc ở đâu đó bên này. Ta sẽ chấp nhận điều đó trong các bài tối ưu hóa này.
We're going to be fine with finding local optimums.
Ta sẽ chấp nhận việc tìm cực trị cục bộ.
We might just randomly initialize a few times and see if we find local optims that are better or worse with a different initializations, and then keep the best one.
Ta có thể khởi tạo ngẫu nhiên vài lần và xem các cực trị cục bộ tìm được tốt hơn hay tệ hơn với các khởi tạo khác nhau, rồi giữ cái tốt nhất.
So in this case, we initialize twice; once here, once here. We would have found this one and this one.
Trong trường hợp này, ta khởi tạo hai lần; một lần ở đây, một lần ở đây. Chúng ta sẽ tìm được điểm này và điểm này.
And we'd have retained this one here and said, that's the one that maximizes our score.
Và ta sẽ giữ lại điểm này ở đây và nói, đây là điểm cho điểm số lớn nhất.
So that would mean we can discreetly perturb a little bit in each direction. You might wonder how much should we perturb in each direction.
Vậy nghĩa là ta có thể dịch chuyển rời rạc một chút theo mỗi hướng. Bạn có thể thắc mắc nên dịch chuyển bao nhiêu theo mỗi hướng.
And do we really need to do it in both directions?
Và liệu có thật sự cần làm cả hai hướng không?
Because if we look in one direction, doesn't that already tell us something about the slope and tell us it's going uphill in that direction so then it will be downhill in the other direction if this function is smooth.
Vì nếu ta nhìn theo một hướng, chẳng phải điều đó đã cho ta biết phần nào về độ dốc và cho biết theo hướng đó là đi lên dốc nên hướng ngược lại sẽ là xuống dốc nếu hàm này trơn.
So maybe we can only look in one direction, or maybe we can actually do something a little different, which is compute a derivative. Compute a derivative, which is this equation over here.
Vậy có thể ta chỉ cần nhìn một hướng, hoặc có thể làm điều gì đó hơi khác, đó là tính đạo hàm. Tính đạo hàm, chính là phương trình ở đây.
What is this doing? It's saying we are at w0.
Nó đang làm gì? Nó nói rằng ta đang ở w0.
And we're taking the limit of — taking a step to the right, to the left, looking at the difference, and dividing by how far we stepped. So this is computing the slope.
Và ta lấy giới hạn của việc bước một bước sang phải, sang trái, xét hiệu giá trị, rồi chia cho độ dài bước. Vậy đây là tính độ dốc.
So it's the linear approximation to the function right here that we're getting. That's what the derivative is doing. You probably covered derivatives a long time ago.
Tức là ta có xấp xỉ tuyến tính của hàm ngay tại điểm này. Đó là việc đạo hàm làm. Có lẽ các bạn đã học đạo hàm từ lâu rồi.
Maybe you've seen them again since. The intuition that matters the most for this lecture is that it's computing a linear approximation to your function locally.
Có thể sau đó bạn cũng đã gặp lại. Trực giác quan trọng nhất cho bài giảng này là nó tính một xấp xỉ tuyến tính của hàm tại địa phương.
And it turns out that it typically is not — we'll see more about this later — it's not that hard to compute a derivative.
Và thường thì việc này không, sau này ta sẽ nói thêm, không khó để tính đạo hàm.
There are rulebooks for that that tell you, if this is your function, this is your derivative. So you can just kind of use that rulebook and say, OK, this is my derivative.
Có sẵn các bảng quy tắc cho biết nếu hàm của bạn là thế này, thì đạo hàm là thế này. Bạn cứ dùng bảng quy tắc đó và nói, được, đây là đạo hàm của tôi.
Let's say you do this for this function. Then you could say, well, it's sloping up to the right. So I'm going to make a step to the right.
Giả sử bạn làm vậy với hàm này. Bạn sẽ thấy nó dốc lên về bên phải. Nên tôi sẽ bước sang phải.
And you would make your step to the right. Maybe now you're here, then here. Again, you compute the derivative. You see it's sloping up to the right.
Và bạn bước sang phải. Giờ có thể bạn ở đây, rồi đến đây. Lại tính đạo hàm. Bạn thấy nó dốc lên về bên phải.
You do another step. Now you're here. Compute the derivative. Again, it's sloping up to the right.
Bạn bước thêm một bước. Giờ bạn ở đây. Tính đạo hàm. Lại dốc lên về bên phải.
Oops. I'm not here yet. You take another step. Now you're here.
Ối. Tôi chưa tới đây. Bạn bước thêm một bước. Giờ bạn ở đây.
It's starting to flatten out a little bit. You'll take another step. And then if you land at the top, you'll see that the derivative is 0.
Nó bắt đầu phẳng dần ra. Bạn bước thêm một bước nữa. Và nếu bạn đáp xuống đỉnh, bạn sẽ thấy đạo hàm bằng 0.
It's a flat fit, which means in no direction can you improve. And you might call it done.
Nó phẳng, nghĩa là không hướng nào cải thiện được nữa. Và bạn có thể coi là xong.
So that would be doing a kind of procedure that will generalize to what we're going to do in higher dimensions. At every point we compute the linear approximation.
Vậy đây là một quy trình sẽ khái quát hóa cho những gì ta sẽ làm trong không gian nhiều chiều hơn. Tại mỗi điểm ta tính xấp xỉ tuyến tính.
And we just trust the linear approximation to tell us in which direction to step. We take a step, and then we repeat this process.
Và ta tin vào xấp xỉ tuyến tính đó để biết nên bước theo hướng nào. Ta bước một bước, rồi lặp lại quy trình này.
And notice that this would not be possible if your variables were discrete.
Và lưu ý rằng điều này sẽ không thể làm được nếu các biến là rời rạc.
If you have discrete variables that take on the values red, green, blue, there's no way to take a derivative against red, green, blue the way you can with continuous variables.
Nếu bạn có biến rời rạc nhận các giá trị đỏ, xanh lá, xanh dương, thì không có cách nào lấy đạo hàm theo đỏ, xanh lá, xanh dương như ta làm với biến liên tục.
So it should start to become clear that the fact that this is a continuous space actually helps a lot in doing this kind of optimization. Any questions about this?
Nên bắt đầu rõ rằng không gian liên tục này thực sự giúp ích rất nhiều cho kiểu tối ưu hóa này. Có câu hỏi nào về phần này không?
Yes.
Vâng.
STUDENT
Do you have a particular reason [INAUDIBLE]??
Thầy có lý do cụ thể nào cho [KHÔNG NGHE RÕ]?
PROFESSOR
Say it again.
Em nhắc lại nhé.
STUDENT
[INAUDIBLE] PROFESSOR: So there are different definitions of derivatives. The question is, does it matter how we define it here? Not really.
[KHÔNG NGHE RÕ] GIÁO SƯ: Có nhiều định nghĩa khác nhau về đạo hàm. Câu hỏi là, cách ta định nghĩa ở đây có quan trọng không? Không hẳn.
If you prefer a right derivative or a left derivative or a symmetric clock, as shown here, it doesn't matter too much. Symmetric maybe makes the most sense. It's kind of cleanest.
Nếu bạn thích đạo hàm phải hay đạo hàm trái hay dạng đối xứng như ở đây, thì cũng không quá quan trọng. Đối xứng có lẽ hợp lý nhất. Nó gọn gàng nhất.
But don't worry about those differences.
Nhưng đừng bận tâm về những khác biệt đó.
What's key is that the derivative is something that is a local approximation, a local linear approximation, to your function that tells you in which direction is up, which direction is down.
Điều then chốt là đạo hàm là một xấp xỉ cục bộ, một xấp xỉ tuyến tính cục bộ của hàm, cho bạn biết hướng nào là lên, hướng nào là xuống.
And in fact, it also tells you whether it thinks you're going up quickly, or only gradually, or it's flattening out.
Và thực ra nó còn cho biết bạn đang đi lên nhanh, hay chỉ từ từ, hay đang phẳng dần.
OK. How about 2D version of this? And 2D will be the highest dimension that we're able to draw. But once we have 2D, hopefully the intuition will generalize to higher dimensions in your minds.
Được rồi. Còn phiên bản 2D của việc này thì sao? 2D sẽ là số chiều cao nhất mà ta vẽ được. Nhưng khi đã có 2D, hy vọng trực giác sẽ khái quát lên nhiều chiều hơn trong đầu các bạn.
One thing I want to point out here is when we have a 2D function we're optimizing, often the way we're going to visualize it is by looking at contour maps drawn underneath here.
Một điều tôi muốn chỉ ra ở đây là khi tối ưu một hàm 2D, cách ta thường trực quan hóa nó là nhìn bản đồ đường mức vẽ bên dưới đây.
So if you look at those, these are concentric circles shown at the bottom underneath this hill shape. They're showing height contours. On a given line, the value of the function is the same.
Nếu nhìn vào đó, đây là các vòng tròn đồng tâm ở phía dưới hình quả đồi này. Chúng biểu diễn các đường đồng mức độ cao. Trên một đường cho trước, giá trị của hàm là như nhau.
And in fact, the more you go to the middle, the higher the value of the function. And the more you go to the outside, the lower the value of the function.
Và thực tế, càng vào giữa thì giá trị của hàm càng cao. Còn càng ra ngoài thì giá trị của hàm càng thấp.
And often we won't even draw the thing on top. We'll just show those contours. And that should tell you something about where the good parts are.
Và thường ta còn không vẽ phần hình phía trên. Ta chỉ vẽ các đường đồng mức đó. Và chúng sẽ cho bạn biết điều gì đó về nơi nào là vùng tốt.
If I could look at those contours, somewhere underneath here in the middle should be the right spot, because that's where things get higher, higher, higher.
Nếu nhìn vào các đường đồng mức này, thì đâu đó bên dưới, ở giữa đây, phải là điểm tốt nhất, vì ở đó giá trị cứ cao dần, cao dần lên.
The procedure we'll use is a generalization of what we just did for one dimension, gradient ascent. Now, if you read a bunch of literature, you'll see gradients appear.
Thủ tục ta dùng là tổng quát hóa của việc vừa làm với một chiều: gradient ascent. Nếu đọc nhiều tài liệu, bạn sẽ thấy gradient xuất hiện.
Often, you'll see something appear called — instead of ascent, people will have gradient descent.
Thường bạn sẽ thấy một thuật ngữ là — thay vì ascent, người ta dùng gradient descent.
That's if you want to find the bottom of a function. You descend if you want to find the bottom. You ascend if you want to find the top.
Đó là khi bạn muốn tìm đáy của hàm. Muốn tìm đáy thì đi xuống. Muốn tìm đỉnh thì đi lên.
We're going to try to find the top. So for us, it's gradient ascent. But if you see gradient descent, it's essentially the same kind of idea.
Ta sẽ tìm đỉnh. Nên với ta, đó là gradient ascent. Nhưng nếu bạn thấy gradient descent thì về cơ bản là cùng một ý tưởng.
It's just applied in reverse to go to the bottom, rather than going to the top.
Chỉ là áp dụng ngược lại để đi xuống đáy, thay vì đi lên đỉnh.
In many ways they're equivalent. It's just a choice whether you're maximizing or minimizing the objective you care about.
Về nhiều mặt chúng tương đương nhau. Chỉ là chọn cực đại hóa hay cực tiểu hóa mục tiêu mà bạn quan tâm.
So we want to perform an update in the uphill direction for each coordinate, because we have multiple coordinates now.
Ta muốn cập nhật theo hướng đi lên cho từng tọa độ, vì giờ ta có nhiều tọa độ.
The steeper the slope, so the higher the derivative along a coordinate, the bigger the step we're going to take for that coordinate. That's a choice. That's just the way this is set up.
Độ dốc càng lớn, tức đạo hàm theo một tọa độ càng cao, thì bước ta đi càng lớn theo tọa độ đó. Đó là một lựa chọn. Chỉ là cách thiết lập như vậy.
But some intuition as to why this might make sense, it's very steep uphill in a direction. That's a very promising direction.
Nhưng trực giác vì sao điều này hợp lý: nếu một hướng dốc lên rất mạnh, đó là hướng rất hứa hẹn.
You might want to put a lot of effort in going in that direction, whereas in some other direction, things that really, really flat.
Bạn nên dồn nhiều công sức để đi theo hướng đó, còn hướng khác mà mọi thứ rất phẳng thì sao?
Well, why would you spend a lot of time in that direction? It seems like there's not much action in that direction.
Sao phải tốn nhiều thời gian theo hướng đó? Có vẻ hướng đó chẳng có gì đáng kể.
That's the intuition underneath here, but we'll see a little more formal intuition later. So consider a function with two variables, w1, w2.
Đó là trực giác ở đây, nhưng lát nữa ta sẽ có trực giác chặt chẽ hơn. Xét hàm hai biến w1, w2.
And we'll do updates that are just of the form that we saw in the previous slide, effectively. We'll say I'm updating my first entry, w1, by whatever it was before.
Ta cập nhật theo đúng dạng như trên slide trước. Ta cập nhật thành phần đầu tiên, w1, bằng giá trị trước đó.
I'm keeping that plus a small change. There will be a learning rate again, like we saw in Q-learning. And this thing here is the derivative with respect to w1.
Giữ nguyên nó cộng thêm một thay đổi nhỏ. Lại có một learning rate, như trong Q-learning. Và đây là đạo hàm theo w1.
So it's when you are on this landscape here. Let's say this is w1. And you're at some point over here.
Tức là khi bạn đứng trên địa hình này. Giả sử đây là w1. Và bạn ở một điểm bên này.
You would say, well, let's see what happens as I move in the w1 direction, which would be effectively along this curve here.
Bạn sẽ xem thử điều gì xảy ra khi di chuyển theo hướng w1, tức đi dọc theo đường cong này.
Keep moving in w1 direction. You move along that curve. You measure the slope along that curve.
Cứ đi theo hướng w1. Bạn đi dọc đường cong đó. Bạn đo độ dốc dọc đường cong đó.
And that tells you whether you should move to a higher w1 or a lower w1, depending on whether it's an upslope or a downslope aligned with w1. And then you take that step.
Và nó cho biết bạn nên tăng hay giảm w1, tùy đó là dốc lên hay dốc xuống theo hướng w1. Rồi bạn bước một bước.
The same thing for w2. So going back to the picture, we're still here. Let's assume this is w2.
w2 cũng tương tự. Quay lại hình, ta vẫn ở đây. Giả sử đây là w2.
We will then consider walking along this curve, but we're not considering the entire curve, of course.
Ta sẽ xét đi dọc đường cong này, nhưng tất nhiên không xét cả đường cong.
We're just looking at the local derivative over here to see what the slope is along the w2 direction. And that will inform us whether we want to increase or decrease w2.
Ta chỉ nhìn đạo hàm cục bộ ở đây để biết độ dốc theo hướng w2. Và nó cho ta biết nên tăng hay giảm w2.
And then let's think about this. Let's say the derivatives are all positive, meaning if we move in a positive direction for w1, things go uphill. Then indeed we increase w1.
Giờ hãy nghĩ thế này. Giả sử các đạo hàm đều dương, nghĩa là nếu đi theo chiều dương của w1, ta đi lên dốc. Thì đúng là ta tăng w1.
The same for w2. If we move in a positive direction for w1 and that happens to bring us downhill, that means the derivative is negative.
w2 cũng vậy. Nếu đi theo chiều dương của w1 mà lại đi xuống dốc, nghĩa là đạo hàm âm.
Then that negative derivative here will ensure that we move in the negative direction for w1.
Thì đạo hàm âm ở đây sẽ đảm bảo ta đi theo chiều âm của w1.
Let's do this in vector notation. So we have a weight vector w. We update it by some learning rate times this thing over here. This might be new notation to you.
Giờ viết theo ký hiệu vectơ. Ta có vectơ trọng số w. Ta cập nhật nó bằng learning rate nhân với đại lượng này. Có thể ký hiệu này mới với bạn.
What does that mean? It means it is a vector with entries of the vector corresponding to derivatives. In this case, it's a two dimensional function.
Nó nghĩa là gì? Đó là một vectơ mà các phần tử tương ứng với các đạo hàm. Ở đây là hàm hai chiều.
So we have a derivative with respect to the first variable and a derivative with respect to the second variable inside this vector.
Nên trong vectơ này có đạo hàm theo biến thứ nhất và đạo hàm theo biến thứ hai. bên trong vectơ này.
But keep in mind this thing here is nothing more than a shorthand for saying, I'm going to build a vector with all the partial derivatives. And this thing is called the gradient.
Nhưng nhớ rằng đây chẳng qua chỉ là cách viết tắt của việc nói: ta xây một vectơ gồm tất cả các đạo hàm riêng. Và đại lượng này gọi là gradient.
So when we say gradient ascent, what it means is we compute the gradient, which is a vector with all the coordinate-wise derivatives. And then we take a step in the direction of that gradient.
Vậy khi nói gradient ascent, nghĩa là ta tính gradient, tức vectơ chứa đạo hàm theo từng tọa độ. Rồi ta bước một bước theo hướng của gradient đó.
And based on the reasoning we did here, we know that taking a step in the direction of the gradient moves us uphill, because if for a certain coordinate the entry is positive, that means we'll move in the positive direction for that coordinate.
Và dựa trên lập luận vừa rồi, ta biết bước theo hướng gradient sẽ đưa ta đi lên, vì nếu với một tọa độ nào đó phần tử dương, nghĩa là ta sẽ đi theo chiều dương của tọa độ đó.
And that's the right direction. And if for a certain coordinate the entry is negative, it means we'll move in the negative direction for that coordinate. And that's also the right direction for that coordinate.
Và đó là hướng đúng. Còn nếu với một tọa độ nào đó phần tử âm, nghĩa là ta sẽ đi theo chiều âm của tọa độ đó. Và đó cũng là hướng đúng cho tọa độ đó.
So pictorially looking from the top, we have some contours here. The highest scoring point is in the middle there. If we run gradient ascent, then we start here.
Hình dung nhìn từ trên xuống, ta có các đường đồng mức ở đây. Điểm có điểm số cao nhất ở giữa kia. Nếu chạy gradient ascent, ta bắt đầu từ đây.
We'll take a step, and up over. Another step, and up over here, here, here, and so forth. These steps happen to become smaller.
Ta bước một bước, lên đến đây. Một bước nữa, lên đây, đây, đây, và cứ thế. Các bước này nhỏ dần.
There could be two reasons when you see a picture like this that the steps are becoming smaller. One reason could be that you're learning rate was decaying. And so that makes your step smaller.
Có thể có hai lý do khi bạn như thế này, các bước đi nhỏ dần. Một lý do có thể là learning rate đang giảm dần. Và điều đó làm bước đi nhỏ lại.
And that's often going to be the case. Another reason could be things are flattening out. And as things flatten out, well, your derivatives are smaller.
Và thường thì đó chính là trường hợp xảy ra. Lý do khác là hàm đang phẳng dần. Khi hàm phẳng dần thì đạo hàm nhỏ đi.
And so the steps that you compute based on those derivatives are smaller steps.
Và do đó các bước mà ta tính dựa trên những đạo hàm đó cũng nhỏ hơn.
Now, let's ask a question. We've seen the procedure. What is the steepest direction?
Bây giờ, ta hãy đặt một câu hỏi. Ta đã thấy quy trình này. Hướng dốc nhất là hướng nào?
And I put this at the bottom here just to make sure we keep the notation in mind, which might be new to you. Your hill climbing. You're in the fog.
Tôi để cái này ở dưới đây chỉ để các bạn nhớ ký hiệu, có thể còn mới với các bạn. Bạn đang leo đồi. Bạn đang ở trong sương mù.
You're on a mountain.
Bạn đang ở trên một ngọn núi.
And you're saying, well, it's good to measure in each coordinate direction what the derivative is, and then maybe step in that direction or opposite direction based on that, but I'd rather follow the steepest direction uphill rather than doing this per coordinate thing.
Và bạn nói, đo đạo hàm theo từng hướng tọa độ là tốt, rồi có thể bước theo hướng đó hoặc ngược lại dựa trên nó, nhưng tôi muốn đi theo hướng dốc nhất lên đồi hơn là làm theo từng tọa độ như vậy. Tôi có tìm được hướng dốc nhất không?
Can I find the steepest direction? Because that might lead me along the shortest path to get to the top of the hill rather than all these credit-wise calculations.
Vì có thể nó dẫn tôi theo đường ngắn nhất lên đỉnh đồi, thay vì tất cả những phép tính theo từng tọa độ này. Ta có thể thử tính xem.
Well, we can try to compute that. We're going to be at some point w right now, which is some coordinates that we're at. And we're considering changing our coordinates.
Giả sử hiện giờ ta đang ở điểm w nào đó, tức là một bộ tọa độ nào đó. Và ta đang xét việc thay đổi tọa độ. Và ta chỉ được thay đổi tọa độ một chút.
And we're only allowed to change our coordinates a little bit. What is this thing here? Delta 1 squared plus delta 2 squared. That is the amount that we move.
Đây là cái gì? Delta 1 bình phương cộng delta 2 bình phương. Đó là quãng ta di chuyển.
Remember, if you have, say, delta 1 on this axis, delta 2 on this axis, you have a point over here.
Nhớ rằng, nếu delta 1 trên trục này, delta 2 trên trục này, bạn có một điểm ở đây.
This distance over here is the square root of delta 1 squared plus delta 2 squared. So how far we move is the sum of the square, the square root of that.
Khoảng cách này là căn bậc hai của delta 1 bình phương cộng delta 2 bình phương. Vậy ta di chuyển xa bao nhiêu là tổng bình phương, lấy căn bậc hai. Như vậy ta giới hạn quãng được phép di chuyển.
So we're limiting how far we're allowed to move. What this is defining is effectively a circular region around where we're currently at. And we're only allowed to move within that circle.
Điều này thực chất xác định một vùng hình tròn quanh vị trí hiện tại. Và ta chỉ được di chuyển trong hình tròn đó.
Now, I'm going to say, we're asking the question here, which move is going to increase our objective the most as long as we're required to stay within that circle?
Bây giờ, ta hỏi rằng bước nào làm hàm mục tiêu tăng nhiều nhất khi bắt buộc phải ở trong hình tròn đó?
And if that circle is really, really small, then effectively what we're finding based on that is the direction in which the slope is the steepest, because we can make only a very small change.
Và nếu hình tròn đó rất, rất nhỏ, thì thực chất ta tìm được hướng có độ dốc lớn nhất, vì ta chỉ thay đổi được rất ít. Và nó phải có tác động lớn nhất.
And it has to have maximal effect. We've got to take the steepest direction.
Ta phải đi theo hướng dốc nhất.
Also, if we're only making a very small change, we can approximate our possibly very complex function with a linear approximation. Assuming it's a smooth function, we can have a linear approximation locally.
Ngoài ra, nếu chỉ thay đổi rất ít, ta có thể xấp xỉ hàm có thể rất phức tạp bằng một xấp xỉ tuyến tính. Giả sử hàm trơn, ta có thể có xấp xỉ tuyến tính cục bộ.
So our original function gw, g evaluated at w plus delta is equal to g at w plus these two terms, which correspond to the linear approximation locally to the function.
Vậy hàm ban đầu g(w), tức g tại w cộng delta, bằng g tại w cộng hai số hạng này, tương ứng với xấp xỉ tuyến tính cục bộ của hàm. Và để ý đây lại là các đạo hàm.
And notice that these are derivatives again.
It's how much does the function change when I changed w1 times delta 1, which is how much we changed w1, plus how much does the function change when we change w2 times delta 2, which is how much we are changing w2.
Đó là hàm thay đổi bao nhiêu khi tôi đổi w1, nhân delta 1, là lượng ta đổi w1, cộng với hàm thay đổi bao nhiêu khi ta đổi w2, nhân delta 2, là lượng ta đổi w2.
We're looking for the delta that has the most effect here while keeping delta small, because we can't move very far. Notice this guy does not have a delta.
Ta tìm delta có tác động lớn nhất mà vẫn giữ delta nhỏ, vì ta không thể đi xa. Để ý số hạng này không có delta. Nên nó không ảnh hưởng đến phép tính.
So it will not affect our calculations. So I actually want to find the steepest ascent direction, not descent.
Tôi muốn tìm hướng tăng dốc nhất, chứ không phải hướng giảm.
So we want to maximize over delta s, where we stay within a small epsilon circle, this linearized approximation over there.
Vậy ta muốn cực đại hóa theo delta, trong đó ta ở trong một hình tròn epsilon nhỏ, xấp xỉ tuyến tính hóa này.
Remember, if we have two vectors — let's say we have a vector a here, and now we have another choice of vector delta, which could be maybe here, or maybe we put delta here, or maybe we put it here.
Nhớ rằng, nếu có hai vectơ — giả sử có vectơ a ở đây, và ta có một lựa chọn vectơ delta khác, có thể ở đây, hoặc đặt delta ở đây, hoặc đặt ở đây.
But if delta has to stay within a circle, the way we can make the inner product the highest between delta and a is by making delta completely aligned with a.
Nhưng nếu delta phải ở trong một hình tròn, cách để tích vô hướng giữa delta và a lớn nhất là cho delta cùng hướng hoàn toàn với a. Nên ta chọn delta hướng theo đây.
So we should pick delta pointing this way. And of course, can't leave the circle. But this is our optimal choice of delta right there to maximize this inner product.
Và tất nhiên, không được ra khỏi hình tròn. Nhưng đây là lựa chọn delta tối ưu để cực đại tích vô hướng này. Đây là a1.
This here is our a1. This is a2. And a transpose delta is a1 delta 1 plus a2 delta 2.
Đây là a2. Và a chuyển vị nhân delta là a1 delta 1 cộng a2 delta 2. Vậy ta thấy phải chọn một delta có dạng này để cực đại hàm mục tiêu.
So what we see is we have to somehow choose a delta that is of this form factor to maximize the objective. What are these a1 and a2? They're actually entries in the gradient.
a1 và a2 là gì? Chúng thực ra là các phần tử của gradient. Thật vậy, a bằng cái này ở đây.
In fact, our a is equal to this guy over here.
And so what we find is that we should point epsilon — point delta in the direction of the gradient, and it can be epsilon long.
Và ta thấy rằng nên hướng epsilon — hướng delta theo hướng của gradient, và độ dài là epsilon. Vậy nghiệm sẽ là cái này ở đây.
So the solution will be this over here. It's a normalized vector, the gradient over the norm of the gradient. So this thing here is normalized.
Đó là một vectơ chuẩn hóa, gradient chia cho chuẩn của gradient. Vậy cái này đã được chuẩn hóa.
It has norm 1 scaled by epsilon, because we cannot move more than epsilon. Which direction is it pointing in? Well, the direction of the gradient. What does that mean?
Nó có chuẩn 1, nhân với epsilon, vì ta không thể đi xa hơn epsilon. Nó hướng theo hướng nào? Hướng của gradient. Điều đó có nghĩa là gì?
The update we did on the previous slide where we said we move in direction one based on the derivative along direction one and move in direction two based on the derivative along direction two is actually giving us the optimal local improvement direction.
Cách cập nhật ở slide trước là ta đi theo hướng một dựa trên đạo hàm theo hướng một và đi theo hướng hai dựa trên đạo hàm theo hướng hai, thực ra cho ta hướng cải thiện cục bộ tối ưu.
So even though we were thinking about it with coordinates and we said, "Well, let's look at this coordinate.
Vậy dù ta đã nghĩ về nó theo từng tọa độ vậy và ta nói: "Hãy xét tọa độ này.
Let's look at that coordinate," the way we happened to scale the steps along each coordinate — namely, we scaled them by the derivatives — gives us the direction of that steepest uphill.
Rồi xét tọa độ kia." Cách ta co giãn các bước dọc theo mỗi tọa độ, cụ thể là co giãn chúng theo các đạo hàm, chính là cho ta hướng dốc lên nhanh nhất.
So we were already doing the right thing to go in the steepest direction.
Vậy là ta đã làm đúng rồi khi đi theo hướng dốc nhất.
So that's great. We have this optimization problem. We want to find a good w. We can compute a vector of derivatives.
Tuyệt vời. Ta có bài toán tối ưu hóa này. Ta muốn tìm w tốt. Ta tính được một vectơ các đạo hàm.
That vector of derivatives tells us which direction to step. We step, and we repeat. And over time we climb the hill until we find, hopefully, some good local optimum.
Vectơ đạo hàm đó cho biết nên bước theo hướng nào. Ta bước, rồi lặp lại. Dần dần ta leo đồi cho đến khi tìm được, hy vọng là, một cực trị địa phương tốt.
We've seen it in two dimensions. In more dimensions, it's essentially the same. The gradient vector will now have more entries. In n dimensions, it will have n entries.
Ta đã thấy điều này trong hai chiều. Nhiều chiều hơn thì về cơ bản cũng vậy. Vectơ gradient giờ sẽ có nhiều phần tử hơn. Trong n chiều, nó có n phần tử.
But other than that, procedurally, it's the same. You compute a derivative with respect to w1. With respect to w2 all the way till wn. Those are all derivatives with respect to just one variable.
Ngoài ra, về thủ tục thì giống hệt. Bạn tính đạo hàm theo w1. Theo w2, cho đến wn. Đó đều là đạo hàm theo đúng một biến.
If you know how to take a derivative of a function, stick to one variable, you know how to do this.
Nếu bạn biết lấy đạo hàm của một hàm theo một biến, thì bạn biết làm việc này.
You have to just do it many times, because there's n variables to do it for. You build your vector, take a step in that direction, and repeat. So this is the procedure.
Chỉ cần làm nhiều lần, vì có n biến cần tính. Bạn dựng vectơ, bước theo hướng đó, rồi lặp lại. Đó là thủ tục.
We initialize maybe randomly, and then we iterate. We compute the gradient at the current position that we're at, w, take a step in that direction, and we keep repeating.
Ta khởi tạo có thể ngẫu nhiên, rồi lặp. Ta tính gradient tại vị trí hiện tại, w, bước theo hướng đó, và cứ thế lặp lại.
And the closer we get to an optimum, then the lower the gradient entries will become, because things will start to flatten out.
Càng gần cực trị, các phần tử gradient càng nhỏ đi, vì mọi thứ bắt đầu phẳng dần.
And this will start moving around less and less and less, and hopefully converge.
Và w sẽ di chuyển ngày càng ít, hy vọng là hội tụ.
You might wonder about also the learning rate. It is a tweaking parameter. You might have to play with that a little bit to make it work.
Bạn cũng có thể thắc mắc về learning rate. Đó là một tham số cần tinh chỉnh. Bạn có thể phải thử một chút để nó chạy được.
What would be a rule of thumb when you're, let's say, optimizing a new function. You're like, OK, what should my alpha really be?
Quy tắc ngón tay cái là gì khi, giả sử, bạn tối ưu một hàm mới. Bạn tự hỏi alpha nên là bao nhiêu?
Because if you think about it, if you think of your function g of w, and somebody else gives you a new function that is 10 to the 6 times g of w, you're solving the same problem in many ways.
Vì nếu nghĩ kỹ, bạn có hàm g của w, và ai đó đưa bạn hàm mới bằng 10 mũ 6 lần g của w, thì về nhiều mặt vẫn là cùng một bài toán.
But if the function is 10 to the 6 times g of w, your gradients will all be scaled up by a 10 to the 6.
Nhưng nếu hàm là 10 mũ 6 lần g của w, mọi gradient sẽ bị nhân lên 10 mũ 6.
And your steps will be a million times bigger, even though we're effectively trying to solve the same problem.
Và các bước sẽ lớn gấp một triệu lần, dù thực chất ta đang cố giải cùng một bài toán.
So you can't just have a general learning rate that will work all the time, because somebody could come in and just rescale your function. That learning rate will not work anymore for you.
Nên không thể có một learning rate chung luôn dùng được, vì ai đó có thể co giãn lại hàm của bạn. Khi đó learning rate ấy không còn dùng được nữa.
So how do you get this to work out? It's by looking into the w space. So you might say, ah, let's compute a gradient update. Let's see.
Vậy làm sao để nó hoạt động? Bằng cách nhìn vào không gian w. Bạn có thể nói: tính một bước cập nhật gradient. Xem nào.
OK. How do I rescale this gradient vector such that my updated w changes w about 0.1% to 1%?
Được. Làm sao co giãn vectơ gradient này để w mới thay đổi w khoảng 0,1% đến 1%?
If it does that, then it's reasonably sized, and I'll repeat this, repeat this, repeat this, and over time get to a good point.
Nếu vậy thì kích thước hợp lý, và tôi lặp đi lặp lại, dần dần đến một điểm tốt.
If you do this to decide on your alpha, somebody can rescale your function by a billion, a trillion. And it will not affect what you do with your w.
Nếu chọn alpha theo cách này, ai đó có thể co giãn hàm lên một tỷ, một nghìn tỷ lần. Và nó không ảnh hưởng gì đến w của bạn.
It will all be the same update, because you'll measure the size of your update based on what happens in w space, not in however somebody might have rescaled your function.
Cập nhật vẫn y nguyên, vì bạn đo kích thước bước cập nhật dựa trên không gian w, chứ không phải việc người khác co giãn hàm của bạn thế nào.
So now we know how to optimize. In fact, we've covered something much more general than maximizing likelihoods.
Vậy là ta biết cách tối ưu hóa. Thực ra ta đã học điều tổng quát hơn nhiều so với cực đại hóa likelihood.
We've covered the notion that if you have a function g that depends on some variables that are continuous variables, how you can start from a random point and from there improve, improve, improve to land at the better point for that square that you have.
Ta đã học rằng nếu có hàm g phụ thuộc vào các biến liên tục, thì có thể bắt đầu từ một điểm ngẫu nhiên rồi cải thiện dần, cải thiện dần để đến điểm tốt hơn cho hàm của bạn.
Let's go back to learning. We want to maximize the log likelihood of the data. In this case, labels given the inputs. OK.
Quay lại với việc học. Ta muốn cực đại hóa log likelihood của dữ liệu. Ở đây là các nhãn khi biết đầu vào. Được.
Same thing. We can write out the gradient descent procedure. Our g is now the sum over all data points of the log probability of label given input under the current w.
Vẫn vậy thôi. Ta có thể viết ra thủ tục gradient descent. g giờ là tổng trên mọi điểm dữ liệu của log xác suất của nhãn khi biết đầu vào, với w hiện tại.
Other than that, nothing has changed. Now, the gradient of a sum is the sum of the gradients. So actually, that's rewritten this way over here.
Ngoài ra không có gì thay đổi. Gradient của một tổng bằng tổng các gradient. Nên ở đây nó được viết lại như thế này.
That's our general procedure. Now, if you look at this, you might say, well, it looks like we do a bunch of updates, some together, to update w.
Đó là thủ tục chung của ta. Nhìn vào đây, bạn có thể nghĩ, có vẻ ta làm một loạt cập nhật, gộp lại để cập nhật w.
So I have to go through all my data and compute these gradients, and then I do an update. But what if I just computed one gradient on one data point?
Tôi phải duyệt hết dữ liệu và tính các gradient này, rồi mới cập nhật. Nhưng nếu chỉ tính một gradient trên một điểm dữ liệu thì sao?
Wouldn't I already have some information that I can use to improve w right away and only then go look at the next data point, then go look at the next one?
Chẳng phải tôi đã có chút thông tin để cải thiện w ngay lập tức, rồi mới xem điểm dữ liệu tiếp theo, rồi điểm tiếp theo nữa sao?
So I don't have to, let's say, if I have a million data points do a million calculations of gradients before I can do a change to w. In fact, you'd be right.
Vậy tôi không cần, giả sử có một triệu điểm dữ liệu, tính một triệu gradient rồi mới đổi w. Thực ra bạn nói đúng.
You can do that. That would be called stochastic gradient descent. What you do there, once you compute a gradient, you right away incorporate it.
Bạn có thể làm vậy. Đó gọi là stochastic gradient descent. Ở đó, khi tính xong một gradient, bạn cập nhật nó ngay.
And the upside here is that when you compute the next gradient, you're computing it at a better point on expectation than where you would have computed it otherwise.
Lợi ích là khi tính gradient kế tiếp, bạn tính tại một điểm tốt hơn, theo kỳ vọng, so với điểm bạn sẽ tính nếu không làm vậy.
So you don't waste your time computing a million gradients at the same point. Those last gradients are already computed at a way, way better point than you started from.
Nên bạn không phí thời gian tính một triệu gradient tại cùng một điểm. Những gradient cuối này đã được tính tại một điểm tốt hơn rất nhiều so với điểm ban đầu.
So what does that look like? You still have a kind of infinite loop here till you decide you're happy.
Vậy nó trông như thế nào? Bạn vẫn có một vòng lặp vô hạn ở đây cho đến khi bạn hài lòng.
You pick now a random data point, and just compute the gradient for that data point of the conditional log probability of label given input. Do an update.
Bây giờ bạn chọn một điểm dữ liệu ngẫu nhiên, và chỉ tính gradient cho điểm dữ liệu đó của log xác suất có điều kiện của nhãn khi biết đầu vào. Cập nhật một lần.
You repeat. Now, you might say, well, that means I compute this gradient. And I'm waiting there before I can compute my next gradient.
Rồi lặp lại. Bạn có thể nói, vậy tức là tôi tính gradient này. Và tôi phải chờ ở đó trước khi tính gradient tiếp theo.
But maybe you're computing on a computer that has a lot of parallel compute power. Maybe your GPU can feed through many things in one go in which you do effectively the same calculation.
Nhưng có thể bạn đang tính trên một máy tính có nhiều khả năng tính toán song song. Có thể GPU của bạn có thể xử lý nhiều thứ cùng một lúc, trong đó về cơ bản bạn làm cùng một phép tính.
Then you'd be waiting and not utilizing that. So actually what people mostly use in practice is something in between the two versions we just saw. We first saw batch gradient descent.
Vậy bạn sẽ phải chờ và không tận dụng được điều đó. Nên thực ra thứ mà người ta hay dùng nhất trong thực tế là một cách nằm giữa hai phiên bản vừa rồi. Đầu tiên ta thấy batch gradient descent.
We just look at all your data. Sum the gradient together. Take a step. Then we look at stochastic gradient descent, where we look at one sample, do an update, another sample, do an update.
Ta nhìn toàn bộ dữ liệu. Cộng các gradient lại. Đi một bước. Sau đó ta thấy stochastic gradient descent, nhìn một mẫu, cập nhật, rồi mẫu khác, lại cập nhật.
And in some sense that's optimal, except that if you have parallel compute, you're not utilizing it. If you have parallel compute, you'd say, well, let's take a batch of things.
Và theo một nghĩa nào đó thì đó là tối ưu, trừ việc nếu bạn có tính toán song song, bạn không tận dụng nó. Nếu có tính toán song song, bạn sẽ nói, vậy hãy lấy một lô dữ liệu.
So instead of taking one, I take a batch of examples. Let's call that batch j.
Thay vì lấy một mẫu, tôi lấy một lô các mẫu. Gọi lô đó là j.
And then I sum together the gradients for each data point in that batch, which I can do all in parallel, those gradients.
Rồi tôi cộng các gradient của từng điểm dữ liệu trong lô đó, và có thể tính tất cả song song, các gradient đó.
Then I just reduce, sum it altogether, and do an update based on that.
Sau đó tôi gộp lại, cộng tất cả, và cập nhật dựa trên đó.
So that way, if you think about wall clock time, you're not wasting wall clock time waiting for one to be done and then be able to do the next one.
Như vậy, nếu nghĩ về thời gian thực tế, bạn không lãng phí thời gian thực tế để chờ một mẫu xong rồi mới làm được mẫu tiếp theo.
You can keep running and utilize your GPU kind of to maximum cycles it provides you. And so typically, if you ask, how big should this batch be?
Bạn có thể chạy liên tục và tận dụng GPU ở mức tối đa số chu kỳ mà nó cung cấp. Và nếu hỏi lô này nên lớn cỡ nào?
Typically, the batch will be determined by how much you can compute in parallel. If you can feed 100 examples in parallel, you might feed 100 through.
Thường thì kích thước lô được quyết định bởi việc bạn tính song song được bao nhiêu. Nếu bạn đưa được 100 mẫu song song, bạn sẽ đưa 100 mẫu vào.
If you can compute gradients on 1,000 in parallel, you'll feed 1,000 through. If you can feed a million in parallel, sure, a million go through.
Nếu tính được gradient cho 1.000 mẫu song song, bạn sẽ đưa 1.000 mẫu vào. Nếu đưa được một triệu song song, thì được thôi, một triệu mẫu đi qua.
Whatever you can feed through in parallel is what you would feed through to optimize your wall clock time when you do this.
Bất cứ lượng nào bạn đưa qua được song song là lượng bạn sẽ dùng để tối ưu thời gian thực tế khi làm việc này.
And this one is called mini batch gradient descent, where a mini batch refers to the fact that batch means everything, your entire training data.
Cách này gọi là mini batch gradient descent, trong đó mini batch muốn nói rằng batch nghĩa là tất cả, toàn bộ dữ liệu huấn luyện.
Mini batch means that you take still a batch, but smaller than your entire batch of training data on which you do the gradient calculations to get your update.
Mini batch nghĩa là bạn vẫn lấy một lô, nhưng nhỏ hơn toàn bộ dữ liệu huấn luyện, để tính gradient nhằm có được bản cập nhật.
Any questions about this?
Có câu hỏi nào về phần này không?
How about computing all the derivatives? Because we've been assuming that we can just say, hey, give me a gradient, and then we just take a step in that direction.
Còn việc tính tất cả các đạo hàm thì sao? Vì ta vẫn giả định rằng ta chỉ cần nói, này, cho tôi một gradient, rồi ta đi một bước theo hướng đó.
We'll look at that later. So let's not worry about that for now. I'll revisit that at the end of lecture.
Ta sẽ xem phần đó sau. Giờ chưa cần lo về nó. Tôi sẽ quay lại phần đó vào cuối buổi.
So once we've seen also neural networks, which are a generalization of logistic regression, we'll beg the same question. OK.
Khi ta đã thấy mạng nơ-ron, vốn là sự tổng quát hóa của hồi quy logistic, ta sẽ lại đặt đúng câu hỏi đó. Được rồi.
Let's take a two-minute break here, and then let's generalize this all to neural networks.
Ta nghỉ hai phút ở đây, rồi sẽ tổng quát hóa tất cả sang mạng nơ-ron.
All right. Any questions about the first half?
Được rồi. Có câu hỏi nào về nửa đầu không?
Yes.
Vâng.
STUDENT
Can we use something like linear programming to solve for this?
Ta có thể dùng thứ như quy hoạch tuyến tính để giải bài này không ạ?
PROFESSOR
So the question is, can we use linear programming to solve this kind of problem? It's an interesting question. So we think about linear programming. What is linear programming?
Câu hỏi là liệu có thể dùng quy hoạch tuyến tính để giải loại bài toán này không. Đây là một câu hỏi thú vị. Hãy nghĩ về quy hoạch tuyến tính. Quy hoạch tuyến tính là gì?
Linear programming is a methodology to — well, if you think about it, it's a methodology, or a problem formulation.
Quy hoạch tuyến tính là một phương pháp... à, nếu nghĩ kỹ thì nó là một phương pháp, hay một cách phát biểu bài toán.
So linear programs are optimization objectives like we saw here, but where the objective has to be linear. So the function itself you're optimizing as linear.
Các chương trình tuyến tính là những mục tiêu tối ưu hóa như ta thấy ở đây, nhưng mục tiêu phải là tuyến tính. Tức là chính hàm mà bạn tối ưu là tuyến tính.
Now, the reason it still is interesting — because if it's just linear you just run to infinity, and that's where the highest number is — is that there are also constraints.
Lý do nó vẫn thú vị là vì nếu chỉ tuyến tính thì bạn cứ chạy ra vô cực, nơi có giá trị cao nhất, nhưng còn có các ràng buộc.
You have to stay in a certain region. And the boundaries of that region are also linearly defined. And so linear programs are optimization problems like this with an objective, but also have constraints.
Bạn phải ở trong một vùng nhất định. Và biên của vùng đó cũng được định nghĩa tuyến tính. Vì vậy các chương trình tuyến tính là bài toán tối ưu hóa như thế này, có mục tiêu, nhưng cũng có ràng buộc.
And the format that is available to you is very limited. The objective has to be linear, and the constraints have to be linear.
Và dạng bài mà bạn được phép dùng rất hạn chế. Mục tiêu phải tuyến tính, và các ràng buộc cũng phải tuyến tính.
If your objective is of that form and possibly you have constraints, then definitely you can use linear programming. No problem. But for many, many problems, the objective will not be linear.
Nếu mục tiêu của bạn có dạng đó và có thể có thêm ràng buộc, thì chắc chắn bạn có thể dùng quy hoạch tuyến tính. Không vấn đề gì. Nhưng với rất nhiều bài toán, mục tiêu sẽ không tuyến tính.
And if you have constraints, which we don't have here. But if you had constraints, they might not be linear, which might limit how much you can use the kind of off-the-shelf linear programming toolboxes.
Còn ràng buộc thì ở đây ta không có. Nhưng nếu có ràng buộc, chúng có thể không tuyến tính, điều này có thể hạn chế việc bạn dùng được các bộ công cụ quy hoạch tuyến tính có sẵn.
But if their assumptions apply, they're highly optimized to do a great job at solving those problems. If you look at what's underneath, some of them use very specialized ideas, like simplex.
Nhưng nếu các giả định của chúng thỏa mãn, chúng được tối ưu hóa rất cao để giải các bài toán đó rất tốt. Nếu nhìn vào bên trong, một số trong chúng dùng những ý tưởng rất chuyên biệt, như simplex.
Others use gradient-based methods underneath, too. And then it would come back to something very similar to this.
Một số khác bên dưới cũng dùng các phương pháp dựa trên gradient. Và khi đó nó quay lại một thứ rất giống cái này.
STUDENT
[INAUDIBLE] PROFESSOR: Yeah.
[KHÔNG NGHE RÕ] GIÁO SƯ: Vâng.
So interior point methods are ones that turn your linear program with constraints into an optimization problem where there's no constraints anymore, but the objective has changed from linear into something that rises to infinity at the boundaries.
Các phương pháp điểm trong (interior point) là những phương pháp biến bài toán quy hoạch tuyến tính có ràng buộc của bạn thành một bài toán tối ưu hóa không còn ràng buộc nào nữa, nhưng hàm mục tiêu đã đổi từ tuyến tính thành thứ tăng lên vô cùng tại các biên.
And then you're back. And you're minimizing in that case. And you're back to a similar setting we have here where a gradient method can find the optimal solution.
Và thế là bạn quay lại. Và trong trường hợp đó bạn đang cực tiểu hóa. Và bạn quay về một thiết lập tương tự như ở đây, nơi một phương pháp gradient có thể tìm ra nghiệm tối ưu.
And so it would end up being extremely similar to what we cover here. You'd have to do first a transformation step. Turn some constraints into objective terms.
Vì vậy nó sẽ cực kỳ giống với những gì ta học ở đây. Trước hết bạn phải làm một bước biến đổi. Chuyển một số ràng buộc thành các số hạng của hàm mục tiêu.
And then you'd be in a very similar situation.
Và sau đó bạn ở trong tình huống rất giống.
Any other questions about what we saw so far? Because we're going to strictly generalize this now.
Còn câu hỏi nào về những gì ta đã thấy cho đến giờ không? Vì bây giờ ta sẽ khái quát hóa hoàn toàn cái này.
OK. Neural nets. We've kind of already seen a neural network. Namely, the multiclass logistic regression reshown here drawn out more explicitly as a network is an example of a neural network.
Được. Mạng nơ-ron. Thật ra ta đã thấy một mạng nơ-ron rồi. Cụ thể, hồi quy logistic đa lớp được chiếu lại ở đây, vẽ rõ hơn dưới dạng một mạng, là một ví dụ của mạng nơ-ron.
We have inputs; feature 1, feature 2, feature 3, up to feature k. They then get somehow fed into this network thing that computes activations z1, z2, z3.
Ta có các đầu vào: đặc trưng 1, đặc trưng 2, đặc trưng 3, đến đặc trưng k. Chúng được đưa vào cái mạng này để tính các giá trị kích hoạt z1, z2, z3.
Remember, what was z1? z1 is just some weight vector for class 1 inner product with f of x. And so what does this drawing mean?
Nhớ lại, z1 là gì? z1 chỉ là vectơ trọng số của lớp 1 nhân vô hướng với f của x. Vậy hình vẽ này có nghĩa gì?
Well, weight vector 1, the first entry lives here. Weight vector 1, the second entry lives. Weight vector 1, the third entry lives here.
Vectơ trọng số 1, phần tử đầu tiên nằm ở đây. Vectơ trọng số 1, phần tử thứ hai nằm ở đây. Vectơ trọng số 1, phần tử thứ ba nằm ở đây.
Weight vector 1, k-th entry lives here. Those weight vectors are used to weight the input features. Compute a weighted sum. Get your z1.
Vectơ trọng số 1, phần tử thứ k nằm ở đây. Các vectơ trọng số này dùng để đặt trọng số cho các đặc trưng đầu vào. Tính một tổng có trọng số. Ra được z1.
Something similar is true for how z2 is attained, and z3. These activations can be between anywhere negative infinity and positive infinity. We want to turn it into probabilities.
z2 và z3 cũng được tính tương tự. Các giá trị kích hoạt này có thể nằm ở bất kỳ đâu giữa âm vô cùng và dương vô cùng. Ta muốn biến chúng thành xác suất.
That's where the softmax comes in. And we'll get out conditional probabilities for each possible class given the input.
Đó là chỗ softmax xuất hiện. Và ta sẽ có xác suất có điều kiện cho từng lớp có thể có, khi biết đầu vào.
Now, we still have some work to do here in practice.
Tuy nhiên, trong thực tế ta vẫn còn việc phải làm.
I mean, we now know how to optimize, but when you apply this in practice, you'd have to think about what should be good features.
Ý tôi là, giờ ta đã biết cách tối ưu hóa, nhưng khi áp dụng vào thực tế, bạn phải nghĩ xem đặc trưng nào là tốt.
Should I count the number of loops that I detect in my image to do a digit classification? Or should I count the number of edges that are vertical in this part of the image?
Tôi có nên đếm số vòng lặp phát hiện trong ảnh để phân loại chữ số không? Hay nên đếm số cạnh thẳng đứng ở phần này của ảnh?
Should I have as a feature whether this pixel is dark or not and so forth? So those are choices you make. And those define your feature vector.
Tôi có nên dùng đặc trưng là pixel này tối hay không và v.v.? Đó là những lựa chọn bạn đưa ra. Và chúng xác định vectơ đặc trưng của bạn.
You might wonder, can we maybe more automatically figure that part out, too? And that's where bigger, deeper neural networks come into play.
Bạn có thể tự hỏi, liệu ta có thể tự động hơn để tìm ra phần đó luôn không? Và đó là chỗ các mạng nơ-ron lớn hơn, sâu hơn phát huy tác dụng.
So instead of just having this, what we just have here, we're going to make it a lot bigger. We're going to make it a deep neural network. And we're going to learn the features.
Thay vì chỉ có cái này, cái ta vừa có ở đây, ta sẽ làm nó lớn hơn rất nhiều. Ta sẽ biến nó thành một mạng nơ-ron sâu. Và ta sẽ học các đặc trưng.
So we have our original — whoops. What happened? We have our original inputs over here. Let's say pixel values.
Ta có đầu vào ban đầu của mình, ối. Chuyện gì vậy? Ta có các đầu vào ban đầu ở bên này. Giả sử là giá trị pixel.
And we want to turn that into interesting features on which we can do a multiclass logistic regression calculation to classify what's in the image.
Và ta muốn biến chúng thành các đặc trưng thú vị để thực hiện phép tính hồi quy logistic đa lớp nhằm phân loại thứ có trong ảnh.
What needs to happen there? Traditionally, what would happen is you would think very hard about what you think matters, then write a piece of code that turns your x's into f of x's.
Cần làm gì ở đó? Theo truyền thống, bạn sẽ suy nghĩ rất kỹ về điều bạn cho là quan trọng, rồi viết đoạn mã biến các x thành các f của x.
But ultimately, that piece of code, that's all it is. It's some code. It's some calculation. The main idea in deep neural networks is to stop counting on people coming up with that calculation.
Nhưng suy cho cùng, đoạn mã đó chỉ là vậy thôi. Nó chỉ là một đoạn mã. Nó chỉ là một phép tính. Ý tưởng chính của mạng nơ-ron sâu là thôi không trông chờ con người nghĩ ra phép tính đó.
Just let it figure it out on its own. Let's put a massive amount of calculation there. That looks a lot like what we already saw.
Cứ để nó tự tìm ra. Hãy đặt một lượng tính toán khổng lồ ở đó. Trông nó rất giống cái ta đã thấy.
And that massive amount of calculation, we're not going to program by hand what's happening there. We're going to leave it flexible.
Và lượng tính toán khổng lồ đó, ta sẽ không lập trình thủ công những gì diễn ra ở đó. Ta sẽ để nó linh hoạt.
And hopefully, it results in good features that can then be used in a multiclass logistic regression to find a good classifier.
Và hy vọng nó cho ra các đặc trưng tốt để sau đó dùng trong hồi quy logistic đa lớp nhằm tìm ra một bộ phân loại tốt.
And so the massive amount of computation is what lives over here. It turns the input values x into feature values f of x.
Và lượng tính toán khổng lồ đó nằm ở bên này. Nó biến các giá trị đầu vào x thành các giá trị đặc trưng f của x.
What's actually happening here? Each circle corresponds to effectively a neuron, loosely inspired by neurons. So it's a network of neurons. And each one of them does a calculation that looks like this.
Thực sự điều gì đang diễn ra ở đây? Mỗi hình tròn tương ứng về cơ bản với một nơ-ron, lấy cảm hứng một cách sơ lược từ nơ-ron thần kinh. Vậy đây là một mạng các nơ-ron. Và mỗi nơ-ron thực hiện một phép tính trông như thế này.
So it's saying, I'm taking a weighted sum — so a sum that's weighted — of my inputs to compute an activation of a neuron in layer k.
Nó nói rằng: tôi lấy một tổng có trọng số, tức là một tổng được đặt trọng số, của các đầu vào để tính giá trị kích hoạt của một nơ-ron ở lớp k.
We use the neurons in layer k minus 1 and take a weighted sum of the activations in layer k minus 1. You might wonder, is this a good choice?
Ta dùng các nơ-ron ở lớp k trừ 1 và lấy tổng có trọng số các giá trị kích hoạt ở lớp k trừ 1. Bạn có thể tự hỏi, đây có phải lựa chọn tốt không?
Is this really what we want?
Đây có thật sự là điều ta muốn không?
If we want to compute features, do we really want kind of just like a bunch of neurons that take weighted sums of what's in the previous layer and pass that on and repeat?
Nếu muốn tính các đặc trưng, ta có thật sự muốn chỉ một loạt nơ-ron lấy tổng có trọng số của những gì ở lớp trước, truyền đi rồi lặp lại không?
If you just take weighted sums, pass on, and repeat, that's actually not going to work very well. That's why there is still this little g up front here.
Nếu chỉ lấy tổng có trọng số, truyền đi rồi lặp lại, thì thực ra nó sẽ không hoạt động tốt lắm. Đó là lý do vẫn có chữ g nhỏ ở phía trước đây.
g looks at what comes out of the original calculation, which could be anywhere between negative infinity and positive infinity, and then rescales it in some nonlinear way.
g nhìn vào kết quả của phép tính ban đầu, mà có thể nằm bất kỳ đâu từ âm vô cùng đến dương vô cùng, rồi nó co giãn lại theo một cách phi tuyến.
Why? If everything is linear, if you don't have g and everything is just linear, everything stays linear. And you get nothing new by having many, many layers.
Tại sao? Nếu mọi thứ đều tuyến tính, nếu không có g và mọi thứ chỉ là tuyến tính, thì mọi thứ vẫn là tuyến tính. Và có rất nhiều lớp cũng chẳng thu được gì mới.
Because linear times linear times linear times linear, however many times linear, still linear. But linear followed by this g thing is non-linear. And then you do a linear again followed by g.
Vì tuyến tính nhân tuyến tính nhân tuyến tính nhân tuyến tính, bao nhiêu lần đi nữa vẫn là tuyến tính. Nhưng tuyến tính rồi đến g thì là phi tuyến. Rồi bạn lại làm tuyến tính và tiếp theo là g.
It's more non-linear, more non-linear, more non-linear, more and more flexibility in what you calculate.
Càng lúc càng phi tuyến, càng phi tuyến hơn nữa, cho bạn ngày càng linh hoạt hơn trong những gì tính được.
And we'll see something later that if this thing is big enough and indeed you have a g in there, you will get a very expressive program living there.
Về sau ta sẽ thấy rằng nếu mạng này đủ lớn và quả thật có g trong đó, thì bạn sẽ có một chương trình có khả năng biểu diễn rất mạnh.
And that's the best way to think of this. This is your feature calculation program.
Và đó là cách tốt nhất để nghĩ về nó. Đây là chương trình tính đặc trưng của bạn.
If you prefer to calculate the features by a program you write by writing lines of code, that's fine. That's the traditional approach.
Nếu bạn thích tính đặc trưng bằng một chương trình do bạn tự viết từng dòng mã, cũng được. Đó là cách tiếp cận truyền thống.
The more popular approach these days is that you don't write lines of code for that feature calculation program, you just give it a massive network. And how does it get programmed?
Cách phổ biến hơn ngày nay là bạn không viết dòng mã nào cho chương trình tính đặc trưng đó, mà chỉ đưa cho nó một mạng khổng lồ. Vậy nó được lập trình thế nào?
Well, you find the w's, the weightings, and all the connections that result in good features such that you do get a good classifier on your daa.
Bạn tìm các w, tức các trọng số, và mọi kết nối sao cho cho ra đặc trưng tốt, để bạn có được bộ phân loại tốt trên dữ liệu.
To unify notation a little bit, instead of calling these f1 through fk — and note that the number of — actually, two things. First, we will unify notation.
Để thống nhất ký hiệu một chút, thay vì gọi những cái này là f1 đến fk — và lưu ý là số lượng — thực ra có hai điều. Thứ nhất, ta sẽ thống nhất ký hiệu.
These are all z's early on. And that's f. They're the features, but just unified, we'll call those z for the n-th layer.
Các lớp đầu đều là z. Và đó là f. Chúng là các đặc trưng, nhưng để thống nhất, ta gọi chúng là z của lớp thứ n.
So the n-th layer in the neural network happens to be the features that go into the multiclass logistic regression.
Vậy lớp thứ n trong mạng nơ-ron chính là các đặc trưng đi vào hồi quy logistic đa lớp.
Then when you look at the bottom here, we have capital L input numbers, then we have — or pixel values, whatever it is — we have layer 1 has capital K1 number of hidden units z.
Rồi nhìn xuống dưới đây, ta có L đầu vào, rồi ta có — hoặc giá trị điểm ảnh, tùy là gì — lớp 1 có K1 đơn vị ẩn z.
Layer 2 has capital K2. Layer n minus 1 is capital K n minus 1, and then layer n has capital Kn.
Lớp 2 có K2. Lớp n trừ 1 có K n trừ 1, và lớp n có Kn.
So it could be that you have 10 inputs, then the next layer has maybe 100 z's. The next layer might have 1,000, then a million. Then maybe again 10,000, 1,000, down to 500.
Nên có thể bạn có 10 đầu vào, lớp kế tiếp có thể có 100 z. Lớp sau có thể 1.000, rồi một triệu. Rồi có thể lại 10.000, 1.000, giảm xuống 500.
And then maybe at the end, you're down to three that are over here that are your output activations, which get turned into a probability through the softmax.
Và cuối cùng có thể chỉ còn ba ở đây là các kích hoạt đầu ra, được biến thành xác suất qua softmax.
So even though the drawing here is very symmetric, keep that in mind. It doesn't have to be the same number in each column of hidden units. In fact, it can vary very wildly.
Nên dù hình vẽ ở đây rất đối xứng, hãy nhớ điều này. Không nhất thiết phải có cùng số lượng ở mỗi cột đơn vị ẩn. Thực tế, nó có thể thay đổi rất nhiều.
You might wonder about this g. What might it look like? The popular choices in practice look like the blue curves shown over here. These figures also have a yellow curve.
Bạn có thể thắc mắc về g này. Nó trông như thế nào? Các lựa chọn phổ biến trong thực tế giống các đường cong xanh hiển thị ở đây. Các hình này còn có đường cong màu vàng.
The yellow curve is the derivative of the blue curve. Don't worry about it too much.
Đường màu vàng là đạo hàm của đường màu xanh. Đừng lo về nó quá.
If you can imagine, given we're going to have to compute derivatives, it matters that these functions have derivatives that we know about, because we're going to need derivatives.
Hãy hình dung, vì ta sẽ phải tính đạo hàm, nên điều quan trọng là các hàm này có đạo hàm mà ta biết rõ, vì ta sẽ cần đến đạo hàm.
But look at the blue one, sigmoid. We've looked at them a lot before. That's how to squash something between 0 and 1.
Nhưng nhìn đường xanh này, sigmoid. Ta đã gặp chúng nhiều lần rồi. Đó là cách ép một giá trị vào khoảng từ 0 đến 1.
Negative infinity goes to 0, positive affinity goes to 1, and a gradual transition in between. How about hyperbolic tangent? Actually, it looks very similar. Look at those two.
Âm vô cùng về 0, dương vô cùng về 1, và chuyển dần ở giữa. Còn tang hyperbolic thì sao? Thực ra nó trông rất giống. Nhìn hai cái đó.
Look at it very carefully. You'll see they actually kind of look the same, except that one of them is kind of just shifted a little bit and expanded.
Nhìn thật kỹ. Bạn sẽ thấy chúng thực ra trông giống nhau, chỉ khác là một cái bị dịch đi một chút và giãn ra.
This one here, hyperbolic tangent, goes from negative 1 to positive 1 instead of 0 to 1, but otherwise has the same shape as the sigmoid.
Cái này, tang hyperbolic, đi từ âm 1 đến dương 1 thay vì từ 0 đến 1, nhưng ngoài ra có cùng hình dạng với sigmoid.
You might wonder why might people care about having both of those. If you have one of them, isn't that enough, like if they're the same shape?
Bạn có thể tự hỏi tại sao người ta cần cả hai. Có một cái là đủ rồi chứ, như nếu chúng cùng hình dạng?
Sometimes when you think about your problem, it makes more sense to think about things as being on versus off.
Đôi khi khi nghĩ về bài toán, ta thấy hợp lý hơn khi coi mọi thứ là bật hoặc tắt.
And that's where the 0-1 can make a lot of sense, because you're multiplying a 0. That's going to have an off thing. Nothing comes through.
Và khi đó 0-1 rất hợp lý, vì bạn nhân với 0. Đó sẽ là trạng thái tắt. Không có gì đi qua.
Sometimes it makes more sense to think of it as negative versus positive activation. And then the hyperbolic tangent can make more sense.
Đôi khi hợp lý hơn khi coi đó là kích hoạt âm so với dương. Và khi đó tang hyperbolic hợp lý hơn.
There's also some practical reasons why often the hyperbolic tangent works a little better.
Cũng có một vài lý do thực tế khiến tang hyperbolic thường hoạt động tốt hơn một chút.
It's because your numbers tend to be centered around 0, which for a lot of optimizing when you do gradient descent, it tends to work a little better when things are naturally centered around 0 than when they're offset away from 0, which you have in the sigmoid.
Đó là vì các số của bạn có xu hướng tập trung quanh 0, mà với nhiều bài tối ưu hóa khi bạn dùng gradient descent, nó thường chạy tốt hơn một chút khi mọi thứ tự nhiên tập trung quanh 0 so với khi bị lệch khỏi 0, như trường hợp của sigmoid.
So your default choice might more likely be this one here than the one on the left, but both can have their merits.
Nên lựa chọn mặc định của bạn có lẽ là cái này hơn là cái bên trái, nhưng cả hai đều có ưu điểm riêng.
You might wonder, if I have to compute derivatives — it's a lot of work — what's the simplest thing we can do to make sure things are not linear, but as simple as possible?
Bạn có thể nghĩ, nếu phải tính đạo hàm — rất tốn công — thì việc đơn giản nhất ta có thể làm để đảm bảo mọi thứ không tuyến tính, mà vẫn đơn giản nhất có thể là gì?
That's the rectified leaner unit. The function runs here. If you're low at n0, you stay 0, or you become 0. And if you're higher than 0, you stay what you are.
Đó là rectified linear unit. Hàm này chạy ở đây. Nếu giá trị thấp hơn 0, nó giữ ở 0, hay đúng hơn là trở thành 0. Còn nếu lớn hơn 0, nó giữ nguyên giá trị.
So this is very similar to linear. Any positive thing essentially just passes through as is, and your negative thing becomes zeroed out. So that's also very fast.
Nên hàm này rất giống hàm tuyến tính. Mọi giá trị dương về cơ bản cứ đi qua nguyên vẹn, còn giá trị âm thì bị đưa về 0. Nên hàm này cũng rất nhanh.
You don't have to compute any exponentials to compute this thing. You just check if you have 0 or not, and set the 0 as needed. So it can be computed very fast.
Bạn không phải tính hàm mũ nào để tính hàm này. Chỉ cần kiểm tra xem có bằng 0 hay không, rồi đặt về 0 nếu cần. Vì vậy nó tính rất nhanh.
Derivatives are very easy to compute. No exponentials involved either. I mean, this thing contributes either multiplication with 0 or a multiplication with 1 to your derivative calculation. So very, very simple.
Đạo hàm cũng rất dễ tính. Cũng không có hàm mũ nào. Ý tôi là, thành phần này chỉ đóng góp phép nhân với 0 hoặc phép nhân với 1 vào việc tính đạo hàm. Nên rất, rất đơn giản.
It is probably the most popular one right now for people to use. But all three of these are reasonable. What's key about them is that none of them is just a line.
Có lẽ đây là hàm được dùng phổ biến nhất hiện nay . Nhưng cả ba hàm này đều hợp lý. Điểm mấu chốt là không hàm nào trong số đó chỉ là một đường thẳng.
If it's just a line, it's not going to work, because that is linear. And if things are linear and linear and linear, you don't get enough flexibility to capture non-linear patterns in your data.
Nếu chỉ là một đường thẳng thì sẽ không hiệu quả, vì như vậy là tuyến tính. Và nếu cứ tuyến tính chồng lên tuyến tính, bạn không có đủ độ linh hoạt để nắm bắt các mẫu phi tuyến trong dữ liệu.
So training the weights — question. Yes.
Còn việc huấn luyện các trọng số... bạn hỏi à. Vâng.
STUDENT
[INAUDIBLE] PROFESSOR: Sure.
[KHÔNG NGHE RÕ] GIÁO SƯ: Được.
STUDENT
If we need a [INAUDIBLE],, we'd just multiply the sigmoid function by 2 and the minus 1. [INAUDIBLE]?
Nếu cần một [KHÔNG NGHE RÕ], thì ta chỉ cần nhân hàm sigmoid với 2 rồi trừ 1 phải không? [KHÔNG NGHE RÕ]?
PROFESSOR
That's pretty much — I don't think it's exactly the same thing, but it would get pretty close.
Gần như vậy. Tôi nghĩ nó không hoàn toàn giống hệt, nhưng sẽ khá gần.
STUDENT
So it'd just be [INAUDIBLE] or there are special features for [INAUDIBLE]??
Vậy chỉ là [KHÔNG NGHE RÕ] hay có các đặc trưng đặc biệt cho [KHÔNG NGHE RÕ]?
PROFESSOR
It might even be the same. You'd have to do some calculation. But there is — yeah, it's roughly something like that. You scale it by a factor two and shift it.
Thậm chí có thể giống hệt. Bạn phải tính toán một chút. Nhưng đại khái là như vậy. Bạn co giãn nó theo hệ số hai và dịch đi.
So you might be right that times 2 minus 1 does it. Or it might be something very close to that.
Nên có thể bạn đúng, nhân 2 trừ 1 là được. Hoặc là một thứ rất gần với vậy.
So define w, which is now not just the w for the multiclass logistic regression, but the w's that live in the entire network. We can just have the same objective again.
Vậy ta định nghĩa w, giờ không chỉ là w của hồi quy logistic đa lớp, mà là tất cả các w trong toàn bộ mạng. Ta lại có thể dùng cùng một mục tiêu.
We've already seen this pattern many times now. We just try to maximize the probability of the labels in our data given the inputs for the corresponding data points.
Ta đã thấy mẫu này nhiều lần rồi. Ta chỉ cố cực đại hóa xác suất của các nhãn trong dữ liệu, cho trước các đầu vào của các điểm dữ liệu tương ứng.
Different choices of w will lead to different scores. We want to find a w that maximizes the score. This again is a continuous optimization, because the w's live in continuous space.
Các lựa chọn w khác nhau sẽ cho điểm số khác nhau. Ta muốn tìm w làm cực đại điểm số. Đây lại là một bài toán tối ưu liên tục, vì các w nằm trong không gian liên tục.
So we can follow the same procedures. The w will be a lot larger vector.
Nên ta có thể làm theo cùng quy trình. w sẽ là một vectơ lớn hơn nhiều.
So competing a derivative of with respect to every entry of w will take a little more time than when you have a smaller w. But it's the same principle.
Nên việc tính đạo hàm theo từng phần tử của w sẽ tốn thời gian hơn so với khi w nhỏ hơn. Nhưng nguyên tắc vẫn vậy.
You just run gradient descent, and you stop when the log likelihood of your holdout data starts to go down.
Bạn chạy gradient descent, và dừng khi log likelihood trên dữ liệu holdout bắt đầu giảm.
That's always what we do in this kind of training. We train. We train. We train.
Đó luôn là cách ta làm trong kiểu huấn luyện này. Ta huấn luyện. Ta huấn luyện. Ta huấn luyện.
And our training data, that's what gives us our gradients. We've got to be careful we're not memorizing our training. We've got to learn the pattern in the train data that generalizes to other data.
Và dữ liệu huấn luyện cho ta các gradient. Ta phải cẩn thận để không học thuộc lòng dữ liệu huấn luyện. Ta phải học mẫu trong dữ liệu huấn luyện mà tổng quát hóa được sang dữ liệu khác.
So once on the other data the holdout data things start going down, we call it done. That's our result. What are some properties? Here's a very interesting property.
Nên khi trên dữ liệu khác, tức dữ liệu holdout, kết quả bắt đầu đi xuống, ta coi là xong. Đó là kết quả của ta. Có những tính chất nào? Đây là một tính chất rất thú vị.
And this is part of why neural nets are sometimes pretty well justified and so popular. It's the universal function approximation theorem.
Và đây một phần là lý do mạng nơ-ron đôi khi được biện minh khá tốt và rất phổ biến. Đó là định lý xấp xỉ hàm phổ quát.
That says that even just a two-layer network, if just had one layer of z's added on to what we used to have, if that layer is big enough, that network can approximate any mapping that's continuous from input to output to arbitrary precision.
Định lý nói rằng ngay cả mạng hai lớp, tức chỉ thêm một lớp z vào những gì ta có trước đây, nếu lớp đó đủ lớn, mạng có thể xấp xỉ mọi ánh xạ liên tục từ đầu vào đến đầu ra với độ chính xác tùy ý.
So no matter what function you're trying to learn from your input to output of your data, if your network is big enough, you'll be able to learn that pattern.
Vậy dù hàm bạn muốn học từ đầu vào đến đầu ra của dữ liệu là gì, nếu mạng đủ lớn, bạn sẽ học được mẫu đó.
Now, again, do keep in mind you don't just want to memorize that pattern, of course. You want to stop the training once the holdout accuracy starts going down.
Một lần nữa, hãy nhớ là bạn không chỉ muốn học thuộc lòng mẫu đó. Bạn muốn dừng huấn luyện khi độ chính xác trên dữ liệu holdout bắt đầu giảm.
But the network, in principle, can learn the entire pattern in your training data if your network is big enough.
Nhưng về nguyên tắc, mạng có thể học toàn bộ mẫu trong dữ liệu huấn luyện nếu mạng đủ lớn.
What's happening underneath? Effectively, you're learning the features. You're turning your original raw pixel values or your word counts or whatever it is into something more meaningful to do a classification on.
Bên dưới đang xảy ra điều gì? Thực chất, bạn đang học các đặc trưng. Bạn biến các giá trị pixel thô ban đầu, hay số lần xuất hiện của từ, hay bất cứ thứ gì, thành thứ có ý nghĩa hơn để thực hiện phân loại.
More formally, and the star here means that you're not expected to understand even the phrasings of these theorems, let alone the proofs.
Chính thức hơn, và dấu sao ở đây có nghĩa là các bạn không cần hiểu ngay cả cách phát biểu của các định lý này, chứ đừng nói chứng minh.
But there are a bunch of formal theorems saying that if your network is big enough, it can capture up to arbitrary precision any mapping from input to output that's continuous.
Nhưng có hàng loạt định lý chính thức nói rằng nếu mạng đủ lớn, nó có thể biểu diễn với độ chính xác tùy ý mọi ánh xạ liên tục từ đầu vào đến đầu ra.
And there's a bunch of papers that came out around the same time, late '80s, early '90s stating this. If you've taken a signal processing class, you might actually have seen something similar.
Và có nhiều bài báo xuất hiện cùng thời điểm, cuối những năm 80, đầu những năm 90, phát biểu điều này. Nếu bạn đã học môn xử lý tín hiệu, có thể bạn đã thấy điều tương tự.
If you saw a Fourier analysis, you would say, OK, if you have a function that's periodic, you can approximate it to arbitrary accuracy with a sum of sinusoids.
Nếu bạn đã học phân tích Fourier, thì bạn biết: nếu có một hàm tuần hoàn, bạn có thể xấp xỉ nó với độ chính xác tùy ý bằng tổng các hàm sin.
Well, the same thing is happening here.
Ở đây cũng xảy ra điều tương tự.
We're saying if you have a function that's smooth — nothing about periodic — if you have a function that's smooth, if you have a big enough network, that network can approximate that function to arbitrary precision.
Ta nói rằng nếu bạn có một hàm trơn, không cần tuần hoàn, chỉ cần là hàm trơn, và mạng đủ lớn, mạng đó có thể xấp xỉ hàm đó với độ chính xác tùy ý.
So that's a good thing, because that means that if somehow our network is not capturing the pattern, we know what to do. We can say, let's just make the network bigger.
Đó là điều tốt, vì nghĩa là nếu mạng của ta bằng cách nào đó chưa nắm được quy luật, thì ta biết phải làm gì. Ta có thể nói: cứ làm mạng lớn hơn.
Now, again, you might end up overfitting. You ought to be careful there.
Tất nhiên, bạn vẫn có thể bị quá khớp. Phải cẩn thận chỗ đó.
But if your network does not capture the pattern of what's in your data and the accuracy doesn't really go up anywhere, you might just want to make your network bigger.
Nhưng nếu mạng không nắm được quy luật trong dữ liệu và độ chính xác chẳng tăng lên được chút nào, thì bạn có thể thử làm mạng lớn hơn.
Let's play around with this. So here's a demo site where we can look at some examples.
Giờ ta thử nghịch một chút. Đây là một trang demo để xem vài ví dụ.
So here is our — let's choose a linearly separable dataset here. Two classes, linearly separable.
Đây là... ta chọn một tập dữ liệu khả tách tuyến tính. Hai lớp, khả tách tuyến tính.
Now, it's not finding — the initialization does not have the right classifier. We have two inputs, x1 and x2. And this is the output of the classifier.
Hiện giờ nó chưa tìm ra... khởi tạo ban đầu chưa có bộ phân loại đúng. Ta có hai đầu vào, x1 và x2. Và đây là đầu ra của bộ phân loại.
Let's train it. So we take a step. Well, after one step, it's already gotten pretty far. And it's aligning itself a little more to make those probabilities higher for those data points.
Ta huấn luyện nó. Chạy một bước. Sau một bước, nó đã tiến khá xa rồi. Và nó đang tự điều chỉnh thêm một chút để tăng xác suất cho các điểm dữ liệu đó.
And let's run this faster. You see it's making those probabilities even higher. It's going to make that sigmoid steeper. And it got everything right.
Giờ cho chạy nhanh hơn. Bạn thấy xác suất còn cao hơn nữa. Hàm sigmoid sẽ dốc hơn. Và nó phân loại đúng hết.
Now, let's take a look at if we add some noise in our data. So let's put a bunch of noise. So now there is no linear separation for the other points.
Giờ xem nếu ta thêm nhiễu vào dữ liệu thì sao. Ta thêm khá nhiều nhiễu. Giờ không còn đường phân tách tuyến tính cho các điểm còn lại.
We can again run logistic regression, which is happening underneath. We do an update, update. The mini batch size here is 10.
Ta lại chạy hồi quy logistic, đó là thứ đang chạy bên dưới. Ta cập nhật, cập nhật. Kích thước mini batch ở đây là 10.
So every update is taking the gradient according to 10 data points, doing an update, repeat. And so keep going. It starts aligning this thing.
Nên mỗi lần cập nhật ta tính gradient theo 10 điểm dữ liệu, cập nhật, rồi lặp lại. Cứ tiếp tục. Nó bắt đầu căn chỉnh lại.
It's not going to find a solution that's perfectly precise in the training data. But it is finding a solution that you might argue captures the correct pattern from that training data.
Nó sẽ không tìm được nghiệm hoàn toàn chính xác trên dữ liệu huấn luyện. Nhưng nó tìm ra một nghiệm mà bạn có thể cho là nắm đúng quy luật của dữ liệu huấn luyện đó.
Now, let's reduce noise again all the way to 0. Let's take a more difficult dataset. This one here. What if you run logistic regression now?
Giờ giảm nhiễu về 0 lại. Ta lấy tập dữ liệu khó hơn. Tập này. Nếu chạy hồi quy logistic bây giờ thì sao?
Well, let's run it and see what happens. It doesn't do too well. You see nothing is very dark blue. Nothing is very dark yellow, meaning nowhere it's very confident about the labels.
Chạy thử xem. Nó làm không tốt lắm. Bạn thấy chỗ nào cũng không xanh đậm. Cũng không có chỗ nào vàng đậm, nghĩa là không chỗ nào nó thật tự tin về nhãn.
The labels are never confident. And rightfully so, because it's often wrong about the label. So it's splitting the probabilities closer to 0.5 for most of them.
Nó chẳng bao giờ tự tin về nhãn. Và đúng thôi, vì nó thường đoán sai nhãn. Nên nó để xác suất gần 0.5 ở hầu hết các điểm.
And that's the best it can do here. But we've seen if we have a neural network, we might be able to do something more expressive. Let's add some layers.
Và đó là mức tốt nhất nó làm được ở đây. Nhưng ta đã thấy nếu dùng mạng nơ-ron, ta có thể làm được điều biểu diễn tốt hơn. Ta thêm vài tầng.
Let's add a hidden layer. How many units do you want here? Well, let's start with two units. Let's train and see what happens.
Thêm một tầng ẩn. Các bạn muốn bao nhiêu đơn vị? Thử bắt đầu với hai đơn vị. Huấn luyện xem sao.
You find something where for two of the regions it does pretty well. And then the other region, it assigns kind of like a 0.5 probability it doesn't know.
Ta thấy ở hai vùng nó làm khá tốt. Còn vùng kia, nó gán xác suất khoảng 0.5, tức là nó không biết.
Well, you've seen the universal function approximation theorem. It says if your network is big enough, it should be able to capture the pattern in the data.
Các bạn đã thấy định lý xấp xỉ hàm phổ quát. Nó nói nếu mạng đủ lớn, thì nó có thể nắm được quy luật trong dữ liệu.
Well, if you're not happy with this, let's make the network bigger. Let's add more units.
Nếu bạn chưa hài lòng với kết quả này, ta làm mạng lớn hơn. Thêm đơn vị.
Actually, let's keep the same number of layers for now, but add more neurons in this particular one layer we have. Actually, think about it.
Thực ra giữ nguyên số tầng đã, chỉ thêm nơ-ron vào một tầng duy nhất này. Thật ra thử nghĩ xem.
How many neurons do you think you need to capture the pattern in this data? Four. Why?
Theo bạn cần bao nhiêu nơ-ron để nắm được quy luật của dữ liệu này? Bốn. Tại sao?
Well, intuitively, four makes a lot of sense, right? Think about it. There are four regions. So you kind of want to be able to point in all those four directions.
Theo trực giác thì bốn rất hợp lý, đúng không? Nghĩ xem. Có bốn vùng. Nên ta muốn có thể hướng về cả bốn hướng đó.
That's what your first layer could do. And then the next layer could say, well, if one of these two is active, it's blue. If one of these two is active, it's yellow.
Đó là việc tầng đầu có thể làm. Rồi tầng tiếp theo nói: nếu một trong hai cái này được kích hoạt thì là xanh. Nếu một trong hai cái kia được kích hoạt thì là vàng.
So the first region splits into four, and then the next one consolidates. So let's see what happens when we have four. Let's run the training.
Tức là tầng đầu chia thành bốn, rồi tầng sau gộp lại. Xem điều gì xảy ra khi ta có bốn. Chạy huấn luyện.
And we see that's indeed starting to capture the pattern in the data pretty well. What's this blue one doing at the top here? Not clear. That's probably overfitting.
Và ta thấy đúng là nó bắt đầu nắm được quy luật của dữ liệu khá tốt. Cái vùng xanh ở trên cùng này là gì vậy? Không rõ. Có lẽ là quá khớp.
There's nothing blue there. There's also nothing yellow there. That's the kind of thing where probably we've overtrained at this point, that it popped out with something blue over there.
Ở đó không có gì xanh cả. Cũng không có gì vàng. Kiểu này có lẽ là ta đã huấn luyện quá mức, nên nó bật ra một vùng xanh ở đó.
What happens if we make the network even bigger? We add more neurons, more neurons. Let's train again.
Nếu làm mạng lớn hơn nữa thì sao? Thêm nơ-ron, thêm nơ-ron. Huấn luyện lại.
So far the non-linearity we've been using is 10h. That was one of the choices. What if we changed this into linear? We've got a big network.
Từ nãy giờ hàm phi tuyến ta dùng là tanh. Đó là một trong các lựa chọn. Nếu đổi nó thành tuyến tính thì sao? Ta có một mạng lớn.
Everything's linear. The g function is doing nothing, just identity. What'll happen when we train? Let's see.
Mọi thứ đều tuyến tính. Hàm g không làm gì cả, chỉ là hàm đồng nhất. Điều gì sẽ xảy ra khi huấn luyện? Xem nào.
Your prediction, hopefully, was it's not going to find a good solution, because if everything is linear, it's like having a linear classifier that has only just one layer, no hidden units, and that's the best you can do.
Hy vọng dự đoán của bạn là nó sẽ không tìm được nghiệm tốt, vì nếu mọi thứ đều tuyến tính thì cũng như bộ phân loại tuyến tính chỉ có một tầng, không có đơn vị ẩn, và đó là mức tốt nhất bạn làm được.
And it assigns roughly 0.5 probability most places here. How about another non-linearity, ReLU, which was a thing down below 0, you become 0. Above 0, you stay what you are.
Và nó gán xác suất khoảng 0,5 ở hầu hết các vùng ở đây. Còn một hàm phi tuyến khác, ReLU, thì sao? Dưới 0 thì giá trị bị đưa về 0. Trên 0 thì giữ nguyên.
The minimal thing to become non-linear is like have essentially two lines, right? Let's see what happens. ReLU, no problem. It finds a nice solution here.
Để trở thành phi tuyến, tối thiểu cần về cơ bản là có hai đường thẳng, đúng không? Hãy xem chuyện gì xảy ra. ReLU, không vấn đề gì. Nó tìm được một lời giải tốt ở đây.
How about another dataset? This one here, concentric circle. Let's remove some hidden layers. Let's think about what will happen when we just try to learn a linear classifier.
Còn tập dữ liệu khác thì sao? Đây, các vòng tròn đồng tâm. Hãy bỏ bớt một số tầng ẩn. Hãy nghĩ xem chuyện gì sẽ xảy ra khi ta chỉ cố học một bộ phân loại tuyến tính.
It's not going to do too well, right? No matter how long we train.
Nó sẽ không làm tốt lắm, đúng không? Dù ta huấn luyện bao lâu đi nữa.
And it'll probably make sure that it's not too confident anywhere, because that would give it a very bad log likelihood score. If you're confident about the wrong thing, that gives you a bad score.
Và nó có lẽ sẽ đảm bảo không quá tự tin ở bất kỳ đâu, vì như vậy sẽ cho điểm log likelihood rất tệ. Nếu bạn tự tin về điều sai, bạn sẽ bị điểm xấu.
So you want to be somewhat unconfident in most places to make sure you don't make bad mistakes. What if we add hidden layers?
Nên ở hầu hết các nơi, bạn muốn hơi thiếu tự tin để chắc chắn không mắc lỗi nặng. Nếu ta thêm các tầng ẩn thì sao?
Let's see. Let's add one hidden layer. We have ReLUs. Let's train.
Hãy xem. Thêm một tầng ẩn. Ta dùng các ReLU. Huấn luyện nào.
And it's able to parcel out that middle region. If it hadn't been able to do it, then we could have just grown the network more. What if we only have one unit here?
Và nó tách được vùng ở giữa. Nếu nó không làm được thì ta có thể làm mạng lớn hơn. Nếu ở đây chỉ có một đơn vị thì sao?
What will happen if you just had one unit in your hidden layer?
Chuyện gì xảy ra nếu tầng ẩn chỉ có một đơn vị?
That doesn't allow you to do much, because that one unit, effectively, is like one classifier, one linear classifier. You're saying, I'm going to first run one linear classifier on my data.
Như vậy không làm được nhiều, vì đơn vị đó, về bản chất, giống như một bộ phân loại tuyến tính. Bạn nói: trước hết tôi chạy một bộ phân loại tuyến tính trên dữ liệu.
And all I get to do later is then use the result of that one linear classifier.
Và sau đó tôi chỉ được dùng kết quả của bộ phân loại tuyến tính đó.
So if I do something like that, if I do something like that training, it's not going to do very well.
Nên nếu tôi làm như vậy, nếu tôi huấn luyện như vậy, nó sẽ không tốt lắm.
It's not going to help much to have that one hidden layer, because it's not giving you additional expressiveness. It's essentially still just a classifier.
Có một tầng ẩn như thế cũng không giúp được nhiều, vì nó không mang lại khả năng biểu diễn thêm. Về cơ bản nó vẫn chỉ là một bộ phân loại.
You need a lot more to be able to get the expressiveness to fit to this kind of data. Not a lot more. In this case, just three more.
Bạn cần nhiều hơn nữa để có đủ khả năng biểu diễn để khớp loại dữ liệu này. Không cần nhiều hơn quá nhiều. Trường hợp này chỉ cần thêm ba đơn vị.
How about something even more complicated? This spiral, can we fit that? Well, let's see. With four hidden layer — four hidden units, can we do it?
Còn thứ phức tạp hơn nữa thì sao? Hình xoắn ốc này, ta khớp được không? Hãy xem. Với bốn đơn vị ẩn, ta làm được không?
Let's try. It's trying. It's getting some of the points, but not that many. Well, let's just make the network bigger.
Thử xem. Nó đang cố. Nó đúng được vài điểm, nhưng không nhiều. Vậy hãy làm mạng lớn hơn.
Let's add some neurons here. Let's add some more layers. Let's make those layers big enough, because this is a pretty complicated pattern to capture. And let's see what happens.
Thêm một số nơ-ron ở đây. Thêm vài tầng nữa. Làm các tầng đủ lớn, vì đây là một mẫu khá phức tạp để nắm bắt. Và xem chuyện gì xảy ra.
Train this thing.
Huấn luyện nó.
It's not easy. This is a complicated function to fit. So you see it takes a long time for it to make progress. It's hard to figure out how to move w.
Không dễ. Đây là một hàm phức tạp để khớp. Bạn thấy nó mất rất lâu mới tiến bộ. Rất khó biết cách dịch chuyển w.
And it's very subtle, what you have to do to make progress on this, but it is making some progress.
Và điều cần làm để tiến bộ ở đây rất tinh tế, nhưng nó đang tiến bộ dần.
If you look at the learning curve over here, here going down is good, because they count the number of errors rather than the accuracy.
Nhìn vào đường cong học ở đây, đi xuống là tốt, vì họ đếm số lỗi chứ không phải độ chính xác.
You see that over time it's really starting to capture the pattern. There's still some weird overfitting happening, for sure, if you look at this, like the blue ray that kept shooting out of here.
Bạn thấy theo thời gian nó thật sự bắt đầu nắm bắt được mẫu. Chắc chắn vẫn còn hiện tượng quá khớp kỳ lạ đang xảy ra, nếu bạn nhìn vào đây, như tia xanh cứ bắn ra từ chỗ này.
But at this point, it's actually pretty much there.
Nhưng đến lúc này thì về cơ bản nó đã gần đúng.
So even though it is a very complicated non-linear pattern, having a network where each unit has its own local non-linearity is enough to be able to capture this.
Vậy dù đây là một mẫu phi tuyến rất phức tạp, một mạng mà mỗi đơn vị có phi tuyến cục bộ riêng là đủ để nắm bắt nó.
So this is publicly available, this demo. It's linked from the slides. It's a lot of fun to play around with.
Bản demo này được công khai. Có liên kết trong slide. Chơi với nó rất vui.
You get intuition for what a neural network can capture or not capture in terms of data patterns.
Bạn sẽ có trực giác về việc mạng nơ-ron có thể hay không thể nắm bắt những mẫu dữ liệu nào.
So how about computing all the derivatives that we need? Well, you probably have all taken classes at some point that resulted in a table like this.
Vậy còn việc tính mọi đạo hàm ta cần thì sao? Có lẽ các bạn đều từng học những lớp có một bảng như thế này.
This table effectively tells you for every function that's in a table what's the derivative. We might say, well, nowhere in that table do I see my neural network.
Bảng này cho bạn biết với mỗi hàm trong bảng thì đạo hàm là gì. Ta có thể nói: trong bảng đó đâu có mạng nơ-ron của tôi.
It's just not in there. Will there be a book that has your neural network in that table? Probably not.
Nó đơn giản là không có. Liệu có cuốn sách nào có mạng nơ-ron của bạn trong bảng không? Có lẽ không.
Usually, these tables have sines, cosines, and x squared, and x to the third, and so forth. They don't have this massive neural network in there, and then saying, here's the derivative.
Thường các bảng này có sin, cos, x bình phương, x mũ ba, v.v. Chúng không có cái mạng nơ-ron khổng lồ này rồi ghi: đây là đạo hàm.
What these books do have, though, is something called chain rule.
Nhưng những cuốn sách này có một thứ gọi là quy tắc chuỗi.
Chain rule says if you have a function that consists of the composition of multiple functions, you can compute the derivative of that composed function by computing derivatives of the components and multiply them together.
Quy tắc chuỗi nói rằng nếu bạn có một hàm là hợp của nhiều hàm, bạn có thể tính đạo hàm của hàm hợp đó bằng cách tính đạo hàm của các thành phần rồi nhân chúng lại.
And that's what a neural network is. You have a sequence of functions being composed together to go all the way from the input to the output.
Và mạng nơ-ron chính là như vậy. Bạn có một chuỗi các hàm được hợp lại với nhau để đi từ đầu vào đến đầu ra.
And you just apply the chain rule many, many times.
Và bạn chỉ việc áp dụng quy tắc chuỗi rất nhiều lần.
If the network is big, you'll have to apply the chain rule — if it's, let's say, 100 layers deep, you'll have to apply the chain rule 100 times, because you're composing 100 times.
Nếu mạng lớn, bạn sẽ phải áp dụng quy tắc chuỗi, chẳng hạn nếu sâu 100 tầng thì phải áp dụng 100 lần, vì bạn hợp hàm 100 lần.
But that's all you need to do. So there are rules for this. It doesn't mean it's painless to work through this.
Nhưng đó là tất cả những gì cần làm. Vậy là có các quy tắc cho việc này. Điều đó không có nghĩa là làm nó sẽ không vất vả.
If we give you a network and we say give us the derivative with respect to weight three in layer two of this network given this data, that would be a lot of work for you to write out by hand.
Nếu mình đưa cho các bạn một mạng và yêu cầu tính đạo hàm theo trọng số thứ ba ở lớp hai của mạng này, với dữ liệu này, thì sẽ tốn rất nhiều công sức để các bạn viết ra bằng tay.
But the rules are very well defined. So actually, there's no reason to be doing this by hand. These rules are very well defined.
Nhưng các quy tắc được định nghĩa rất rõ ràng. Nên thực ra không có lý do gì để làm việc này bằng tay. Các quy tắc này được định nghĩa rất rõ.
Any composed function that only reduces to the things that are in the table here, you can just apply the rules and call it done. It'll automatically generate a solution.
Bất kỳ hàm hợp nào chỉ quy về những thứ có trong bảng ở đây thì bạn chỉ cần áp dụng các quy tắc là xong. Nó sẽ tự động sinh ra lời giải.
If you go to Mathematica, something like that, input a function, it outputs often a massive derivative thing of that function. So there's something called automatic differentiation, which does that for you.
Nếu bạn dùng Mathematica hay thứ tương tự, nhập một hàm vào, nó thường xuất ra một đạo hàm khổng lồ của hàm đó. Có một thứ gọi là đạo hàm tự động (automatic differentiation), làm việc đó cho bạn.
It'll say, you give me a function. I will look it up in those tables, and I'll apply the chain rule for you. And here is the result for you.
Bạn đưa cho nó một hàm. Nó sẽ tra trong các bảng đó, và áp dụng quy tắc chuỗi cho bạn. Rồi đây là kết quả của bạn.
That's what these tools do. Some tools or brand names of the tools are Theano out of the University of Montreal, TensorFlow out of Google, PyTorch out of Facebook, Chainer out of Preferred Networks.
Đó là việc các công cụ này làm. Một số công cụ, hay tên thương hiệu của chúng, là Theano của Đại học Montreal, TensorFlow của Google, PyTorch của Facebook, Chainer của Preferred Networks.
So these are alternative tools. There are, of course, subtle differences, but at a high level, do the same thing.
Đây là các công cụ thay thế nhau. Dĩ nhiên có những khác biệt nhỏ, nhưng ở mức tổng quát thì chúng làm cùng một việc.
You can feed in a function, and out will come the derivative of that function with respect to whichever variable that you want the derivative with respect to.
Bạn đưa vào một hàm, và đầu ra sẽ là đạo hàm của hàm đó theo biến nào mà bạn muốn lấy đạo hàm.
In fact, if you have a function in our case of the form gxyw — x the input, y the output, and w all the weights — you can ask for the entire gradient vector in one go, and there's an efficient way to reuse calculations you do for the different entries such that actually you can compute the entire gradient
Thực ra, nếu bạn có hàm dạng g(x, y, w) trong trường hợp của ta, x là đầu vào, y là đầu ra, w là tất cả trọng số, bạn có thể yêu cầu toàn bộ vectơ gradient cùng một lúc, và có cách hiệu quả để tái sử dụng các phép tính cho những thành phần khác nhau, nhờ đó bạn có thể tính toàn bộ vectơ
vector at the computational cost of roughly two to three times the cost of just the forward calculation through the function. So you might have thought derivatives are expensive.
gradient với chi phí tính toán khoảng hai đến ba lần chi phí của riêng phép tính lượt xuôi qua hàm. Có thể bạn nghĩ đạo hàm rất tốn kém.
We're going to have to wait a long time to get those out.
Chắc phải chờ rất lâu mới có kết quả.
No, if you can do the forward calculation through the network, there's a backward calculation that only takes two, three times longer that will give you the entire gradient vector.
Không, nếu bạn tính được lượt xuôi qua mạng, thì có một phép tính lượt ngược chỉ mất lâu hơn hai, ba lần và cho bạn toàn bộ vectơ gradient.
For this class, you just need to know that this exists, that this is the case. You don't need to know the details of how it's done.
Trong môn này, bạn chỉ cần biết rằng điều này tồn tại, rằng nó đúng như vậy. Bạn không cần biết chi tiết cách làm.
I mean, if you want to go look it up, there are a lot of tutorials online telling about, what is back variation, what is automatic differentiation, and so forth.
Nếu muốn tìm hiểu thì có rất nhiều hướng dẫn trên mạng nói về lan truyền ngược là gì, đạo hàm tự động là gì, và v.v.
We're not going to quiz you on that. We do not expect that you know that, but know it's possible. We can do a forward calculation.
Chúng tôi sẽ không kiểm tra phần đó. Không yêu cầu các bạn biết, nhưng hãy biết rằng điều đó khả thi. Ta có thể tính lượt xuôi.
Just at two, three times the cost, you can do a backward one. Summary of the key ideas that we've covered at this point.
Chỉ với chi phí gấp hai, ba lần, ta tính được lượt ngược. Tóm tắt các ý chính ta đã học đến giờ.
The way we've formulated learning classifiers is by optimizing the probability of labels given the input, optimized the probability of all the labels.
Cách ta xây dựng việc học bộ phân loại là tối ưu xác suất của các nhãn cho đầu vào, tối ưu xác suất của tất cả các nhãn.
The product of the probabilities of the labels is the same as the — it's equivalent to optimizing the log of the product of the probabilities, which is the sum of the logs, and that's what we've been doing.
Tích các xác suất của các nhãn thì tương đương với — tương đương với việc tối ưu log của tích các xác suất, tức là tổng các log, và đó là điều ta vẫn làm.
So we've maximized the sum of the log probabilities of all the labels given the inputs. Against what? Against w, which is all the weightings that we have in our network.
Ta cực đại hóa tổng log xác suất của tất cả các nhãn cho các đầu vào. Theo biến nào? Theo w, tức là tất cả các trọng số trong mạng của ta.
w is a continuous vector. It turns out that helps us. We can do a gradient ascent.
w là một vectơ liên tục. Hóa ra điều đó giúp ích cho ta. Ta có thể dùng gradient ascent.
We can locally look at the derivative of our objective with respect to each of the entries in w and use that to choose a direction in which to step.
Ta có thể xét cục bộ đạo hàm của hàm mục tiêu theo từng thành phần của w và dùng nó để chọn hướng để bước đi.
And that direction, the gradient direction, is the steepest increase in our objective direction. So it's the fastest way to increase our objective with a local step.
Và hướng đó, hướng gradient, là hướng làm hàm mục tiêu tăng dốc nhất. Tức là cách nhanh nhất để tăng hàm mục tiêu bằng một bước cục bộ.
We keep doing this till we hit early stopping, meaning we hit a point where on the holdout data accuracy starts dropping, because that means we're memorizing, rather than learning the pattern.
Ta cứ làm vậy cho đến khi dừng sớm, nghĩa là đến lúc độ chính xác trên dữ liệu holdout bắt đầu giảm, vì điều đó nghĩa là ta đang học thuộc lòng chứ không học quy luật.
What does it mean to have a deep neural net?
Mạng nơ-ron sâu nghĩa là gì?
It means that your last layer would still be a logistic regression in what we covered, but now there are many, many more layers coming before that.
Nghĩa là lớp cuối cùng vẫn là hồi quy logistic như ta đã học, nhưng giờ có rất nhiều lớp nằm trước nó.
And those replace, in some sense, human ingenuity of deciding what is a feature due to a word count, the log of a word count. You do loop counting.
Và theo một nghĩa nào đó, chúng thay thế sự khéo léo của con người khi chọn đặc trưng, như số lượng từ hay log của số lượng từ. Bạn đếm các vòng lặp.
You do connected components counting. All that stuff gets replaced by here is a massive neural net, and we know it can approximate any function from input to output.
Bạn đếm các thành phần liên thông. Tất cả được thay bằng: đây là một mạng nơ-ron khổng lồ, và ta biết nó có thể xấp xỉ bất kỳ hàm nào từ đầu vào đến đầu ra.
Well, let it find the one that has the right features from looking at the data. That's what the universal function approximation theorem tells us.
Vậy hãy để nó tìm ra hàm có các đặc trưng đúng bằng cách nhìn vào dữ liệu. Đó là điều định lý xấp xỉ hàm phổ quát cho ta biết.
Network large enough, then the neural net can approximate any continuous mapping, including the one that we want. And hopefully, this gradient decent procedure will find that one. Sometimes we need multiple initializations, multiple runs.
Nếu mạng đủ lớn, mạng nơ-ron có thể xấp xỉ bất kỳ ánh xạ liên tục nào, kể cả ánh xạ mà ta muốn. Và hy vọng quy trình gradient descent này sẽ tìm ra nó. Đôi khi ta cần nhiều lần khởi tạo, nhiều lần chạy.
But often it will find a very good one. This gradient itself, well, that's just a vector of derivatives. A vector of derivatives, in principle, nothing special about that.
Nhưng thường thì nó sẽ tìm được một nghiệm rất tốt. Bản thân gradient này chỉ là một vectơ các đạo hàm. Một vectơ các đạo hàm, về nguyên tắc, không có gì đặc biệt.
You just take a derivative in respect to each of the entries, each of the weight vector entries.
Bạn chỉ lấy đạo hàm theo từng thành phần, từng thành phần của vectơ trọng số.
In practice, it could be a lot of tedious work to do that if you're going to do it by hand, but luckily there are automatic differentiation tools, which allow you to just input the forward calculation, specify the network, and then it'll do the backward calculation that gives you the derivatives.
Trên thực tế, làm việc đó bằng tay có thể rất tẻ nhạt và tốn công, nhưng may là có các công cụ đạo hàm tự động, cho phép bạn chỉ cần nhập phần tính toán xuôi, khai báo mạng, rồi công cụ sẽ tự thực hiện phần tính ngược để cho ra các đạo hàm.
How is that done? That's outside of the scope of 188. How well does it work? Let's see.
Việc đó được làm như thế nào? Phần đó nằm ngoài phạm vi của CS 188. Nó hoạt động tốt đến mức nào? Để xem nào.
We've got three minutes left, which is not enough to really cover how well this works. So let's shift those slides to Tuesday.
Chúng ta còn ba phút, mà như vậy không đủ để trình bày kỹ nó hoạt động tốt ra sao. Nên ta sẽ dời những slide đó sang thứ Ba.
All right. That's it for today. See you on Tuesday.
Được rồi. Hôm nay đến đây thôi. Hẹn gặp lại các bạn vào thứ Ba.
Đăng nhập để đánh giá học liệu này.
Đăng nhập để bình luận — chưa ai bình luận về học liệu này.
Không có khóa học liên quan.