rtlee9 / recipe-summarization

Sequence to sequence recipe summarization
MIT License
136 stars 75 forks source link

AttributeError: 'Tensor' object has no attribute 'ndim' #2

Closed thogiti closed 6 years ago

thogiti commented 7 years ago

Hi Ryan.

I am a beginner and trying to learn deep learning.

I was following your recipe summarization code and I got below 'ndim' attribution error when I was running predict.ipynb.

The below error happens when I execute the codebloc: model = Sequential() model.add(rnn_model)

if activation_rnn_size: model.add(SimpleContext(name='simplecontext_1'))

Here is the full error:


AttributeError Traceback (most recent call last)

in () 3 4 if activation_rnn_size: ----> 5 model.add(SimpleContext(name='simplecontext_1')) C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\keras\models.py in add(self, layer) 330 output_shapes=[self.outputs[0]._keras_shape]) 331 else: --> 332 output_tensor = layer(self.outputs[0]) 333 if isinstance(output_tensor, list): 334 raise TypeError('All layers in a Sequential model ' C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\keras\engine\topology.py in __call__(self, x, mask) 570 if inbound_layers: 571 # This will call layer.build() if necessary. --> 572 self.add_inbound_node(inbound_layers, node_indices, tensor_indices) 573 # Outputs were already computed when calling self.add_inbound_node. 574 outputs = self.inbound_nodes[-1].output_tensors C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\keras\engine\topology.py in add_inbound_node(self, inbound_layers, node_indices, tensor_indices) 633 # creating the node automatically updates self.inbound_nodes 634 # as well as outbound_nodes on inbound layers. --> 635 Node.create_node(self, inbound_layers, node_indices, tensor_indices) 636 637 def get_output_shape_for(self, input_shape): C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\keras\engine\topology.py in create_node(cls, outbound_layer, inbound_layers, node_indices, tensor_indices) 164 165 if len(input_tensors) == 1: --> 166 output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0])) 167 output_masks = to_list(outbound_layer.compute_mask(input_tensors[0], input_masks[0])) 168 # TODO: try to auto-infer shape C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\keras\layers\core.py in call(self, x, mask) 639 if 'mask' in arg_spec.args: 640 arguments['mask'] = mask --> 641 return self.function(x, **arguments) 642 643 def get_config(self): in simple_context(X, mask, n, maxlend, maxlenh) 12 activation_energies = K.batch_dot(head_activations, desc_activations, axes=([2],[2])) 13 # make sure we dont use description words that are masked out ---> 14 assert mask.ndim == 2 15 print(mask[:, None ,:maxlend]) 16 activation_energies = K.switch(mask[:, None, :maxlend], activation_energies, -1e20) AttributeError: 'Tensor' object has no attribute 'ndim'
rtlee9 commented 7 years ago

Hi - can you try switching the backend to Theano? I ran into this problem as well, and switching backends resolved the issue for me.