Skip to content

Commit 0428dfe

Browse files
committed
Merge branch '2021' of github.com:aamini/introtodeeplearning into 2021
2 parents 0604062 + 9c66b8b commit 0428dfe

File tree

8 files changed

+114
-126
lines changed

8 files changed

+114
-126
lines changed

lab1/Part2_Music_Generation.ipynb

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -922,51 +922,29 @@
922922
"id": "HgVvcrYmSKGG"
923923
},
924924
"source": [
925-
"## 2.7 Experiment and **get awarded for the best songs**!!\n",
925+
"## 2.7 Experiment and **get awarded for the best songs**!\n",
926926
"\n",
927927
"Congrats on making your first sequence model in TensorFlow! It's a pretty big accomplishment, and hopefully you have some sweet tunes to show for it.\n",
928928
"\n",
929-
"If you want to go further, try to optimize your model and submit your best song! Tweet us at [@MITDeepLearning](https://twitter.com/MITDeepLearning) or [email us](mailto:[email protected]) a copy of the song (if you don't have Twitter), and we'll give out prizes to our favorites! \n",
930-
"\n",
931929
"Consider how you may improve your model and what seems to be most important in terms of performance. Here are some ideas to get you started:\n",
932930
"\n",
933931
"* How does the number of training epochs affect the performance?\n",
934932
"* What if you alter or augment the dataset? \n",
935933
"* Does the choice of start string significantly affect the result? \n",
936934
"\n",
937-
"Have fun and happy listening!\n",
935+
"Try to optimize your model and submit your best song! **MIT students and affiliates will be eligible for prizes during the IAP offering**. To enter the competition, please [email us](mailto:[email protected]) with your name and the following:\n",
938936
"\n",
937+
"* a recording of your song;\n",
938+
"* Jupyter notebook with the code you used to generate the song;\n",
939+
"* a description and/or diagram of the architecture and hyperparameters you used -- if there are any additional or interesting modifications you made to the template code, please include these in your description.\n",
939940
"\n",
940-
"![Let's Dance!](http://33.media.tumblr.com/3d223954ad0a77f4e98a7b87136aa395/tumblr_nlct5lFVbF1qhu7oio1_500.gif)\n",
941+
"You can also tweet us at [@MITDeepLearning](https://twitter.com/MITDeepLearning) a copy of the song! See this example song generated by a previous 6.S191 student (credit Ana Heart): <a href=\"https://twitter.com/AnaWhatever16/status/1263092914680410112?s=20\">song from May 20, 2020.</a>\n",
942+
"<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n",
941943
"\n",
942-
"\n"
943-
]
944-
},
945-
{
946-
"cell_type": "code",
947-
"metadata": {
948-
"id": "jX9zPJkAPI11"
949-
},
950-
"source": [
951-
"# Example submission by a previous 6.S191 student (credit: Ana Heart) \n",
944+
"Have fun and happy listening!\n",
952945
"\n",
953-
"%%html\n",
954-
"<blockquote class=\"twitter-tweet\"><a href=\"https://twitter.com/AnaWhatever16/status/1263092914680410112?s=20\">May 20, 2020</a></blockquote> \n",
955-
"<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>"
956-
],
957-
"execution_count": null,
958-
"outputs": []
959-
},
960-
{
961-
"cell_type": "code",
962-
"metadata": {
963-
"id": "zFdnDAcV_Ml1"
964-
},
965-
"source": [
966-
""
967-
],
968-
"execution_count": null,
969-
"outputs": []
946+
"![Let's Dance!](http://33.media.tumblr.com/3d223954ad0a77f4e98a7b87136aa395/tumblr_nlct5lFVbF1qhu7oio1_500.gif)"
947+
]
970948
}
971949
]
972950
}

