简体   繁体   中英

size of the input ot a neural network is not the one expected

I'm trying to build a neural network to classify reddit messages as follow:

original_train= train[0] # messages
data_list= original_train[0:500] # take first 500 examples as training set
originaly_train=train[1] # labels/ categories
y_train=originaly_train[0:500]
x_validation=original_train[500:1000] # take another 500 examples as training set
y_validation=originaly_train[500:1000]



model = Sequential()
model.add(layers.Dense(50, activation = "relu", input_shape=(1000, )))
# Hidden - Layers
model.add(layers.Dropout(0.3, noise_shape=None, seed=None))
model.add(layers.Dense(100, activation = "relu"))
model.add(layers.Dropout(0.2, noise_shape=None, seed=None))
model.add(layers.Dense(50, activation = "relu"))
# Output- Layer
model.add(layers.Dense(20, activation = "sigmoid"))
model.summary()

model.compile(loss="categorical_crossentropy",
              optimizer="Adadelta",
              metrics=['accuracy'])


model.fit(vectorized_training, y_train_neralnet,
          batch_size=128,
          epochs=12,
          verbose=1,
          validation_data=(vectorized_validation, y_validation_neralnet))

Here, the input vector to the neural network should be a vector of dimension 1000 and the output is suppose to be vector of size 20 because we are trying to classify 20 objects.

so my vectorized_training is of shape (500,1000) and y_train_neralnet is of shape(500,20) the same is for vectorized_validation and y_validation_neralnet.

This is a text classification problem. So we have a set of words. Each input is a vector of frequencies of those word appearing in the message. the corresponding label is a vector of dimension 20 where you get a 1 at a specific position and zero else where to indicate which of the 20 labels it belongs to. But I get this error:

ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 500 arrays: [array([[0],
   [0],
   [0],
   [1],
   [0],
   [1],
   [0],
   [1],
   [0],
   [0],
   [0],
   [0],
   [0],
   [0],
   [0],
   [0],
   ...

Try to replace input_shape=(1000,) for input_shape=(1000)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM