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

Method zero_state

tensorflow/python/ops/rnn_cell_impl.py:311–340  ·  view source on GitHub ↗

Return zero-filled state tensor(s). Args: batch_size: int, float, or unit Tensor representing the batch size. dtype: the data type to use for the state. Returns: If `state_size` is an int or TensorShape, then the return value is a `N-D` tensor of shape `[batch_size,

(self, batch_size, dtype)

Source from the content-addressed store, hash-verified

309 return self.zero_state(batch_size, dtype)
310
311 def zero_state(self, batch_size, dtype):
312 """Return zero-filled state tensor(s).
313
314 Args:
315 batch_size: int, float, or unit Tensor representing the batch size.
316 dtype: the data type to use for the state.
317
318 Returns:
319 If `state_size` is an int or TensorShape, then the return value is a
320 `N-D` tensor of shape `[batch_size, state_size]` filled with zeros.
321
322 If `state_size` is a nested list or tuple, then the return value is
323 a nested list or tuple (of the same structure) of `2-D` tensors with
324 the shapes `[batch_size, s]` for each s in `state_size`.
325 """
326 # Try to use the last cached zero_state. This is done to avoid recreating
327 # zeros, especially when eager execution is enabled.
328 state_size = self.state_size
329 is_eager = context.executing_eagerly()
330 if is_eager and _hasattr(self, "_last_zero_state"):
331 (last_state_size, last_batch_size, last_dtype,
332 last_output) = getattr(self, "_last_zero_state")
333 if (last_batch_size == batch_size and last_dtype == dtype and
334 last_state_size == state_size):
335 return last_output
336 with ops.name_scope(type(self).__name__ + "ZeroState", values=[batch_size]):
337 output = _zero_state_tensors(state_size, batch_size, dtype)
338 if is_eager:
339 self._last_zero_state = (state_size, batch_size, dtype, output)
340 return output
341
342 # TODO(b/134773139): Remove when contrib RNN cells implement `get_config`
343 def get_config(self): # pylint: disable=useless-super-delegation

Callers 15

get_initial_stateMethod · 0.95
dynamic_rnnFunction · 0.45
static_rnnFunction · 0.45
dynamic_rnnFunction · 0.45
static_rnnFunction · 0.45
dynamic_rnnFunction · 0.45
static_rnnFunction · 0.45
dynamic_rnnFunction · 0.45
static_rnnFunction · 0.45
zero_stateMethod · 0.45
dynamic_rnnFunction · 0.45
static_rnnFunction · 0.45

Calls 5

_hasattrFunction · 0.85
typeFunction · 0.85
_zero_state_tensorsFunction · 0.85
executing_eagerlyMethod · 0.80
name_scopeMethod · 0.45

Tested by 5

lstm_model_fnFunction · 0.36
dynamic_lstm_model_fnFunction · 0.36
create_lstm_per_eg_gradFunction · 0.36
loop_fnFunction · 0.36
create_dynamic_lstmFunction · 0.36