ढलान की ओर: Gradient Descent और वे दो कदम जिन्हें सब छोड़ देते हैं
learning rate की सटीक सीमा निकालें, फिर 3,600 दिशाओं की brute-force खोज को बिना बताए gradient फिर से खोजते देखें.
इस पेज पर
पिछला अध्याय एक घाटी पर खत्म हुआ था.
यह कोई रूपक वाली घाटी नहीं थी: एक असली curve था, loss को एक ही parameter के विरुद्ध plot किया गया था, जो नीचे झुकता था और फिर ऊपर लौट आता था। और उसके नीचे का loss इसलिए नहीं चुना गया था कि वह साफ-सुथरा था — वह measurements में noise के बारे में एक कथन से derive हुआ था, और squared error एक convention की जगह consequence के रूप में बाहर आया था.
तो हमारे पास एक bottom वाला landscape है, और यह मानने की वजह है कि bottom ही सही जगह है। जो हमारे पास नहीं है, वह वहाँ पहुँचने का तरीका है.
यह अध्याय वही बनाता है, और यह वही algorithm है जो इस course के बाकी हर model को train करता है — हर एक को, बिना अपवाद, उन models तक भी जिनमें सैकड़ों अरब parameters हैं। यह लगभग बीस lines में समा जाता है। कठिन दो हिस्से उन बीस lines में नहीं हैं, और वही दो चीज़ें हैं जिन्हें लगभग हर explanation छोड़ देती है:
- minus sign क्यों। update gradient को subtract करता है। हर tutorial इसे लिखता है; बहुत कम बताते हैं कि gradient वह direction क्यों है जो ऊपर जाता है, और यही एकमात्र fact है जो minus sign को विश्वास की छलांग से कुछ अधिक बनाता है.
- कदम कितना बड़ा। “बहुत बड़ा diverge करता है, बहुत छोटा slow है” सच है और बेकार है। एक exact number है, वह loss से compute किया जा सकता है, और यह chapter उसे दो बार compute करता है — एक बार toy parabola के लिए और एक बार actual data के लिए.
setup, और आप सिर्फ search क्यों नहीं कर सकते
सेक्शन का लिंक: setup, और आप सिर्फ search क्यों नहीं कर सकतेताकि यह chapter अपने-आप खड़ा रहे, फिर से कहें: Chapter 1 की conveyor belt से वे आठ parts, लेकिन सवाल अलग। accept or reject नहीं — वह बाद में लौटेगा — बल्कि किसी part की width से उसका weight predict करना.
import numpy as np
WIDTH = np.array([18.0, 19.5, 20.2, 21.0, 24.0, 25.5, 23.0, 26.0])
WEIGHT = np.array([47.0, 52.0, 49.0, 55.0, 61.0, 66.0, 70.0, 58.0])
x = WIDTH - WIDTH.mean() # 22.15 mm
y = WEIGHT - WEIGHT.mean() # 57.25 gmeasurements centred हैं, ठीक Chapter 1 की तरह और उसी वजह से जो इस chapter के खत्म होने से पहले ब्याज सहित लौटेगी। model एक line है, , और loss वह mean squared error है जिसे पिछले chapter ने derive किया था:
दो parameters। फिर बहुत सारी values try क्यों न करें? चलिए सच में करते हैं — से और से तक एक grid, के steps में:
grid 501 x 1001 = 501,501 evaluations in 3.67 s
best found: a = 2.1000, b = -0.0000, L = 24.592450दो numbers को दो decimal places तक pin down करने के लिए आधा million evaluations — और वह second एक machine पर wall clock है, इसलिए rerun तीन से छह के बीच कहीं भी land कर सकता है; evaluation count और minimum वे हिस्से हैं जो reproduce होते हैं। इस chapter के अंत में Gradient Descent आठ steps में चार decimal places और छत्तीस में पूरा float64 answer पा लेता है.
लेकिन speed argument नहीं है, और यही point पूरे course का फैसला करता है। Grid search की cost parameters के लिए, हर एक पर values होने पर, evaluations है। हर axis पर एक thousand values के साथ:
| model | parameters | grid evaluations |
|---|---|---|
| यह line | 2 | |
| Chapter 5 का XOR network | 9 | |
| एक छोटा multilayer network | 20,000 |
तीसरी row कोई बड़ा number नहीं है, यह meaningless number है — observable universe में लगभग atoms हैं। models बढ़ने पर search धीमी नहीं होती; वह मौजूद रहना बंद कर देती है। आगे जो कुछ भी आता है, वह उस table की वजह से मौजूद है.
derivative एक measurement है जिसे आप ले सकते हैं
सेक्शन का लिंक: derivative एक measurement है जिसे आप ले सकते हैंएक पल के लिए fix कर दें ताकि एक parameter और एक curve हो, वही picture जो पिछले chapter ने छोड़ी थी। उस पर एक point लें, , और पूछें: अगर मैं को एक छोटे amount से nudge करूँ, तो loss per unit nudge कितना move करता है?
वह ratio rise over run है — curve पर दो points से गुजरती straight line की slope। जैसे-जैसे shrink होता है, दोनों points साथ खिसकते हैं और line tangent बन जाती है। उसकी slope derivative है: में change के per unit loss जिस rate से बदलता है। यह किसी चीज़ का approximation नहीं है, और न ही कोई infinitely small quantity। यह ordinary ratios की limit है.
इसे run करना worthwhile है, क्योंकि numbers ऐसी बात कहते हैं जो definition नहीं कहती:
def loss1(a):
return np.mean((a * x - y) ** 2)
for h in [1.0, 1e-2, 1e-4, 1e-6, 1e-8, 1e-10, 1e-12, 1e-14]:
q = (loss1(1.0 + h) - loss1(1.0)) / h
print(f"h = {h:<8.0e} slope estimate = {q:.10f} error = {abs(q + 16.385):.3e}")h = 1e+00 slope estimate = -8.9400000000 error = 7.445e+00
h = 1e-02 slope estimate = -16.3105500000 error = 7.445e-02
h = 1e-04 slope estimate = -16.3842555001 error = 7.445e-04
h = 1e-06 slope estimate = -16.3849925556 error = 7.444e-06
h = 1e-08 slope estimate = -16.3850003787 error = 3.787e-07
h = 1e-10 slope estimate = -16.3850444324 error = 4.443e-05
h = 1e-12 slope estimate = -16.3851154866 error = 1.155e-04
h = 1e-14 slope estimate = -17.0530256582 error = 6.680e-01यहाँ दो चीज़ें होती हैं और दोनों load-bearing हैं.
error बस vaguely के proportional नहीं है — यह exactly है। को सौ से divide करें, error हर बार four significant figures तक सौ से divide होता है। वह constant decoration नहीं है: यह loss के second derivative का half है, और उस idea का पहला appearance है जो अब से दो sections बाद आएगा — कि किसी point के पास curve, line plus के proportional correction जैसा दिखता है.
और फिर pattern टूट जाता है। से नीचे estimate खराब हो जाता है, और पर यह second digit में गलत है। कुछ mathematical नहीं हुआ; पिछले chapter का floating-point box हुआ। और अपने पहले ten digits में agree करते हैं, उन्हें subtract करने से वे digits destroy हो जाते हैं, और wreckage को tiny number से divide करने पर जो बचता है वह amplify हो जाता है। एक best है — यहाँ के आसपास, लगभग machine epsilon का square root — और उससे छोटा जाना more careful नहीं, less careful है। इसे याद रखें; इस chapter के अंत में एक function इस पर depend करता है.
calculus से exact slope, measurement के बजाय, है। इसलिए हम measuring रोककर deriving शुरू कर सकते हैं.
composition, और chain rule
सेक्शन का लिंक: composition, और chain ruleयह वह idea है जिस पर course का बाकी हिस्सा बना है, एक बार साफ-साफ stated.
दो functions को compose करना यानी एक को दूसरे में feed करना: । बस.
deep network composition जैसा नहीं है। वह है composition। एक layer एक function है; layers stack करना उन्हें compose करना है; “depth” chain में functions की संख्या है। जब Chapter 5 एक network बनाता है, वह बना रहा होता है और कुछ नहीं। इसका मतलब है कि हमारे purposes के लिए calculus का single most important rule वही है जो composition को differentiate करता है:
rates multiply करते हैं। अगर , से तीन गुना तेजी से बदलता है, और , से दुगुना तेजी से बदलता है, तो , से छह गुना तेजी से बदलता है। यही पूरा content है, और इसी वजह से ten layers से पीछे pass होता signal ten numbers से multiplied होता है — इसलिए Chapter 6 एक section इस पर खर्च करता है कि क्या होता है जब वे numbers सभी one से थोड़ा कम होते हैं.
इसे अपने loss पर use करें। residual लिखें, ताकि । हर , inner function के through पर depend करता है, जिसका derivative है। Chain rule, term by term:
ये curly symbols एक partial derivative mark करते हैं: एक variable के respect में differentiate करें और बाकी सबको constant मानें। कुछ नया नहीं होता — यह वही limit है जो पहले थी, बस एक axis के along ली गई। partials को vector में collect करें और आपके पास gradient है:
point पर वह vector है। दो numbers। सवाल यह है कि उनका मतलब क्या है, और यही पहला step है जिसे सब छोड़ देते हैं.
gradient uphill क्यों point करता है
सेक्शन का लिंक: gradient uphill क्यों point करता हैgradient axes के along slopes का vector है। हमने बस इतना ही prove किया है। यह obvious नहीं है — और obvious होना भी नहीं चाहिए — कि उन्हें vector में assemble करने से कोई चीज़ किसी particular direction में point करेगी.
तो वह चीज़ define करें जो हम सच में चाहते हैं। एक unit vector चुनें, एक direction। directional derivative वह rate है जिससे उस direction में चलते हुए loss बदलता है:
Chain rule इसे computable बना देता है। के along चलना, को rate पर और को rate पर बदलता है, और contributions add होते हैं:
किसी भी direction में change का rate gradient और उस direction का dot product है। और अब punchline, जो geometry की one line है। vectors के बीच angle के साथ dot product लिखते हुए,
क्योंकि की length 1 है। जिस एक चीज़ को आप control करते हैं वह है, जो पर largest और half turn, degrees पर smallest है। इसलिए:
- steepest ascent खुद के along है, और वहाँ slope exactly है.
- steepest descent के along है, और वहाँ slope है.
- gradient के perpendicular, loss बिल्कुल नहीं बदलता। इसलिए contour map की lines gradient को right angles पर cross करती हैं.
यही minus sign है। कोई convention नहीं, कोई sign flip नहीं जिसे किसी ने चुना: fastest decrease की direction negative gradient है क्योंकि half turn पर minimised होता है, और किसी अन्य कारण से नहीं.
क्योंकि यह claim सभी directions के बारे में है, इसे सभी directions के against test करें। उनमें से 3,600 sample करें, हर tenth of a degree पर एक, और हर एक को nudging से measure करें:
theta = np.array([1.0, 4.0])
g = grad(theta)
print("gradient ", g)
print("its length ", np.linalg.norm(g))
print("its angle ", np.degrees(np.arctan2(g[1], g[0])) % 360, "degrees")
best = max(
((loss(theta + 1e-6 * u) - loss(theta - 1e-6 * u)) / 2e-6, np.degrees(ang))
for ang, u in (
(a, np.array([np.cos(a), np.sin(a)])) for a in np.arange(3600) * 2 * np.pi / 3600
)
)
print("steepest slope", best[0], "at", best[1], "degrees")gradient [-16.385 8. ]
its length 18.23371122399386
its angle 153.97598928042032 degrees
steepest slope 18.233709624837502 at 154.0 degreesएक search जिसे gradients के बारे में कुछ नहीं पता, 3,600 directions में, अपनी steepest climb 154.0 degrees पर पाती है — gradient की अपनी direction, search की 0.1-degree resolution के भीतर। और जो slope उसे वहाँ मिलती है, 18.2337, वह six figures तक gradient की length है। theorem gradients के meaning की story नहीं है; यह measurable fact है, और यही measurement है.
downhill एक छोटा step सच में मदद क्यों करता है
सेक्शन का लिंक: downhill एक छोटा step सच में मदद क्यों करता हैअब दूसरा skipped step। हमें पता है कि down कौन-सी direction है। इससे यह follow नहीं होता कि उस तरफ चलने से loss कम होगा, क्योंकि “down” infinitesimal nudge के बारे में statement है और step infinitesimal नहीं है.
bridge है linearisation। किसी point के पास, smooth function अपनी tangent plus correction होता है:
यह first-order Taylor expansion है। discarded curvature है — वही term जिसने slope table के estimate को exactly से गलत बनाया था। उस step को डालें जो हम लेना चाहते हैं, :
loss से drop करता है। इसका हर हिस्सा non-negative है, इसलिए promise real है — काफी small के लिए, क्योंकि neglected term की तरह grow करता है और eventually उसे खा जाता है। यही पूरी theory है। यहाँ promise निभता है, और फिर टूटता है:
eta = 0.2 promised 66.49364500 delivered -16.01619240 ratio -0.240868
eta = 0.1 promised 33.24682250 delivered 12.61936315 ratio 0.379566
eta = 0.01 promised 3.32468225 delivered 3.11840766 ratio 0.937957
eta = 0.001 promised 0.33246822 delivered 0.33040548 ratio 0.993796
eta = 0.0001 promised 0.03324682 delivered 0.03322620 ratio 0.999380
eta = 1e-05 promised 0.00332468 delivered 0.00332448 ratio 0.999938इसे bottom से पढ़ें। जैसे shrink होता है, delivered drop promised one पर converge करता है — ratio 0.99938, फिर 0.99994 — यानी Taylor का theorem correct है। top से पढ़ें और पर delivered “drop” negative sixteen है। step downhill गया और loss ऊपर गया.
तो update rule है
और इसके साथ एक condition आती है जिसे कोई state नहीं करता, कि काफी small हो। Exactly किसके compared to small, यह अगला section है.
learning rate की ceiling है, और वह computable है
सेक्शन का लिंक: learning rate की ceiling है, और वह computable हैसबसे simple valley से शुरू करें, , जहाँ । Gradient Descent का एक step है
position हर step पर से multiplied है। यह geometric sequence है, और geometric sequences का exactly one rule है: multiplier absolute value में 1 से smaller हो तो वे shrink करते हैं और otherwise grow करते हैं। इसलिए , जो है.
boundary exactly पर है। “लगभग 1” नहीं, “1 usually too big है” नहीं। पर multiplier है और point हमेशा और के बीच bounce करता है, न approach करता है न escape। इसके नीचे, converge; इसके ऊपर, diverge। interval पर फिर split होता है, जहाँ multiplier sign बदलता है: उससे नीचे approach monotone है, उससे ऊपर point overshoot करता है और sides alternate करता है, और exactly पर multiplier 0 है और one single step minimum पर land करता है.
algebra की four lines से four regimes। जाइए और boundaries खुद cross कीजिए:
और अब interesting one:
अब general rule, जो same argument से निकलता है। multiplier वास्तव में था, और किसी minimum के पास multi-parameter loss में हर direction के लिए ऐसा one number होता है — second derivatives की matrix के eigenvalues। हर direction को एक साथ stable होना पड़ता है, इसलिए ceiling largest से set होती है:
के लिए, , ceiling 1, जो हमने अभी derive किया। हमारी belt के लिए, second-derivative matrix है जिसमें inputs की two-column matrix है, और उसके eigenvalues 2 और 14.89 हैं, इसलिए ceiling है। यह पाँच significant figures वाली prediction है। इसे test करें:
lr=0.1343 -> L = 24.5924
lr=0.13431 -> L = 24.5924
lr=0.13432 -> L = 4707.8 BLEW UP
lr=0.13433 -> L = 4.00452e+16 BLEW UP
lr=0.1344 -> L = 1.18229e+107 BLEW UPlinear algebra की एक line और for loop की hundred thousand iterations के बीच five decimal places की agreement.
और यहीं Chapter 1 वापस आता है। ऊपर सबने centred measurements use किए। raw millimetres और grams पर identical code run करें और eigenvalues 2 और 14.89 के बजाय 0.0298 और 998.1 हैं। ceiling 0.134 से 0.002004 पर collapse हो जाती है — उतनी ही exact तरह, lr=0.002003 पर converging और lr=0.002004 पर blowing up.
ceiling से भी bad eigenvalues के बीच का ratio है। condition number measure करता है कि valley round होने से कितनी दूर है: एक long thin trench rate को steep walls के लिए काफी small होने को force करता है, और फिर trench का floor उसी crawl पर walked होता है। हमारा centred में 7.44 से raw में 33,452 हो जाता है। हर version जिस best rate को ले सकता है, उसके साथ:
| features | condition number | best rate | optimum के 1% के भीतर steps |
|---|---|---|---|
| centred | 7.44 | 0.1184 | 10 |
| raw millimetres and grams | 33,452 | 0.0020037 | 79,513 |
same data, same code, अंत में same answer — और आठ हजार गुना काम, क्योंकि किसी ने mean subtract नहीं किया। Chapter 1 में इसी omission ने perceptron को epochs में छह हजार का factor cost किया था, और वहाँ diagnosis geometric था: data origin से दूर float कर रहा था। यहाँ optimisation costume में वही geometry है, और यही वजह है कि input normalisation hygiene advice नहीं बल्कि arithmetic है.1
बीस lines
सेक्शन का लिंक: बीस linesऊपर कुछ भी library नहीं चाहता था। पूरा optimiser यहाँ है.
def loss(theta):
a, b = theta
return np.mean((a * x + b - y) ** 2)
def grad(theta):
a, b = theta
residual = a * x + b - y
return np.array([np.mean(2 * residual * x), np.mean(2 * residual)])
def descend(theta, lr, steps):
theta = np.array(theta, dtype=float)
for _ in range(steps):
theta = theta - lr * grad(theta)
return theta
theta = descend([0.0, 0.0], lr=0.05, steps=60)
print(theta, loss(theta))[ 2.10040296e+00 -2.76445533e-15] 24.592448791134984इन आठ points के लिए closed-form least-squares answer , है, के loss के साथ। loop ने इसे eight significant figures तक ढूँढ लिया, बिना यह जाने कि closed form exist करता है — जो matter करता है, क्योंकि Chapter 5 से आगे ऐसा कोई नहीं होगा.
trajectory, क्योंकि इसे देखना ही point है:
0 a=0.000000 b=0.000000 L=57.437500
1 a=1.563750 b=0.000000 L=26.736582
2 a=1.963288 b=-0.000000 L=24.732418
5 a=2.098116 b=-0.000000 L=24.592488
10 a=2.100400 b=-0.000000 L=24.592449
60 a=2.100403 b=-0.000000 L=24.592449distance का अधिकांश first two steps में cover हो जाता है, क्योंकि gradient तब largest होता है जब आप bottom से सबसे दूर होते हैं और approach करने पर shrink होता है। Gradient Descent minimum के पास automatically slow down करता है। यह feature है और Chapter 6 में, problem भी.
slope और कहाँ zero है
सेक्शन का लिंक: slope और कहाँ zero हैअब तक के argument में एक hole है। step तब रुकता है जब , और हम इसे “the minimum” कहते आए हैं। zero gradient वाला point critical point है, और minimum होना उसका केवल एक तरीका है:
- एक local minimum: हर direction में uphill, लेकिन संभव है कि कहीं भी lowest ऐसा point न हो;
- एक local maximum: हर direction में downhill;
- एक saddle point: कुछ directions में uphill और कुछ में downhill। surface में है, जो origin पर zero है, जहाँ function same time पर -axis के along minimum और -axis के along maximum है.
Gradient Descent इन्हें अलग नहीं बता सकता, क्योंकि वह हमेशा सिर्फ gradient देखता है, और gradient तीनों पर zero है.
हमारी line का एक critical point है और वही answer है — linear model पर squared-error loss convex है, एक single bowl, और उस पर descent global minimum ढूँढने में fail नहीं हो सकता। यह property इस course से contact में survive नहीं करती। neural network का loss convex नहीं होता, और Chapter 5 से आगे “the minimum” कोई ऐसी चीज़ नहीं है जो exist करती हो: कई minima होते हैं, अलग-अलग depths के, और आपको कौन-सा मिलता है यह इस पर depend करता है कि आप कहाँ से शुरू हुए। यह one sentence है और one sentence ही रहेगा, क्योंकि theory बड़ी है और practical consequence छोटा.
आप पूरा consequence एक curve पर देख सकते हैं। लें, जिसमें अलग depths की दो valleys हैं:
x = -1.046681 f(x) = -0.352386 minimum
x = 0.101031 f(x) = 0.005026 maximum
x = 0.945649 f(x) = -0.152639 minimumshallow valley में land करना loss में 56.7% worse है, और algorithm के पास जानने का कोई तरीका नहीं, क्योंकि valley के अंदर से हर direction uphill है। Gradient Descent में इसका कोई repair नहीं है और कोई आने वाला भी नहीं। practice में जो है, वह यह finding है कि यह picture जितना suggest करती है उससे बहुत कम matter करता है — real network की बहुत high dimensions में most critical points traps के बजाय saddles निकलते हैं,2 और Chapter 5 measure करता है कि एक small network सच में कितनी बार stuck होता है.
cheaper steps: stochastic, minibatch, momentum
सेक्शन का लिंक: cheaper steps: stochastic, minibatch, momentumऊपर grad के बारे में एक बात आपको bother करनी चाहिए: यह हर step के लिए entire dataset पर sum करता है। आठ parts कुछ नहीं। एक million का मतलब parameters को एक बार move करने के लिए एक million gradient computations है.
escape यह है कि gradient एक average है, और average को sample से estimate किया जा सकता है। random handful — एक minibatch — पर इसे compute करें, और उस पर step लें। estimate noisy है; वह unbiased भी है, और hundreds of cheap noisy steps एक expensive exact one को beat करते हैं। hundred thousand synthetic parts पर, steps के बजाय per-example gradients गिनते हुए:
| method | optimum के 0.1% के भीतर steps | per-example gradients |
|---|---|---|
| full batch | 7 | 700,000 |
| minibatch of 32 | 100 | 3,200 |
| one example at a time | 17,580 | 17,580 |
same जगह पहुँचने के लिए two hundred and nineteen times less arithmetic। और extreme — one example at a time, Robbins और Monro3 की original stochastic approximation — winner नहीं है: यह 32 के batches से five times worse है, क्योंकि matrices multiply करने वाले hardware पर 32 examples की cost one से लगभग अधिक नहीं होती, जबकि noise batch size के square root के साथ गिरता है। यही trade-off वजह है कि आप जो भी training script पढ़ेंगे उसमें batch_size होगा.
Momentum दूसरा cheap fix है, और उसका निशाना सीधे trench है। badly conditioned valley में steps narrow direction के across zig-zag करते हैं जबकि long one के along creep करते हैं। Momentum past gradients का running average रखता है, ताकि oscillating components cancel हों और consistent one accumulate हो:4
दो extra lines। raw uncentred belt पर — condition number 33,452, हमारे पास worst case — best rate पर जो plain descent ले सकता है:
momentum beta=0.0 -> 79,513 steps to 1%
momentum beta=0.9 -> 1,609 steps to 1%
momentum beta=0.99 -> 461 steps to 1%दो lines of code के लिए 172 का factor। Chapter 6 इसे Adam में बदलता है; mechanism पहले से यहाँ है.
वह check जिसकी आपको Chapter 5 में ज़रूरत होगी
सेक्शन का लिंक: वह check जिसकी आपको Chapter 5 में ज़रूरत होगीइस chapter में हर gradient hand-derived था और इसलिए wrong हो सकता था। fix शुरुआत की slope table है: derivative को numerically measure करें और compare करें। central difference, , use करें, जो leading error term cancel करता है और same के लिए बहुत अधिक accurate है.
def numeric_grad(f, theta, h=1e-5):
theta = np.asarray(theta, dtype=float)
out = np.zeros_like(theta)
for i in range(theta.size):
bump = np.zeros_like(theta)
bump[i] = h
out[i] = (f(theta + bump) - f(theta - bump)) / (2 * h)
return out
def gradcheck(f, df, theta, h=1e-5):
analytic = np.asarray(df(theta), dtype=float)
numeric = numeric_grad(f, theta, h)
return np.max(np.abs(analytic - numeric) / np.maximum(1e-8, np.abs(analytic) + np.abs(numeric)))comparison का relative form matter करता है: का absolute difference size के gradient पर disaster है और size वाले पर irrelevant.
relative error: 1.8929136036763527e-11
with 2 dropped: 0.33333333331650744पहली line ऊपर का hand-derived gradient है। दूसरी वही function है जिसमें एक component से factor of 2 छूट गया है — single character का typo — और check उसे तुरंत पकड़ लेता है। लगभग से नीचे कुछ भी agreement है; से ऊपर कुछ भी bug है। इस function को रखें: Chapter 5 इसे automatic differentiation engine debug करने के लिए use करता है, और यही एकमात्र वजह है कि wrong gradient findable है.
यह आगे कहाँ जाता है
सेक्शन का लिंक: यह आगे कहाँ जाता हैइस chapter की हर चीज़ एक unstated assumption पर टिकी थी: कि आप लिख सकते हैं.
दो parameters वाली line के लिए, वह algebra की one line थी। यह लगभग तुरंत one line होना बंद कर देता है। किसी symbolic algebra system से network के loss का derivative single first-layer weight के respect में, single example के लिए पूछें, और answer में arithmetic count करें:
| network | one partial derivative में operations |
|---|---|
| four hidden units, one layer | 40 |
| four hidden units, two layers | 301 |
| four hidden units, three layers | 1,717 |
तीसरी row 57 parameters वाला network है — इतना छोटा network कि Chapter 6 में footnote होता — और उसका gradient हाथ से लिखने का मतलब one training example के लिए लगभग 97,869 operations है। कोई notation इसे rescue नहीं करता। जो rescue करता है वह observation है कि composition पर apply किया गया chain rule enormous structure रखता है, वही intermediate quantities बार-बार appear होती हैं, और उन्हें सही order में compute करने से all derivatives roughly one forward pass की price में मिल जाते हैं। वह Chapter 5 है.
लेकिन पहले एक छोटा problem है, और वह तुरंत इंतज़ार कर रहा है.
अब हमारे पास ऐसी machine है जो किसी भी differentiable loss पर downhill roll करेगी। इसे belt के original question — accept or reject, target जो 1 या 0 है — पर point करें, output पर sigmoid लगाएँ ताकि यह probability predict करे, और squared error minimise करें। यह run करेगा। यह तब भी मुश्किल से move करेगा जब यह सबसे अधिक wrong होगा, और gradient बताता है क्यों:
| output | prediction | truth | gradient with squared error | gradient with cross-entropy |
|---|---|---|---|---|
| 0.5000 | 1 | |||
| 0.1192 | 1 | |||
| 0.0025 | 1 | |||
| 1 |
एक model जो confidently, catastrophically wrong है — answer 1 होने पर 0.0000454 predict कर रहा है — का squared-error gradient produce करता है। उसे पता ही नहीं कि वह trouble में है। दूसरी column, एक ऐसे loss से जिसे हमने अभी derive नहीं किया है, 1.0 report करती है: maximum urgency, exactly जहाँ deserved है.
जिससे वह सवाल उठता है जिससे अगला chapter शुरू होता है। पिछले chapter ने कहा था कि loss noise के बारे में assumption है, और squared error Gaussian noise assume करता है। yes-or-no answer का कौन-सा noise model होता है — और जब आप उसी derivation को उस पर run करते हैं तो कौन-सा loss निकलता है?
Sources and method
सेक्शन का लिंक: Sources and methodmethod इन सब से पुराना है: Cauchy ने 1847 में Académie des Sciences को एक note में इसे describe किया था, systems of equations solve करने के तरीके के रूप में, उनके squared residuals के sum पर downhill चलते हुए। इस chapter के साथ पढ़ने लायक और भी: Sebastian Ruder का An overview of gradient descent optimization algorithms (arXiv:1609.04747), जो fourteen readable pages में momentum से Adam तक cover करता है; Nocedal और Wright की Numerical Optimization (2nd ed., Springer, 2006) का chapter 3, जिसका theorem 3.3 condition number के terms में quadratic पर steepest descent की convergence rate देता है — यही theory है जिसके पीछे conditioning step count तय करती है, हालांकि वह line search treat करता है न कि ऊपर measured fixed-step ceiling, या Deisenroth, Faisal और Ong की Mathematics for Machine Learning के §5.8 और §7.1 उसी ground के लिए less machinery के साथ; Prince की Understanding Deep Learning का §6.1 और Goodfellow, Bengio और Courville की Deep Learning का §4.3; Dive into Deep Learning §12.1–12.3, जिसमें minibatch analysis यहाँ की room से अधिक measurements के साथ है; और Géron की Hands-On Machine Learning (3rd ed.) का chapter 4, learning rate को derive करने की बजाय tune करने वाली चीज़ के रूप में सबसे practical treatment। MIT 6.390 notes classification से पहले Gradient Descent रखते हैं, जैसे यह course करता है और same reason से.
संदर्भ
सेक्शन का लिंक: संदर्भ-
LeCun, Y., Bottou, L., Orr, G. B. and Müller, K.-R. Efficient BackProp, in Neural Networks: Tricks of the Trade (Springer, 1998), pp. 9–50. Section 4.3 recommendation देता है और section 5.1 ऊपर detail box में use किया गया argument: inputs को centre और scale करने से second-derivative matrix के eigenvalues बदलते हैं, और इसलिए steps की संख्या, सिर्फ numerical comfort नहीं. ↩
-
Dauphin, Y. N., Pascanu, R., Gulcehre, C., Cho, K., Ganguli, S. and Bengio, Y. Identifying and attacking the saddle point problem in high-dimensional non-convex optimization, arXiv:1406.2572 (2014). यह argument कि high dimensions में critical points overwhelmingly local minima के बजाय saddles होते हैं, क्योंकि minimum के लिए हजारों directions में से हर एक का एक साथ upward curve करना आवश्यक है. ↩
-
Robbins, H. and Monro, S. A Stochastic Approximation Method. Annals of Mathematical Statistics 22(3), pp. 400–407 (1951). वह paper जिसने establish किया कि gradient का noisy estimate enough है, अगर step size सही तरह से shrink करे. ↩
-
Polyak, B. T. Some methods of speeding up the convergence of iteration methods. USSR Computational Mathematics and Mathematical Physics 4(5), pp. 1–17 (1964). heavy-ball method, जो ऊपर का momentum update है, backpropagation के इस field तक पहुँचने से twenty-two years पहले. ↩