input dimension error in han.show_sent_attention()
AmritaBh opened this issue · 0 comments
AmritaBh commented
han.show_sent_attention(x)
is supposed to take in an array of size (max_sent_num, max_sent_length) as input. But the return Model(self.model.input, dummy_layer).predict(x)
throws a ValueError, saying that the array should have 3 dimensions instead of 2.
Error traceback attached ( data[i]
has shape (10, 100) ) :
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-67-285d332a8fb7> in <module>
----> 1 sent_att = han.show_sent_attention(data[i])
2 sent_tokenized_review = sent_tokenize(all_text[i])
3
4 temp_df = han.sent_att_to_df(sent_tokenized_reviews, sent_att)
~/Privacy_Work/interpretable-han-for-document-classification-with-keras/han/model.py in show_sent_attention(self, x)
183 )(prev_tensor)
184
--> 185 return Model(self.model.input, dummy_layer).predict(x)
186
187 @staticmethod
/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
1439
1440 # Case 2: Symbolic tensors or Numpy array-like.
-> 1441 x, _, _ = self._standardize_user_data(x)
1442 if self.stateful:
1443 if x[0].shape[0] > batch_size and x[0].shape[0] % batch_size != 0:
/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
577 feed_input_shapes,
578 check_batch_axis=False, # Don't enforce the batch size.
--> 579 exception_prefix='input')
580
581 if y is not None:
/usr/local/lib/python3.6/dist-packages/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
133 ': expected ' + names[i] + ' to have ' +
134 str(len(shape)) + ' dimensions, but got array '
--> 135 'with shape ' + str(data_shape))
136 if not check_batch_axis:
137 data_shape = data_shape[1:]
ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (10, 100)