MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _time_step

Function _time_step

modelzoo/features/embedding_variable/dien/script/rnn.py:734–780  ·  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

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

Callers

nothing calls this directly

Calls 6

tupleFunction · 0.85
_rnn_stepFunction · 0.70
readMethod · 0.45
set_shapeMethod · 0.45
flattenMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected