شبکه های عصبی: تمرین های تعاملی
با مجموعهها، منظم بمانید ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
در تمرینهای تعاملی زیر، عملکرد درونی شبکههای عصبی را بیشتر بررسی خواهید کرد. ابتدا، خواهید دید که چگونه تغییرات پارامتر و هایپرپارامتر بر پیش بینی های شبکه تأثیر می گذارد. سپس از چیزهایی که آموخته اید برای آموزش شبکه عصبی برای تطبیق داده های غیرخطی استفاده خواهید کرد.
تمرین 1
ویجت زیر یک شبکه عصبی را با پیکربندی زیر راه اندازی می کند:
- لایه ورودی با 3 نورون حاوی مقادیر
0.00
، 0.00
و 0.00
- لایه پنهان با 4 نورون
- لایه خروجی با 1 نورون
- تابع فعال سازی ReLU برای تمام گره های لایه پنهان و گره خروجی اعمال می شود
تنظیمات اولیه شبکه را مرور کنید (توجه: هنوز روی دکمه های ▶️ یا >| کلیک نکنید )، و سپس کارهای زیر ویجت را کامل کنید.
وظیفه 1
مقادیر سه ویژگی ورودی به مدل شبکه عصبی همه 0.00
است. روی هر یک از گره های شبکه کلیک کنید تا تمام مقادیر اولیه را ببینید. قبل از زدن دکمه Play ( ▶️ ) به این سوال پاسخ دهید:
به نظر شما چه نوع مقدار خروجی تولید خواهد شد: مثبت، منفی یا 0؟
مقدار خروجی مثبت
شما مقدار خروجی مثبت را انتخاب کردید. دستورالعملهای زیر را برای استنتاج روی دادههای ورودی دنبال کنید و ببینید درست میگویید یا خیر.
مقدار خروجی منفی
شما مقدار خروجی منفی را انتخاب کردید. دستورالعملهای زیر را برای استنتاج روی دادههای ورودی دنبال کنید و ببینید درست میگویید یا خیر.
مقدار خروجی 0
شما مقدار خروجی را 0 انتخاب کردید. دستورالعملهای زیر را برای استنتاج روی دادههای ورودی دنبال کنید و ببینید درست میگویید یا خیر.
اکنون روی دکمه Play (▶️) در بالای شبکه کلیک کنید و تمام مقادیر لایه پنهان و گره خروجی را تماشا کنید. پاسخ شما در بالا درست بود؟
برای توضیح اینجا را کلیک کنید
مقدار دقیق خروجی که دریافت می کنید بر اساس نحوه اولیه سازی تصادفی پارامترهای وزن و بایاس متفاوت خواهد بود. با این حال، از آنجایی که هر نورون در لایه ورودی دارای مقدار 0 است، وزنهای مورد استفاده برای محاسبه مقادیر گره لایه پنهان همگی صفر خواهند شد. برای مثال، اولین محاسبه گره لایه پنهان به صورت زیر خواهد بود:
y = ReLU(w 11 * 0.00 + w 21 * 0.00 + w 31 * 0.00 + b)
y = ReLU(b)
بنابراین مقدار هر گره لایه پنهان برابر با مقدار ReLU بایاس (b) خواهد بود که اگر b منفی باشد 0 و اگر b 0 یا مثبت باشد، خود b خواهد بود.
سپس مقدار گره خروجی به صورت زیر محاسبه می شود:
y = ReLU(w 11 * x 11 + w 21 * x 21 + w 31 * x 31 + w 41 * x 41 + b)
وظیفه 2
قبل از اصلاح شبکه عصبی به سوال زیر پاسخ دهید:
اگر بعد از اولین لایه پنهان، یک لایه مخفی دیگر به شبکه عصبی اضافه کنید و به این لایه جدید 3 گره بدهید و تمام پارامترهای ورودی و وزن/بایاس را ثابت نگه دارید، محاسبات کدام گره های دیگر تحت تأثیر قرار می گیرد؟
تمام گره های شبکه، به جز گره های ورودی
شما همه گره های شبکه را انتخاب کردید، به جز گره های ورودی . دستورالعمل های زیر را دنبال کنید تا شبکه عصبی را به روز کنید و ببینید درست می گویید یا خیر.
فقط گره ها در اولین لایه پنهان
شما فقط گره های اولین لایه پنهان را انتخاب کردید. دستورالعمل های زیر را دنبال کنید تا شبکه عصبی را به روز کنید و ببینید درست می گویید یا خیر.
فقط گره خروجی
شما فقط گره خروجی را انتخاب کردید. دستورالعمل های زیر را دنبال کنید تا شبکه عصبی را به روز کنید و ببینید درست می گویید یا خیر.
اکنون شبکه عصبی را تغییر دهید تا یک لایه پنهان جدید با 3 گره به صورت زیر اضافه شود:
- روی دکمه + در سمت چپ لایه مخفی متن 1 کلیک کنید تا یک لایه مخفی جدید قبل از لایه خروجی اضافه کنید.
- روی دکمه + بالای لایه جدید مخفی دو بار کلیک کنید تا 2 گره دیگر به لایه اضافه شود.
پاسخ شما در بالا درست بود؟
برای توضیح اینجا را کلیک کنید
فقط گره خروجی تغییر می کند. از آنجایی که استنتاج برای این شبکه عصبی "تغذیه به جلو" است (محاسبات از ابتدا تا انتها پیشرفت می کنند)، افزودن یک لایه جدید به شبکه تنها بر گره های بعد از لایه جدید تأثیر می گذارد، نه بر روی آن هایی که قبل از آن هستند.
وظیفه 3
روی گره دوم (از بالا) در اولین لایه پنهان گراف شبکه کلیک کنید. قبل از هر گونه تغییر در پیکربندی شبکه، به سوال زیر پاسخ دهید:
اگر مقدار وزن w 12 را تغییر دهید (در زیر اولین گره ورودی، x 1 نمایش داده می شود)، محاسبات کدام گره های دیگر می تواند برای برخی از مقادیر ورودی تحت تأثیر قرار گیرد؟
هیچ کدام
هیچ کدوم رو انتخاب نکردی دستورالعمل های زیر را دنبال کنید تا شبکه عصبی را به روز کنید و ببینید درست می گویید یا خیر.
گره دوم در اولین لایه پنهان، تمام گره ها در لایه پنهان دوم و گره خروجی.
شما گره دوم را در اولین لایه پنهان، تمام گره ها را در لایه پنهان دوم و گره خروجی را انتخاب کردید. دستورالعمل های زیر را دنبال کنید تا شبکه عصبی را به روز کنید و ببینید درست می گویید یا خیر.
تمام گره های اولین لایه پنهان، لایه پنهان دوم و لایه خروجی.
شما تمام گره ها را در اولین لایه پنهان، دومین لایه پنهان و لایه خروجی انتخاب کردید. دستورالعمل های زیر را دنبال کنید تا شبکه عصبی را به روز کنید و ببینید درست می گویید یا خیر.
اکنون، در قسمت متن وزن w 12 (در زیر اولین گره ورودی، x 1 نمایش داده می شود) کلیک کنید، مقدار آن را به 5.00
تغییر دهید و Enter را بزنید. به روز رسانی های نمودار را مشاهده کنید.
پاسخ شما درست بود؟ هنگام تأیید پاسخ خود مراقب باشید: اگر مقدار گره تغییر نکند، آیا این بدان معناست که محاسبه اساسی تغییر نکرده است؟
برای توضیح اینجا را کلیک کنید
تنها گره ای که در اولین لایه پنهان تحت تأثیر قرار می گیرد، گره دوم است (همانی که روی آن کلیک کردید). محاسبات مقدار برای گره های دیگر در اولین لایه پنهان حاوی w 12 به عنوان پارامتر نیست، بنابراین آنها تحت تأثیر قرار نمی گیرند. تمام گره های لایه پنهان دوم تحت تأثیر قرار می گیرند، زیرا محاسبات آنها به مقدار گره دوم در لایه پنهان اول بستگی دارد. به طور مشابه، مقدار گره خروجی تحت تأثیر قرار می گیرد زیرا محاسبات آن به مقادیر گره ها در لایه پنهان دوم بستگی دارد.
آیا فکر میکنید پاسخ «هیچکدام» است زیرا با تغییر مقدار وزن، هیچ یک از مقادیر گره در شبکه تغییر نمیکند؟ توجه داشته باشید که یک محاسبه اساسی برای یک گره ممکن است بدون تغییر مقدار گره تغییر کند (به عنوان مثال، ReLU(0) و ReLU(-5) هر دو خروجی 0 تولید می کنند). تنها با نگاه کردن به مقادیر گره، در مورد اینکه چگونه شبکه تحت تأثیر قرار گرفته است، فرضیاتی را مطرح نکنید. حتما محاسبات را نیز بررسی کنید.
تمرین 2
در تمرینهای متقاطع ویژگی در ماژول دادههای دستهبندی ، شما بهطور دستی تلاقیهای ویژگی را برای جا دادن دادههای غیرخطی ساختهاید. اکنون، خواهید دید که آیا میتوانید یک شبکه عصبی بسازید که به طور خودکار یاد بگیرد که چگونه دادههای غیرخطی را در طول آموزش جاسازی کند.
وظیفه شما: یک شبکه عصبی را پیکربندی کنید که بتواند نقاط نارنجی را از نقاط آبی در نمودار زیر جدا کند و در داده های آموزشی و آزمایشی کمتر از 0.2 از دست بدهد.
دستورالعمل:
در ویجت تعاملی زیر:
- با آزمایش برخی از تنظیمات پیکربندی زیر، فراپارامترهای شبکه عصبی را تغییر دهید:
- با کلیک بر روی دکمه های + و - در سمت چپ عنوان لایه های پنهان در نمودار شبکه، لایه های پنهان را اضافه یا حذف کنید.
- با کلیک بر روی دکمه های + و - بالای ستون لایه پنهان، نورون ها را از یک لایه پنهان اضافه یا حذف کنید.
- نرخ یادگیری را با انتخاب یک مقدار جدید از کشویی نرخ یادگیری در بالای نمودار تغییر دهید.
- تابع فعال سازی را با انتخاب یک مقدار جدید از منوی کشویی Activation در بالای نمودار تغییر دهید.
- برای آموزش مدل شبکه عصبی با استفاده از پارامترهای مشخص شده، روی دکمه Play (▶️) در بالای نمودار کلیک کنید.
- مشاهده تجسم مدل برازش دادهها در حین پیشرفت آموزش و همچنین مقادیر Test loss و Training loss در بخش Output .
- اگر مدل در دادههای آزمایشی و آموزشی به ضرر کمتر از 0.2 نرسید، روی تنظیم مجدد کلیک کنید و مراحل 1 تا 3 را با مجموعهای از تنظیمات پیکربندی متفاوت تکرار کنید. این روند را تا رسیدن به نتایج مطلوب تکرار کنید.
برای راه حل ما اینجا را کلیک کنید
ما توانستیم به ضرر تست و تمرین زیر 0.2 برسیم:
- افزودن 1 لایه پنهان حاوی 3 نورون.
- انتخاب نرخ یادگیری 0.01.
- انتخاب یک تابع فعال سازی ReLU.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2024-08-16 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2024-08-16 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Neural networks: Interactive exercises\n\nIn the interactive exercises below, you'll further explore the inner workings of\nneural networks. First, you'll see how parameter and hyperparameter changes\naffect the network's predictions. Then you'll use what you've learned to train a\nneural network to fit nonlinear data.\n\nExercise 1\n----------\n\nThe following widget sets up a neural network with the following configuration:\n\n- Input layer with 3 neurons containing the values `0.00`, `0.00`, and `0.00`\n- Hidden layer with 4 neurons\n- Output layer with 1 neuron\n- [**ReLU**](/machine-learning/glossary#ReLU) activation function applied to all hidden layer nodes and the output node\n\nReview the initial setup of the network (note: **do not** click the **▶️** or\n**\\\u003e\\|** buttons yet), and then complete the tasks below the widget.\n\n### Task 1\n\nThe values for the three input features to the neural network model are all\n`0.00`. Click each of the nodes in the network to see all the initialized\nvalues. Before hitting the Play (**▶️**) button, answer this question: \nWhat kind of output value do you think will be produced: positive, negative, or 0? \nPositive output value \nYou chose **positive\noutput value**. Follow the instructions below to perform inference on the input data and see if you're right. \nNegative output value \nYou chose **negative\noutput value**. Follow the instructions below to perform inference on the input data and see if you're right. \nOutput value of 0 \nYou chose **output\nvalue of 0**. Follow the instructions below to perform inference on the input data and see if you're right.\n\nNow click the Play (▶️) button above the network, and watch all the hidden-layer\nand output node values populate. Was your answer above correct? \n**Click here for an explanation**\n\nThe exact output value you get will vary based on how the weight\nand bias parameters are randomly initialized. However, since each neuron\nin the input layer has a value of 0, the weights used to calculate the\nhidden-layer node values will all be zeroed out. For example, the first\nhidden layer node calculation will be:\n\ny = ReLU(w~11~\\* 0.00 + w~21~\\* 0.00 + w~31~\\* 0.00 + b)\n\ny = ReLU(b)\n\nSo each hidden-layer node's value will be equal to the ReLU value of the\nbias (b), which will be 0 if b is negative and b itself if b is 0 or\npositive.\n\nThe value of the output node will then be calculated as follows:\n\ny = ReLU(w~11~\\* x~11~ + w~21~\\* x~21~\n+ w~31~\\* x~31~ + w~41~\\* x~41~ + b)\n\n### Task 2\n\nBefore modifying the neural network, answer the following question: \nIf you add another hidden layer to the neural network after the first hidden layer, and give this new layer 3 nodes, keeping all input and weight/bias parameters the same, which other nodes' calculations will be affected? \nAll the nodes in the network, except the input nodes \nYou chose **all the\nnodes in the network, except the input nodes**. Follow the instructions below to update the neural network and see if you're correct. \nJust the nodes in the first hidden layer \nYou chose **just the\nnodes in the first hidden layer**. Follow the instructions below to update the neural network and see if you're correct. \nJust the output node \nYou chose **just the\noutput node**. Follow the instructions below to update the neural network and see if you're correct.\n\nNow modify the neural network to add a new hidden layer with 3 nodes as follows:\n\n1. Click the **+** button to the left of the text **1 hidden layer** to add a new hidden layer before the output layer.\n2. Click the **+** button above the new hidden layer twice to add 2 more nodes to the layer.\n\nWas your answer above correct? \n**Click here for an explanation**\n\nOnly the output node changes. Because inference for this neural network\nis \"feed-forward\" (calculations progress from start to finish), the addition\nof a new layer to the network will only affect nodes *after* the new\nlayer, not those that precede it.\n\n### Task 3\n\nClick the second node (from the top) in the first hidden layer of the network\ngraph. Before making any changes to the network configuration, answer the\nfollowing question: \nIf you change the value of the weight w~12~ (displayed below the first input node, x~1~), which other nodes' calculations *could* be affected for some input values? \nNone \nYou chose **none**. Follow the instructions below to update the neural network and see if you're correct. \nThe second node in the first hidden layer, all the nodes in the second hidden layer, and the output node. \nYou chose **the second\nnode in the first hidden layer, all the nodes in the second hidden layer,\nand the output node**. Follow the instructions below to update the neural network and see if you're correct. \nAll the nodes in the first hidden layer, the second hidden layer, and the output layer. \nYou chose **all the\nnodes in the first hidden layer, the second hidden layer, and the\noutput layer**. Follow the instructions below to update the neural network and see if you're correct.\n\nNow, click in the text field for the weight w~12~ (displayed below the\nfirst input node, x~1~), change its value to `5.00`, and hit Enter.\nObserve the updates to the graph.\n\nWas your answer correct? Be careful when verifying your answer: if a node\nvalue doesn't change, does that mean the underlying calculation didn't change? \n**Click here for an explanation**\n\nThe only node affected in the first hidden layer is the second node (the\none you clicked). The value calculations for the other nodes in the first\nhidden layer do not contain w~12~ as a parameter, so they are not\naffected. All the nodes in the second hidden layer are affected, as their\ncalculations depend on the value of the second node in the first\nhidden layer. Similarly, the output node value is affected because its\ncalculations depend on the values of the nodes in the second hidden layer.\n\nDid you think the answer was \"none\" because none of the node values in the\nnetwork changed when you changed the weight value? Note that an underlying\ncalculation for a node may change without changing the node's value\n(e.g., ReLU(0) and ReLU(--5) both produce an output of 0).\nDon't make assumptions about how the network was affected just by\nlooking at the node values; make sure to review the calculations as well.\n\nExercise 2\n----------\n\nIn the [Feature cross exercises](/machine-learning/crash-course/categorical-data/feature-cross-exercises)\nin the [Categorical data module](/machine-learning/crash-course/categorical-data),\nyou manually constructed feature crosses to fit nonlinear data.\nNow, you'll see if you can build a neural network that can automatically learn\nhow to fit nonlinear data during training.\n\n**Your task:** configure a neural network that can separate the orange dots from\nthe blue dots in the diagram below, achieving a loss of less than 0.2 on both\nthe training and test data.\n\n**Instructions:**\n\nIn the interactive widget below:\n\n1. Modify the neural network hyperparameters by experimenting with some of the following config settings:\n - Add or remove hidden layers by clicking the **+** and **-** buttons to the left of the **HIDDEN LAYERS** heading in the network diagram.\n - Add or remove neurons from a hidden layer by clicking the **+** and **-** buttons above a hidden-layer column.\n - Change the learning rate by choosing a new value from the **Learning rate** drop-down above the diagram.\n - Change the activation function by choosing a new value from the **Activation** drop-down above the diagram.\n2. Click the Play (▶️) button above the diagram to train the neural network model using the specified parameters.\n3. Observe the visualization of the model fitting the data as training progresses, as well as the [**Test loss**](/machine-learning/glossary#test-loss) and [**Training loss**](/machine-learning/glossary#training-loss) values in the **Output** section.\n4. If the model does not achieve loss below 0.2 on the test and training data, click reset, and repeat steps 1--3 with a different set of configuration settings. Repeat this process until you achieve the preferred results.\n\n**Click here for our solution**\n\nWe were able to achieve both test and training loss below 0.2 by:\n\n- Adding 1 hidden layer containing 3 neurons.\n- Choosing a learning rate of 0.01.\n- Choosing an activation function of ReLU. \n| **Key terms:**\n|\n| - [Test loss](/machine-learning/glossary#test-loss)\n- [Training loss](/machine-learning/glossary#training-loss) \n[Help Center](https://support.google.com/machinelearningeducation)"]]