0 | module NN.Architectures.RNN
10 | RNNCell : (x, s, y : Type) -> Type
11 | RNNCell x s y = (x, s) -\-> (y, s)
16 | RNN : (x, s, y : Type) -> (n : Nat) ->Type
17 | RNN x s y n = (Vect n x, s) -\-> (Vect n y, s)
22 | RNNImpl : (cell : DPair (x, s) (const p) -> (y, s)) ->
23 | DPair (Vect n x, s) (const p) -> (Vect n y, s)
24 | RNNImpl _ (
([], s) ** _)
= ([], s)
25 | RNNImpl cell (
((x :: xs), s) ** p)
=
26 | let (y, s') = cell (
(x, s) ** p)
27 | (ys, s'') = RNNImpl cell (
(xs, s') ** p)
32 | RNNPara : (cell : RNNCell x s y) ->
33 | IsNotDependent cell =>
35 | RNNPara (MkPara (const p) cell) @{MkNonDep p cell} = MkPara
41 | runRNN : (rnn : RNN x s y n) ->
43 | (initialState : s) ->
44 | (p : Param rnn (xs, initialState)) ->
46 | runRNN rnn xs initialState p = fst $
Run rnn (xs, initialState) p
49 | exampleRNN : RNNCell Double Double Double
50 | exampleRNN = MkPara (\_ => ()) (\((x, s) ** ()) => (if s > 4 then x else 0, s + 1))
53 | exampleInput : Vect 10 Double
54 | exampleInput = [1,2,3,4,5,6,7,8,9,10]
57 | exampleOutput : Vect 10 Double
58 | exampleOutput = runRNN (RNNPara exampleRNN) exampleInput 0 ()