You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/12/11 09:44:17 UTC

[GitHub] eaglecros commented on issue #8669: module.Module and CSVIter

eaglecros commented on issue #8669: module.Module and CSVIter
URL: https://github.com/apache/incubator-mxnet/issues/8669#issuecomment-350672417
 
 
   Ok, so with your message, and another test I did, I believe I have come to the reason of the problem... Now I just need to understand how to solve it :)
   
   ```
   l,c,v = numpy.loadtxt(filename, delimiter='\t',dtype='int').T
   iter_train = mx.io.NDArrayIter({'user': l, 'item': c}, label=v, batch_size=args.bsize)
   print(iter_train.provide_data)
   ```
   returns
   
   ```
   [DataDesc[item,(100,),<class 'numpy.float32'>,NCHW], DataDesc[user,(100,),<class 'numpy.float32'>,NCHW]]
   ```
   
   However, 
   
   ```
   iter_train = mx.io.CSVIter(data_csv=f1, data_shape=(2,), label_csv=f2, label_shape=(1,), batch_size=1000, data_name=['user','item'])
   print(iter_train.provide_data)
   ```
   outputs
   
   ```
   [DataDesc[['user', 'item'],(1000, 2),<class 'numpy.float32'>,NCHW]]
   ```
   
   In addition, I tried commenting out lines 62-65 on `mxnet/module/base_module.py`, the ones that led to the error, i.e.:
   
   ```
   def _check_names_match(data_names, data_shapes, name, throw):
       """Check that input names matches input data descriptors."""
       actual = [x[0] for x in data_shapes]
       if sorted(data_names) != sorted(actual):
           msg = "Data provided by %s_shapes don't match names specified by %s_names (%s vs. %s)"%(
               name, name, str(data_shapes), str(data_names))
   #        if throw:
   #            raise ValueError(msg)
   #        else:
   #            warnings.warn(msg)
   ```
   and then I got this error, which I believe means that it is not a simple naming problem:
   
   ```
   Traceback (most recent call last):
     File "/home/german/trabajo/Sciling/git/recsys-sbcorporation/train2.py", line 172, in <module>
       model = train_model(ctx=mx.cpu(0), net=nn, data_names=('user','item'), train_iter=train_iter, val_iter=train_iter)
     File "/home/german/trabajo/Sciling/git/recsys-sbcorporation/train2.py", line 133, in train_model
       model.fit(train_iter, num_epoch=args.nepochs, optimizer='adam', optimizer_params=(('learning_rate', 0.001),), eval_metric='mse', eval_data=val_iter)
     File "/usr/local/lib/python3.5/dist-packages/mxnet/module/base_module.py", line 460, in fit
       for_training=True, force_rebind=force_rebind)
     File "/usr/local/lib/python3.5/dist-packages/mxnet/module/module.py", line 428, in bind
       state_names=self._state_names)
     File "/usr/local/lib/python3.5/dist-packages/mxnet/module/executor_group.py", line 237, in __init__
       self.bind_exec(data_shapes, label_shapes, shared_group)
     File "/usr/local/lib/python3.5/dist-packages/mxnet/module/executor_group.py", line 333, in bind_exec
       shared_group))
     File "/usr/local/lib/python3.5/dist-packages/mxnet/module/executor_group.py", line 598, in _bind_ith_exec
       input_shapes = dict(data_shapes)
   TypeError: unhashable type: 'list'
   ```
   
   adding both tests, I believe that the problem is that CSVIter is returning a (sort of) Nx2 matrix, whereas NDArrayIter is producing a 2xN matrix (i.e., CSVIter is producing the transposed version). However, I believe I need the 2xN version of NDArrayIter to produce the embeddings... but I might be wrong. 
   
   Again, and to keep the discussion contextualized, the core of my code currently looks like this:
   
   ```
   f1 = "tmp1"; f2 = "tmp2"
   iter_train = mx.io.CSVIter(data_csv=f1, data_shape=(2,), label_csv=f2, label_shape=(1,), batch_size=1000, data_name=['user','item'])
   user = mx.symbol.Embedding(data=user, input_dim=max_user, output_dim=factor_size)
   item = mx.symbol.Embedding(data=item, input_dim=max_item, output_dim=factor_size)
   pred = mx.symbol.concat(user, item)
   pred = mx.symbol.flatten(pred)
   pred = mx.symbol.FullyConnected(data=pred, num_hidden=64)
   pred = mx.symbol.Activation(data=pred, act_type='relu')
   pred = mx.symbol.FullyConnected(data=pred, num_hidden=1)
   pred = mx.symbol.LinearRegressionOutput(data=pred, label=score)
   model = mx.module.Module(context=mx.cpu(0), data_names=('user','item'), symbol=pred)
   model.fit(iter_train, num_epoch=10, optimizer='adam', optimizer_params=(('learning_rate', 0.001),), eval_metric='mse', eval_data=val_iter)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services