What are symbolic tensors, and why do they throw “use `steps_per_epoch` argument” error?

和自甴很熟 提交于 2020-01-25 04:06:07

问题


Note: I already solved my issue, but I'm posting the question in case others have it too and because I don't understand how I solved it.

I was building a Named Entity Classifier (sequence labelling model) in Keras with Tensorflow backend. When I tried to fit the model, I got this error (which, amazingly, returns only 4 Google results):

"If your data is in the form of symbolic tensors, you should specify the `steps_per_epoch` argument (instead of the batch_size argument, because symbolic tensors are expected to produce batches of input data)."

This stackoverflow post discussed the issue, and someone suggested to the op:

one of your data tensors that is being used by Fit() is a symbolic tensor. The one hot label function returns a symbolic tensor. Try something like:

label_onehot = tf.Session().run(K.one_hot(label, 5))

Then I read on this (not related) site:

The Wolfram System also has powerful algorithms to manipulate algebraic combinations of expressions representing [...] arrays. These expressions are called symbolic arrays or symbolic tensors.

These two sources made me think symbolic arrays (at least in TensorFlow) might be something more like arrays of functions that are yet to be evaluated, rather than actual values.

So, using %whos to view all my variables, I saw that my X and Y data were tensors (rather than arrays, like I normally use for my models). The data/info column had quite a complicated description for them, but I lost it once I solved my issue and I can't work out how to get back to the state where I was getting the error.

In any case, I know I solved the problem by changing my data pre-processing so that the X and y data (i.e. X_train and y_train) were of type <class 'numpy.ndarray'> and of dimensions (num sents, max len) for X_train and (num_sents, max len, 1) for y_train (the 1 is necessary because my final layer expects 3D input). Now the model works fine. But I'm still wondering, what are these symbolic tensors and how/why is using steps per epoch instead of batch size supposed to help? I tried that too initially but had no luck.


回答1:


This can be solved bu using the eval() or numpy() function of your tensors.

Check: How can I convert a tensor into a numpy array in TensorFlow?



来源:https://stackoverflow.com/questions/57417690/what-are-symbolic-tensors-and-why-do-they-throw-use-steps-per-epoch-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!