Skip to content

Commit 1912402

Browse files
committed
add warning block in RNN
1 parent 60c7de7 commit 1912402

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/layers/recurrent.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,33 +142,33 @@ julia> r(rand(Float32, 3, 10)) |> size # batch size of 10
142142
(5, 10)
143143
```
144144
145-
The following is a demonstration of when failing to call `reset!` between batch size changes can cause erroneous outputs.
145+
!!! warning Failing to call `reset!` when the input batch size changes can lead to unexpected behavior. See the following example:
146146
147-
```julia
148-
julia> r = RNN(3, 5)
149-
Recur(
150-
RNNCell(3, 5, tanh), # 50 parameters
151-
) # Total: 4 trainable arrays, 50 parameters,
152-
# plus 1 non-trainable, 5 parameters, summarysize 432 bytes.
147+
```julia
148+
julia> r = RNN(3, 5)
149+
Recur(
150+
RNNCell(3, 5, tanh), # 50 parameters
151+
) # Total: 4 trainable arrays, 50 parameters,
152+
# plus 1 non-trainable, 5 parameters, summarysize 432 bytes.
153153
154-
julia> r.state |> size
155-
(5, 1)
154+
julia> r.state |> size
155+
(5, 1)
156156
157-
julia> r(rand(Float32, 3)) |> size
158-
(5,)
157+
julia> r(rand(Float32, 3)) |> size
158+
(5,)
159159
160-
julia> r.state |> size
161-
(5, 1)
160+
julia> r.state |> size
161+
(5, 1)
162162
163-
julia> r(rand(Float32, 3, 10)) |> size # batch size of 10
164-
(5, 10)
163+
julia> r(rand(Float32, 3, 10)) |> size # batch size of 10
164+
(5, 10)
165165
166-
julia> r.state |> size # state shape has changed
167-
(5, 10)
166+
julia> r.state |> size # state shape has changed
167+
(5, 10)
168168
169-
julia> r(rand(Float32, 3)) |> size # erroneously outputs a length 5*10 = 50 vector.
170-
(50,)
171-
```
169+
julia> r(rand(Float32, 3)) |> size # erroneously outputs a length 5*10 = 50 vector.
170+
(50,)
171+
```
172172
"""
173173
RNN(a...; ka...) = Recur(RNNCell(a...; ka...))
174174
Recur(m::RNNCell) = Recur(m, m.state0)

0 commit comments

Comments
 (0)