Bihaqo / exp-machines

Exponential Machines implementation
MIT License
39 stars 14 forks source link

running error "movielens-learning.ipynb" in [11] Init mode #2

Open michelenazareth opened 7 years ago

michelenazareth commented 7 years ago

Hello,

I tried to run "movielens-learning.ipynb" and I got this following error (in [11], "Init mode" part):

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-b8fe01c64add> in <module>()
      3 model = TFExpMachine(rank=target_rank, s_features=s_features, init_std=0.001, reg=0.012, exp_reg=1.8)
      4 model.init_from_cores(w_cores)
----> 5 model.build_graph()
      6 model.initialize_session()

/home/michele/exp-machines/src/TFExpMachine.pyc in build_graph(self)
     62             cur_col = self.X[:, 0]
     63             tower = tf.gather(self.G[0], cur_col)
---> 64             self.outputs = tf.add(self.G[0][0], tower)
     65             for i in range(1, self.n_features):
     66                 cur_col = self.X[:, i]

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/variables.pyc in <lambda>(a, b)
    613       setattr(Variable, operator, lambda a: Variable._RunOp(operator, a, None))
    614     else:
--> 615       setattr(Variable, operator, lambda a, b: Variable._RunOp(operator, a, b))
    616 
    617   # NOTE(mrry): This enables the Variable's overloaded "right" binary

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/variables.pyc in _RunOp(operator, a, b)
    637     # pylint: disable=protected-access
    638     if b is not None:
--> 639       return getattr(ops.Tensor, operator)(a._AsTensor(), b)
    640     else:
    641       return getattr(ops.Tensor, operator)(a._AsTensor())

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.pyc in _SliceHelper(tensor, slice_spec)
    336       sizes.append(1)
    337       squeeze_dims.append(dim)
--> 338   sliced = slice(tensor, indices, sizes)
    339   if squeeze_dims:
    340     return squeeze(sliced, squeeze_dims=squeeze_dims)

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.pyc in slice(input_, begin, size, name)
    386     A `Tensor` the same type as `input`.
    387   """
--> 388   return gen_array_ops._slice(input_, begin, size, name=name)
    389 
    390 

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.pyc in _slice(input, begin, size, name)
   1999   """
   2000   result = _op_def_lib.apply_op("Slice", input=input, begin=begin, size=size,
-> 2001                                 name=name)
   2002   return result
   2003 

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.pyc in apply_op(self, op_type_name, name, **keywords)
    701           op = g.create_op(op_type_name, inputs, output_types, name=scope,
    702                            input_types=input_types, attrs=attr_protos,
--> 703                            op_def=op_def)
    704           outputs = op.outputs
    705           return _Restructure(ops.convert_n_to_tensor(outputs),

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device)
   2310                     original_op=self._default_original_op, op_def=op_def)
   2311     if compute_shapes:
-> 2312       set_shapes_for_outputs(ret)
   2313     self._add_op(ret)
   2314     self._record_op_seen_by_control_dependencies(ret)

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in set_shapes_for_outputs(op)
   1702       raise RuntimeError("No shape function registered for standard op: %s"
   1703                          % op.type)
-> 1704   shapes = shape_func(op)
   1705   if shapes is None:
   1706     raise RuntimeError(

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.pyc in _SliceShape(op)
   1508   ndims = begin_shape.merge_with(sizes_shape)[0].value
   1509   if ndims is not None:
-> 1510     input_shape.assert_has_rank(ndims)
   1511   begin_value = tensor_util.constant_value(op.inputs[1])
   1512   sizes_value = tensor_util.constant_value(op.inputs[2])

/home/michele/miniconda2/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.pyc in assert_has_rank(self, rank)
    619     """
    620     if self.ndims not in (None, rank):
--> 621       raise ValueError("Shape %s must have rank %d" % (self, rank))
    622 
    623   def with_rank(self, rank):

ValueError: Shape (8, 1, 10) must have rank 1

Can you please help me with this above error ?

Bihaqo commented 7 years ago

Hi Michele,

Sorry for such a long response. Can you please clarify the version of TensorFlow you are using? I've just tried to download this repository and run it from scratch with TF 1.0.1 installed from PIP and it worked (not to mention that I had to replace batch_matmul with matmul in one place (TFExpMachine.py:69)).