ruidan / Unsupervised-Aspect-Extraction

Code for acl2017 paper "An unsupervised neural attention model for aspect extraction"
Apache License 2.0
338 stars 117 forks source link

TensorFlow version #12

Closed CImrie closed 6 years ago

CImrie commented 6 years ago

Hi, what version of tensorflow was used? I have tried TF 0.11.0, 1.4.1 and 1.8.0.

With TF 0.11.0 I get:

File "/notebooks/model.py", line 15, in ortho_reg
    reg = K.sum(K.square(K.dot(w_n, K.transpose(w_n)) - K.eye(w_n.shape[0].eval())))
AttributeError: 'Tensor' object has no attribute 'shape'

and with 1.4.1 and above I get:

  File "/notebooks/model.py", line 30, in create_model
    att_weights = Attention(name='att_weights')([e_w, y_s])
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 572, in __call__
    self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 635, in add_inbound_node
    Node.create_node(self, inbound_layers, node_indices, tensor_indices)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 172, in create_node
    output_tensors = to_list(outbound_layer.call(input_tensors, mask=input_masks))
  File "/notebooks/layers.py", line 57, in call
    y = K.repeat_elements(y, self.steps, axis=1)
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 1525, in repeat_elements
    return concatenate(x_rep, axis)
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 1427, in concatenate
    return tf.concat(axis, [to_dense(x) for x in tensors])
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 1096, in concat
    dtype=dtypes.int32).get_shape().assert_is_compatible_with(
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 836, in convert_to_tensor
    as_ref=False)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 926, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 229, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 208, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 383, in make_tensor_proto
    _AssertCompatible(values, dtype)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 303, in _AssertCompatible
    (dtype.name, repr(mismatch), type(mismatch).__name__))
TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

The first error suggests to me you used something later than 0.11.0 since they added the 'shape' property to tensors, but 0.12.0 and above reversed the parameters in tf.concat, so I'm not yet sure how keras 1.2.1 was used.

Any help would be appreciated :)

ruidan commented 6 years ago

As mentioned in README, the code was only tested under Keras 1.2.1 with theano 0.9.0 as backend. harpaj created a keras-tensorflow version of this code as mentioned in #10.

CImrie commented 6 years ago

Hi,

Thanks for getting back to me so quickly, this is very useful. Sorry for the original question - I am new to TensorFlow and didn't realise Keras uses it as one of many backends (I expected it to just use TensorFlow underneath all the time).

Thanks!