0

我使用 word2vec 和 biLstm 来实现电影评论的情感分析。当我在 Jupyter 笔记本上训练我的模型时,我总是收到TypeError: update() got an unexpected keyword argument 'force' at the last batch of the first epoch。

这是我的代码:

batch_size = 50
result = model.fit(
    X_train,
    Y_train,
    validation_data=(X_test, Y_test),
    batch_size=batch_size,
    epochs=5
)

和错误:

Train on 1600 samples, validate on 400 samples
Epoch 1/5
1550/1600 [============================>.] - ETA: 2s - loss: 0.7257 - acc: 0.4961
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-360-8eaf5ac2ad33> in <module>()
     17     validation_data=(X_test, Y_test),
     18     batch_size=batch_size,
---> 19     epochs=5
     20 )

~/opt/anaconda3/envs/WDPS/lib/python3.6/site-packages/keras/models.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)
    958                               initial_epoch=initial_epoch,
    959                               steps_per_epoch=steps_per_epoch,
--> 960                               validation_steps=validation_steps)
    961 
    962     def evaluate(self, x, y, batch_size=32, verbose=1,

~/opt/anaconda3/envs/WDPS/lib/python3.6/site-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)
   1648                               initial_epoch=initial_epoch,
   1649                               steps_per_epoch=steps_per_epoch,
-> 1650                               validation_steps=validation_steps)
   1651 
   1652     def evaluate(self, x=None, y=None,

~/opt/anaconda3/envs/WDPS/lib/python3.6/site-packages/keras/engine/training.py in _fit_loop(self, f, ins, out_labels, batch_size, epochs, verbose, callbacks, val_f, val_ins, shuffle, callback_metrics, initial_epoch, steps_per_epoch, validation_steps)
   1231                             for l, o in zip(out_labels, val_outs):
   1232                                 epoch_logs['val_' + l] = o
-> 1233             callbacks.on_epoch_end(epoch, epoch_logs)
   1234             if callback_model.stop_training:
   1235                 break

~/opt/anaconda3/envs/WDPS/lib/python3.6/site-packages/keras/callbacks.py in on_epoch_end(self, epoch, logs)
     71         logs = logs or {}
     72         for callback in self.callbacks:
---> 73             callback.on_epoch_end(epoch, logs)
     74 
     75     def on_batch_begin(self, batch, logs=None):

~/opt/anaconda3/envs/WDPS/lib/python3.6/site-packages/keras/callbacks.py in on_epoch_end(self, epoch, logs)
    304                 self.log_values.append((k, logs[k]))
    305         if self.verbose:
--> 306             self.progbar.update(self.seen, self.log_values, force=True)
    307 
    308 

TypeError: update() got an unexpected keyword argument 'force'

起初,我在epochs=5下有一行代码verbose = 1。将出现相同的错误,并且箭头指向verbose = 1。然后我将其更改为verbose=2或删除verbose。但我仍然有问题。

我试图改变批量大小和训练集的数量。但它仍然没有成功。

它总是显示在最后一批。

python版本= 3.6.2
keras版本= 2.1.1

4

0 回答 0