lab1/solutions/Part2_Music_Generation_Solution.ipynb

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
" <td align=\"center\"><a target=\"_blank\" href=\"http://introtodeeplearning.com\">\n",
2727
" <img src=\"https://i.ibb.co/Jr88sn2/mit.png\" style=\"padding-bottom:5px;\" />\n",
2828
" Visit MIT Deep Learning</a></td>\n",
29-
" <td align=\"center\"><a target=\"_blank\" href=\"https://colab.research.google.com/github/aamini/introtodeeplearning/blob/master/lab1/soltuions/Part2_Music_Generation_Solution.ipynb\">\n",
29+
" <td align=\"center\"><a target=\"_blank\" href=\"https://colab.research.google.com/github/aamini/introtodeeplearning/blob/master/lab1/solutions/Part2_Music_Generation_Solution.ipynb\">\n",
3030
" <img src=\"https://i.ibb.co/2P3SLwK/colab.png\" style=\"padding-bottom:5px;\" />Run in Google Colab</a></td>\n",
3131
" <td align=\"center\"><a target=\"_blank\" href=\"https://github.com/aamini/introtodeeplearning/blob/master/lab1/solutions/Part2_Music_Generation_Solution.ipynb\">\n",
3232
" <img src=\"https://i.ibb.co/xfJbPmL/github.png\" height=\"70px\" style=\"padding-bottom:5px;\" />View Source on GitHub</a></td>\n",
@@ -941,51 +941,30 @@
941941
"id": "HgVvcrYmSKGG"
942942
},
943943
"source": [
944-
"## 2.7 Experiment and **get awarded for the best songs**!!\n",
944+
"## 2.7 Experiment and **get awarded for the best songs**!\n",
945945
"\n",
946946
"Congrats on making your first sequence model in TensorFlow! It's a pretty big accomplishment, and hopefully you have some sweet tunes to show for it.\n",
947947
"\n",
948-
"If you want to go further, try to optimize your model and submit your best song! Tweet us at [@MITDeepLearning](https://twitter.com/MITDeepLearning) or [email us](mailto:[email protected]) a copy of the song (if you don't have Twitter), and we'll give out prizes to our favorites! \n",
949-
"\n",
950948
"Consider how you may improve your model and what seems to be most important in terms of performance. Here are some ideas to get you started:\n",
951949
"\n",
952950
"* How does the number of training epochs affect the performance?\n",
953951
"* What if you alter or augment the dataset? \n",
954952
"* Does the choice of start string significantly affect the result? \n",
955953
"\n",
956-
"Have fun and happy listening!\n",
954+
"Try to optimize your model and submit your best song! **MIT students and affiliates will be eligible for prizes during the IAP offering**. To enter the competition, please [email us](mailto:[email protected]) with your name and the following:\n",
957955
"\n",
956+
"* a recording of your song;\n",
957+
"* Jupyter notebook with the code you used to generate the song;\n",
958+
"* a description and/or diagram of the architecture and hyperparameters you used -- if there are any additional or interesting modifications you made to the template code, please include these in your description.\n",
958959
"\n",
959-
"![Let's Dance!](http://33.media.tumblr.com/3d223954ad0a77f4e98a7b87136aa395/tumblr_nlct5lFVbF1qhu7oio1_500.gif)\n",
960+
"You can also tweet us at [@MITDeepLearning](https://twitter.com/MITDeepLearning) a copy of the song! See this example song generated by a previous 6.S191 student (credit Ana Heart): <a href=\"https://twitter.com/AnaWhatever16/status/1263092914680410112?s=20\">song from May 20, 2020.</a></blockquote> \n",
961+
"<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n",
960962
"\n",
963+
"Have fun and happy listening!\n",
964+
"\n",
965+
"![Let's Dance!](http://33.media.tumblr.com/3d223954ad0a77f4e98a7b87136aa395/tumblr_nlct5lFVbF1qhu7oio1_500.gif)\n",
961966
"\n"
962967
]
963-
},
964-
{
965-
"cell_type": "code",
966-
"metadata": {
967-
"id": "jX9zPJkAPI11"
968-
},
969-
"source": [
970-
"# Example submission by a previous 6.S191 student (credit: Ana Heart) \n",
971-
"\n",
972-
"%%html\n",
973-
"<blockquote class=\"twitter-tweet\"><a href=\"https://twitter.com/AnaWhatever16/status/1263092914680410112?s=20\">May 20, 2020</a></blockquote> \n",
974-
"<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>"
975-
],
976-
"execution_count": null,
977-
"outputs": []
978-
},
979-
{
980-
"cell_type": "code",
981-
"metadata": {
982-
"id": "zFdnDAcV_Ml1"
983-
},
984-
"source": [
985-
""
986-
],
987-
"execution_count": null,
988-
"outputs": []
989968
}
990969
]
991970
}

