diff --git a/Week08/QUIZ_week8_solution.ipynb b/Week08/QUIZ_week8_solution.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..2ce067a84809f88e5e5537081d4a39a3a8012126 --- /dev/null +++ b/Week08/QUIZ_week8_solution.ipynb @@ -0,0 +1,83 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "\n", + "x = -120\n", + "\n", + "# hidden layer with ReLu\n", + "h1 = max(-10 - 0.1 * x, 0)\n", + "h2 = max(0.15 * x, 0)\n", + "\n", + "# output layer\n", + "y1_hat = 4 + 0.5 * h1\n", + "y2_hat = 2.1 * h1 + 0.2 * h2\n", + "\n", + "# softmax\n", + "y1 = math.exp(y1_hat) / (math.exp(y1_hat) + math.exp(y2_hat))\n", + "y2 = math.exp(y2_hat) / (math.exp(y1_hat) + math.exp(y2_hat))\n", + "\n", + "# loss\n", + "loss = -math.log(y2) # since we know it belongs to class 2\n", + "\n", + "# partial derivative, we know that t2 = 1\n", + "dLdw22 = h1 * (y1 - 0)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "y1 = 0.6899744811276124\n", + "loss = 1.1711006659477776\n", + "dLdw22 = 1.3799489622552248\n" + ] + } + ], + "source": [ + "print(f'{y1 = }')\n", + "print(f'{loss = }')\n", + "print(f'{dLdw22 = }')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "aia2023", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.9" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +}