I am working on the code for the function ‘sample’ in A2 of W1. I cannot make it work because of different sizes in vocab_size and p (27 vs. 2700). I tried to troubleshoot it several times, but I am really stuck. This is the code I implemented:
codes removed by moderator as it is against community guidelines.
Any help will be greatly appreciated. Thanks in advance.
Hi @gugasparini, your code was removed by a moderator as it is against community guidelines. But you can share a screenshot of your complete error so that the mentors can help you out.
I have double checked sizes of all vectors and matrices and do not know how to bring p (p=y.ravel()) and vocab_size to be the same size so that idx can work
Once again, appreciate any help. I am really stuck
In addition to Tom’s points, here’s a thread which shows the sizes of the various values in this function. Please compare your results to what you see there and maybe that will give some insight.
Ok, I did some experiments based on the code that you showed. Your mistake is that you have created x as a 1D vector with shape (vocab_size,). It must be a 2D vector with shape (vocab_size, 1).
The way various operations work when you mix 2D and 1D vectors is different and can be surprising (in a bad way ).
One other note is that they gave you a softmax function, so you don’t have to write that out yourself: you can just call it.
Thank you @paulinpaloalto very much for your advice. That was indeed the problem. I corrected it and the code ran successfully!
Really appreciate it! Thank you @lukmanaj and @TMosh for your help as well!