Skip to content

Commit c99be6c

Browse files
Merge #1637
1637: updated recurrence.md which fixes #1564 r=CarloLucibello a=aditkumar72 changed `rand` and `randn` definition to `rand(Float32, ...)` and `randn(Float32, ...)` Co-authored-by: Aditya Tewary <aditkumar72@gmail.com>
2 parents e7686b2 + 9b6000a commit c99be6c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/src/models/recurrence.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ An aspect to recognize is that in such model, the recurrent cells `A` all refer
1313
In the most basic RNN case, cell A could be defined by the following:
1414

1515
```julia
16-
Wxh = randn(5, 2)
17-
Whh = randn(5, 5)
18-
b = randn(5)
16+
Wxh = randn(Float32, 5, 2)
17+
Whh = randn(Float32, 5, 5)
18+
b = randn(Float32, 5)
1919

20-
function rnn(h, x)
21-
h = tanh.(Wxh * x .+ Whh * h .+ b)
22-
return h, h
20+
function rnn_cell(h, x)
21+
h = tanh.(Wxh * x .+ Whh * h .+ b)
22+
return h, h
2323
end
2424

25-
x = rand(2) # dummy data
26-
h = rand(5) # initial hidden state
25+
x = rand(Float32, 2) # dummy data
26+
h = rand(Float32, 5) # initial hidden state
2727

28-
h, y = rnn(h, x)
28+
h, y = rnn_cell(h, x)
2929
```
3030

3131
Notice how the above is essentially a `Dense` layer that acts on two inputs, `h` and `x`.

0 commit comments

Comments
 (0)