Need help with code for mask_exclude_positives - have no idea what to put.
The structure seems to be very different from the exercise.

1 Like

Hi @Jenna

Yes, the structure is a bit different, but the idea is the same. What you need is adapt this code from lab:

mask_1 = np.identity(b) == 1            # mask to exclude the diagonal
mask_2 = sim_an > sim_ap.reshape(b, 1)  # mask to exclude sim_an > sim_ap
mask = mask_1 | mask_2

and you have these suggestions from the Assignment:

Next, we’ll create mean_negative. As the name suggests, this is the mean of all the ‘negative’/blue values in score on a row by row basis. We can use fastnp.eye(batch_size) and a constant, this time to create a mask with zeros on the diagonal. Element-wise multiply this with score to get just the 'negative values. This is negative_zero_on_duplicate in the code. Compute the mean by using fastnp.sum on negative_zero_on_duplicate for axis=1 and divide it by (batch_size - 1) . This is mean_negative.

Please message me if you still won’t be able to implement it.

Hi @arvyzukai , I am still not able to understand this part. Can you help me with this?


You could find this thread useful:

Take a look at it and let me know if you have further questions.


1 Like