Skip to content

Commit f24080b

Browse files
committed
updates up to report deliverable
1 parent 64e4659 commit f24080b

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

lab2/solutions/Part2_Debiasing_Solution.ipynb

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@
534534
"\n",
535535
"We will apply our SS-VAE to a *supervised classification* problem -- the facial detection task. Importantly, note how the encoder portion in the SS-VAE architecture also outputs a single supervised variable, $z_o$, corresponding to the class prediction -- face or not face. Usually, VAEs are not trained to output any supervised variables (such as a class prediction)! This is the key distinction between the SS-VAE and a traditional VAE. \n",
536536
"\n",
537-
"Keep in mind that we only want to learn the latent representation of *faces*, as that is where we are interested in uncovering potential biases, even though we are training a model on a binary classification problem. So, we will need to ensure that, **for faces**, our SS-VAE model both learns a representation of the unsupervised latent variables, captured by the distribution $q_\\phi(z|x)$, **and** outputs a supervised class prediction $z_o$, but that, **for negative examples**, it only outputs a class prediction $z_o$."
537+
"Keep in mind that we only want to learn the latent representation of *faces*, as that is where we are interested in uncovering potential biases, even though we are training a model on a binary classification problem. So, we will need to ensure that, **for faces**, our SS-VAE model both learns a representation of the unsupervised latent variables, captured by the distribution $q_\\phi(z|x)$, and outputs a supervised class prediction $z_o$, but that, **for negative examples**, it only outputs a class prediction $z_o$."
538538
],
539539
"metadata": {
540540
"id": "A3IOB3d61WSN"
@@ -840,38 +840,27 @@
840840
"id": "Eo34xC7MbaiQ"
841841
},
842842
"source": [
843-
"## 2.6 Evaluation of Supervised VAE on Test Dataset\n",
843+
"## 2.6 Using the SS-VAE to uncover and diagnose biases\n",
844844
"\n",
845-
"Finally let's test our 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."
846-
]
847-
},
848-
{
849-
"cell_type": "code",
850-
"execution_count": null,
851-
"metadata": {
852-
"id": "bgK77aB9oDtX"
853-
},
854-
"outputs": [],
855-
"source": [
856-
"dbvae_logits = [dbvae.predict(np.array(x, dtype=np.float32)) for x in test_faces]\n",
857-
"dbvae_probs = tf.squeeze(tf.sigmoid(dbvae_logits))\n",
858-
"\n",
859-
"xx = np.arange(len(keys))\n",
860-
"plt.bar(xx, standard_classifier_probs.numpy().mean(1), width=0.2, label=\"Standard CNN\")\n",
861-
"plt.bar(xx+0.2, dbvae_probs.numpy().mean(1), width=0.2, label=\"Supervised VAE\")\n",
862-
"plt.xticks(xx, keys); \n",
863-
"plt.title(\"Network predictions on test dataset\")\n",
864-
"plt.ylabel(\"Probability\"); plt.legend(bbox_to_anchor=(1.04,1), loc=\"upper left\")"
845+
"With the SS-VAE model trained, we are ready to use it to uncover and diagnose hidden biases that exist within the dataset.\n",
846+
"\n",
847+
"Recall that our goal with the SS-VAE was to learn the underlying ***latent distribution*** of features in the training dataset, in order to uncover potential feature representation disparities that exist within the data.\n",
848+
"\n",
849+
"Additionally, training the SS-VAE required both a VAE reconstruction loss as well as a supervised classification loss. The VAE reconstruction loss direclty reflects how well the model is able to handle particular input data -- the higher the reconstruction loss, the harder that particular example is for the model to learn.\n",
850+
"\n",
851+
"We consider both these aspects to understand sources of uncertainty and bias within the model."
865852
]
866853
},
867854
{
868855
"cell_type": "markdown",
869-
"metadata": {
870-
"id": "hdGHO9FHtMyx"
871-
},
872856
"source": [
873-
"Now, let's investigate how well the VAE actually learned the latent features of the faces! To do this, we'll look at the examples in the test dataset with the highest loss. What can you tell about which features seemed harder to learn for the VAE? What might this tell us about how the model is biased?"
874-
]
857+
"### Linking model performance to uncertainty and bias\n",
858+
"\n",
859+
"We begin by considering the examples in the test dataset with the highest loss. What can you tell about which features seemed harder to learn for the VAE? What might this tell us about where the model struggles, and what predictions it may be more biased or uncertain about?"
860+
],
861+
"metadata": {
862+
"id": "QfVngr5J6sj3"
863+
}
875864
},
876865
{
877866
"cell_type": "code",
@@ -881,7 +870,7 @@
881870
},
882871
"outputs": [],
883872
"source": [
884-
"# Load a random sample of 2000 faces from our dataset and compute the model performance on them\n",
873+
"# Load a random sample of 5000 faces from our dataset and compute the model performance on them\n",
885874
"(x, y) = loader.get_batch(5000, only_faces=True)\n",
886875
"y_logit, z_mean, z_logsigma, x_recon = dbvae(x)\n",
887876
"loss, class_loss, vae_loss = debiasing_loss_function(x, x_recon, y, y_logit, z_mean, z_logsigma)\n",
@@ -922,9 +911,13 @@
922911
"id": "8SQSszTFjstZ"
923912
},
924913
"source": [
925-
"## 2.7 Calculating Bias Scores\n",
914+
"### Uncovering hidden biases through learned latent features \n",
926915
"\n",
927-
"As we've seen above, loss is a powerful way to visualize which samples in our dataset have high *uncertainty*, or which ones the model has had trouble learning. However, this isn't necessarily the same as bias! How can determine the *probability* of a sample occurring in our dataset, and debias based off of that? In this section, we'll develop a way to score samples based on their bias and adapt this score during training."
916+
"As we've seen above, loss is a powerful way to visualize which samples in our dataset the model has had trouble learning -- these examples are those that have high *model uncertainty*. However, this is not necessarily the same as bias!\n",
917+
"\n",
918+
"How can we determine the relative frequencies and distributions of different latent features learned by the model? How may these metrics reveal underlying biases?\n",
919+
"\n",
920+
"Let's investigate how well the SS-VAE actually learned the latent features of the faces. To do this, we will inspect individual latent features -- holding all others constant -- and look at the distribution of these features in the data and their corresponding examples. We can examine how the shape and probability density of the learned latent features."
928921
]
929922
},
930923
{
@@ -960,6 +953,19 @@
960953
"execution_count": null,
961954
"outputs": []
962955
},
956+
{
957+
"cell_type": "markdown",
958+
"source": [
959+
"Carefully inspect the different latent variables and their corresponding frequency distributions. What can you tell about which features are under- or over-represented in the data? What might this tell us about how the model is biased?\n",
960+
"\n",
961+
"How do these feature distribution differences affect classification performance? In addition to these qualitative inspections, we can directly compare different values of individual latent variables to corresponding relative classification accuracies (marginalizing out the effects of the other latent variables).\n",
962+
"\n",
963+
"What trends do you observe with this evaluation? How does this affect your understanding of the bias of the facial detection classifier?"
964+
],
965+
"metadata": {
966+
"id": "y97C5Qsh8GvB"
967+
}
968+
},
963969
{
964970
"cell_type": "code",
965971
"source": [

0 commit comments

Comments
 (0)