Reputation: 525
I have a model for a chatbot that I trained with a dataset to provide "standard" conversations like hello, how are u and stuff. Now I want to "extend" the existing Model with a dataset that provides answers to questions related to shipping, what's in stock etc.
Here is my working/already trained model:
# create Sequential model
model = Sequential()
# add first layer with input shape dependent on size of input and "relu" activation function
model.add(Dense(256, input_shape=(len(training_data_x[0]),), activation=activations.relu))
# add Dropout to prevent overfitting
model.add(Dropout(0.6))
# additional layer with 64 neurons
model.add(Dense(128, activation=activations.relu))
model.add(Dropout(0.2))
# Additional dense layer with num of neurons of classes & softmax activation function
# -> adds results in output layer to "1" to get %
model.add(Dense(len(training_data_y[0]), activation=activations.softmax))
# print(len(training_data_y[0])) = 71
sgd = SGD(learning_rate=0.01, decay=1e-6, momentum=0.9, nesterov=True)
# compile the model
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
output = model.fit(np.array(training_data_x), np.array(training_data_y), epochs=200, batch_size=5, verbose=1)
plot_model_output(output)
model.summary()
model.save('./MyModel_tf', save_format='tf')
The training data is prepared in a separate class and takes a certain json file as input.
Now I just swapped the JSON file for the one with data related to the stuff I want to add to the model and tried fitting it like this:
json_data = json.loads(open('data.json').read())
model = load_model('MyModel_tf')
model.fit(np.array(training_data_x), np.array(training_data_y), epochs=200, batch_size=5, verbose=1)
However when I run it I get this error:
ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 652), found shape=(None, 71)
I am assuming the data is the problem.. however it is structured exactly the same just way shorter.
My questions:
Upvotes: 2
Views: 499
Reputation: 26698
The problem is probably coming from this line
model.add(Dense(256, input_shape=(len(training_data_x[0]),), activation=activations.relu))
where you define the input shape of your model based on the size of the feature dimension of training_data_x
. Now that you have defined this very specific input shape, all data fed into your model must have the same feature dimension size. That is the reason for your error.
Upvotes: 1