brunch

You can make anything
by writing

C.S.Lewis

by 라인하트 Oct 24. 2020

앤드류 응의 머신러닝(8-3): 인공신경망 모델표현 I

   온라인 강의 플랫폼 코세라의 창립자인 앤드류 응 (Andrew Ng) 교수는 인공지능 업계의 거장입니다. 그가 스탠퍼드 대학에서 머신 러닝 입문자에게 한 강의를 그대로 코세라 온라인 강의 (Coursera.org)에서 무료로 배울 수 있습니다. 이 강의는 머신러닝 입문자들의 필수코스입니다. 인공지능과 머신러닝을 혼자 공부하면서 자연스럽게 만나게 되는 강의입니다. 


Neural Networks : Representation

인공 신경망 : 표현


Neural Network (신경망)


Model Representation (모델 표현)    


   In this video, I want to start telling you about how we represent neural networks. In other words, how we represent our hypothesis or how we represent our model when using neural networks. 


   이번 강의에서 신경망을 표현하는 방법을 설명합니다. 신경망에서 사용하는 가설이나 모델을 어떻게 표현하는 지를 공부합니다. 



   Neural networks were developed as simulating neurons or networks of neurons in the brain. So, to explain the hypothesis representation let's start by looking at what a single neuron in the brain looks like. Your brain and mine is jam packed full of neurons like these and neurons are cells in the brain. 


   신경망은 뇌 속의 뉴런과 뉴런의 네트워크를 모방하였습니다. 먼저 뇌 속에 있는 단일 뉴런의 모양을 살펴봅니다. 인간의 뇌는 뇌 세포인 뉴런으로 가득 차있습니다.




   And two things to draw attention to are that first. The neuron has a cell body, like so, and moreover, the neuron has a number of input wires, and these are called the dendrites. You think of them as input wires, and these receive inputs from other locations. And a neuron also has an output wire called an Axon, and this output wire is what it uses to send signals to other neurons, so to send messages to other neurons. So, at a simplistic level what a neuron is, is a computational unit that gets a number of inputs through it input wires and does some computation and then it says outputs via its axon to other nodes or to other neurons in the brain. 


   이 그림에서 뉴런의 두 가지 부분을 주목해야 합니다. 하나는 세포체와 수상돌기입니다. 수상돌기는 여러 다른 위치에서 입력을 받는 입력 단자입니다. 또 다른 하나는 축삭돌기 있습니다. 축삭돌기는 다른 뉴런에 신호를 보내거나 메시지를 보내는 출력 단자입니다. 따라서, 단순화하면 뉴런은 계산 유닛입니다. 여러 개의 입력 단자로부터 값을 받아 계산을 수행합니다. 그리고 출력 값을 다른 노드나 뉴런으로 전달하기 위해 출력 단자를 이용합니다. 



   Here's a illustration of a group of neurons. The way that neurons communicate with each other is with little pulses of electricity, they are also called spikes but that just means pulses of electricity. So here is one neuron and what it does is if it wants a send a message what it does is sends a little pulse of electricity. Varis axon to some different neuron and here, this axon that is this open wire, connects to the dendrites of this second neuron over here, which then accepts this incoming message that some computation. And they, in turn, decide to send out this message on this axon to other neurons, and this is the process by which all human thought happens. It's these Neurons doing computations and passing messages to other neurons as a result of what other inputs they've got. And, by the way, this is how our senses and our muscles work as well. If you want to move one of your muscles the way that where else in your neuron may send this electricity to your muscle and that causes your muscles to contract and your eyes, some senses like your eye must send a message to your brain while it does it senses hosts electricity entity to a neuron in your brain like so. 


   여기 뉴런 그룹을 설명한 그림이 있습니다. 뉴런은 서로 스파이크라는 전기 신호를 사용하여 통신합니다. 위쪽의 뉴런이 작은 전기 신호를 축삭돌기를 통해서 다른 뉴런에게 보냅니다. 그리고 축삭돌기는 다른 뉴런의 수상돌기와 연결되어 있습니다. 전기 신호를 받은 아래의 뉴런은 특정 계산을 수행하고 다른 뉴런에게 출삭돌기를 통해 전기 신호를 보냅니다. 전기 신호는 보내려는 메시지입니다. 이것이 인간의 몸에서 뉴런이 다른 뉴런과 통신하는 프로세스입니다. 즉, 뉴런은 다른 뉴런으로부터 메시지를 계산을 하고 다른 뉴런에게 메시지를 전달합니다. 이것이 사람의 감각과 근육이 작용하는 원리입니다. 만일 여러분이 몸을 움직이려고 한다면, 여러분의 뉴런은 근육에 전기 신호를 보내고 근육이 수축합니다. 눈과 같은 감각기관이 뇌로 메시지를 보내면 동일한 방식으로 감지합니다.


   In a neuron network, or rather, in an artificial neuron network that we've implemented on the computer, we're going to use a very simple model of what a neuron does we're going to model a neuron as just a logistic unit. 


   신경망에서, 또는 컴퓨터에서 구현하려는 인공 신경망에서 매우 단순한 모델을 사용합니다. 뉴런은 단지 논리 유닛입니다.



   So, when I draw a yellow circle like that, you should think of that as a playing a role analysis, who's maybe the body of a neuron, and we then feed the neuron a few inputs who's various dendrites or input wiles. And the neuron does some computation. And output some value on this output wire, or in the biological neuron, this is an axon. And whenever I draw a diagram like this, what this means is that this represents a computation of h of x equals one over one plus e to the negative theta transpose x, where as usual, x and theta are our parameter vectors, like so. So this is a very simple, maybe a vastly oversimplified model, of the computations that the neuron does, where it gets a number of inputs, x1, x2, x3 and it outputs some value computed like so. When I draw a neural network, usually I draw only the input nodes x1, x2, x3. Sometimes when it's useful to do so, I'll draw an extra node for x0. This x0 now that's sometimes called the bias unit or the bias neuron, but because x0 is already equal to 1, sometimes, I draw this, sometimes I won't just depending on whatever is more notationally convenient for that example.


    Finally, one last bit of terminology when we talk about neural networks, sometimes we'll say that this is a neuron or an artificial neuron with a Sigmoid or logistic activation function. So this activation function in the neural network terminology. This is just another term for that function for that non-linearity g(z) = 1 over 1+e to the -z. And whereas so far I've been calling theta the parameters of the model, I'll mostly continue to use that terminology. Here, it's a copy to the parameters, but in neural networks, in the neural network literature sometimes you might hear people talk about weights of a model and weights just means exactly the same thing as parameters of a model. But I'll mostly continue to use the terminology parameters in these videos, but sometimes, you might hear others use the weights terminology. So, this little diagram represents a single neuron.


   여기 노란색 원은 뉴런입니다.  



   피처 x1, x2, x3는 수상돌기 혹은 입력단자로 뉴런에 정보를 전달합니다. 뉴런은 계산을 한 후 출력값을 축삭돌기 또는 출력 단자로 전달합니다. 여기 다이어그램에서 가설 hθ(x)는 1/(1+e^(-θ^TX))입니다. 여기서 피처 x와 파라미터 θ는 벡터입니다. 이 다이어그램은 뉴런이 동작하는 방식을 매우 단순하게 표현한 모델입니다. 인공 신경망을 그릴 때 입력 노드 x1, x2, x3만을 표시하지만, 필요한 상황에서는 x0 노드를 추가로 표현합니다. x0는 bias 유닛 또는 bias 뉴런이고, x0는 항상 1입니다. x0를 표시하거나 가끔 생략합니다. 하기도 합니다.


   마지막으로, 신경망에서 쓰는 용어를 설명합니다. 다이어그램을 시그모이드 또는 로지스틱 활성화 함수를 가진 뉴런 또는 인공 뉴런이라고 부릅니다. 인공신경망에서 활성화 함수는 다음과 같은 비선형 함수로 나타냅니다.


   지금까지 가설 모델의 파라미터를 θ로 표현했듯이 앞으로도 그대로 사용합니다. 신경망에서 파라미터 θ를 모델의 가중치를 표현하기도 합니다. 앞으로도 θ를 파라미터라고 부르겠지만 다른 전문가들은 가중치라고 부르기도 합니다. 


  


    What a neural network is, is just a group of this different neurons strong together. Completely, here we have input units x1, x2, x3 and once again, sometimes you can draw this extra note x0 and Sometimes not, just flow that in here. And here we have three neurons which have written 81, 82, 83. I'll talk about those indices later. And once again we can if we want add in just a0 and add the mixture bias unit there. There's always a value of 1. And then finally we have this third node and the final layer, and there's this third node that outputs the value that the hypothesis h(x) computes. 


   여기 여러 개의 뉴런을 그룹으로 연결한 신경망이 있습니다. 



   입력 유닛 x1, x2, x3 가 있습니다. 가끔은 인터셉트 노드 x0를 그릴 수도 있고 그리지 않을 수도 있습니다. 중간층의 a^(2)1, a^(2)2, a^(2)3로 적힌 세 개의 뉴런이 있습니다. a옆에 위 첨자는 나중에 설명합니다. 여기서도  a^(2)0를 추가합니다. x0와 a^(2)0는 바이어스(bias) 유닛이고 출력 값은 항상 1입니다. 마지막 층에 있는 노드는 가설 h(x)를 계산한 값을 출력합니다.  



   To introduce a bit more terminology, in a neural network, the first layer, this is also called the input layer because this is where we Input our features, x1, x2, x3. The final layer is also called the output layer because that layer has a neuron, this one over here, that outputs the final value computed by a hypothesis. And then, layer 2 in between, this is called the hidden layer. The term hidden layer isn't a great terminology, but this ideation is that, you know, you supervised early, where you get to see the inputs and get to see the correct outputs, where 

there's a hidden layer of values you don't get to observe in the training setup. It's not x, and it's not y, and so we call those hidden. And they try to see neural nets with more than one hidden layer but in this example, we have one input layer, Layer 1, one hidden layer, Layer 2, and one output layer, Layer 3. But basically, anything that isn't an input layer and isn't an output layer is called a hidden layer.


   신경망에서 사용하는 몇 가지 용어를 설명합니다. 첫 번째 층은 입력층(Input Layer)입니다. 입력층은 피처 x1, x2, x3를 입력받습니다. 마지막 층은 출력층(Output Layer)입니다. 이 그림의 마지막 층은 한 개의 뉴런으로 되어 있습니다. 마지막 층의 뉴런이 가설을 계산한 최종 값을 출력합니다. 입력층과 출력층 사이에 있는 층은 은닉층(Hidden Layer)입니다. 은닉층은 적절한 용어가 아닐 수 있습니다. 지도 학습 학습 데이터 셋은 입력값과 출력값이 있지만 은닉층의 값은 없습니다. 은닉층의 값은 x도 y도 아니기 때문에 은닉이라고 합니다. 나중에 여러 개의 은닉층을 가진 신경망도 다룰 것입니다. 여기서는 입력층 하나, 은닉층 하나, 출력층 하나 총 3개의 층이 있습니다. 입력층과 출력층이 아닌 모든 층이 은닉층입니다.  


        

   So I want to be really clear about what this neural network is doing. Let's step through the computational steps that are and body represented by this diagram. To explain these specific computations represented by a neural network, here's a little bit more notation. I'm going to use a superscript j subscript i to denote the activation of neuron i or of unit i in layer j. So completely this gave superscript to sub group one, that's the activation of the first unit in layer two, in our hidden layer. And by activation I just mean the value that's computed by and as output by a specific. In addition, new network is parametrize by these matrixes, theta super script j Where theta j is going to be a matrix of weights controlling the function mapping form one layer, maybe the first layer to the second layer, or from the second layer to the third layer.


   신경망을 계속 설명합니다. 신경망을 계산하는 과정을 정리합니다. 우선 몇 가지 표기법을 다룹니다.

   위 첨자 j는 층(Layer)을 나타내고 아래 첨자 i는 뉴런 혹은 유닛의 활성화 함수의 순서를 나타냅니다. 예를 들어, a^(2) 1 위 첨자 2 아래 첨자 1 은 은닉층인 Layer 2의 첫 번째 유닛의 활성화 함수를 가리킵니다. 정확히는 유닛의 활성화 함수는 유닛에서 계산한 출력 값을 의미합니다. 신경망은 행렬로 표현합니다. Θ^(j)는 한 층을 다른 층으로 매핑하는 함수를 조절하는 가중치의 매트릭스입니다. 예를 들어 첫 번째 층에서 두 번째 층으로 전달하는 가중치이고, 두 번째 층에서 세 번째 층으로 전달하는 가중치입니다. 




   So here are the computations that are represented by this diagram. This first hidden unit here has it's value computed as follows, there's a is a21 is equal to the sigma function of the sigma activation function, also called the logistics activation function, apply to this sort of linear combination of these inputs. And then this second hidden unit has this activation value computer as sigmoid of this. And similarly for this third hidden unit is computed by that formula. So here we have 3 theta 1 which is matrix of parameters governing our mapping from our three different units, our hidden units. Theta 1 is going to be a 3. Theta 1 is going to be a 3x4-dimensional matrix. And more generally, if a network has SJU units in there j and sj + 1 units and sj + 1 then the matrix theta j which governs the function mapping from there sj + 1. That will have to mention sj +1 by sj + 1 I'll just be clear about this notation right. This is Subscript j + 1 and that's s subscript j, and then this whole thing, plus 1, this whole thing (sj + 1), okay?  So that's s subscript j + 1 by, So that's s subscript j + 1 by sj + 1 where this plus one is not part of the subscript.    Okay, so we talked about what the three hidden units do to compute their values. 


   여기 신경망을 계산하는 식이 있습니다. 

    은닉층의 첫 번째 은닉 유닛의 활성화 함수 a^(2) 1은 시그모이드 함수, 시그모이드 활성화 함수 또는 로지스틱 활성화 함수입니다. 입력층의 피처에 가중치 파라미터 θ를 더 합니다. 은닉층의 두 번째 은닉 유닛의 활성화 함수 a^(2)2와 은닉층의 세 번째 은닉 유닛의 활성화 함수 a^(2)3도 같은 방식으로 계산합니다. 여기 3개의 입력 유닛과 3개의 은닉 유닛이 있습니다. 3개의 입력 유닛과 3개의 은닉 유닛에 대응하는 θ^(1) 행렬의 차원은 3 X 4차원입니다. 일반적으로, 신경망의 j번째 층에 sj개 유닛이 있고 j+1번째 층에 sj + 1개 유닛이 있을 때  j 개의 층에서 j+1로 매핑하는 θ^(j) 행렬은 sj+1 X (sj + 1) 차원 행렬입니다. 이 표기법은 왼쪽에 있는 s(j+1)은 (j+1)이 아래 첨자이고, 오른쪽에 (sj + 1)는 j가 아래 첨자인 Sj에 1을 더한 것입니다. 그래서 이것은 S(j+1)이 아래 첨자인 s 곱하기 그래서 이것은 j+1이 아래 첨자인 sj+1 * (sj + 1)입니다. 이 + 1 은 아래 첨자에 포함되지 않는다는 것에 주의합니다. 지금까지 이 세 개의 히든 유닛들의 값이 어떻게 계산되는지를 설명했습니다. 


   Finally, there's a loss of this final and after that we have one more unit which computer h of x and that's equal can also be written as a(3)1 and that's equal to this. And you notice that I've written this with a superscript two here, because theta of superscript two is the matrix of parameters, or the matrix of weights that controls the function that maps from the hidden units, that is the layer two units to the one layer three unit, that is the output unit. 


   마지막으로 출력층의 출력 유닛은 hθ(x)를 계산합니다. 그리고 여기 위 첨자 2를 쓴 것은 θ^(2)는 파라미터θ의 행렬 또는 두 번째 층 유닛들을 세 번째 층이자 출력층  유닛으로 매핑하는 가중치의 행렬입니다. 


  To summarize, what we've done is shown how a picture like this over here defines an artificial neural network which defines a function h that maps with x's input values to hopefully to some space that provisions y. And these hypothesis are parameterized by parameters denoting with a capital theta so that, as we vary theta, we get different hypothesis and we get different functions. Mapping say from x to y.


   So this gives us a mathematical definition of how to represent the hypothesis in the neural network. In the next few videos what I would like to do is give you more intuition about what these hypothesis representations do, as well as go through a few examples and talk about how to compute them efficiently.


   요악하자면,  뉴런과 신경망의 정의를 살펴보았습니다. 인공신경망은 가설 함수 hθ(x)를 정의하고  hθ(x)는 x를 입력받아 y를 예측하는 함수입니다. 가설 함수는 파라미터 θ 에 의해 조절됩니다. 파라미터 행렬은 대문자 Θ로 표기하고, 우리가 Θ의 값을 변경하면 가설이 달라지고, 가설이 달라지면 x에서 y로 매핑하는 함수도 달라집니다.  


   지금까지 신경망에서 가설의 수학적 정의를 배웠습니다. 다음 강의에서 가설의 정의와 역할을 살펴보고 몇 가지 예를 다루겠습니다. 그리고 가설을 효율적으로 계산하는 방법에 대해서도 설명하겠습니다. 



앤드류 응의 머신러닝 동영상 강의



정리하며 - 인공 신경망의 모델 표현


   신경망은 뇌 속의 뉴런과 뉴런의 네트워크를 모방하여 개발하였습니다. 하나의 뉴런은  작은 전기 신호를 수상돌기로 수신한 후 세포체에서 계산을 한 후 축삭돌기 통해 다른 뉴런에게 메시지를 보냅니다. 신경망 또는 인공 신경망은 뉴런을 그대로 모방하여 논리적인 유닛으로 나타냅니다.

   보통 뉴런을 위의 다이어그램으로 표현합니다.  가설 함수 h(x) = 1/(1+e^(-θ^TX)) 로 로지스틱 회귀의 가설입니다. 여기서 x와 파라미터 θ는 벡터입니다. 상황에 따라 x0 노드를 추가할 수 있고, bias 유닛 x0는 항상 1입니다. 이것을 뉴런 또는 Sigmoid 활성화 함수를 가진 인공 뉴런이나 로지스틱 활성화 함수를 가진 인공 뉴런이라고 부릅니다. 



    인공신경망에서 θ는 파라미터 또는 가중치로 표현한다.



   인공신경망은 여러 개의 뉴런이 또는 시그모이드 활성화 함수를 가진 인공 뉴런이 네트워크를 이룹니다. 입력을 받는 첫 번째 층을 입력층, 마지막 층은 출력층이라고 합니다. 입력층과 출력층 사이에 있는 모든 층들을 은닉층이라고 합니다. 당연히 지도 학습에서 훈련용 데이터 셋에는 입력과 출력 값은 있지만, 은닉층의 값들은 없습니다. 



    각 층에 있는 뉴런인 논리 유닛을 표현하기 위해 다음 표현을 씁니다.


           a^(2)1 : 두 번째 층의 첫 번째 유닛의 활성화 함수

         a^(3)1 : 세 번째 층의 첫 번째 유닛의 활성화 함수

           a^(1)1 : 첫 번째 층의 첫 번째 유닛의 활성화 함수 (첫 번째 층은 입력층을 의미)


   두 번째 층의 모든 유닛에 파라미터 θ^(j)와 입력 xi은 3*4 행렬로 표현할 수 있습니다. θ^(j)는 한층에서 다른 층으로 매핑하는 가중치 행렬입니다.


   따라서, 인공신경망은 가설 함수 hθ(x)를 정의하고  hθ(x)는 x를 입력받아 y를 예측하는 함수입니다. 가설 함수는 파라미터 또는 가중치 Θ에 의해 조절됩니다. 파라미터들은 대문자 로 표기합니다.


매거진의 이전글 앤드류 응의 머신러닝(8-1): 비선형 가설
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari