Closed coreych closed 5 years ago
I had a similar error,
and it was dude to the following line:
encoder_inputs_t.append(tf.placeholder(tf.int32, shape=[None], name="encoder{0}".format(i)))
replace every such line, like above, to below
encoder_inputs_t.append(tf.placeholder(tf.int32, shape=[None,], name="encoder{0}".format(i)))
Check the value of shape attribute. This surprising worked for me 👍
@AbhishekAshokDubey which file is located of you changed the code?
hi, did you fixed the problem?
@coreych ,did you fix this problem?
Please switch to latest Tensorflow version.
In the last layer of the model use proper shape. For eg you used model.add(Dense(256, activation='softmax')) as the last layer. Here 256 restricts output's value from [0, 256) change its shape to the maximum output label. For eg your output is from label [0,23000) then use model.add(Dense(23000, activation='softmax'))
Switch to latest TensorFlow version.
please help
InvalidArgumentError: Received a label value of 3298 which is outside the valid range of [0, 2). Label values: 980 3113 2936 1164 2232 3298 1612 2849 1877 3205 3065 1432 2407 2582 1300 2143 1074 1000 2692 1341 1770 1976 2120
[[node sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits (defined at
Function call stack: train_function
if its a regression problem, according to me its possible to get such response from the system. In case of classification, you have to use softmax on the output layer to ivercome such problem,
@vipinbansal1 Thanks for the response I did try to use softmax but the issue was not resolved
numDim = X_train_normalized.shape[1] dnnModel = tf.keras.Sequential([ layers.Dense(16, activation = 'relu', input_shape =(numDim,)), layers.BatchNormalization(), layers.Dropout(0.3), layers.Dense(16, activation = 'relu'), layers.BatchNormalization(), layers.Dropout(0.3), layers.Dense(126, activation = 'relu'), layers.BatchNormalization(), layers.Dropout(0.5), layers.Dense(160, activation = 'relu'), layers.BatchNormalization(), layers.Dropout(0.5), layers.Dense(10, activation = 'relu'), layers.Dropout(0.1), layers.BatchNormalization(), layers.Dense(2)
]) optimizer = tf.keras.optimizers.Adam(0.01) dnnModel.compile(optimizer=optimizer, loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy'])``
numDim = X_train_normalized.shape[1]
dnnModel = tf.keras.Sequential([
layers.Dense(16, activation = 'relu', input_shape =(numDim,)),
layers.BatchNormalization(),
layers.Dropout(0.3),
layers.Dense(16, activation = 'relu'),
layers.BatchNormalization(),
layers.Dropout(0.3),
layers.Dense(126, activation = 'relu'),
layers.BatchNormalization(),
layers.Dropout(0.5),
layers.Dense(160, activation = 'relu'),
layers.BatchNormalization(),
layers.Dropout(0.5),
layers.Dense(10, activation = 'softmax' ),
layers.Dropout(0.1),
layers.BatchNormalization(),
layers.Dense(2)
])
optimizer = tf.keras.optimizers.Adam(0.01)
dnnModel.compile(optimizer=optimizer, loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy'])
dnnModel.fit(X_train_normalized, y_train, epochs=100)
Epoch 1/100
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-93-47e282adff89> in <module>
----> 1 dnnModel.fit(X_train_normalized, y_train, epochs=100)
2 #last results accuracy shows training accuracy
~\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
1181 _r=1):
1182 callbacks.on_train_batch_begin(step)
-> 1183 tmp_logs = self.train_function(iterator)
1184 if data_handler.should_sync:
1185 context.async_wait()
~\Anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in __call__(self, *args, **kwds)
887
888 with OptionalXlaContext(self._jit_compile):
--> 889 result = self._call(*args, **kwds)
890
891 new_tracing_count = self.experimental_get_tracing_count()
~\Anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in _call(self, *args, **kwds)
948 # Lifting succeeded, so variables are initialized and we can run the
949 # stateless function.
--> 950 return self._stateless_fn(*args, **kwds)
951 else:
952 _, _, _, filtered_flat_args = \
~\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py in __call__(self, *args, **kwargs)
3021 (graph_function,
3022 filtered_flat_args) = self._maybe_define_function(args, kwargs)
-> 3023 return graph_function._call_flat(
3024 filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access
3025
~\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
1958 and executing_eagerly):
1959 # No tape is watching; skip to running the function.
-> 1960 return self._build_call_outputs(self._inference_function.call(
1961 ctx, args, cancellation_manager=cancellation_manager))
1962 forward_backward = self._select_forward_and_backward_functions(
~\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py in call(self, ctx, args, cancellation_manager)
589 with _InterpolateFunctionError(self):
590 if cancellation_manager is None:
--> 591 outputs = execute.execute(
592 str(self.signature.name),
593 num_outputs=self._num_outputs,
~\Anaconda3\lib\site-packages\tensorflow\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
57 try:
58 ctx.ensure_initialized()
---> 59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
InvalidArgumentError: Received a label value of 3298 which is outside the valid range of [0, 2). Label values: 1074 2232 2849 3298 2936 2407 1341 1770 2120 3205 2143 3065 2582 1877 3113 2692 980 1432 1000 1976 1164 1300 1612
[[node sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits (defined at <ipython-input-93-47e282adff89>:1) ]] [Op:__inference_train_function_12138]
Function call stack:
train_function
last layer should have softmax as an activation function. Refer online available source code for more info...
Thank you, got it right.
Anyhow has a similar issue?
Run the following command
And the error:
Reading development and training data (limit: 0). reading data line 100000 W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Received a label value of 19143 which is outside the valid range of [0, 256). Label values: 149 567 18943 7 7 1024 7 78 20 160 1216 320 11712 78 273 5 33 566 78 138 20 212 1650 392 104 1359 69 83 14028 3 241 487 33 273 7 33 142 3 7 619 547 7 7 124 33 415 4 2753 3035 33 562 79 79 127 354 47 19143 62 117 20 33 1664 78 6290 W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Received a label value of 10939 which is outside the valid range of [0, 256). Label values: 13 5942 168 5 64 4 5 4 25 221 32 9 595 4 7 149 48 141 30 31 29 6 8 4 9 114 8 6 4 7 34 4 5 8 44 9 111 10245 5 59 9 5 136 5 52 6 4 4 2 42 15 6 15 8 150 9 7804 10939 924 96 5 13 16 19 W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Received a label value of 5787 which is outside the valid range of [0, 256). Label values: 527 4 37 24 11 2 24 2 37 23 102 2 108 2 42 750 3 4 15 80 11 7 5787 2 2 9 29 7 2 25 6 4 85 267 5 2 252 2249 24 16 2 24 10 14 8 342 4 2 0 9 144 161 5 125 453 190 16 3 1060 21 85 369 2 2326 W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Received a label value of 10895 which is outside the valid range of [0, 256). Label values: 4 2 1665 87 600 0 295 0 221 950 812 0 50 0 9 5 9 2 23 949 436 488 9 0 0 2 11 100 0 8 125 4 8 42 14 0 4 168 279 2 0 279 280 36 196 4 15 0 0 33 6 9 12 11 4 42 10895 9 4 13 15 358 0 4 W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Received a label value of 10079 which is outside the valid range of [0, 256). Label values: 528 0 4 2577 13 0 189 0 4 4 4 0 3 0 2 9 2 0 4 4 26 18 2 0 0 0 398 4 0 9 34 148 36 7 130 0 2 13 4 0 0 4 4 15 9 745 23 0 0 10079 4101 2 40 5360 2 100 16 2 2 644 106 4 0 2 W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Received a label value of 19143 which is outside the valid range of [0, 256). Label values: 9 0 2 87 300 0 4 0 2 2 2 0 9 0 0 2 0 0 2 2 294 838 0 0 0 0 37 2 0 2 4 7 9 137 10 0 0 568 337 0 0 2 2 16 16 807 77 0 0 9 30 0 13 30 0 43 19143 0 0 9 9 2 0 0 W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Received a label value of 8089 which is outside the valid range of [0, 256). Label values: 2 0 0 290 4 0 2 0 0 0 0 0 2 0 0 0 0 0 0 0 4 4 0 0 0 0 287 0 0 0 4 444 2 9 6065 0 0 8089 4 0 0 0 0 2 2 4 34 0 0 2 2 0 261 2 0 106 16 0 0 2 2 0 0 0 W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Received a label value of 13568 which is outside the valid range of [0, 256). Label values: 0 0 0 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 4 0 0 0 4 9 0 2 4 0 0 4 2 0 0 0 0 0 0 2 4 0 0 0 0 0 13568 0 0 9 2 0 0 0 0 0 0 0 Traceback (most recent call last): File "execute.py", line 319, in
train()
File "execute.py", line 169, in train
target_weights, bucket_id, False)
File "/Users/user/tensorflow/chatbot-master/seq2seq_model.py", line 238, in step
outputs = session.run(output_feed, input_feed)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 767, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 965, in _run
feed_dict_string, options, run_metadata)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1015, in _do_run
target_list, options, run_metadata)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1035, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Received a label value of 19143 which is outside the valid range of [0, 256). Label values: 149 567 18943 7 7 1024 7 78 20 160 1216 320 11712 78 273 5 33 566 78 138 20 212 1650 392 104 1359 69 83 14028 3 241 487 33 273 7 33 142 3 7 619 547 7 7 124 33 415 4 2753 3035 33 562 79 79 127 354 47 19143 62 117 20 33 1664 78 6290
[[Node: model_with_buckets/sequence_loss/sequence_loss_by_example/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits = SparseSoftmaxCrossEntropyWithLogits[T=DT_FLOAT, Tlabels=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](model_with_buckets/embedding_attention_seq2seq/embedding_attention_decoder/attention_decoder/AttnOutputProjection/BiasAdd, model_with_buckets/sequence_loss/sequence_loss_by_example/Reshape)]]
Caused by op u'model_with_buckets/sequence_loss/sequence_loss_by_example/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits', defined at: File "execute.py", line 319, in
train()
File "execute.py", line 137, in train
model = create_model(sess, False)
File "execute.py", line 104, in create_model
model = seq2seq_model.Seq2SeqModel( gConfig['enc_vocab_size'], gConfig['dec_vocab_size'], _buckets, gConfig['layer_size'], gConfig['num_layers'], gConfig['max_gradient_norm'], gConfig['batch_size'], gConfig['learning_rate'], gConfig['learning_rate_decay_factor'], forward_only=forward_only)
File "/Users/user/tensorflow/chatbot-master/seq2seq_model.py", line 166, in init
softmax_loss_function=softmax_loss_function)
File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1195, in model_with_buckets
softmax_loss_function=softmax_loss_function))
File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1110, in sequence_loss
softmax_loss_function=softmax_loss_function))
File "/usr/local/lib/python2.7/site-packages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 1065, in sequence_loss_by_example
labels=target, logits=logit)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.py", line 1713, in sparse_softmax_cross_entropy_with_logits
precise_logits, labels, name=name)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 2378, in _sparse_softmax_cross_entropy_with_logits
features=features, labels=labels, name=name)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2395, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1264, in init
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): Received a label value of 19143 which is outside the valid range of [0, 256). Label values: 149 567 18943 7 7 1024 7 78 20 160 1216 320 11712 78 273 5 33 566 78 138 20 212 1650 392 104 1359 69 83 14028 3 241 487 33 273 7 33 142 3 7 619 547 7 7 124 33 415 4 2753 3035 33 562 79 79 127 354 47 19143 62 117 20 33 1664 78 6290 [[Node: model_with_buckets/sequence_loss/sequence_loss_by_example/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits = SparseSoftmaxCrossEntropyWithLogits[T=DT_FLOAT, Tlabels=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](model_with_buckets/embedding_attention_seq2seq/embedding_attention_decoder/attention_decoder/AttnOutputProjection/BiasAdd, model_with_buckets/sequence_loss/sequence_loss_by_example/Reshape)]]