suriyadeepan / practical_seq2seq

A simple, minimal wrapper for tensorflow's seq2seq module, for experimenting with datasets rapidly
http://suriyadeepan.github.io/2016-12-31-practical-seq2seq/
GNU General Public License v3.0
570 stars 270 forks source link

ValueError: Sample larger than population or is negative while testing #70

Open nidhikamath91 opened 5 years ago

nidhikamath91 commented 5 years ago

Below is my code for testing and I am getting this error

import data import data_utils import seq2seq

import importlib

load data from pickle and npy files

metadata, idx_q, idx_a = data.load_data(PATH='./') (trainX, trainY), (testX, testY), (validX, validY) = data_utils.split_dataset(idx_q, idx_a)

parameters

xseq_len = trainX.shape[-1] yseq_len = trainY.shape[-1] batch_size = 16 xvocab_size = len(metadata['idx2w']) yvocab_size = xvocab_size emb_dim = 1024

importlib.reload(seq2seq)

model = seq2seq.Seq2Seq(xseq_len=xseq_len, yseq_len=yseq_len, xvocab_size=xvocab_size, yvocab_size=yvocab_size, ckpt_path='./ckpt', emb_dim=emb_dim, num_layers=3 ) val_batch_gen = data_utils.rand_batch_gen(validX, validY, 256) test_batch_gen = data_utils.rand_batch_gen(testX, testY, 256) train_batch_gen = data_utils.rand_batch_gen(trainX, trainY, batch_size)

sess = model.restore_last_session()

input_ = test_batchgen.next()[0] output = model.predict(sess, input) print(output.shape)

replies = [] for ii, oi in zip(input_.T, output): q = data_utils.decode(sequence=ii, lookup=metadata['idx2w'], separator=' ') decoded = data_utils.decode(sequence=oi, lookup=metadata['idx2w'], separator=' ').split(' ') if decoded.count('unk') == 0: if decoded not in replies: print('q : [{0}]; a : [{1}]'.format(q, ' '.join(decoded))) replies.append(decoded)

the error is as below

C:\Users\d074437\PycharmProjects\seq2seq>python test.py 2018-10-06 11:22:00.982163: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

Building Graph Traceback (most recent call last): File "test.py", line 39, in input_ = test_batch_gen.__next__()[0] File "C:\Users\d074437\PycharmProjects\seq2seq\data_utils.py", line 38, in rand_batch_gen sample_idx = sample(list(np.arange(len(x))), batch_size) File "C:\Users\d074437\AppData\Local\Programs\Python\Python36\lib\random.py", line 320, in sample raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population or is negative Please let me know how to proceed