Skip to content

Commit a1a6659

Browse files
authored
Merge branch 'r0.9' into r0.9
2 parents 99e52a8 + a096442 commit a1a6659

23 files changed

+1800
-4
lines changed

RELEASE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Higher level functionality in contrib.{layers,losses,metrics,learn}
1313
* More features to Tensorboard
1414
* Improved support for string embedding and sparse features
15+
* The RNN api is finally "official" (see, e.g., `tf.nn.dynamic_rnn`,
16+
`tf.nn.rnn`, and the classes in `tf.nn.rnn_cell`).
1517
* TensorBoard now has an Audio Dashboard, with associated audio summaries.
1618

1719
## Big Fixes and Other Changes
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
### `tf.nn.bidirectional_rnn(cell_fw, cell_bw, inputs, initial_state_fw=None, initial_state_bw=None, dtype=None, sequence_length=None, scope=None)` {#bidirectional_rnn}
2+
3+
Creates a bidirectional recurrent neural network.
4+
5+
Similar to the unidirectional case above (rnn) but takes input and builds
6+
independent forward and backward RNNs with the final forward and backward
7+
outputs depth-concatenated, such that the output will have the format
8+
[time][batch][cell_fw.output_size + cell_bw.output_size]. The input_size of
9+
forward and backward cell must match. The initial state for both directions
10+
is zero by default (but can be set optionally) and no intermediate states are
11+
ever returned -- the network is fully unrolled for the given (passed in)
12+
length(s) of the sequence(s) or completely unrolled if length(s) is not given.
13+
14+
##### Args:
15+
16+
17+
* <b>`cell_fw`</b>: An instance of RNNCell, to be used for forward direction.
18+
* <b>`cell_bw`</b>: An instance of RNNCell, to be used for backward direction.
19+
* <b>`inputs`</b>: A length T list of inputs, each a tensor of shape
20+
[batch_size, input_size].
21+
* <b>`initial_state_fw`</b>: (optional) An initial state for the forward RNN.
22+
This must be a tensor of appropriate type and shape
23+
`[batch_size x cell_fw.state_size]`.
24+
If `cell_fw.state_size` is a tuple, this should be a tuple of
25+
tensors having shapes `[batch_size, s] for s in cell_fw.state_size`.
26+
* <b>`initial_state_bw`</b>: (optional) Same as for `initial_state_fw`, but using
27+
the corresponding properties of `cell_bw`.
28+
* <b>`dtype`</b>: (optional) The data type for the initial state. Required if
29+
either of the initial states are not provided.
30+
* <b>`sequence_length`</b>: (optional) An int32/int64 vector, size `[batch_size]`,
31+
containing the actual lengths for each of the sequences.
32+
* <b>`scope`</b>: VariableScope for the created subgraph; defaults to "BiRNN"
33+
34+
##### Returns:
35+
36+
A tuple (outputs, output_state_fw, output_state_bw) where:
37+
outputs is a length `T` list of outputs (one for each input), which
38+
are depth-concatenated forward and backward outputs.
39+
output_state_fw is the final state of the forward rnn.
40+
output_state_bw is the final state of the backward rnn.
41+
42+
##### Raises:
43+
44+
45+
* <b>`TypeError`</b>: If `cell_fw` or `cell_bw` is not an instance of `RNNCell`.
46+
* <b>`ValueError`</b>: If inputs is None or an empty list.
47+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
### `tf.nn.rnn(cell, inputs, initial_state=None, dtype=None, sequence_length=None, scope=None)` {#rnn}
2+
3+
Creates a recurrent neural network specified by RNNCell `cell`.
4+
5+
##### The simplest form of RNN network generated is:
6+
7+
state = cell.zero_state(...)
8+
outputs = []
9+
for input_ in inputs:
10+
output, state = cell(input_, state)
11+
outputs.append(output)
12+
return (outputs, state)
13+
14+
However, a few other options are available:
15+
16+
An initial state can be provided.
17+
If the sequence_length vector is provided, dynamic calculation is performed.
18+
This method of calculation does not compute the RNN steps past the maximum
19+
sequence length of the minibatch (thus saving computational time),
20+
and properly propagates the state at an example's sequence length
21+
to the final state output.
22+
23+
The dynamic calculation performed is, at time t for batch row b,
24+
(output, state)(b, t) =
25+
(t >= sequence_length(b))
26+
? (zeros(cell.output_size), states(b, sequence_length(b) - 1))
27+
: cell(input(b, t), state(b, t - 1))
28+
29+
##### Args:
30+
31+
32+
* <b>`cell`</b>: An instance of RNNCell.
33+
* <b>`inputs`</b>: A length T list of inputs, each a tensor of shape
34+
[batch_size, input_size].
35+
* <b>`initial_state`</b>: (optional) An initial state for the RNN.
36+
If `cell.state_size` is an integer, this must be
37+
a tensor of appropriate type and shape `[batch_size x cell.state_size]`.
38+
If `cell.state_size` is a tuple, this should be a tuple of
39+
tensors having shapes `[batch_size, s] for s in cell.state_size`.
40+
* <b>`dtype`</b>: (optional) The data type for the initial state. Required if
41+
initial_state is not provided.
42+
* <b>`sequence_length`</b>: Specifies the length of each sequence in inputs.
43+
An int32 or int64 vector (tensor) size `[batch_size]`, values in `[0, T)`.
44+
* <b>`scope`</b>: VariableScope for the created subgraph; defaults to "RNN".
45+
46+
##### Returns:
47+
48+
A pair (outputs, state) where:
49+
- outputs is a length T list of outputs (one for each input)
50+
- state is the final state
51+
52+
##### Raises:
53+
54+
55+
* <b>`TypeError`</b>: If `cell` is not an instance of RNNCell.
56+
* <b>`ValueError`</b>: If `inputs` is `None` or an empty list, or if the input depth
57+
(column size) cannot be inferred from inputs via shape inference.
58+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Operator adding input embedding to the given cell.
2+
3+
Note: in many cases it may be more efficient to not use this wrapper,
4+
but instead concatenate the whole sequence of your inputs in time,
5+
do the embedding on this batch-concatenated sequence, then split it and
6+
feed into your RNN.
7+
- - -
8+
9+
#### `tf.nn.rnn_cell.EmbeddingWrapper.__init__(cell, embedding_classes, embedding_size, initializer=None)` {#EmbeddingWrapper.__init__}
10+
11+
Create a cell with an added input embedding.
12+
13+
##### Args:
14+
15+
16+
* <b>`cell`</b>: an RNNCell, an embedding will be put before its inputs.
17+
* <b>`embedding_classes`</b>: integer, how many symbols will be embedded.
18+
* <b>`embedding_size`</b>: integer, the size of the vectors we embed into.
19+
* <b>`initializer`</b>: an initializer to use when creating the embedding;
20+
if None, the initializer from variable scope or a default one is used.
21+
22+
##### Raises:
23+
24+
25+
* <b>`TypeError`</b>: if cell is not an RNNCell.
26+
* <b>`ValueError`</b>: if embedding_classes is not positive.
27+
28+
29+
- - -
30+
31+
#### `tf.nn.rnn_cell.EmbeddingWrapper.output_size` {#EmbeddingWrapper.output_size}
32+
33+
Integer: size of outputs produced by this cell.
34+
35+
36+
- - -
37+
38+
#### `tf.nn.rnn_cell.EmbeddingWrapper.state_size` {#EmbeddingWrapper.state_size}
39+
40+
41+
42+
43+
- - -
44+
45+
#### `tf.nn.rnn_cell.EmbeddingWrapper.zero_state(batch_size, dtype)` {#EmbeddingWrapper.zero_state}
46+
47+
Return zero-filled state tensor(s).
48+
49+
##### Args:
50+
51+
52+
* <b>`batch_size`</b>: int, float, or unit Tensor representing the batch size.
53+
* <b>`dtype`</b>: the data type to use for the state.
54+
55+
##### Returns:
56+
57+
If `state_size` is an int, then the return value is a `2-D` tensor of
58+
shape `[batch_size x state_size]` filled with zeros.
59+
60+
If `state_size` is a nested list or tuple, then the return value is
61+
a nested list or tuple (of the same structure) of `2-D` tensors with
62+
the shapes `[batch_size x s]` for each s in `state_size`.
63+
64+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Operator adding an output projection to the given cell.
2+
3+
Note: in many cases it may be more efficient to not use this wrapper,
4+
but instead concatenate the whole sequence of your outputs in time,
5+
do the projection on this batch-concatenated sequence, then split it
6+
if needed or directly feed into a softmax.
7+
- - -
8+
9+
#### `tf.nn.rnn_cell.OutputProjectionWrapper.__init__(cell, output_size)` {#OutputProjectionWrapper.__init__}
10+
11+
Create a cell with output projection.
12+
13+
##### Args:
14+
15+
16+
* <b>`cell`</b>: an RNNCell, a projection to output_size is added to it.
17+
* <b>`output_size`</b>: integer, the size of the output after projection.
18+
19+
##### Raises:
20+
21+
22+
* <b>`TypeError`</b>: if cell is not an RNNCell.
23+
* <b>`ValueError`</b>: if output_size is not positive.
24+
25+
26+
- - -
27+
28+
#### `tf.nn.rnn_cell.OutputProjectionWrapper.output_size` {#OutputProjectionWrapper.output_size}
29+
30+
31+
32+
33+
- - -
34+
35+
#### `tf.nn.rnn_cell.OutputProjectionWrapper.state_size` {#OutputProjectionWrapper.state_size}
36+
37+
38+
39+
40+
- - -
41+
42+
#### `tf.nn.rnn_cell.OutputProjectionWrapper.zero_state(batch_size, dtype)` {#OutputProjectionWrapper.zero_state}
43+
44+
Return zero-filled state tensor(s).
45+
46+
##### Args:
47+
48+
49+
* <b>`batch_size`</b>: int, float, or unit Tensor representing the batch size.
50+
* <b>`dtype`</b>: the data type to use for the state.
51+
52+
##### Returns:
53+
54+
If `state_size` is an int, then the return value is a `2-D` tensor of
55+
shape `[batch_size x state_size]` filled with zeros.
56+
57+
If `state_size` is a nested list or tuple, then the return value is
58+
a nested list or tuple (of the same structure) of `2-D` tensors with
59+
the shapes `[batch_size x s]` for each s in `state_size`.
60+
61+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
The most basic RNN cell.
2+
- - -
3+
4+
#### `tf.nn.rnn_cell.BasicRNNCell.__init__(num_units, input_size=None, activation=tanh)` {#BasicRNNCell.__init__}
5+
6+
7+
8+
9+
- - -
10+
11+
#### `tf.nn.rnn_cell.BasicRNNCell.output_size` {#BasicRNNCell.output_size}
12+
13+
14+
15+
16+
- - -
17+
18+
#### `tf.nn.rnn_cell.BasicRNNCell.state_size` {#BasicRNNCell.state_size}
19+
20+
21+
22+
23+
- - -
24+
25+
#### `tf.nn.rnn_cell.BasicRNNCell.zero_state(batch_size, dtype)` {#BasicRNNCell.zero_state}
26+
27+
Return zero-filled state tensor(s).
28+
29+
##### Args:
30+
31+
32+
* <b>`batch_size`</b>: int, float, or unit Tensor representing the batch size.
33+
* <b>`dtype`</b>: the data type to use for the state.
34+
35+
##### Returns:
36+
37+
If `state_size` is an int, then the return value is a `2-D` tensor of
38+
shape `[batch_size x state_size]` filled with zeros.
39+
40+
If `state_size` is a nested list or tuple, then the return value is
41+
a nested list or tuple (of the same structure) of `2-D` tensors with
42+
the shapes `[batch_size x s]` for each s in `state_size`.
43+
44+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Operator adding dropout to inputs and outputs of the given cell.
2+
- - -
3+
4+
#### `tf.nn.rnn_cell.DropoutWrapper.__init__(cell, input_keep_prob=1.0, output_keep_prob=1.0, seed=None)` {#DropoutWrapper.__init__}
5+
6+
Create a cell with added input and/or output dropout.
7+
8+
Dropout is never used on the state.
9+
10+
##### Args:
11+
12+
13+
* <b>`cell`</b>: an RNNCell, a projection to output_size is added to it.
14+
* <b>`input_keep_prob`</b>: unit Tensor or float between 0 and 1, input keep
15+
probability; if it is float and 1, no input dropout will be added.
16+
* <b>`output_keep_prob`</b>: unit Tensor or float between 0 and 1, output keep
17+
probability; if it is float and 1, no output dropout will be added.
18+
* <b>`seed`</b>: (optional) integer, the randomness seed.
19+
20+
##### Raises:
21+
22+
23+
* <b>`TypeError`</b>: if cell is not an RNNCell.
24+
* <b>`ValueError`</b>: if keep_prob is not between 0 and 1.
25+
26+
27+
- - -
28+
29+
#### `tf.nn.rnn_cell.DropoutWrapper.output_size` {#DropoutWrapper.output_size}
30+
31+
32+
33+
34+
- - -
35+
36+
#### `tf.nn.rnn_cell.DropoutWrapper.state_size` {#DropoutWrapper.state_size}
37+
38+
39+
40+
41+
- - -
42+
43+
#### `tf.nn.rnn_cell.DropoutWrapper.zero_state(batch_size, dtype)` {#DropoutWrapper.zero_state}
44+
45+
Return zero-filled state tensor(s).
46+
47+
##### Args:
48+
49+
50+
* <b>`batch_size`</b>: int, float, or unit Tensor representing the batch size.
51+
* <b>`dtype`</b>: the data type to use for the state.
52+
53+
##### Returns:
54+
55+
If `state_size` is an int, then the return value is a `2-D` tensor of
56+
shape `[batch_size x state_size]` filled with zeros.
57+
58+
If `state_size` is a nested list or tuple, then the return value is
59+
a nested list or tuple (of the same structure) of `2-D` tensors with
60+
the shapes `[batch_size x s]` for each s in `state_size`.
61+
62+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Gated Recurrent Unit cell (cf. http://arxiv.org/abs/1406.1078).
2+
- - -
3+
4+
#### `tf.nn.rnn_cell.GRUCell.__init__(num_units, input_size=None, activation=tanh)` {#GRUCell.__init__}
5+
6+
7+
8+
9+
- - -
10+
11+
#### `tf.nn.rnn_cell.GRUCell.output_size` {#GRUCell.output_size}
12+
13+
14+
15+
16+
- - -
17+
18+
#### `tf.nn.rnn_cell.GRUCell.state_size` {#GRUCell.state_size}
19+
20+
21+
22+
23+
- - -
24+
25+
#### `tf.nn.rnn_cell.GRUCell.zero_state(batch_size, dtype)` {#GRUCell.zero_state}
26+
27+
Return zero-filled state tensor(s).
28+
29+
##### Args:
30+
31+
32+
* <b>`batch_size`</b>: int, float, or unit Tensor representing the batch size.
33+
* <b>`dtype`</b>: the data type to use for the state.
34+
35+
##### Returns:
36+
37+
If `state_size` is an int, then the return value is a `2-D` tensor of
38+
shape `[batch_size x state_size]` filled with zeros.
39+
40+
If `state_size` is a nested list or tuple, then the return value is
41+
a nested list or tuple (of the same structure) of `2-D` tensors with
42+
the shapes `[batch_size x s]` for each s in `state_size`.
43+
44+

0 commit comments

Comments
 (0)