# C5W2A1 Equalize function - output diff from expected Output

For Sequence Model W2 " Programming Assignment: Operations on Word Vectors - Debiasing". My equalize function output is like below.

cosine similarities before equalizing:
cosine_similarity(word_to_vec_map["man"], gender) =  -0.1171109576533683
cosine_similarity(word_to_vec_map["woman"], gender) =  0.3566661884627037

cosine similarities after equalizing:
cosine_similarity(e1, gender) =  -0.23871136142883795
cosine_similarity(e2, gender) =  0.23871136142883792


The cosine similarities after equalizing seems to make sense as they are equal in terms of abs value. But the value differs from the given expected output below. Is it expected?

cosine similarities after equalizing:

cosine_similarity(e1, gender) =	-0.058578740443554995
cosine_similarity(e2, gender) =	0.058578740443555



I don’t want to share the code, but after some search, I think my code is very similar to the one posted with some minor diff (like using np.dot(x,x) vs np.sum(x * x) ).

Any insight here?

Hey @QiuLei_Guo,
Welcome, and we are glad that you could become a part of our community

Please note that posting solutions code publicly is strictly against the Coursera’s Code of Honour, so if you find any person who has done the same, please report it to the community, instead of using the solutions code for completing the assignments, or even for reference purposes. I am sure since this is your first time, you might be unaware of this, so please keep this in mind for future references.

Now, coming back to the issue, can you please check your DM once?

Cheers,
Elemento

Hey @QiuLei_Guo,
Please re-check your code for corrected_e_w1B and corrected_e_w2B in your implementation of the equalize function with the mathematical equations given in the markup. Let us know if this resolves your issue.

Cheers,
Elemento

Thanks @Elemento . Good catch. For equation (9) and (10), I thought it’s (e_w1B - mu_B) / ||(e_w1B - mu_B)|| for normalization. It turns out the correct one is (e_w1B - mu_B) / ||(e_w1 - mu_B)||

Let me dive deep a bit to understand why. If you have some quick answers and insight, that would be great as well.

Hey @QiuLei_Guo,
I just checked out the reference, and it was a pretty long one, so I won’t be delving into that as of now But let me try to make a kernel with some intuitive visualization that can help you understand what the different equations are trying to do. I might need some time for that, I will revert back to you as soon as I am done with it.

Cheers,
Elemento

1 Like

Hey @QiuLei_Guo,
It looks like you might have come across a discrepancy in the equations Check out this kernel (version 6).

You will find that in the first section, where I have used e_wxB to normalize, the corrected vectors are equidistant from the orthogonal axis (as stated). But in the second section, where I have used e_wx to normalize, the corrected vectors aren’t equidistant.

Let me raise an issue regarding this with the team, and I will get back to you with the updates. Till then, you can proceed with the further assignments.

Cheers,
Elemento

1 Like

Thank you @Elemento , you are amazing!

Hey @QiuLei_Guo,
The discrepancy has been resolved. Thanks once again for pointing out the discrepancy.

Cheers,
Elemento

Hi @Elemento I’m facing the exact same issue, can you advise how to fix it?
Tks

Hello @rodrigoaraujo! Elemento is not available. Could you please share your full error?

Hi @saifkhanengr thanks for the reply the issue is pretty much the same as the original topic.

There is no error, however the results of cosine similarities after equalizing are 0.058578… and not 0.23871…

I have reviwed my equations, looked at the kernel ‘Elemento’ has created, but can’t figure out where is the problem.

Any insights where I might making a mistake?

Phew!

It took me quite a long time to figure out what was wrong with Rodrigo’s code. His code for corrected_e_w1B and corrected_e_w2B are equivalent to:

e_{w1B} - \frac{{{\mu_B}} } {||e_{w1B} - \mu_B||_2}

But the original is:

\frac{e_{\text{w1B}} - \mu_B} {||e_{w1B} - \mu_B||_2}

In short, a “parentheses” issue.

Thank you @saifkhanengr for the time spent on pointing out the issue.