Expected dense_Dense1_input to have shape “a” but got array with shape “b”

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Expected dense_Dense1_input to have shape “a” but got array with shape “b”



Anyone would help me with this TensorFlow JS project ?
It's a Chat bot with machine learn, I stuck on 'build neural network' ,
giveme this error



Project Link : https://github.com/ran-j/ChatBotNodeJS



The training code at /routes/index.js line 189


//Build neural network
model = tf.sequential();
model.add(tf.layers.dense(inputShape: [documents.length], units: 100));
model.add(tf.layers.dense(units: 4));
model.compile(loss: 'categoricalCrossentropy', optimizer: 'sgd');

model.fit(xs, ys, epochs: 1000);





could you show us your xs tensor?
– Sebastian Speitel
Aug 10 at 16:04


xs





Tensor isDisposedInternal: false, size: 1296, shape: [ 27, 48 ], dtype: 'float32', strides: [ 48 ], dataId: , id: 0, rankType: '2'
– RanJS
Aug 10 at 16:15





Is the 27 the batch input amount or the 48 or is your input two dimensional? Try using model.fit(xs.transpose(), ys, epochs: 1000);
– Sebastian Speitel
Aug 10 at 16:29


model.fit(xs.transpose(), ys, epochs: 1000);





i dont know, my data is like this pastebin.com/ktacvqCh
– RanJS
Aug 10 at 16:42





And that is your documents array?
– Sebastian Speitel
Aug 10 at 16:59




2 Answers
2



The error indicates that there is a mismatch between the shape defined for the model and the tensors used by the model be it the training or test tensors.



In order to get rid of the error you need both shapes to match.



Expected dense_Dense1_input to have shape a but got array with shape b



In the error a is the shape of the model and b is the shape of the tensor that is throwing the error. So one needs to change whether the shape of the model to b or the shape of the tensor to be a.



The easiest way is to change the model shape to b since the second way would imply a reshape of the tensor i.e


model.add(tf.layers.dense(inputShape: b, units: 100));



Given the model of the question, it will be


model.add(tf.layers.dense(inputShape: [27, 48], units: 100));



documents.length is the amount of training data you have and not the inputShape of your model. So your training data doesn't have the correct shape for your model.


documents.length



The correct shape would be xs.shape.


xs.shape



So your fist layer should be:


tf.layers.dense(inputShape: xs.shape, units: 100)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard