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 2018/03/01 21:35:35 UTC

[GitHub] sxjscience commented on a change in pull request #9934: [Gluon] Support variable sequence length in gluon.RecurrentCell

sxjscience commented on a change in pull request #9934: [Gluon] Support variable sequence length in gluon.RecurrentCell 
URL: https://github.com/apache/incubator-mxnet/pull/9934#discussion_r171700972
 
 

 ##########
 File path: python/mxnet/gluon/rnn/rnn_cell.py
 ##########
 @@ -83,15 +83,28 @@ def _format_sequence(length, inputs, layout, merge, in_layout=None):
             F = ndarray
             batch_size = inputs[0].shape[batch_axis]
         if merge is True:
-            inputs = [F.expand_dims(i, axis=axis) for i in inputs]
-            inputs = F.concat(*inputs, dim=axis)
+            inputs = F.stack(*inputs, axis=axis)
             in_axis = axis
 
     if isinstance(inputs, tensor_types) and axis != in_axis:
         inputs = F.swapaxes(inputs, dim1=axis, dim2=in_axis)
 
     return inputs, axis, F, batch_size
 
+def _mask_sequence_variable_length(F, data, length, valid_length, time_axis, merge):
+    assert valid_length is not None
+    if isinstance(data, tensor_types):
+        outputs = F.SequenceMask(data, sequence_length=valid_length, use_sequence_length=True,
+                                 axis=time_axis)
+    else:
+        outputs = F.SequenceMask(F.stack(*data, axis=time_axis),
+                                 sequence_length=valid_length,
+                                 use_sequence_length=True,
+                                 axis=time_axis)
+    if not merge:
+        outputs = F.split(outputs, num_outputs=length, axis=time_axis, squeeze_axis=True)
+        outputs = [outputs[i] for i in range(length)]
 
 Review comment:
   I find it not very good to reuse `_format_sequence` because there are additional clauses for determining the F in `_format_sequence`. Directly writing the splitting logic here should be more clear.

----------------------------------------------------------------
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