I have been stuck on exercise 4 of the week 3 question duplicates assignment.
The issue that I am facing is that my classify function outputs the incorrect accuracy and confusion matrix. All of the unit tests pass for exercises 1-3 and I’ve gone through all of my code to find a possible source of the issue, but there are none I am aware of.
I suspect there is a simple error in my classify function, but even after looking through the community I am unable to find what the issue may be. Here’s a walkthrough of each step in my solution:
Split the model’s output into v1 and v2.
Compute d with tf.math.reduce_sum of the similarity between v2 and v1 using tf.matmul.
Compute y_pred as where d is greater than threshold and cast to float.
Calculate correct predictions with y_pred == y_test and casting the result to float, then calculating accuracy using tf.math.reduce_mean.
Create the confusion matrix using y_pred and y_test
Extremely sorry @reyaes I missed your DM reply between other notifications
Correction required
In GRADE FUNCTION Siamese
code line
Add the normalizing layer using the Lambda function
you need to add axis argument too for the correction dimensionality
In the same grade cell, for input1 and input2, mention the shape as a tuple(1)
GRADE FUNCTION TripletLossFn
your codes are quite right, but while calculating tripletloss1 and triplet loss2, you are missing a tupe again for the calculation to work upon. instruction mentions
subtract positive from margin and add `closest_negative, so it should be placed as
(0, (margin-positive)+closest_negative)) same for tripletloss2
GRADE FUNCTION train_model, in the model argument, you aren’t suppose to use len function. text_vectorizer is your function key and vocabulary_size is the size of your vocab for vocab_size in the model code. You don’t require get.vocabulary()
when you do these corrections, first clear out the kernel output, then restart and re-run each cell as you make these corrections for successful resolution of your issue. let me know if you are still encountering any issue.
Could there be issues with my notebook instance that Coursera is running? I could contact Coursera support, but I am not sure what else could be the issue.
I found the source of the error was indeed in the classify function. I was using tf.linalg.matmul instead of element-wise multiplication.
I was confused by this because we use tf.linalg.matmul to calculate similarity in the loss function, so I thought I had to do the same in the classify function. The instructions do say “Multiply v1 and v2 element-wise,” which I overlooked.
I hope others with the same issue can find this solution helpful.