Я нахожусь в обучении модели tagger последовательности Bi-lstm и получаю следующую ошибку с параметрами этой модели:
model = Sequential()
model.add(Bidirectional(LSTM(units=512, return_sequences=True,
recurrent_dropout=0.2, dropout=0.2),input_shape=(max_len,300,)))
model.add(Bidirectional(LSTM(units=512, return_sequences=True,
recurrent_dropout=0.2, dropout=0.2)))
model.add(TimeDistributed(Dense(len(tags2index), activation="softmax")))
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
Вот краткое описание модели:
Layer (type) Output Shape Param #
=================================================================
bidirectional_20 (Bidirectio (None, 60, 1024) 3330048
_________________________________________________________________
bidirectional_21 (Bidirectio (None, 60, 1024) 6295552
_________________________________________________________________
time_distributed_6 (TimeDist (None, 60, 9) 9225
=================================================================
Total params: 9,634,825
Trainable params: 9,634,825
Non-trainable params: 0
Вот входные фигуры:
print(np.array(X_train).shape)
print(y_train.shape)
(6509, 60, 300)
(6509, 60, 1)
Где 6509 - это число примеров, 60 - длина каждого примера, а 300 - размер измерений вектора слова
Старт поезда со следующим кодом:
batch_size = 32
history = model.fit(np.array(X_train), y_train, validation_data=(np.array(X_eval), y_eval),
batch_size=batch_size, epochs=3, verbose=1)
Получение этой трассировки:
Train on 6509 samples, validate on 1628 samples
Epoch 1/3
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-237-3415d7ea0889> in <module>()
1 history = model.fit(np.array(X_train), y_train, validation_data=(np.array(X_eval), y_eval),
----> 2 batch_size=batch_size, epochs=3, verbose=1)
/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
1037 initial_epoch=initial_epoch,
1038 steps_per_epoch=steps_per_epoch,
-> 1039 validation_steps=validation_steps)
1040
1041 def evaluate(self, x=None, y=None,
/usr/local/lib/python3.6/dist-packages/keras/engine/training_arrays.py in fit_loop(model, f, ins, out_labels, batch_size, epochs, verbose, callbacks, val_f, val_ins, shuffle, callback_metrics, initial_epoch, steps_per_epoch, validation_steps)
197 ins_batch[i] = ins_batch[i].toarray()
198
--> 199 outs = f(ins_batch)
200 outs = to_list(outs)
201 for l, o in zip(out_labels, outs):
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in __call__(self, inputs)
2713 return self._legacy_call(inputs)
2714
-> 2715 return self._call(inputs)
2716 else:
2717 if py_any(is_tensor(x) for x in inputs):
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _call(self, inputs)
2673 fetched = self._callable_fn(*array_vals, run_metadata=self.run_metadata)
2674 else:
-> 2675 fetched = self._callable_fn(*array_vals)
2676 return fetched[:len(self.outputs)]
2677
/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in __call__(self, *args, **kwargs)
1437 ret = tf_session.TF_SessionRunCallable(
1438 self._session._session, self._handle, args, status,
-> 1439 run_metadata_ptr)
1440 if run_metadata:
1441 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/errors_impl.py in __exit__(self, type_arg, value_arg, traceback_arg)
526 None, None,
527 compat.as_text(c_api.TF_Message(self.status.status)),
--> 528 c_api.TF_GetCode(self.status.status))
529 # Delete the underlying status object from memory otherwise it stays alive
530 # as there is a reference to status from this from the traceback due to
InvalidArgumentError: Incompatible shapes: [1920] vs. [32,60]
[[{{node metrics_3/acc/Equal}}]]
Я вижу, что 1920 = 32 * 60, но почему TF сравнивает эти размеры?
Кстати, я использую Colab для этой задачи.
Самое запутанное, что он работает с batch_size = 1: (
Не могли бы вы помочь, что я испортил?
Заранее спасибо!