# [Week 2] Assignment 1: Operations on Word Vectors - Debiasing - Exercise 5.2

Are the formulas really correct and is the expected output really correct??
I tried different things (used np.linalg.norm or calculated everything without this function) but still can’t get the expected output.

My result is like:
man 0,9999
woman -0,9999

Help is very much appreciated

3 Likes

Hi, I’ve also tried with different methods for the L2 norm and `np.absolute()` but my results always comes back as:

cosine_similarity(e1, gender) = -0.7004364289309388
cosine_similarity(e2, gender) = 0.7004364289309387

Although their absolute values are, practically, identical, they do not match the “expected output” after equalizing (the values before equalizing match the expected output).

1 Like

Same for me:
cosine_similarity(e1, gender) = -0.7004364289309387
cosine_similarity(e2, gender) = 0.7004364289309387

1 Like

For me now also like this

cosine similarities after equalizing:
cosine_similarity(e1, gender) = -0.7004364289309388
cosine_similarity(e2, gender) = 0.7004364289309389

But it should be:
cosine similarities after equalizing:

cosine_similarity(e1, gender) =-0.942653373599985
cosine_similarity(e2, gender)=0.9231551731025899

One mentor could comment on this pls ?

1 Like

Got the same results as the posts above. Could mentor pls comment?

2 Likes

I am also getting
cosine similarities after equalizing:
cosine_similarity(e1, gender) = -0.7004364289309388
cosine_similarity(e2, gender) = 0.7004364289309388

1 Like

Hi,

I also get the same:

cosine_similarity(e1, gender) = -0.7004364289309388
cosine_similarity(e2, gender) = 0.7004364289309387

Kindly help. Thanks.

1 Like

I also got the same result.

cosine similarities after equalizing:
cosine_similarity(e1, gender) = -0.7004364289309388
cosine_similarity(e2, gender) = 0.7004364289309389

I have followed the equations.

1 Like

The formulas are correct. You just need to be careful how to put it in code.

||bias_axis||22

can be calculated by calling np.linalg.norm(bias_axis), and then raise the returned value to the power of 2

Also, make sure the brackets are in the right places.

1 Like

Hi Mr. Kic,
I used np.square(np.linalg.norm(bias_axis)) to compute ||bias_axis||22, but I still get the same results as others.

cosine similarities after equalizing:
cosine_similarity(e1, gender) = -0.7004364289309388
cosine_similarity(e2, gender) = 0.7004364289309389

Thanks and Best Regards,
Leonardo Edgar

2 Likes

I use np.linalg.norm(bias_axis) and raise it to the power of 2, but still get the same results as others.

I understand that the formulae in the notebook are correct. Could you please doublecheck that the expected output in the notebook is correct too?

2 Likes

I am seeking help on this one. So please give us a little time to sort this out.

As this is an optional exercise, it does not count toward your grade. You can submit this assignment and move on to the next one.

I will let you know the outcome ASAP.

1 Like

I am also having trouble on this assignment, but in a couple different ways. First, I when I implement the equations, I get a calculation error. That is, the result is NaN. The problem appears to come from the sqrt(1-|mu_orth|^2).
I double and triple checked my calculation of mu_orth and cannot find a mistake. Furthermore, I don’t see how the equations could be correct. mu_orth could sometimes be greater than 1, which would make the square root here imaginary (or undefined, here NaN). I looked at the reference paper and, I think, some basis set vectors were normalized (i.e., length of 1), which would guarantee that mu_orth was less than or equal to one.

To avoid the square root of -something, I replaced 1 with |mu|^2. I didn’t get the results expected, but they were equal magnitude, opposite sign results.

1 Like

I believe that the formula in the notebook is sqrt(|1-norm^2(mu_orth)|), i.e. the absolute value is applied to 1-norm^2(mu_orth).
However, I am not sure how this formula was derived.

1 Like

Ahhh. I see that now. Thanks. I am now getting what everyone else in this thread calculated. Much appreciated.

However, looking at the reference paper, I don’t see how that absolute value can possibly be correct. The language is a little different (more general but also more complicated) in the paper, but the equivalent equation in the paper doesn’t have an absolute value. I suspect someone was having my problem and “fixed” it without understanding the underlying theory.

2 Likes

I believe you’re right. I’ve read the paragraph where the formulae are presented in the article and understood it in the following way.

The new ‘equalized’ embedding is presented as the sum of two orthogonal vectors: mu_orth (which is v in the article) and (w_b - mu_b). The new embedding is scaled so that it has unit length. In order to achieve this, the second term (w_b - mu_b) is multiplied by a coefficient k, which we’re going to derive. We start with e_new = mu_orth + k*(w_b - mu_b).

The norm of the sum equals sqrt(|mu_orth|^2 +k^2*|w_b - mu_b|^2). For this expression to equal 1, we have to solve the equation |mu_orth|^2 +k^2*|w_b - mu_b|^2 = 1 for k. From here we get k = sqrt(1 - |mu_orth|^2) / *|w_b - mu_b|, which is what we see in the formula. This only works if |mu_orth|^2 is less than 1. This is probably true in the case of the article, because their original embeddings are unit vectors (see page 3).

However, in our homework exercise the norm of the embeddings is greater than one. I checked this for np.linalg.norm(word_to_vec_map[“man”]). If |mu_orth| > 1, it’s impossible to get a unit vector by adding another orthogonal vector to mu_orth. I don’t see where the absolute value under the square root sign is coming from. It looks like after all the formulae (9) and (10) are not correct.

1 Like

It looks like (9) should be simply

corrected_e_w1B = e_w1B - mu_B

without any scaling. In this case I get

cosine_similarity(e1, gender) = -0.2423973757231344
cosine_similarity(e2, gender) = 0.24239737572313433 ,

which is close to the original values

cosine_similarity(word_to_vec_map[“man”], gender) = -0.11711095765336832
cosine_similarity(word_to_vec_map[“woman”], gender) = 0.35666618846270376

but more “symmetric”. I wonder whether this is correct.

1 Like

Thank you this helps to understand where the `sqrt(1 - norm(mu_orth) ^2)` comes from !

Actually, the simplification is then like this :

`e_w1B = e_w1 - mu_orth` and
`corrected_e_w1B = k * (e_w1B - mu_B)` which is as given :
`corrected_e_w1B = sqrt(abs(1 - norm(mu_orth) ^ 2)) / norm(e_w1B - mu_B) * (e_w1B - mu_B)`

And it gives for me the same as the others :
cosine similarities after equalizing:
`cosine_similarity(e1, gender) = -0.7004364289309387`
`cosine_similarity(e2, gender) = 0.7004364289309387`

1 Like

Hi Kic,

as an old learner, I remember there was a post addressing this problem in the old Discussion Forum and it corrected the equitions provided in Exersice instruction.

Unfortunately, I cannot find that post because all the old posts seem gone. But if you can find those old posts, maybe it will help.

1 Like

Hi @Wenyu,

Thank you for letting us know about this. However, I have no access to the original version of the Discussion Forum. I am sure more information will be given by the staff team soon. Let’s wait for their answers.

1 Like