Code in Variational Classifier

In Variational Classifier Code, let’s say

 Y.shape = (200,)
index = np.random.permutation(range(len(Y)))
num_train = 150
# Y value (i.e.,  -1, 1) corresponding to array of # index of size 150. Also since, index contains # randomly permutated values from 0 to 200, # so selecting first 150 numbers possibly #have  more than 150 in magnitude (i.e., 186, # 157, etc.)
Y_train = Y[index[:num_train]] 

# Now, let's define one more parameter,
batch_index = np.random.randint(0, num_train, (batch_size,))
# It takes 5 random values from 0 to 150 ,

# In optimization loop, here is the problem,
Y_train_batch = Y_train[batch_index]

batch_ index is chosen randomly 5 values but in Y_train is also randomly permutated values. In many cases if batch_index contain value (example :128 as a value) but it didn’t have Y_train. So many times it gives me this error :KeyError: ‘[117] not in index’.

Its not give me error if i choose ,

Y_train = Y[:150]
# rather than randomly generated between 0 to 200 and select 150.

Please, I tried my best explaining the difficulty i am facing. If someone understand the problem show me how can i fix it and where did i go wrong?

Hello @Kshitij_Dave,

Is this the model you are referring to? Variational classifier If so, could you provide more information on the changes you are trying to make. Best regards.

Sorry for late reply. Yes, this is tutorial I am referring to. If you try to implement it on any other datasets, it will probably don’t work in the first time because of the contradicting line of “code” they have used.
I have shared link of jupyter notebook where i have distinguish the problematic part used in the Xanadu notebook . Please see it.

The dataset i used,

Hey! :smile:
It seems that the problem is in the dictionary management. Be careful how you use them or try to access their keys (it doesn’t behave the same as with arrays). If you make sure that before training, what you have are arrays, you will see that it works fine :rocket: If the error persists, let me know

Sorry sir. But i didn’t quite understand what it means by dictionary management. I have given notebook where i perform same task as it is. Please could you clarify much more specifically?

If you put this line below Y=Y[:200] it should work.
Normally it is better to work with arrays instead of dictionaries :slight_smile: