我试图创建一个将接受动态输入的模型,并且为此编写了以下代码。
inpt = Input(shape=(None,))
emb_layer = Embedding(vocabulary_size, 100, weights=[embedding_matrix], trainable = False)(inpt)
bdlstm1 = Bidirectional(LSTM(64, return_sequences = True))(emb_layer)
dns2 = Dense(no_labels, activation='softmax')(bdlstm1)
model = Model(inpt, dns2)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(x, y)
当我使用
运行代码进行输入时我遇到以下错误:
File "<ipython-input-26-d29713cc11ee>", line 1, in <module>
model.fit(x,y)
File "C:\Users\hrithikp\AppData\Local\conda\conda\envs\test_env\lib\site-packages\keras\engine\training.py", line 1039, in fit
validation_steps=validation_steps)
File "C:\Users\hrithikp\AppData\Local\conda\conda\envs\test_env\lib\site-packages\keras\engine\training_arrays.py", line 199, in fit_loop
outs = f(ins_batch)
File "C:\Users\hrithikp\AppData\Local\conda\conda\envs\test_env\lib\site-packages\keras\backend\tensorflow_backend.py", line 2715, in __call__
return self._call(inputs)
File "C:\Users\hrithikp\AppData\Local\conda\conda\envs\test_env\lib\site-packages\keras\backend\tensorflow_backend.py", line 2655, in _call
dtype=tf.as_dtype(tensor.dtype).as_numpy_dtype))
File "C:\Users\hrithikp\AppData\Local\conda\conda\envs\test_env\lib\site-packages\numpy\core\numeric.py", line 538, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.