Hello,
I’ve been struggling a bit with UNQ_C2. After reading below what I did, can you please help me finding out what I missed or did wrong? Thank you for your help.
After computing y, y.shape = (27, 100)
Preliminary question: I don’t understand the 100, what is the intuition for that?
My piece of code is:
probs = y.ravel() # probs.shape = (2700,)
idx = np.random.choice(a = range(len(probs)), p = probs)
First issue:
The np.random.choice issues an error: “ValueError: probabilities do not sum to 1”
Indeed, the softmax was operated on each of the 100 channels independently, then after flattening, the sum is ~100, not ~1
Then I tried to normalize:
probs = y.ravel() / n_a
idx = np.random.choice(a = range(len(probs)), p = probs)
This leads to the 2nd error.
Second issue:
The “IndexError: index 2354 is out of bounds for axis 0 with size 27” is outputted
Indeed, idx should be within [0, vocab_size[, not within [0, len(probs)[
In np.random.choice(a, p), both a and p shall have the same dimension. I don’t know how to reduce p to [0, vocab_size[ so that a cal also be reduced to [0, vocab_size[.
What I can do tho is to reduce the output of np.random.choice from [0, len(probs)[ to [0, vocab_size[
probs = y.ravel() / n_a
idx = np.random.choice(a = range(len(probs)), p = probs) % vocab_size
This leads to the 3rd issue.
Third issue:
An assert is broken “AssertionError: Wrong values”
At this point I’m clueless.
Note: in another thread, some people mentioned that the softmax function was not properly working. Unless the result of the softmax sum has to be precisely 1.0, there seems it works quite well.
for i,_ in enumerate(y):
print(f’y_{i} = {y[:,i].sum()}')
y_0 = 0.9999999999999998
y_1 = 0.9999999999999998
y_2 = 0.9999999999999998
y_3 = 0.9999999999999998
y_4 = 0.9999999999999998
y_5 = 0.9999999999999998
y_6 = 0.9999999999999998
y_7 = 0.9999999999999998
y_8 = 0.9999999999999998
y_9 = 0.9999999999999998
y_10 = 0.9999999999999998
y_11 = 0.9999999999999998
y_12 = 0.9999999999999998
y_13 = 0.9999999999999998
y_14 = 0.9999999999999998
y_15 = 0.9999999999999998
y_16 = 0.9999999999999998
y_17 = 0.9999999999999998
y_18 = 0.9999999999999998
y_19 = 0.9999999999999998
y_20 = 0.9999999999999998
y_21 = 0.9999999999999998
y_22 = 0.9999999999999998
y_23 = 0.9999999999999998
y_24 = 0.9999999999999998
y_25 = 0.9999999999999998
y_26 = 0.9999999999999998