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

Method call

tensorflow/contrib/rnn/python/ops/rnn_cell.py:1783–1843  ·  view source on GitHub ↗

Run one step of the Intersection RNN. Args: inputs: input Tensor, 2D, batch x input size. state: state Tensor, 2D, batch x num units. Returns: new_y: batch x num units, Tensor representing the output of the +RNN after reading `inputs` when previous state was `stat

(self, inputs, state)

Source from the content-addressed store, hash-verified

1781 return self._num_units
1782
1783 def call(self, inputs, state):
1784 """Run one step of the Intersection RNN.
1785
1786 Args:
1787 inputs: input Tensor, 2D, batch x input size.
1788 state: state Tensor, 2D, batch x num units.
1789
1790 Returns:
1791 new_y: batch x num units, Tensor representing the output of the +RNN
1792 after reading `inputs` when previous state was `state`.
1793 new_state: batch x num units, Tensor representing the state of the +RNN
1794 after reading `inputs` when previous state was `state`.
1795
1796 Raises:
1797 ValueError: If input size cannot be inferred from `inputs` via
1798 static shape inference.
1799 ValueError: If input size != output size (these must be equal when
1800 using the Intersection RNN).
1801 """
1802 sigmoid = math_ops.sigmoid
1803 tanh = math_ops.tanh
1804
1805 input_size = inputs.get_shape().with_rank(2).dims[1]
1806 if input_size.value is None:
1807 raise ValueError("Could not infer input size from inputs.get_shape()[-1]")
1808
1809 with vs.variable_scope(
1810 vs.get_variable_scope(), initializer=self._initializer):
1811 # read-in projections (should be used for first layer in deep +RNN
1812 # to transform size of inputs from I --> N)
1813 if input_size.value != self._num_units:
1814 if self._num_input_proj:
1815 with vs.variable_scope("in_projection"):
1816 if self._linear1 is None:
1817 self._linear1 = _Linear(inputs, self._num_units, True)
1818 inputs = self._linear1(inputs)
1819 else:
1820 raise ValueError("Must have input size == output size for "
1821 "Intersection RNN. To fix, num_in_proj should "
1822 "be set to num_units at cell init.")
1823
1824 n_dim = i_dim = self._num_units
1825 cell_inputs = array_ops.concat([inputs, state], 1)
1826 if self._linear2 is None:
1827 self._linear2 = _Linear(cell_inputs, 2 * n_dim + 2 * i_dim, True)
1828 rnn_matrix = self._linear2(cell_inputs)
1829
1830 gh_act = rnn_matrix[:, :n_dim] # b x n
1831 h_act = rnn_matrix[:, n_dim:2 * n_dim] # b x n
1832 gy_act = rnn_matrix[:, 2 * n_dim:2 * n_dim + i_dim] # b x i
1833 y_act = rnn_matrix[:, 2 * n_dim + i_dim:2 * n_dim + 2 * i_dim] # b x i
1834
1835 h = tanh(h_act)
1836 y = self._y_activation(y_act)
1837 gh = sigmoid(gh_act + self._forget_bias)
1838 gy = sigmoid(gy_act + self._forget_bias)
1839
1840 new_state = gh * state + (1.0 - gh) * h # passed thru time

Callers

nothing calls this directly

Calls 7

_LinearClass · 0.85
with_rankMethod · 0.80
variable_scopeMethod · 0.80
tanhClass · 0.50
sigmoidClass · 0.50
get_shapeMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected