2

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.

nbro
  • 15,395
  • 32
  • 113
  • 196
KMunro
  • 348
  • 4
  • 14
  • The code that produces the problem should be included, as it provides context for your issue – Dr. Snoopy Aug 08 '19 at 17:57
  • Hi Matias, I know, I'm very sorry but as I mentioned I can't get it back to the erroneous state. I can delete the post if a few people tell me I should, but I was hoping someone might know generally, without code, what symbolic tensors are. – KMunro Aug 08 '19 at 18:45
  • By context I mean for example your current fit call and the code that produces the x and y values, as there are many kinds of symbolic tensors and it will help answer your question. – Dr. Snoopy Aug 08 '19 at 19:34
  • Yes I understand but I'm not getting the symbolic tensors anymore, none of my variables are tensors now and I don't know where the bug used to be that used to produce tensors. So my question was just generally 'what are symbolic tensors in tensorflow' and I thought I'd include the way I solved my original issue in case it indirectly helped other people. But I think I'll delete the post. Sorry, I know you're trying to help. – KMunro Aug 09 '19 at 08:18

1 Answers1

-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?