问题是将给定的学生答案与给出模态答案或正确答案的教师进行比较,并为学生的答案打分。经过大量研究,具有 LSTM 的 Siamese 架构似乎是神经网络架构的一个非常好的选择,因为该问题与查找两对句子之间的文本相似性高度相似。我目前采用了最简单的架构,其中一个嵌入层使用预训练的 word2vec 模型,在嵌入之上添加 LSTM,采用多对一架构,然后使用余弦相似度来计算正确答案和学生给出的答案之间的相似度.
模型创建似乎很好,但我在使用余弦相似度度量合并两个 LSTM 时遇到问题
这是我的代码..
true_ans_model = Sequential()
true_ans_model.add(Embedding(nbwords+1, EMBEDDING_DIM, weights= weightMatrixWithPadding], mask_zero=True, trainable=False ))
x_left = true_ans_model.add(LSTM(MAX_SENTENCE_LENGTH,return_sequences=False))
stud_ans_model = Sequential()
stud_ans_model.add(Embedding(nbwords+1, EMBEDDING_DIM, weights=[weightMatrixWithPadding], mask_zero=True, trainable=False ))
stud_ans_model.add(LSTM(MAX_SENTENCE_LENGTH, return_sequences=False))
merge_lstms = merge([x_left, x_right], mode='cos', dot_axes=1)
这是错误:
ValueError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\keras\engine\topology.py in assert_input_compatibility(self, inputs)
418 try:
--> 419 K.is_keras_tensor(x)
420 except ValueError:
~\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py in is_keras_tensor(x)
392 tf.SparseTensor)):
--> 393 raise ValueError('Unexpectedly found an instance of type `' + str(type(x)) + '`. '
394 'Expected a symbolic tensor instance.')
ValueError: Unexpectedly found an instance of type `<class 'NoneType'>`. Expected a symbolic tensor instance.
During handling of the above exception, another exception occurred:
~\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py in is_keras_tensor(x)
392 tf.SparseTensor)):
--> 393 raise ValueError('Unexpectedly found an instance of type `' + str(type(x)) + '`. '
394 'Expected a symbolic tensor instance.')
ValueError: Unexpectedly found an instance of type `<class 'NoneType'>`.
Expected a symbolic tensor instance.
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-41-7a6e14b23349> in <module>()
----> 1 merge_lstms = merge([x_left, x_right], mode='cos', dot_axes=1)
#final_layer = dot([x_left,x_right], axes=1, normalize=True)
predictions = Dense(1, activation = 'sigmoid')(final_layer)
~\Anaconda3\lib\site-packages\keras\legacy\layers.py in merge(inputs, mode, concat_axis, dot_axes, output_shape, output_mask, arguments, name)
466 arguments=arguments,
467 name=name)
--> 468 return merge_layer(inputs)
469
470
~\Anaconda3\lib\site-packages\keras\engine\topology.py in __call__(self, inputs, **kwargs)
550 # Raise exceptions in case the input is not compatible
551 # with the input_spec specified in the layer constructor.
--> 552 self.assert_input_compatibility(inputs)
553
554 # Collect input shapes to build layer.
~\Anaconda3\lib\site-packages\keras\engine\topology.py in assert_input_compatibility(self, inputs)
423 'Received type: ' +
424 str(type(x)) + '. Full input: ' +
--> 425 str(inputs) + '. All inputs to the
layer '
426 'should be tensors.')
ValueError: Layer merge_3 was called with an input that isn't a symbolic tensor. Received type: <class 'NoneType'>. Full input: [None, None]. All inputs to the layer should be tensors.