我发现使用sparse_softmax_cross_entropy_with_logits最多只能有300个标签?
我对此一无所获。
如果我还有更多呢?
编辑:
如果我不限制为300个班级,则会得到以下跟踪:evrytime:
2019-03-05 15:24:17.899610: W tensorflow/core/framework/op_kernel.cc:1273] OP_REQUIRES failed at sparse_xent_op.cc:90 : Invalid argument: Received a label value of 428 which is outside the valid range of [0, 300). Label values: 428 262
Traceback (most recent call last):
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1334, in _do_call
return fn(*args)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1319, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1407, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Received a label value of 428 which is outside the valid range of [0, 300). Label values: 428 262
[[{{node QAModel/loss/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits}} = SparseSoftmaxCrossEntropyWithLogits[T=DT_FLOAT, Tlabels=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](QAModel/StartDist/SimpleSoftmaxLayer/Add, _arg_QAModel/Placeholder_4_0_5)]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 236, in <module>
tf.app.run()
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
_sys.exit(main(argv))
File "main.py", line 194, in main
qa_model.train(sess, train_context_path, train_qn_path, train_ans_path, dev_qn_path, dev_context_path, dev_ans_path)
File "C:\Users\\IB\QA-Models-Bidaf\code\qa_model.py", line 764, in train
loss, global_step, param_norm, grad_norm = self.run_train_iter(session, batch, summary_writer)
File "C:\Users\\IB\QA-Models-Bidaf\code\qa_model.py", line 359, in run_train_iter
[_, summaries, loss, global_step, param_norm, gradient_norm] = session.run(output_feed, input_feed)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 929, in run
run_metadata_ptr)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1152, in _run
feed_dict_tensor, options, run_metadata)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1328, in _do_run
run_metadata)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1348, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Received a label value of 428 which is outside the valid range of [0, 300). Label values: 428 262
[[node QAModel/loss/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits (defined at C:\Users\\IB\QA-Models-Bidaf\code\qa_model.py:318) = SparseSoftmaxCrossEntropyWithLogits[T=DT_FLOAT, Tlabels=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](QAModel/StartDist/SimpleSoftmaxLayer/Add, _arg_QAModel/Placeholder_4_0_5)]]
Caused by op 'QAModel/loss/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits', defined at:
File "main.py", line 236, in <module>
tf.app.run()
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
_sys.exit(main(argv))
File "main.py", line 165, in main
qa_model = QAModel(FLAGS, id2word, word2id, emb_matrix)
File "C:\Users\\IB\QA-Models-Bidaf\code\qa_model.py", line 64, in __init__
self.add_loss()
File "C:\Users\\IB\QA-Models-Bidaf\code\qa_model.py", line 318, in add_loss
loss= tf.nn.sparse_softmax_cross_entropy_with_logits(logits=self.logits, labels=self.ans_span) # loss_start has shape (batch_size)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 2049, in sparse_softmax_cross_entropy_with_logits
precise_logits, labels, name=name)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 8063, in sparse_softmax_cross_entropy_with_logits
labels=labels, name=name)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
return func(*args, **kwargs)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 3274, in create_op
op_def=op_def)
File "C:\Users\\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1770, in __init__
self._traceback = tf_stack.extract_stack()
InvalidArgumentError (see above for traceback): Received a label value of 428 which is outside the valid range of [0, 300). Label values: 428 262
[[node QAModel/loss/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits (defined at C:\Users\\IB\QA-Models-Bidaf\code\qa_model.py:318) = SparseSoftmaxCrossEntropyWithLogits[T=DT_FLOAT, Tlabels=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](QAModel/StartDist/SimpleSoftmaxLayer/Add, _arg_QAModel/Placeholder_4_0_5)]]
每次我都将范围提高到300。为什么?!
valid range of [0, 300)
答案 0 :(得分:0)
当我参加YouTube8M Kaggle比赛时,它有大约5千个课程,我们使用了比赛组织者(即Google)提供的损失 看看https://github.com/mpekalski/Y8M/blob/master/video_level_code/losses.py