C3W3_Assignment - Exercise 02

Hello @arvyzukai
Cc: @reinoudbosch @mugdhagovilkar @sugaprho @Krzysztof_Jakubczyk

I’m still not achieving the expected loss value of approximately 0.7, and given that I’ve explored a wide range of modifications and adjustments without success, it may be best to seek additional guidance from all of you.

A summary of my efforts and the challenges I’ve encountered.

  1. Initial Approach:

    • Implemented a TripletLossFn using cosine similarity and TensorFlow operations, aiming to achieve a triplet loss value close to 0.7.
  2. Challenges and Adjustments:

    • Struggled to align the loss value with the target of ~0.7.
    • Adjusted the margin parameter and experimented with different input vectors.
    • Explored modifications such as L2 normalization and changing the axis parameter in mean negative calculation.
    • Simplified the loss function to focus on direct computation using cosine similarity.
    • Ensured variables like batch_size were correctly used within the loss function.
  3. Testing and Validation Efforts:

    • Regularly tested the modified loss function with both the provided dataset (two specific numpy arrays) and simpler vectors.
    • Despite these efforts, the loss values did not approximate the expected ~0.7.
  4. Persistent Issues:

    • Continued difficulty in achieving the expected loss value, even after multiple iterations and approaches.
    • Encountered an AssertionError when attempting to assert the computed loss value against the expected target, despite adjusting the tolerance level.
  5. Request for Insights:

    • Seeking guidance or suggestions from my fellow learners, particularly regarding any special considerations or overlooked aspects in the assignment specifications.


Hello @RyeToast,

I am also doing the same course and same assignment currently :joy: :sob: :nerd_face: :ok_woman: :woman_facepalming:

I will tag NLP Mentor, @arvyzukai probably he is better person to handle your issue.
I am also a learner for this course right now, sorry @RyeToast.



1 Like

Hello @RyeToast

did you read this two instructions before the TripleLossFn

As this will be run inside Tensorflow, use all operation supplied by tf.math or tf.linalg , instead of numpy functions.

Use the TensorFlow functions tf.eye and tf.math.reduce_max for the identity matrix and the maximum respectively.

probably in this grader cell you are recalling codes correctly. when you click on these instruction in the assignment it directs you to the document on how to recall these codes. Kindly refer them as I can’t be sure as I have not seen your codes.


1 Like

Hello DP,

Thank you for your guidance on the Triplet Loss assignment. I’ve been making several adjustments based on the provided instructions and your suggestions. However, I’m still facing challenges in achieving the expected output of approximately 0.7 for the Triplet Loss. Here’s a summary of the steps I’ve taken and the results so far:

  1. Adjusted Implementation: I’ve revised the TripletLossFn to ensure it uses TensorFlow operations (tf.math and tf.linalg) as recommended. I also experimented with adjusting the margin in the loss function.

  2. Tested with Simplified Data: I created a simplified test case with basic vectors to test the loss function, which resulted in a loss of 0.6.

  3. Used Grader’s Test Data: When running the loss function with the grader’s test data, I obtained a loss value of 0.40000004.

Despite these efforts, the loss values I’m obtaining are still not close to the target of 0.7. I’m wondering if there might be an underlying issue with the test data or if there’s a specific aspect of the loss function calculation I might be overlooking.

Would you have any additional suggestions or insights that might help me align the loss value more closely with the expected target? Your expertise and advice would be greatly appreciated.

Thank you for your time and assistance.

1 Like

are you still getting the assertion error?

Hello @RyeToast,

are you doing the older version of the assignment??

as the cell for me related def TripletLossFn(v1, v2, margin=0.25): is completely different than what you shared in DM.

I am sharing an image how it is seen to me (if it is not same as yours, then kindly use Updated lab and get the latest version by clicking on Help, which will give you updated version of the assignment.


Hi @RyeToast

You might have changed your code too much times and you could have got lost in the process. A good approach would be refresh your environment and redo the Assignment (only filling/pasting the code where asked, between: start code here … end code here).

EDIT: Thanks to @Ramkumar_Anantha, I updated the old calculations with the new updated Course’ version

But first make sure you haven’t changed your code too much (just reading your first post indicates many places where you could have got wrong and failed to recover).



I got the latest version and rebooted, but my code is still the same. I’ll try yours and see what happens???


you mean you don’t have codes like mine??

@RyeToast, did you follow the steps correctly.

You need to delete the file from the file section, then do the rebooting, then after get latest version, you need to Update lab.

@arvy can you please look this updated version of assignment how can be obtained as the learner rebooted and got the get the latest version.


I don’t really know how the courses are handled. I personally don’t remember the procedure how I switched the courses (probably it happened through a link as I was a tester(couple of moths ago)). I remember logging in and all my notebooks were new (so keep that in mind because you’ll have to redo the C3 and C4).

Maybe these threads can help:

But to be honest, I don’t know if the things are the same (have they changed the policy since then) or how are things now regarding that.


Here’s what it originally started out as:

def TripletLossFn(v1, v2, margin=0.25):

# {Deleted by moderator}
return triplet_loss

“You need to delete the file from the file section, then do the rebooting, then after get latest version, you need to Update lab.”

How do I do that?

you have your notebook open?

Here’s what I’m seeing:

you mean ‘jupyter’, yes.

where are your arguments statements? anyways leave that.

I asked you the previous question, as I want you to follow steps one by one mention

click file then open, there select all files and delete.

please do and let me know, then I will tell you further steps. also to be safer side please clear your cache and browser history

okay deleting files.

It’s asking if I permanently want to delete these files.