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

Method __init__

tensorflow/python/ops/rnn_cell_impl.py:1213–1249  ·  view source on GitHub ↗

Create a RNN cell composed sequentially of a number of RNNCells. Args: cells: list of RNNCells that will be composed in this order. state_is_tuple: If True, accepted and returned states are n-tuples, where `n = len(cells)`. If False, the states are all concatenated along th

(self, cells, state_is_tuple=True)

Source from the content-addressed store, hash-verified

1211 "tf.keras.layers.StackedRNNCells, and will be replaced by "
1212 "that in Tensorflow 2.0.")
1213 def __init__(self, cells, state_is_tuple=True):
1214 """Create a RNN cell composed sequentially of a number of RNNCells.
1215
1216 Args:
1217 cells: list of RNNCells that will be composed in this order.
1218 state_is_tuple: If True, accepted and returned states are n-tuples, where
1219 `n = len(cells)`. If False, the states are all concatenated along the
1220 column axis. This latter behavior will soon be deprecated.
1221
1222 Raises:
1223 ValueError: if cells is empty (not allowed), or at least one of the cells
1224 returns a state tuple but the flag `state_is_tuple` is `False`.
1225 """
1226 super(MultiRNNCell, self).__init__()
1227 if not cells:
1228 raise ValueError("Must specify at least one cell for MultiRNNCell.")
1229 if not nest.is_sequence(cells):
1230 raise TypeError("cells must be a list or tuple, but saw: %s." % cells)
1231
1232 if len(set([id(cell) for cell in cells])) < len(cells):
1233 logging.log_first_n(
1234 logging.WARN, "At least two cells provided to MultiRNNCell "
1235 "are the same object and will share weights.", 1)
1236
1237 self._cells = cells
1238 for cell_number, cell in enumerate(self._cells):
1239 # Add Trackable dependencies on these cells so their variables get
1240 # saved with this object when using object-based saving.
1241 if isinstance(cell, trackable.Trackable):
1242 # TODO(allenl): Track down non-Trackable callers.
1243 self._track_trackable(cell, name="cell-%d" % (cell_number,))
1244 self._state_is_tuple = state_is_tuple
1245 if not state_is_tuple:
1246 if any(nest.is_sequence(c.state_size) for c in self._cells):
1247 raise ValueError("Some cells return tuples of states, but the flag "
1248 "state_is_tuple is not set. State sizes are: %s" %
1249 str([c.state_size for c in self._cells]))
1250
1251 @property
1252 def state_size(self):

Callers

nothing calls this directly

Calls 3

anyFunction · 0.85
__init__Method · 0.45
_track_trackableMethod · 0.45

Tested by

no test coverage detected