RNN that accepts a state saver for time-truncated RNN calculation. Args: cell: An instance of `RNNCell`. inputs: A length T list of inputs, each a `Tensor` of shape `[batch_size, input_size]`. state_saver: A state saver object with methods `state` and `save_state`. state_nam
(cell,
inputs,
state_saver,
state_name,
sequence_length=None,
scope=None)
| 1449 | "which is equivalent to this API") |
| 1450 | @tf_export(v1=["nn.static_state_saving_rnn"]) |
| 1451 | def static_state_saving_rnn(cell, |
| 1452 | inputs, |
| 1453 | state_saver, |
| 1454 | state_name, |
| 1455 | sequence_length=None, |
| 1456 | scope=None): |
| 1457 | """RNN that accepts a state saver for time-truncated RNN calculation. |
| 1458 | |
| 1459 | Args: |
| 1460 | cell: An instance of `RNNCell`. |
| 1461 | inputs: A length T list of inputs, each a `Tensor` of shape `[batch_size, |
| 1462 | input_size]`. |
| 1463 | state_saver: A state saver object with methods `state` and `save_state`. |
| 1464 | state_name: Python string or tuple of strings. The name to use with the |
| 1465 | state_saver. If the cell returns tuples of states (i.e., `cell.state_size` |
| 1466 | is a tuple) then `state_name` should be a tuple of strings having the same |
| 1467 | length as `cell.state_size`. Otherwise it should be a single string. |
| 1468 | sequence_length: (optional) An int32/int64 vector size [batch_size]. See the |
| 1469 | documentation for rnn() for more details about sequence_length. |
| 1470 | scope: VariableScope for the created subgraph; defaults to "rnn". |
| 1471 | |
| 1472 | Returns: |
| 1473 | A pair (outputs, state) where: |
| 1474 | outputs is a length T list of outputs (one for each input) |
| 1475 | states is the final state |
| 1476 | |
| 1477 | Raises: |
| 1478 | TypeError: If `cell` is not an instance of RNNCell. |
| 1479 | ValueError: If `inputs` is `None` or an empty list, or if the arity and |
| 1480 | type of `state_name` does not match that of `cell.state_size`. |
| 1481 | """ |
| 1482 | state_size = cell.state_size |
| 1483 | state_is_tuple = nest.is_sequence(state_size) |
| 1484 | state_name_tuple = nest.is_sequence(state_name) |
| 1485 | |
| 1486 | if state_is_tuple != state_name_tuple: |
| 1487 | raise ValueError("state_name should be the same type as cell.state_size. " |
| 1488 | "state_name: %s, cell.state_size: %s" % |
| 1489 | (str(state_name), str(state_size))) |
| 1490 | |
| 1491 | if state_is_tuple: |
| 1492 | state_name_flat = nest.flatten(state_name) |
| 1493 | state_size_flat = nest.flatten(state_size) |
| 1494 | |
| 1495 | if len(state_name_flat) != len(state_size_flat): |
| 1496 | raise ValueError("#elems(state_name) != #elems(state_size): %d vs. %d" % |
| 1497 | (len(state_name_flat), len(state_size_flat))) |
| 1498 | |
| 1499 | initial_state = nest.pack_sequence_as( |
| 1500 | structure=state_size, |
| 1501 | flat_sequence=[state_saver.state(s) for s in state_name_flat]) |
| 1502 | else: |
| 1503 | initial_state = state_saver.state(state_name) |
| 1504 | |
| 1505 | (outputs, state) = static_rnn( |
| 1506 | cell, |
| 1507 | inputs, |
| 1508 | initial_state=initial_state, |
nothing calls this directly
no test coverage detected