MCPcopy Create free account
hub / github.com/alibaba/bigcomputing / _time_step

Function _time_step

DIEN/rnn.py:729–775  ·  view source on GitHub ↗

Take a time step of the dynamic RNN. Args: time: int32 scalar Tensor. output_ta_t: List of `TensorArray`s that represent the output. state: nested tuple of vector tensors that represent the state. Returns: The tuple (time + 1, output_ta_t with updated flow, new_stat

(time, output_ta_t, state, att_scores=None)

Source from the content-addressed store, hash-verified

727 for ta, input_ in zip(input_ta, flat_input))
728
729 def _time_step(time, output_ta_t, state, att_scores=None):
730 """Take a time step of the dynamic RNN.
731
732 Args:
733 time: int32 scalar Tensor.
734 output_ta_t: List of `TensorArray`s that represent the output.
735 state: nested tuple of vector tensors that represent the state.
736
737 Returns:
738 The tuple (time + 1, output_ta_t with updated flow, new_state).
739 """
740
741 input_t = tuple(ta.read(time) for ta in input_ta)
742 # Restore some shape information
743 for input_, shape in zip(input_t, inputs_got_shape):
744 input_.set_shape(shape[1:])
745
746 input_t = nest.pack_sequence_as(structure=inputs, flat_sequence=input_t)
747 if att_scores is not None:
748 att_score = att_scores[:, time, :]
749 call_cell = lambda: cell(input_t, state, att_score)
750 else:
751 call_cell = lambda: cell(input_t, state)
752
753 if sequence_length is not None:
754 (output, new_state) = _rnn_step(
755 time=time,
756 sequence_length=sequence_length,
757 min_sequence_length=min_sequence_length,
758 max_sequence_length=max_sequence_length,
759 zero_output=zero_output,
760 state=state,
761 call_cell=call_cell,
762 state_size=state_size,
763 skip_conditionals=True)
764 else:
765 (output, new_state) = call_cell()
766
767 # Pack state if using state tuples
768 output = nest.flatten(output)
769
770 output_ta_t = tuple(
771 ta.write(time, out) for ta, out in zip(output_ta_t, output))
772 if att_scores is not None:
773 return (time + 1, output_ta_t, new_state, att_scores)
774 else:
775 return (time + 1, output_ta_t, new_state)
776
777 if att_scores is not None:
778 _, output_final_ta, final_state, _ = control_flow_ops.while_loop(

Callers

nothing calls this directly

Calls 1

_rnn_stepFunction · 0.85

Tested by

no test coverage detected