Doubt in C1_W4 assignment


Please explain the the highlighted part. I am not getting how to write it in code.

Hi @PG_Coursera

It means that after finding the nearest French embedding for each transformed English embedding, you compare the index of this nearest French embedding with the index of the correct French embedding. If they match, it means the translation was predicted correctly.

Hope it helps! Feel free to ask if you need further assistance.

Hi @PG_Coursera

This should help you understand :point_down:t2:

Regards
DP

Ma’am, I had solved that problem. Thanks for the concern.

1 Like


Sir, I am not getting the meaning of this error. How to fix it?

This should help you understand your error

Regards
DP

Hi @PG_Coursera

I haven’t seen your codes yet, you have not created the planes index it is looking for, hence throwing this error.

Also rather than sending whole notebook, only send screenshot of the grade cell you are having issue. I usually don’t download learner’s notebook untill i suspect multiple errors.

Regards
DP

I did not get you. What does this planes index mean?

if you notice in your error, it mentions set the planes at index{idx}

as you indexing in python start from 0 and not from i, so you need to check while the has value of vector is a combination of vector and planes, you not assigning index value or the start point to this hash value, will throw this error.

For example, suppose you are recalling hash value as h, make sure you have assigned an index value such h.shape[0]

if you can send me the codes screenshot for that particular grades this showed error I can have a look, but send through personal DM. don’t post codes here.

Regards
DP

The point of the error message is that the array h[] in that line of code is not the correct shape. So what shape is it? Add this statement before the loop:

print(f"h.shape = {h.shape}")

From the error message it sounds like it has no elements on axis 0. The way that loop is written, h will need to have as many elements on axis 0 as n_planes, right? So why did it end up with 0 elements on axis 0?

The process I described there is one way to approach debugging: you start from the error message. The first step is to be sure you understand what it is telling you. Then you work backwards to figure out where the actual problem is.

@paulinpaloalto Thanks for the help, Sir


I am getting this error for make_hash_table function. But all the test cases for hash_value_of_vector function were passed. Why is it so?

Did you do what I suggested and print the shape of h? That new error with the changed code is probably just confirming my theory in my previous post: that h is basically empty. What you need to figure out is why that happened.

For hash_value_of_vector function, what you’d suggested, I have applied it and got the correct result. But for make_hash_table function, it is instructed that the code block cannot be edited! How to check then?

Are you sure that your hash_value_of_vector function passes the tests in the notebook?

The point of make_hash_table is that it calls the hash_value_of_vector function that you wrote, so it won’t work correctly unless your function is correct.

Please show us the output you are getting that is a problem.


Here is the screenshot of hash_value_of_vector test code.

Ok, it looks like your function is correct, but it still fails when called from make_hash_table and make_hash_table is not modifiable. So that leaves one more theory:

There must be something wrong with the input parameters that are being passed to the test case for make_hash_table. Notice that it depends on the variable planes_l. Did you run the cell that creates that? Also notice that the cell that creates planes_l is modifiable, but the contents were just given to you. Are you sure you didn’t modify it? Here’s what it looks like in my notebook:

np.random.seed(0)
planes_l = [np.random.normal(size=(N_DIMS, N_PLANES))
            for _ in range(N_UNIVERSES)]

Well, I guess there is one other possible theory: that your notebook is not the latest one or maybe it’s been damaged in some way. E.g. that could happen if you downloaded it and ran it on some other platform than the course website and then re-uploaded it.

Ok, after a private DM conversation to look at the actual code, it turns out the issue is that the code written in hash_value_of_vector was not general enough. It passes the test case for that function, but make_hash_table passes inputs with different dimensions. I added some print statements to figure out what is going on. Here’s what I see with the test case for hash_value_of_vector:

dot_product.shape (1, 10)
type(h) <class 'numpy.ndarray'>
h.shape (10,)
dot_product.shape (1, 8)
type(h) <class 'numpy.ndarray'>
h.shape (8,)

Then when I run make_hash_table, here’s what I see:

dot_product.shape (10,)
type(h) <class 'numpy.float64'>
h.shape ()

So the hash_value_of_vector code is not correctly handling the case in which the inputs give a 1D vector for dot_product.

It would be better if the test case for hash_value_of_vector caught this error, so I will file an enhancement request about that.