Hello,
I keep getting the assertion error for wrong values in the sample/ sample test. The same error I guess propagates in the model() function. In the sample. I have added the bias terms, used random choice by using ravel() on probability vector. Also before next iteration i shuffle the probability vector.
Can someone give a hint where I am going wrong
First, letβs talk about the sample
function. This is the structure of the code given to you:
### START CODE HERE ###
# Step 1: Create the a zero vector x that can be used as the one-hot vector
# Representing the first character (initializing the sequence generation). (β1 line)
x = None
# Step 1': Initialize a_prev as zeros (β1 line)
a_prev = None
# Create an empty list of indices. This is the list which will contain the list of indices of the characters to generate (β1 line)
indices = []
# idx is the index of the one-hot vector x that is set to 1
# All other positions in x are zero.
# Initialize idx to -1
idx = None
# Loop over time-steps t. At each time-step:
# Sample a character from a probability distribution
# And append its index (`idx`) to the list "indices".
# You'll stop if you reach 50 characters
# (which should be very unlikely with a well-trained model).
# Setting the maximum number of characters helps with debugging and prevents infinite loops.
counter = 0
newline_character = char_to_ix['\n']
while (idx != newline_character and counter != 50):
# Step 2: Forward propagate x using the equations (1), (2) and (3)
a = None
z = None
y = None
# For grading purposes
np.random.seed(counter + seed)
# Step 3: Sample the index of a character within the vocabulary from the probability distribution y
# (see additional hints above)
idx = None
# Append the index to "indices"
indices.append(idx)
# Step 4: Overwrite the input x with one that corresponds to the sampled index `idx`.
# (see additional hints above)
x = None
x[idx] = None
# Update "a_prev" to be "a"
a_prev = None
# for grading purposes
seed += 1
counter +=1
### END CODE HERE ###
Most of the steps are simple but how you are doing the step 3? Please explain it in words (without revealing your code).
In step 3, I used the 2D to 1D converted probability vector to sample a single random index from an ordered list of indices.
I think this is correct. I am sending you a private message to see your code.
To update others, for step 4, we have:
x = None
x[idx] = None
Think about it. All values of x
are zero as we use np.zeros but we want to replace one value of zero with 1. And that value index is idx. So, how to do this?
If I want to replace any value of a particular index, I will do like this:
x[index] = replaced_value
1 Like
This was helpful. Thanks for explanation.
1 Like