Adds a standard LSTM recurrent network operator to a model. cell_class: LSTMCell or compatible subclass model: ModelHelper object new operators would be added to input_blob: the input sequence in a format T x N x D where T is sequence size, N - batch size and D - inpu
(
cell_class,
model,
input_blob,
seq_lengths,
initial_states,
dim_in,
dim_out,
scope=None,
outputs_with_grads=(0,),
return_params=False,
memory_optimization=False,
forget_bias=0.0,
forward_only=False,
drop_states=False,
return_last_layer_only=True,
static_rnn_unroll_size=None,
**cell_kwargs
)
| 1465 | |
| 1466 | |
| 1467 | def _LSTM( |
| 1468 | cell_class, |
| 1469 | model, |
| 1470 | input_blob, |
| 1471 | seq_lengths, |
| 1472 | initial_states, |
| 1473 | dim_in, |
| 1474 | dim_out, |
| 1475 | scope=None, |
| 1476 | outputs_with_grads=(0,), |
| 1477 | return_params=False, |
| 1478 | memory_optimization=False, |
| 1479 | forget_bias=0.0, |
| 1480 | forward_only=False, |
| 1481 | drop_states=False, |
| 1482 | return_last_layer_only=True, |
| 1483 | static_rnn_unroll_size=None, |
| 1484 | **cell_kwargs |
| 1485 | ): |
| 1486 | ''' |
| 1487 | Adds a standard LSTM recurrent network operator to a model. |
| 1488 | |
| 1489 | cell_class: LSTMCell or compatible subclass |
| 1490 | |
| 1491 | model: ModelHelper object new operators would be added to |
| 1492 | |
| 1493 | input_blob: the input sequence in a format T x N x D |
| 1494 | where T is sequence size, N - batch size and D - input dimension |
| 1495 | |
| 1496 | seq_lengths: blob containing sequence lengths which would be passed to |
| 1497 | LSTMUnit operator |
| 1498 | |
| 1499 | initial_states: a list of (2 * num_layers) blobs representing the initial |
| 1500 | hidden and cell states of each layer. If this argument is None, |
| 1501 | these states will be added to the model as network parameters. |
| 1502 | |
| 1503 | dim_in: input dimension |
| 1504 | |
| 1505 | dim_out: number of units per LSTM layer |
| 1506 | (use int for single-layer LSTM, list of ints for multi-layer) |
| 1507 | |
| 1508 | outputs_with_grads : position indices of output blobs for LAST LAYER which |
| 1509 | will receive external error gradient during backpropagation. |
| 1510 | These outputs are: (h_all, h_last, c_all, c_last) |
| 1511 | |
| 1512 | return_params: if True, will return a dictionary of parameters of the LSTM |
| 1513 | |
| 1514 | memory_optimization: if enabled, the LSTM step is recomputed on backward |
| 1515 | step so that we don't need to store forward activations for each |
| 1516 | timestep. Saves memory with cost of computation. |
| 1517 | |
| 1518 | forget_bias: forget gate bias (default 0.0) |
| 1519 | |
| 1520 | forward_only: whether to create a backward pass |
| 1521 | |
| 1522 | drop_states: drop invalid states, passed through to LSTMUnit operator |
| 1523 | |
| 1524 | return_last_layer_only: only return outputs from final layer |
nothing calls this directly
no test coverage detected
searching dependent graphs…