{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "_8ZwOksxZ0-q"
},
"source": [
"# Project: Deep Learning - Calculations"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "_R3K9DR2Z0-r"
},
"source": [
"**Instructions for Students:**\n",
"\n",
"Please carefully follow these steps to complete and submit your project:\n",
"\n",
"1. **Make a copy of the Project**: Please make a copy of this project either to your own Google Drive or download locally. Work on the copy of the project. The master project is **Read-Only**, meaning you can edit, but it will not be saved when you close the master project. To avoid total loss of your work, remember to make a copy.\n",
"\n",
"2. **Completing the Project**: You are required to work on and complete all tasks in the provided project. Be disciplined and ensure that you thoroughly engage with each task.\n",
" \n",
"3. **Creating a Google Drive Folder**: Each of you must create a new folder on your Google Drive. This will be the repository for all your completed project files, aiding you in keeping your work organized and accessible.\n",
" \n",
"4. **Uploading Completed Project**: Upon completion of your project, make sure to upload all necessary files, involving codes, reports, and related documents into the created Google Drive folder. Save this link in the 'Student Identity' section and also provide it as the last parameter in the `submit` function that has been provided.\n",
" \n",
"5. **Sharing Folder Link**: You're required to share the link to your project Google Drive folder. This is crucial for the submission and evaluation of your project.\n",
" \n",
"6. **Setting Permission to Public**: Please make sure your Google Drive folder is set to public. This allows your instructor to access your solutions and assess your work correctly.\n",
"\n",
"Adhering to these procedures will facilitate a smooth project evaluation process for you and the reviewers."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XeK2fKDrZ0-s"
},
"source": [
"## Project Description\n",
"\n",
"The Deep Learning Projects are divided into two parts, the first is the Calculations worth 30% in this notebook and the second one is Pytorch Project worth 70%.\n",
"\n",
"The two projects will help you gain experience to learn about Deep Learning in detail.\n",
"\n",
"Happy coding!"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Lgd8szRCZ0-t"
},
"source": [
"## Grading Criteria\n",
"\n",
"There are 4 primary tasks in this project, all have the same weight. Each task will give you either 100 point if you are correct and 0 if you are wrong. The final score for the project will the the average of all 4 tasks.\n",
"\n",
"There is also an optional task (Task 5) that you can do to challenge your understanding.\n",
"\n",
"* Task 1: This task will assess your ability to do basic matrix multiplication which is an important part in machine and deep learning.\n",
"\n",
"* Task 2: This task will assess your ability to understand how a neural network work through weight and biases.\n",
"\n",
"* Task 3: The task will assess your ability to understand how a neural network layer works.\n",
"\n",
"* Task 4: This task will assess your ability to understand how backpropagation works in a neural network.\n",
"\n",
"* Task 5 (optional): This task will assess your ability to understand how to calculate cost and why it's important by using backpropagation in a neural network.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "W1dT1yHmZ0-t"
},
"source": [
"## Student Identity"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "-Vysq0mbZ0-t"
},
"outputs": [],
"source": [
"# @title #### Student Identity\n",
"student_id = \"\" # @param {type:\"string\"}\n",
"name = \"\" # @param {type:\"string\"}\n",
"drive_link = \"\" # @param {type:\"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TuVolX9FZ0-u"
},
"source": [
"## Import package"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Pl3QEX2HZ0-u"
},
"outputs": [],
"source": [
"!pip install fastbook\n",
"\n",
"!pip install rggrader\n",
"from rggrader import submit"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4gtGSA8SZ0-v"
},
"source": [
"\n",
"## Task 1\n",
"\n",
"Given\n",
"\n",
"$$\n",
"X = \\begin{bmatrix}\n",
"a \\\\\n",
"b \\\\\n",
"c \\\\\n",
"d \\\\\n",
"e\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"and\n",
"\n",
"$$\n",
"M =\n",
"\\begin{bmatrix}\n",
"-2 & 3 & 3 & 3 & -4 \\\\\n",
"0 & -4 & -1 & 1 & 2 \\\\\n",
"1 & 5 & 4 & 2 & 0 \\\\\n",
"-2 & 5 & -5 & 3 & 1 \\\\\n",
"-3 & 2 & 4 & 3 & 4 \\\\\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"and\n",
"\n",
"$$\n",
"M \\cdot X =\n",
" =\n",
"\\begin{bmatrix}\n",
"-33 \\\\\n",
"9 \\\\\n",
"-34 \\\\\n",
"-38 \\\\\n",
" -40\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"What is the value of $a + b + c + d + e$?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "JCwFuKpEZ0-v"
},
"outputs": [],
"source": [
"# You may add any code here to derive your variables\n",
"# Please change this\n",
"a = 0\n",
"b = 0\n",
"c = 0\n",
"d = 0\n",
"e = 0\n",
"total = a + b + c + d + e\n",
"\n",
"print(f\"The total is {total}\")\n",
"\n",
"assignment_id = \"09-deep-learning-project\"\n",
"question_id = \"q1_linear_algebra\"\n",
"submit(student_id, name, assignment_id, str(total), question_id, drive_link)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "AnzwjHI5Z0-v"
},
"source": [
"## Task 2\n",
"\n",
"What is the output of the following Neural Network?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5Dhvs1l-Z0-v",
"outputId": "8fec2c6f-eb16-4791-bcee-d3414a8b7fab"
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from fastbook import *\n",
"\n",
"\n",
"# Draw neurons with multiple inputs and weights\n",
"gv('''\n",
"z_1[shape=box3d width=1 height=0.7 label=\"b = -2, ReLU\"];\n",
"z_2[shape=box3d width=1 height=0.7 label=\"b = -6, ReLU\"];\n",
"z_3[shape=box3d width=1 height=0.7 label=\"b = 4, ReLU\"];\n",
"input_1[width=1 height=0.7 label=\"4\"];\n",
"input_2[width=1 height=0.7 label=\"-3\"];\n",
"input_1 -> z_1 [label=\"4\"]\n",
"input_2 -> z_1 [label=\"2\"]\n",
"input_1 -> z_2 [label=\"0\"]\n",
"input_2 -> z_2 [label=\"-1\"]\n",
"\n",
"z_1 -> z_3 [label=\"2\"]\n",
"z_2 -> z_3 [label=\"3\"]\n",
"z_3 ->output\n",
"\n",
"\n",
"''')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "jtzFBQeIZ0-w"
},
"outputs": [],
"source": [
"# You may add any code here to derive your variables\n",
"# Please change this\n",
"output = 0\n",
"\n",
"print(f\"The output is {output}\")\n",
"\n",
"assignment_id = \"09-deep-learning-project\"\n",
"question_id = \"q2_simple_neural_network\"\n",
"submit(student_id, name, assignment_id, str(output), question_id, drive_link)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nw5Rc4_QZ0-w"
},
"source": [
"## Task 3\n",
"\n",
"Given the following Neural Networks:\n",
"\n",
"First layer:\n",
"\n",
"$$\n",
"W = \\begin{bmatrix}\n",
"0.23 & 0.67 & 0.12 \\\\\n",
"-0.89 & -0.45 & 0.78 \\\\\n",
"0.34 & 0.56 & -0.90 \\\\\n",
"-0.12 & 0.34 & 0.56 \\\\\n",
"0.78 & -0.90 & 0.23 \\\\\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"$$\n",
"bias = \\begin{bmatrix}\n",
"0.23 \\\\\n",
"-0.89 \\\\\n",
"0.34 \\\\\n",
"0.12 \\\\\n",
"-0.78 \\\\\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"Second layer:\n",
"\n",
"$$\n",
"W = \\begin{bmatrix}\n",
"0.23 & 0.67 & 0.12 & 0.45 & 0.89 \\\\\n",
"0.12 & 0.34 & 0.56 & 0.78 & 0.90 \\\\\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"$$\n",
"bias = \\begin{bmatrix}\n",
"1.96 \\\\\n",
"-1.08 \\\\\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"Third layer:\n",
"$$\n",
"W = \\begin{bmatrix}\n",
"1.08 & -0.16\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"$$\n",
"bias = \\begin{bmatrix}\n",
"-2.8\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"All layers use the ReLU activation function.\n",
"\n",
"What is the output given the following inputs?\n",
"\n",
"$$\n",
"X = \\begin{bmatrix}\n",
"1 \\\\\n",
"2 \\\\\n",
"4 \\\\\n",
"\\end{bmatrix}\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "4d8Oibi1Z0-x"
},
"outputs": [],
"source": [
"# You may add any code here to derive your variables\n",
"\n",
"# Please change this\n",
"output = 0\n",
"\n",
"print(f\"The output is {output}\")\n",
"\n",
"assignment_id = \"09-deep-learning-project\"\n",
"question_id = \"q3_complex_neural_network\"\n",
"submit(student_id, name, assignment_id, str(output), question_id, drive_link)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Vn5o5XmfZ0-x"
},
"source": [
"## Task 4\n",
"\n",
"Given [the following sheet (sheet name = Project A)](https://docs.google.com/spreadsheets/d/15JWbRFB4k5CNcfD-2hduHHssXIc1SGhNVSpu_30wVAw/edit#gid=180755192)\n",
"\n",
"Make a backpropagation algorithm to train the network. You can refer to AND and NOT sheet. Use sigmoid activation function for all\n",
"\n",
"Hint: it needs 1 layer with 1 neuron\n",
"\n",
"What is the cost at 10th iteration (the iteration start from 1)?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "d2aSUbaaZ0-x"
},
"outputs": [],
"source": [
"# Please clone the Google Sheet and do your calculation there\n",
"\n",
"# Please change this\n",
"cost = 0\n",
"\n",
"# Don't forget to fill in the link to your Google Sheet\n",
"link_to_gsheet = \"\"\n",
"\n",
"print(f\"The cost is {cost}\")\n",
"\n",
"assignment_id = \"09-deep-learning-project\"\n",
"\n",
"question_id = \"q4_cost_function_cost\"\n",
"submit(student_id, name, assignment_id, str(cost), question_id)\n",
"\n",
"question_id = \"q4_cost_function_gsheet\"\n",
"submit(student_id, name, assignment_id, str(link_to_gsheet), question_id, drive_link)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Kh7uzjtDZ0-x"
},
"source": [
"## Task 5 (Bonus - Optional)\n",
"\n",
"_This task is optional, it will earn you a distinction, but will not give you additional points._\n",
"\n",
"Given [the following sheet (sheet name = Project B)](https://docs.google.com/spreadsheets/d/15JWbRFB4k5CNcfD-2hduHHssXIc1SGhNVSpu_30wVAw/edit#gid=1029811725)\n",
"\n",
"Make a backpropagation algorithm to train the network. You can refer to AND and NOT sheet. Use sigmoid activation function for all\n",
"\n",
"Hint: it needs 2 layer (1 hidden layer + 1 output layer). The hidden layer has 2 neurons\n",
"\n",
"What is the cost at 10th iteration (the iteration start from 1)?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "KJJOi3V1Z0-x"
},
"outputs": [],
"source": [
"# Please clone the Google Sheet and do your calculation there\n",
"\n",
"# Please change this\n",
"cost = 0\n",
"\n",
"# Don't forget to fill in the link to your Google Sheet\n",
"link_to_gsheet = \"\"\n",
"\n",
"print(f\"The cost is {cost}\")\n",
"\n",
"assignment_id = \"09-deep-learning-project\"\n",
"\n",
"question_id = \"q5_cost_function_cost\"\n",
"submit(student_id, name, assignment_id, str(cost), question_id)\n",
"\n",
"question_id = \"q5_cost_function_gsheet\"\n",
"submit(student_id, name, assignment_id, str(link_to_gsheet), question_id, drive_link)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.3"
},
"colab": {
"provenance": []
}
},
"nbformat": 4,
"nbformat_minor": 0
}