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

Method call

tensorflow/python/keras/layers/recurrent.py:675–775  ·  view source on GitHub ↗
(self,
           inputs,
           mask=None,
           training=None,
           initial_state=None,
           constants=None)

Source from the content-addressed store, hash-verified

673 return super(RNN, self).__call__(inputs, **kwargs)
674
675 def call(self,
676 inputs,
677 mask=None,
678 training=None,
679 initial_state=None,
680 constants=None):
681 inputs, initial_state, constants = self._process_inputs(
682 inputs, initial_state, constants)
683
684 if mask is not None:
685 # Time step masks must be the same for each input.
686 # TODO(scottzhu): Should we accept multiple different masks?
687 mask = nest.flatten(mask)[0]
688
689 if nest.is_sequence(inputs):
690 # In the case of nested input, use the first element for shape check.
691 input_shape = K.int_shape(nest.flatten(inputs)[0])
692 else:
693 input_shape = K.int_shape(inputs)
694 timesteps = input_shape[0] if self.time_major else input_shape[1]
695 if self.unroll and timesteps is None:
696 raise ValueError('Cannot unroll a RNN if the '
697 'time dimension is undefined. \n'
698 '- If using a Sequential model, '
699 'specify the time dimension by passing '
700 'an `input_shape` or `batch_input_shape` '
701 'argument to your first layer. If your '
702 'first layer is an Embedding, you can '
703 'also use the `input_length` argument.\n'
704 '- If using the functional API, specify '
705 'the time dimension by passing a `shape` '
706 'or `batch_shape` argument to your Input layer.')
707
708 kwargs = {}
709 if generic_utils.has_arg(self.cell.call, 'training'):
710 kwargs['training'] = training
711
712 # TF RNN cells expect single tensor as state instead of list wrapped tensor.
713 is_tf_rnn_cell = getattr(self.cell, '_is_tf_rnn_cell', None) is not None
714 if constants:
715 if not generic_utils.has_arg(self.cell.call, 'constants'):
716 raise ValueError('RNN cell does not support constants')
717
718 def step(inputs, states):
719 constants = states[-self._num_constants:] # pylint: disable=invalid-unary-operand-type
720 states = states[:-self._num_constants] # pylint: disable=invalid-unary-operand-type
721
722 states = states[0] if len(states) == 1 and is_tf_rnn_cell else states
723 output, new_states = self.cell.call(
724 inputs, states, constants=constants, **kwargs)
725 if not nest.is_sequence(new_states):
726 new_states = [new_states]
727 return output, new_states
728 else:
729
730 def step(inputs, states):
731 states = states[0] if len(states) == 1 and is_tf_rnn_cell else states
732 output, new_states = self.cell.call(inputs, states, **kwargs)

Callers 5

callMethod · 0.45
stepMethod · 0.45
callMethod · 0.45
callMethod · 0.45
callMethod · 0.45

Calls 8

_process_inputsMethod · 0.95
executing_eagerlyMethod · 0.80
rnnMethod · 0.80
add_updateMethod · 0.80
flattenMethod · 0.45
appendMethod · 0.45
assignMethod · 0.45
to_listMethod · 0.45

Tested by

no test coverage detected