डीप न्यूरल नेटवर्क - ReLU के साथ बैकप्रोपोगेशन


17

मुझे ReLU के साथ वापस प्रचार प्राप्त करने में कुछ कठिनाई हो रही है, और मैंने कुछ काम किया है, लेकिन मुझे यकीन नहीं है कि मैं सही रास्ते पर हूं।

लागत समारोह: 12(yy^)2जहांyवास्तविक मूल्य है, और y एक भविष्यवाणी मूल्य है। यह भी मान लें किx> 0 हमेशा।y^x


1 परत ReLU, जहां 1 परत पर वजन w1

यहाँ छवि विवरण दर्ज करें

dCdw1=dCdRdRdw1

dCw1=(yReLU(w1x))(x)


2 परत ReLU, जहां 1 परत पर वजन 2 w2 , और 2 परत w1 और मैं 1 परत w 2 को अद्यतन करना चाहता थाw2

यहाँ छवि विवरण दर्ज करें

dCdw2=dCdRdRdw2

dCw2=(yReLU(w1ReLU(w2x))(w1x)

के बाद से ReLU(w1ReLU(w2x))=w1w2x


3 लेयर ReLU, जहां 1 लेयर पर वेट 3 w3 , 2 लेयर w2 और 3rd लेयर w1

यहाँ छवि विवरण दर्ज करें

dCdw3=dCdRdRdw3

dCw3=(yReLU(w1ReLU(w2(ReLU(w3)))(w1w2x)

के बाद से ReLU(w1ReLU(w2(ReLU(w3))=w1w2w3x

चूँकि श्रृंखला नियम सिग्मॉइड की तुलना में केवल 2 डेरिवेटिव्स के साथ रहता है, जो कि परतों की संख्या के रूप में लंबे समय तक हो सकता है ।n


कहो कि मैं सभी 3 लेयर वेट को अपडेट करना चाहता था, जहाँ , 3rd लेयर है, w 2 , 2nd लेयर है, w 1 , 3rd लेयर हैw1w2w1

dCw1=(yReLU(w1x))(x)

dCw2=(yReLU(w1ReLU(w2x))(w1x)

dCw3=(yReLU(w1ReLU(w2(ReLU(w3)))(w1w2x)

यदि यह व्युत्पत्ति सही है, तो यह लुप्त होने को कैसे रोकता है? सिग्मॉइड की तुलना में, जहां हमारे पास समीकरण में 0.25 से कई गुना अधिक है, जबकि ReLU में कोई निरंतर मूल्य गुणन नहीं है। यदि हज़ारों परतें हैं, तो वज़न के कारण कई गुना अधिक होगा, तो क्या यह गायब नहीं होगा या धीरे-धीरे विस्फोट होगा?


@NeilSlater आपके उत्तर के लिए धन्यवाद! क्या आप विस्तृत कर सकते हैं, मुझे यकीन नहीं है कि आपका क्या मतलब है?
user1157751

आह, मुझे लगता है कि मुझे पता है कि आपका क्या मतलब था। खैर, कारण है कि मैं इस सवाल को लाया हूँ मुझे यकीन है कि व्युत्पत्ति सही है? मैं चारों ओर खोज की और खरोंच से पूरी तरह से व्युत्पन्न ReLU का एक उदाहरण नहीं मिला?
user1157751

जवाबों:


15

ReLU फ़ंक्शन और इसके व्युत्पन्न की कार्य परिभाषाएँ:

ReLU(x)={0,if x<0,x,otherwise.

ddxReLU(x)={0,if x<0,1,otherwise.

व्युत्पन्न इकाई चरण फ़ंक्शन है । यह x=0 पर एक समस्या को अनदेखा करता है , जहां ग्रेडिएंट को कड़ाई से परिभाषित नहीं किया गया है, लेकिन यह तंत्रिका नेटवर्क के लिए एक व्यावहारिक चिंता नहीं है। उपरोक्त सूत्र के साथ, 0 पर व्युत्पन्न 1 है, लेकिन आप इसे समान रूप से 0 मान सकते हैं, या 0.5 के साथ तंत्रिका नेटवर्क के प्रदर्शन पर कोई वास्तविक प्रभाव नहीं डाल सकते हैं।


सरलीकृत नेटवर्क

उन परिभाषाओं के साथ, आइए अपने उदाहरण नेटवर्क पर एक नज़र डालें।

आप लागत समारोह C = 1 के साथ प्रतिगमन चला रहे हैंC=12(yy^)2। आपनेRको कृत्रिम न्यूरॉन के आउटपुट के रूप मेंपरिभाषित किया है, लेकिन आपने इनपुट मूल्य को परिभाषित नहीं किया है। मैं इसे पूर्णता के लिए जोड़ूंगा - इसेzकहूंगा, परत द्वारा कुछ अनुक्रमण जोड़ूंगा, और मैं वैक्टर के लिए लोअर-केस और मैट्रिस के लिए ऊपरी मामले को पसंद करता हूं, इसलिएr(1)पहली लेयर का आउटपुट,z(1)इसके लिएअपने इनपुटxमें न्यूरॉन को जोड़ने वाले वजन के लिएइनपुट औरW(0)(एक बड़े नेटवर्क में, जो एक गहरीआर सेजुड़ सकता हैxr value instead). I have also adjusted the index number for the weight matrix - why that is will become clearer for the larger network. NB I am ignoring having more than neuron in each layer for now.

Looking at your simple 1 layer, 1 neuron network, the feed-forward equations are:

z(1)=W(0)x

y^=r(1)=ReLU(z(1))

The derivative of the cost function w.r.t. an example estimate is:

Cy^=Cr(1)=r(1)12(yr(1))2=12r(1)(y22yr(1)+(r(1))2)=r(1)y

Using the chain rule for back propagation to the pre-transform (z) value:

Cz(1)=Cr(1)r(1)z(1)=(r(1)y)Step(z(1))=(ReLU(z(1))y)Step(z(1))

This Cz(1) is an interim stage and critical part of backprop linking steps together. Derivations often skip this part because clever combinations of cost function and output layer mean that it is simplified. Here it is not.

To get the gradient with respect to the weight W(0), then it is another iteration of the chain rule:

CW(0)=Cz(1)z(1)W(0)=(ReLU(z(1))y)Step(z(1))x=(ReLU(W(0)x)y)Step(W(0)x)x

. . . because z(1)=W(0)x therefore z(1)W(0)=x

That is the full solution for your simplest network.

However, in a layered network, you also need to carry the same logic down to the next layer. Also, you typically have more than one neuron in a layer.


More general ReLU network

If we add in more generic terms, then we can work with two arbitrary layers. Call them Layer (k) indexed by i, and Layer (k+1) indexed by j. The weights are now a matrix. So our feed-forward equations look like this:

zj(k+1)=iWij(k)ri(k)

rj(k+1)=ReLU(zj(k+1))

In the output layer, then the initial gradient w.r.t. rjoutput is still rjoutputyj. However, ignore that for now, and look at the generic way to back propagate, assuming we have already found Crj(k+1) - just note that this is ultimately where we get the output cost function gradients from. Then there are 3 equations we can write out following the chain rule:

First we need to get to the neuron input before applying ReLU:

  1. Czj(k+1)=Crj(k+1)rj(k+1)zj(k+1)=Crj(k+1)Step(zj(k+1))

We also need to propagate the gradient to previous layers, which involves summing up all connected influences to each neuron:

  1. Cri(k)=jCzj(k+1)zj(k+1)ri(k)=jCzj(k+1)Wij(k)

And we need to connect this to the weights matrix in order to make adjustments later:

  1. CWij(k)=Czj(k+1)zj(k+1)Wij(k)=Czj(k+1)ri(k)

You can resolve these further (by substituting in previous values), or combine them (often steps 1 and 2 are combined to relate pre-transform gradients layer by layer). However the above is the most general form. You can also substitute the Step(zj(k+1)) in equation 1 for whatever the derivative function is of your current activation function - this is the only place where it affects the calculations.


Back to your questions:

If this derivation is correct, how does this prevent vanishing?

Your derivation was not correct. However, that does not completely address your concerns.

The difference between using sigmoid versus ReLU is just in the step function compared to e.g. sigmoid's y(1y), applied once per layer. As you can see from the generic layer-by-layer equations above, the gradient of the transfer function appears in one place only. The sigmoid's best case derivative adds a factor of 0.25 (when x=0,y=0.5), and it gets worse than that and saturates quickly to near zero derivative away from x=0. The ReLU's gradient is either 0 or 1, and in a healthy network will be 1 often enough to have less gradient loss during backpropagation. This is not guaranteed, but experiments show that ReLU has good performance in deep networks.

If there's thousands of layers, there would be a lot of multiplication due to weights, then wouldn't this cause vanishing or exploding gradient?

Yes this can have an impact too. This can be a problem regardless of transfer function choice. In some combinations, ReLU may help keep exploding gradients under control too, because it does not saturate (so large weight norms will tend to be poor direct solutions and an optimiser is unlikely to move towards them). However, this is not guaranteed.


Was a chain rule performed on dCdy^?
user1157751

@user1157751: No, Cy^=Cr(1) because y^=r(1). The cost function C is simple enough that you can take its derivative immediately. The only thing I haven't shown there is the expansion of the square - would you like me to add it?
Neil Slater

But C is 12(yy^)2, don't we need to perform chain rule so that we can perform the derivative on y^? dCdy^=dCdUdUdy^, where U=yy^. Apologize for asking really simple questions, my maths ability is probably causing trouble for you : (
user1157751

If you can make things simpler by expanding. Then please do expand the square.
user1157751

@user1157751: Yes you could use the chain rule in that way, and it would give the same answer as I show. I just expanded the square - I'll show it.
Neil Slater
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.