For some reasons I m getting very large values for the loss. What could be the reason?
Hi @Jawad
You can heck your calculations (by printing intermediate values) against these and see where they start to differ:
Cheers
Thank you very much for posting this detailed explanation!
Hi - this is very helpful. Is there anychance you could redo it with the names of the variables? I am getting a bit lost trying to match up the code’s comments with the actual variable names? Thanks.
J
The variable names are actually there. They are hard to see, since they are light grey, but you can see them (they are marked as # scores, # batch_size, # positive … up to the last # triplet_loss next to their actual values).
Cheers
Thanks. There are a few that may be missing labels, like mask_diagonal and mask_negative_zero. Can you please confirm that the data labels "# the first mask to extract the diagonal elements is mask_diagonal and the “second mask to extract elements in the negative_zero…” is mask_negative_zero?
The values I get for mask_exclude_positives is tf.Tensor(
[[ True False]
[ True True]], shape=(2, 2), dtype=bool)
You values are:
[[1 0]
[1 1]
I know these are essentially the same (true=1 and false =0)
And then my negative_without_positiveis tf.Tensor(
[[ 0. -2. ]
[-0.95350769 0. ]], shape=(2, 2), dtype=float64)
instead of [-2. 0.95350769] [-0.95350769 -2. ]
closest_negative is tf.Tensor([0.95350769 0. ]
instead of: [0.95350769 -2. ])
Any suggestions on what to verify? Thanks
There are no mask_diagonal
or mask_negative_zero
variables in the Assignment. You probably created them yourself? But if they were in the Assignment, they would probably represent the code comments from the picture and I could confirm .
The reason I included them is because mask_exclude_positives
consist of two part and the code comments above the line hints at what they should be. So, if you created separate variables for each part and named them “mask_diagonal and mask_negative_zero” then you should be ok.
That is exactly the reason why you have tf.cast((None)|(None), scores.dtype)
completed for you - it converts boolean values to float (for True, False to 1.0, 0.0 in our case).
Most probably you subtract the other way around (or maybe from a different variable). Note the code hint:
# multiply `mask_exclude_positives` with 2.0 and subtract it out of `negative_zero_on_duplicate`
Note, that you should subtract from negative_zero_on_duplicate
(and not the other way around, as I suspect you do).
I would suggest to fix one mistake at a time, since subsequent values depend on previous ones.
Cheers
Thanks - that helped a lot! As suggested, I fixed one mistake at a time…It helps also that I re-read the comments…
One more thing. I got to the w3_unittesttest_TripleLoss and I get the response:
Got a wrong triplet loss for inputs out: …
So I must have some non-starnard code in def TripletLossFn. I don’t have anything hardcoded, but I did in earlier versions, and I will admit my code is not the prettiest…
Is there anyway I can download the original code (with all the “None” so I can redo the lab from the start? Googled how to do it but I couldn’t get a few different methods to work.
To be clear, I am looking for the original version of C3W3_Assignment.ipynb for Assignment 3: Question duplicates.
Thanks!
John
How to get a new copy of the assignment.
- Use the File menu and rename your current notebook.
- Use Help → “Get latest version” to get a new copy.
- Use the File menu and Open the new copy.
- Use Kernel → “Restart & clear output”.
Then you’re ready to use the new notebook.
Thank you TMosh! That worked.
For anyone reading this looking for the correct file name, look for the file called: C3W3_Assignment.ipynb
The ‘Last modified date’ was from 2 months ago so Feb 2024 which may have been when I started this course.