asyml / texar

Toolkit for Machine Learning, Natural Language Processing, and Text Generation, in TensorFlow. This is part of the CASL project: http://casl-project.ai/
https://asyml.io
Apache License 2.0
2.39k stars 374 forks source link

Text Style transfer - Train on my own dataset #281

Closed cece95 closed 4 years ago

cece95 commented 4 years ago

Hi, i followed the instructions to setup the training on my own dataset, the files are in the correct format and i updated config.py but when i run

python main.py --config config

i get the following error `Traceback (most recent call last): File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call return fn(*args) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1350, in _run_fn target_list, run_metadata) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [Condition x == y did not hold element-wise:] [x (sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/Shape_1:0) = ] [64 67] [y (sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/strided_slice:0) = ] [64 21] [[{{node sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/assert_equal_1/Assert/Assert}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "main.py", line 190, in tf.app.run(main=_main) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/home/cece/anaconda3/lib/python3.7/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/home/cece/anaconda3/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "main.py", line 175, in _main _trainepoch(sess, gamma, lambdag, epoch) File "main.py", line 91, in _train_epoch vals_g = sess.run(model.fetches_train_g, feed_dict=feed_dict) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 956, in run run_metadata_ptr) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1180, in _run feed_dict_tensor, options, run_metadata) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1359, in _do_run run_metadata) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1384, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [Condition x == y did not hold element-wise:] [x (sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/Shape_1:0) = ] [64 67] [y (sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/strided_slice:0) = ] [64 21] [[node sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/assert_equal_1/Assert/Assert (defined at /home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py:1748) ]]

Original stack trace for 'sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/assert_equal_1/Assert/Assert': File "main.py", line 190, in tf.app.run(main=_main) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/home/cece/anaconda3/lib/python3.7/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/home/cece/anaconda3/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "main.py", line 67, in _main model = CtrlGenModel(batch, vocab, gamma, lambda_g, config.model) File "/home/cece/Desktop/texar/examples/text_style_transfer/ctrl_gen_model.py", line 35, in init self._build_model(inputs, vocab, gamma, lambda_g) File "/home/cece/Desktop/texar/examples/text_style_transfer/ctrl_gen_model.py", line 80, in _build_model sum_over_timesteps=False) File "/home/cece/anaconda3/lib/python3.7/site-packages/texar/tf/losses/mle_losses.py", line 196, in sequence_sparse_softmax_cross_entropy labels=labels, logits=logits) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/ops/nn_ops.py", line 3410, in sparse_softmax_cross_entropy_with_logits array_ops.shape(logits)[:-1])) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/ops/check_ops.py", line 658, in assert_equal data, summarize, message, name) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/ops/check_ops.py", line 371, in _binary_assert return control_flow_ops.Assert(condition, data, summarize=summarize) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/util/tf_should_use.py", line 198, in wrapped return _add_should_use_warning(fn(*args, *kwargs)) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 165, in Assert return gen_logging_ops._assert(condition, data, summarize, name="Assert") File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_logging_ops.py", line 74, in _assert name=name) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/op_def_library.py", line 794, in _apply_op_helper op_def=op_def) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func return func(args, **kwargs) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3357, in create_op attrs, op_def, compute_device) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3426, in _create_op_internal op_def=op_def) File "/home/cece/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1748, in init self._traceback = tf_stack.extract_stack()`

Any idea on what might have caused it and how to fix it? Thanks in advance

Cesare

ZhitingHu commented 4 years ago

You probably need to set max_decoding_length_* in config.py properly.

tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [Condition x == y did not hold element-wise:] [x (sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/Shape_1:0) = ] [64 67] [y (sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/strided_slice:0) = ] [64 21]

cece95 commented 4 years ago

Hi thanks for your answer, could you explain to me what do you mean by properly? Because I thought I already did

ZhitingHu commented 4 years ago

max_decoding_length_train should be >= the max sequence length in your training data.

The error msg shows you set max_decoding_length_train=21 but the training data contains sequences of length 67

tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [Condition x == y did not hold element-wise:] [x (sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/Shape_1:0) = ] [64 67] [y (sequence_sparse_softmax_cross_entropy/SparseSoftmaxCrossEntropyWithLogits/strided_slice:0) = ] [64 21]

cece95 commented 4 years ago

Oh now I get it, thanks for your explanation :)