Problem is to compare a given student answer to faculty given the modal answer or correct answer and assign grades to the student answer. After researching a lot, Siamese architecture with LSTMs seems to be a very good choice for the neural network architecture as the problem is highly similar to finding textual similarity between two pairs of sentences. I have currently adopted the simplest architecture with one embedding layer that uses pre-trained word2vec model, adds LSTM on top of the embedding with many-to-one architecture and then using cosine similarity to compute the similarity between the correct answer and student given answer.
Model creation seems fine but I have problem while merging the two LSTMs using cosine similariy measure
Here is my code..
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)
Here is the error:
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.