0

I'm trying to train a Neural Network for an NLP application in which I'm using a training set of 25000 examples. I pre-processed these examples into a feature vector of 25000 examples. I have only 3 features. I converted this feature vector into a numpy array using the general method

X = np.array(X) y = np.array(y)

I now have a data set of shape (25000, 3). I compiled my model with input shape = (3, ) with my first layer being Embedding()

I passed a model fit query

history = model.fit(X, y, validation_split= 0.2, epochs = 30, verbose = 1, callbacks = [earlystop, modelcheckpoint, lr_red], 
                    batch_size = 256, shuffle = True
                    )

However, it gives me the error that

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type int).

Even when I typed

print(X[0].shape)

It gave me (3, ), which is what the model should expect right?

Please help me to solve this issue. I really don't know where to even start fixing this.

ASChamp
  • 13
  • 3
  • I believe there is a similar question [here](https://stackoverflow.com/questions/58636087/tensorflow-valueerror-failed-to-convert-a-numpy-array-to-a-tensor-unsupporte) ;) – meti Aug 22 '21 at 04:52

1 Answers1

0

It looks like there's a problem with x datatype, not shape. Tensorflow is kind of strict about datatypes and doesn't support converting all of them (e.g. int as the error message states) to Tensors (which your Embedding layer is probably trying to do). I'd try the following:

X = np.array(X).astype('float32')

(If it doens't work, please provide full traceback)

Brzoskwinia
  • 371
  • 2
  • 11