lab2/Part1_MNIST.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
"id": "VtGZpHVKz5Jt"
210210
},
211211
"source": [
212-
"As we progress through this next portion, you may find that you'll want to make changes to the architecture defined above. **Note that in order to update the model later on, you'll need to re-run the above cell to re-initialize the model. **"
212+
"As we progress through this next portion, you may find that you'll want to make changes to the architecture defined above. **Note that in order to update the model later on, you'll need to re-run the above cell to re-initialize the model.**"
213213
]
214214
},
215215
{

lab2/Part2_Debiasing.ipynb

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -478,27 +478,28 @@
478478
"In practice, how can we train a VAE? In learning the latent space, we constrain the means and standard deviations to approximately follow a unit Gaussian. Recall that these are learned parameters, and therefore must factor into the loss computation, and that the decoder portion of the VAE is using these parameters to output a reconstruction that should closely match the input image, which also must factor into the loss. What this means is that we'll have two terms in our VAE loss function:\n",
479479
"\n",
480480
"1. **Latent loss ($L_{KL}$)**: measures how closely the learned latent variables match a unit Gaussian and is defined by the Kullback-Leibler (KL) divergence.\n",
481-
"2. **Reconstruction loss ($L_{x}{(x,\\hat{x})}$)**: measures how accurately the reconstructed outputs match the input and is given by the $L^1$ norm of the input image and its reconstructed output. \n",
482-
"\n",
483-
"The equations for both of these losses are provided below:\n",
484-
"\n",
485-
"\\begin{equation*}\n",
486-
"L_{KL}(\\mu, \\sigma) = \\frac{1}{2}\\sum\\limits_{j=0}^{k-1}\\small{(\\sigma_j + \\mu_j^2 - 1 - \\log{\\sigma_j})}\n",
487-
"\\end{equation*}\n",
488-
"\n",
489-
"\\begin{equation*}\n",
490-
"L_{x}{(x,\\hat{x})} = ||x-\\hat{x}||_1\n",
491-
"\\end{equation*}\n",
492-
"\n",
493-
"Thus for the VAE loss we have: \n",
494-
"\n",
495-
"\\begin{equation*}\n",
496-
"L_{VAE} = c\\cdot L_{KL} + L_{x}{(x,\\hat{x})}\n",
497-
"\\end{equation*}\n",
498-
"\n",
499-
"where $c$ is a weighting coefficient used for regularization. \n",
500-
"\n",
501-
"Now we're ready to define our VAE loss function:"
481+
"2. **Reconstruction loss ($L_{x}{(x,\\hat{x})}$)**: measures how accurately the reconstructed outputs match the input and is given by the $L^1$ norm of the input image and its reconstructed output."
482+
]
483+
},
484+
{
485+
"cell_type": "markdown",
486+
"metadata": {
487+
"id": "KV1khmq5wt-K"
488+
},
489+
"source": [
490+
"The equation for the latent loss is provided by:\r\n",
491+
"\r\n",
492+
"$$L_{KL}(\\mu, \\sigma) = \\frac{1}{2}\\sum_{j=0}^{k-1} (\\sigma_j + \\mu_j^2 - 1 - \\log{\\sigma_j})$$\r\n",
493+
"\r\n",
494+
"The equation for the reconstruction loss is provided by:\r\n",
495+
"\r\n",
496+
"$$L_{x}{(x,\\hat{x})} = ||x-\\hat{x}||_1$$\r\n",
497+
"\r\n",
498+
"Thus for the VAE loss we have:\r\n",
499+
"\r\n",
500+
"$$L_{VAE} = c\\cdot L_{KL} + L_{x}{(x,\\hat{x})}$$\r\n",
501+
"\r\n",
502+
"where $c$ is a weighting coefficient used for regularization. Now we're ready to define our VAE loss function:"
502503
]
503504
},
504505
{
@@ -557,9 +558,7 @@
557558
"\n",
558559
"As you may recall from lecture, VAEs use a \"reparameterization trick\" for sampling learned latent variables. Instead of the VAE encoder generating a single vector of real numbers for each latent variable, it generates a vector of means and a vector of standard deviations that are constrained to roughly follow Gaussian distributions. We then sample from the standard deviations and add back the mean to output this as our sampled latent vector. Formalizing this for a latent variable $z$ where we sample $\\epsilon \\sim \\mathcal{N}(0,(I))$ we have: \n",
559560
"\n",
560-
"\\begin{equation}\n",
561-
"z = \\mathbb{\\mu} + e^{\\left(\\frac{1}{2} \\cdot \\log{\\Sigma}\\right)}\\circ \\epsilon\n",
562-
"\\end{equation}\n",
561+
"$$z = \\mu + e^{\\left(\\frac{1}{2} \\cdot \\log{\\Sigma}\\right)}\\circ \\epsilon$$\n",
563562
"\n",
564563
"where $\\mu$ is the mean and $\\Sigma$ is the covariance matrix. This is useful because it will let us neatly define the loss function for the VAE, generate randomly sampled latent variables, achieve improved network generalization, **and** make our complete VAE network differentiable so that it can be trained via backpropagation. Quite powerful!\n",
565564
"\n",
@@ -643,9 +642,7 @@
643642
"\n",
644643
"We can write a single expression for the loss by defining an indicator variable $\\mathcal{I}_f$which reflects which training data are images of faces ($\\mathcal{I}_f(y) = 1$ ) and which are images of non-faces ($\\mathcal{I}_f(y) = 0$). Using this, we obtain:\n",
645644
"\n",
646-
"\\begin{equation}\n",
647-
"L_{total} = L_y(y,\\hat{y}) + \\mathcal{I}_f(y)\\Big[L_{VAE}\\Big]\n",
648-
"\\end{equation}\n",
645+
"$$L_{total} = L_y(y,\\hat{y}) + \\mathcal{I}_f(y)\\Big[L_{VAE}\\Big]$$\n",
649646
"\n",
650647
"Let's write a function to define the DB-VAE loss function:\n",
651648
"\n"
@@ -1035,7 +1032,7 @@
10351032
"id": "Eo34xC7MbaiQ"
10361033
},
10371034
"source": [
1038-
"## 2.6 Evaluation of DB-VAE on Test Dataset\n",
1035+
"## 2.6 Evaluation of DB-VAE on test dataset\n",
10391036
"\n",
10401037
"Finally let's test our DB-VAE model on the test dataset, looking specifically at its accuracy on each the \"Dark Male\", \"Dark Female\", \"Light Male\", and \"Light Female\" demographics. We will compare the performance of this debiased model against the (potentially biased) standard CNN from earlier in the lab."
10411038
]
@@ -1065,19 +1062,26 @@
10651062
"id": "rESoXRPQo_mq"
10661063
},
10671064
"source": [
1068-
"## 2.7 Conclusion \n",
1065+
"## 2.7 Conclusion and submission information\n",
10691066
"\n",
10701067
"We encourage you to think about and maybe even address some questions raised by the approach and results outlined here:\n",
10711068
"\n",
10721069
"* How does the accuracy of the DB-VAE across the four demographics compare to that of the standard CNN? Do you find this result surprising in any way?\n",
1073-
"* How can the performance of the DB-VAE classifier be improved even further? We purposely did not optimize hyperparameters to leave this up to you! If you want to go further, try to optimize your model to achieve the best performance. **[Email us](mailto:[email protected]) a copy of your notebook with the 2.6 bar plot executed, and we'll give out prizes to the best performers!** \n",
1070+
"* How can the performance of the DB-VAE classifier be improved even further? We purposely did not optimize hyperparameters to leave this up to you!\n",
10741071
"* In which applications (either related to facial detection or not!) would debiasing in this way be desired? Are there applications where you may not want to debias your model? \n",
10751072
"* Do you think it should be necessary for companies to demonstrate that their models, particularly in the context of tasks like facial detection, are not biased? If so, do you have thoughts on how this could be standardized and implemented?\n",
10761073
"* Do you have ideas for other ways to address issues of bias, particularly in terms of the training data?\n",
10771074
"\n",
1078-
"Hopefully this lab has shed some light on a few concepts, from vision based tasks, to VAEs, to algorithmic bias. We like to think it has, but we're biased ;). \n",
1075+
"Try to optimize your model to achieve improved performance. **MIT students and affiliates will be eligible for prizes during the IAP offering.** To enter the competition, please [email us](mailto:[email protected]) with your name and the following:\n",
1076+
"\n",
1077+
"* Jupyter notebook with the code you used to generate your results;\n",
1078+
"* copy of the bar plot from section 2.6 showing the performance of your model;\n",
1079+
"* a description and/or diagram of the architecture and hyperparameters you used -- if there are any additional or interesting modifications you made to the template code, please include these in your description;\n",
1080+
"* discussion of why these modifications helped improve performance.\n",
1081+
"\n",
1082+
"Hopefully this lab has shed some light on a few concepts, from vision based tasks, to VAEs, to algorithmic bias. We like to think it has, but we're biased ;).\n",
10791083
"\n",
1080-
"<img src=\"https://i.ibb.co/PmCSNXs/tenor.gif\" />"
1084+
"<img src=\"https://i.ibb.co/BjLSRMM/ezgif-2-253dfd3f9097.gif\" />"
10811085
]
10821086
}
10831087
]

lab2/solutions/Part1_MNIST_Solution.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
"id": "VtGZpHVKz5Jt"
212212
},
213213
"source": [
214-
"As we progress through this next portion, you may find that you'll want to make changes to the architecture defined above. **Note that in order to update the model later on, you'll need to re-run the above cell to re-initialize the model. **"
214+
"As we progress through this next portion, you may find that you'll want to make changes to the architecture defined above. **Note that in order to update the model later on, you'll need to re-run the above cell to re-initialize the model.**"
215215
]
216216
},
217217
{

0 commit comments

Comments
 (0)