From 75a68440520c3b60d7ca1c8bbc0cae2c823d7abb Mon Sep 17 00:00:00 2001 From: SEddula Date: Mon, 22 Dec 2025 23:56:26 -0600 Subject: [PATCH 1/3] updated Liquid model name in lab 3 --- lab3/LLM_Finetuning.ipynb | 2 +- lab3/solutions/LLM_Finetuning_Solution.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lab3/LLM_Finetuning.ipynb b/lab3/LLM_Finetuning.ipynb index 022caadc..137c4955 100644 --- a/lab3/LLM_Finetuning.ipynb +++ b/lab3/LLM_Finetuning.ipynb @@ -930,7 +930,7 @@ "OPENROUTER_API_KEY = \"\" # TODO: add your OpenRouter API key here\n", "assert OPENROUTER_API_KEY != \"\", \"You must set your OpenRouter API key before running this cell!\"\n", "\n", - "model_name = \"liquid/lfm-40b\"\n", + "model_name = \"liquid/lfm2-8b-a1b\"\n", "# model_name = \"google/gemma-2-9b-it\"\n", "llm = mdl.lab3.LLMClient(model=model_name, api_key=OPENROUTER_API_KEY)" ] diff --git a/lab3/solutions/LLM_Finetuning_Solution.ipynb b/lab3/solutions/LLM_Finetuning_Solution.ipynb index 04548c20..428e8b30 100644 --- a/lab3/solutions/LLM_Finetuning_Solution.ipynb +++ b/lab3/solutions/LLM_Finetuning_Solution.ipynb @@ -947,7 +947,7 @@ "OPENROUTER_API_KEY = \"\" # TODO: add your OpenRouter API key here\n", "assert OPENROUTER_API_KEY != \"\", \"You must set your OpenRouter API key before running this cell!\"\n", "\n", - "model_name = \"liquid/lfm-40b\"\n", + "model_name = \"liquid/lfm2-8b-a1b\"\n", "# model_name = \"google/gemma-2-9b-it\"\n", "llm = mdl.lab3.LLMClient(model=model_name, api_key=OPENROUTER_API_KEY)" ] From cc8abbd86c3d55b2deacec2fdc320a52ea835227 Mon Sep 17 00:00:00 2001 From: SEddula Date: Mon, 22 Dec 2025 23:59:20 -0600 Subject: [PATCH 2/3] should be state instead of hidden_state as per solutions --- lab1/PT_Part2_Music_Generation.ipynb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lab1/PT_Part2_Music_Generation.ipynb b/lab1/PT_Part2_Music_Generation.ipynb index a99bca7d..afbcbfbb 100644 --- a/lab1/PT_Part2_Music_Generation.ipynb +++ b/lab1/PT_Part2_Music_Generation.ipynb @@ -652,6 +652,11 @@ }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "GuGUJB0ZT_Uo" + }, + "outputs": [], "source": [ "### compute the loss on the predictions from the untrained model from earlier. ###\n", "y.shape # (batch_size, sequence_length)\n", @@ -663,12 +668,7 @@ "\n", "print(f\"Prediction shape: {pred.shape} # (batch_size, sequence_length, vocab_size)\")\n", "print(f\"scalar_loss: {example_batch_loss.mean().item()}\")" - ], - "metadata": { - "id": "GuGUJB0ZT_Uo" - }, - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -906,7 +906,7 @@ "\n", " for i in tqdm(range(generation_length)):\n", " '''TODO: evaluate the inputs and generate the next character predictions'''\n", - " predictions, hidden_state = model('''TODO''', '''TODO''', return_state=True) # TODO\n", + " predictions, state = model('''TODO''', '''TODO''', return_state=True) # TODO\n", "\n", " # Remove the batch dimension\n", " predictions = predictions.squeeze(0)\n", From 84e329f69f6cfc63d326675e3a6961b4465b194b Mon Sep 17 00:00:00 2001 From: SEddula Date: Tue, 23 Dec 2025 15:24:19 -0600 Subject: [PATCH 3/3] ptp was removed from the ndarray class in NumPy 2.0. Use np.ptp(arr, ...) instead. --- lab2/TF_Part2_Debiasing.ipynb | 170 +++++++++--------- .../TF_Part2_Debiasing_Solution.ipynb | 170 +++++++++--------- 2 files changed, 170 insertions(+), 170 deletions(-) diff --git a/lab2/TF_Part2_Debiasing.ipynb b/lab2/TF_Part2_Debiasing.ipynb index 494b74c7..32ea5c3c 100644 --- a/lab2/TF_Part2_Debiasing.ipynb +++ b/lab2/TF_Part2_Debiasing.ipynb @@ -1,21 +1,4 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "TF_Part2_Debiasing.ipynb", - "provenance": [], - "collapsed_sections": [ - "Ag_e7xtTzT1W", - "NDj7KBaW8Asz" - ] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "accelerator": "GPU" - }, "cells": [ { "cell_type": "markdown", @@ -38,9 +21,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "rNbf1pRlSDby" }, + "outputs": [], "source": [ "# Copyright 2025 MIT 6.S191 Introduction to Deep Learning. All Rights Reserved.\n", "#\n", @@ -51,9 +36,7 @@ "# © MIT 6.S191: Introduction to Deep Learning\n", "# http://introtodeeplearning.com\n", "#" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -77,15 +60,15 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "XQh5HZfbupFF" }, + "outputs": [], "source": [ "import IPython\n", "IPython.display.YouTubeVideo('59bMh59JQDo')" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -104,9 +87,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "E46sWVKK6LP9" }, + "outputs": [], "source": [ "!pip install comet_ml --quiet\n", "import comet_ml\n", @@ -130,9 +115,7 @@ "# using Runtime > Change Runtime Type > GPU\n", "assert len(tf.config.list_physical_devices('GPU')) > 0\n", "assert COMET_API_KEY != \"\", \"Please insert your Comet API Key\"" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -153,17 +136,17 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "RWXaaIWy6jVw" }, + "outputs": [], "source": [ "# Get the training data: both images from CelebA and ImageNet\n", "path_to_training_data = tf.keras.utils.get_file('train_face.h5', 'https://www.dropbox.com/s/hlz8atheyozp1yx/train_face.h5?dl=1')\n", "# Instantiate a TrainingDatasetLoader using the downloaded dataset\n", "loader = mdl.lab2.TrainingDatasetLoader(path_to_training_data)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -176,15 +159,15 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "DjPSjZZ_bGqe" }, + "outputs": [], "source": [ "number_of_training_examples = loader.get_train_size()\n", "(images, labels) = loader.get_batch(100)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -197,9 +180,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "Jg17jzwtbxDA" }, + "outputs": [], "source": [ "### Examining the CelebA training dataset ###\n", "\n", @@ -219,9 +204,7 @@ "plt.subplot(1, 2, 2)\n", "plt.imshow(not_face_images[idx_not_face])\n", "plt.title(\"Not Face\"); plt.grid(False)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -253,9 +236,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "82EVTAAW7B_X" }, + "outputs": [], "source": [ "### Define the CNN model ###\n", "\n", @@ -288,9 +273,7 @@ " return model\n", "\n", "standard_classifier = make_standard_classifier()" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -303,6 +286,11 @@ }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "mi-04SAfK6lm" + }, + "outputs": [], "source": [ "### Create a Comet experiment to track our training run ###\n", "def create_experiment(project_name, params):\n", @@ -320,18 +308,15 @@ " experiment.flush()\n", "\n", " return experiment\n" - ], - "metadata": { - "id": "mi-04SAfK6lm" - }, - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "eJlDGh1o31G1" }, + "outputs": [], "source": [ "### Train the standard CNN ###\n", "\n", @@ -376,9 +361,7 @@ "\n", " experiment.log_metric(\"loss\", loss.numpy().mean(), step=step)\n", " step += 1" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -393,9 +376,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "35-PDgjdWk6_" }, + "outputs": [], "source": [ "### Evaluation of standard CNN ###\n", "\n", @@ -406,9 +391,7 @@ "acc_standard = tf.reduce_mean(tf.cast(tf.equal(batch_y, y_pred_standard), tf.float32))\n", "\n", "print(\"Standard CNN accuracy on (potentially biased) training set: {:.4f}\".format(acc_standard.numpy()))" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -423,9 +406,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "vfDD8ztGWk6x" }, + "outputs": [], "source": [ "### Load test dataset and plot examples ###\n", "\n", @@ -435,9 +420,7 @@ " plt.figure(figsize=(5,5))\n", " plt.imshow(np.hstack(group))\n", " plt.title(key, fontsize=15)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -450,9 +433,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "GI4O0Y1GAot9" }, + "outputs": [], "source": [ "### Evaluate the standard CNN on the test data ###\n", "\n", @@ -464,11 +449,9 @@ "yy = standard_classifier_probs.numpy().mean(1)\n", "plt.bar(xx, yy)\n", "plt.xticks(xx, keys)\n", - "plt.ylim(max(0,yy.min()-yy.ptp()/2.), yy.max()+yy.ptp()/2.)\n", + "plt.ylim(max(0,yy.min()-np.ptp(yy)/2.), yy.max()+np.ptp(yy)/2.)\n", "plt.title(\"Standard classifier predictions\");" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -552,9 +535,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "S00ASo1ImSuh" }, + "outputs": [], "source": [ "### Defining the VAE loss function ###\n", "\n", @@ -583,9 +568,7 @@ " vae_loss = # TODO\n", "\n", " return vae_loss" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -615,9 +598,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "cT6PGdNajl3K" }, + "outputs": [], "source": [ "### VAE Reparameterization ###\n", "\n", @@ -637,9 +622,7 @@ " z = # TODO\n", "\n", " return z" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -698,9 +681,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "VjieDs8Ovcqs" }, + "outputs": [], "source": [ "### Loss function for DB-VAE ###\n", "\n", @@ -734,9 +719,7 @@ " total_loss = # TODO\n", "\n", " return total_loss, classification_loss" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -753,9 +736,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "JfWPHGrmyE7R" }, + "outputs": [], "source": [ "### Define the decoder portion of the DB-VAE ###\n", "\n", @@ -784,9 +769,7 @@ " ])\n", "\n", " return decoder" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -799,9 +782,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "dSFDcFBL13c3" }, + "outputs": [], "source": [ "### Defining and creating the DB-VAE ###\n", "\n", @@ -863,9 +848,7 @@ " return y_logit\n", "\n", "dbvae = DB_VAE(latent_dim)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -903,9 +886,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "ewWbf7TE7wVc" }, + "outputs": [], "source": [ "# Function to return the means for an input image batch\n", "def get_latent_mu(images, dbvae, batch_size=1024):\n", @@ -917,9 +902,7 @@ " _, batch_mu, _ = dbvae.encode(batch)\n", " mu[start_ind:end_ind] = batch_mu\n", " return mu" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -932,9 +915,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "HiX9pmmC7_wn" }, + "outputs": [], "source": [ "### Resampling algorithm for DB-VAE ###\n", "\n", @@ -983,9 +968,7 @@ " training_sample_p /= np.sum(training_sample_p)\n", "\n", " return training_sample_p" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -998,9 +981,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "xwQs-Gu5bKEK" }, + "outputs": [], "source": [ "### Training the DB-VAE ###\n", "\n", @@ -1070,9 +1055,7 @@ " step += 1\n", "\n", "experiment.end()" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -1096,9 +1079,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "bgK77aB9oDtX" }, + "outputs": [], "source": [ "dbvae_logits = [dbvae.predict(np.array(x, dtype=np.float32)) for x in test_faces]\n", "dbvae_probs = tf.squeeze(tf.sigmoid(dbvae_logits))\n", @@ -1109,9 +1094,7 @@ "plt.xticks(xx, keys);\n", "plt.title(\"Network predictions on test dataset\")\n", "plt.ylabel(\"Probability\"); plt.legend(bbox_to_anchor=(1.04,1), loc=\"upper left\");\n" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -1143,5 +1126,22 @@ "" ] } - ] + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "collapsed_sections": [ + "Ag_e7xtTzT1W", + "NDj7KBaW8Asz" + ], + "name": "TF_Part2_Debiasing.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 } diff --git a/lab2/solutions/TF_Part2_Debiasing_Solution.ipynb b/lab2/solutions/TF_Part2_Debiasing_Solution.ipynb index d6ccba60..bbc8b78a 100644 --- a/lab2/solutions/TF_Part2_Debiasing_Solution.ipynb +++ b/lab2/solutions/TF_Part2_Debiasing_Solution.ipynb @@ -1,21 +1,4 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "TF_Part2_Debiasing_Solution.ipynb", - "provenance": [], - "collapsed_sections": [ - "Ag_e7xtTzT1W", - "NDj7KBaW8Asz" - ] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "accelerator": "GPU" - }, "cells": [ { "cell_type": "markdown", @@ -38,9 +21,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "rNbf1pRlSDby" }, + "outputs": [], "source": [ "# Copyright 2025 MIT 6.S191 Introduction to Deep Learning. All Rights Reserved.\n", "#\n", @@ -51,9 +36,7 @@ "# © MIT 6.S191: Introduction to Deep Learning\n", "# http://introtodeeplearning.com\n", "#" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -77,15 +60,15 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "XQh5HZfbupFF" }, + "outputs": [], "source": [ "import IPython\n", "IPython.display.YouTubeVideo('59bMh59JQDo')" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -104,9 +87,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "E46sWVKK6LP9" }, + "outputs": [], "source": [ "!pip install comet_ml --quiet\n", "import comet_ml\n", @@ -130,9 +115,7 @@ "# using Runtime > Change Runtime Type > GPU\n", "assert len(tf.config.list_physical_devices('GPU')) > 0\n", "assert COMET_API_KEY != \"\", \"Please insert your Comet API Key\"" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -153,17 +136,17 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "RWXaaIWy6jVw" }, + "outputs": [], "source": [ "# Get the training data: both images from CelebA and ImageNet\n", "path_to_training_data = tf.keras.utils.get_file('train_face.h5', 'https://www.dropbox.com/s/hlz8atheyozp1yx/train_face.h5?dl=1')\n", "# Instantiate a TrainingDatasetLoader using the downloaded dataset\n", "loader = mdl.lab2.TrainingDatasetLoader(path_to_training_data)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -176,15 +159,15 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "DjPSjZZ_bGqe" }, + "outputs": [], "source": [ "number_of_training_examples = loader.get_train_size()\n", "(images, labels) = loader.get_batch(100)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -197,9 +180,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "Jg17jzwtbxDA" }, + "outputs": [], "source": [ "### Examining the CelebA training dataset ###\n", "\n", @@ -219,9 +204,7 @@ "plt.subplot(1, 2, 2)\n", "plt.imshow(not_face_images[idx_not_face])\n", "plt.title(\"Not Face\"); plt.grid(False)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -253,9 +236,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "82EVTAAW7B_X" }, + "outputs": [], "source": [ "### Define the CNN model ###\n", "\n", @@ -288,9 +273,7 @@ " return model\n", "\n", "standard_classifier = make_standard_classifier()" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -303,6 +286,11 @@ }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "mi-04SAfK6lm" + }, + "outputs": [], "source": [ "### Create a Comet experiment to track our training run ###\n", "def create_experiment(project_name, params):\n", @@ -320,18 +308,15 @@ " experiment.flush()\n", "\n", " return experiment\n" - ], - "metadata": { - "id": "mi-04SAfK6lm" - }, - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "eJlDGh1o31G1" }, + "outputs": [], "source": [ "### Train the standard CNN ###\n", "\n", @@ -376,9 +361,7 @@ "\n", " experiment.log_metric(\"loss\", loss.numpy().mean(), step=step)\n", " step += 1" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -393,9 +376,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "35-PDgjdWk6_" }, + "outputs": [], "source": [ "### Evaluation of standard CNN ###\n", "\n", @@ -406,9 +391,7 @@ "acc_standard = tf.reduce_mean(tf.cast(tf.equal(batch_y, y_pred_standard), tf.float32))\n", "\n", "print(\"Standard CNN accuracy on (potentially biased) training set: {:.4f}\".format(acc_standard.numpy()))" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -423,9 +406,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "vfDD8ztGWk6x" }, + "outputs": [], "source": [ "### Load test dataset and plot examples ###\n", "\n", @@ -435,9 +420,7 @@ " plt.figure(figsize=(5,5))\n", " plt.imshow(np.hstack(group))\n", " plt.title(key, fontsize=15)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -450,9 +433,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "GI4O0Y1GAot9" }, + "outputs": [], "source": [ "### Evaluate the standard CNN on the test data ###\n", "\n", @@ -464,11 +449,9 @@ "yy = standard_classifier_probs.numpy().mean(1)\n", "plt.bar(xx, yy)\n", "plt.xticks(xx, keys)\n", - "plt.ylim(max(0,yy.min()-yy.ptp()/2.), yy.max()+yy.ptp()/2.)\n", + "plt.ylim(max(0,yy.min()-np.ptp(yy)/2.), yy.max()+np.ptp(yy)/2.)\n", "plt.title(\"Standard classifier predictions\");" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -552,9 +535,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "S00ASo1ImSuh" }, + "outputs": [], "source": [ "### Defining the VAE loss function ###\n", "\n", @@ -586,9 +571,7 @@ " # vae_loss = # TODO\n", "\n", " return vae_loss" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -618,9 +601,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "cT6PGdNajl3K" }, + "outputs": [], "source": [ "### VAE Reparameterization ###\n", "\n", @@ -640,9 +625,7 @@ " z = z_mean + tf.math.exp(0.5 * z_logsigma) * epsilon\n", " # z = # TODO\n", " return z" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -701,9 +684,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "VjieDs8Ovcqs" }, + "outputs": [], "source": [ "### Loss function for DB-VAE ###\n", "\n", @@ -743,9 +728,7 @@ " # total_loss = # TODO\n", "\n", " return total_loss, classification_loss" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -762,9 +745,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "JfWPHGrmyE7R" }, + "outputs": [], "source": [ "### Define the decoder portion of the DB-VAE ###\n", "\n", @@ -793,9 +778,7 @@ " ])\n", "\n", " return decoder" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -808,9 +791,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "dSFDcFBL13c3" }, + "outputs": [], "source": [ "### Defining and creating the DB-VAE ###\n", "\n", @@ -875,9 +860,7 @@ " return y_logit\n", "\n", "dbvae = DB_VAE(latent_dim)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -915,9 +898,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "ewWbf7TE7wVc" }, + "outputs": [], "source": [ "# Function to return the means for an input image batch\n", "def get_latent_mu(images, dbvae, batch_size=1024):\n", @@ -929,9 +914,7 @@ " _, batch_mu, _ = dbvae.encode(batch)\n", " mu[start_ind:end_ind] = batch_mu\n", " return mu" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -944,9 +927,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "HiX9pmmC7_wn" }, + "outputs": [], "source": [ "### Resampling algorithm for DB-VAE ###\n", "\n", @@ -999,9 +984,7 @@ " training_sample_p /= np.sum(training_sample_p)\n", "\n", " return training_sample_p" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -1014,9 +997,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "xwQs-Gu5bKEK" }, + "outputs": [], "source": [ "### Training the DB-VAE ###\n", "\n", @@ -1089,9 +1074,7 @@ " step += 1\n", "\n", "experiment.end()" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -1115,9 +1098,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "bgK77aB9oDtX" }, + "outputs": [], "source": [ "dbvae_logits = [dbvae.predict(np.array(x, dtype=np.float32)) for x in test_faces]\n", "dbvae_probs = tf.squeeze(tf.sigmoid(dbvae_logits))\n", @@ -1128,9 +1113,7 @@ "plt.xticks(xx, keys);\n", "plt.title(\"Network predictions on test dataset\")\n", "plt.ylabel(\"Probability\"); plt.legend(bbox_to_anchor=(1.04,1), loc=\"upper left\");\n" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -1162,5 +1145,22 @@ "" ] } - ] + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "collapsed_sections": [ + "Ag_e7xtTzT1W", + "NDj7KBaW8Asz" + ], + "name": "TF_Part2_Debiasing_Solution.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 }