-
Notifications
You must be signed in to change notification settings - Fork 13
/
lstm_test.go
36 lines (33 loc) · 944 Bytes
/
lstm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package lstm
import (
"testing"
G "gorgonia.org/gorgonia"
"gorgonia.org/tensor"
)
func TestForwardStep(t *testing.T) {
model := newModelFromBackends(testBackends(5, 4, 100))
tset := &testSet{
values: [][]float32{
{1, 0, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 0, 1, 0},
{0, 0, 0, 0, 1},
}}
hiddenT := tensor.New(tensor.Of(tensor.Float32), tensor.WithShape(model.hiddenSize))
cellT := tensor.New(tensor.Of(tensor.Float32), tensor.WithShape(model.hiddenSize))
lstm := model.newLSTM(hiddenT, cellT)
//lstm := model.newLSTM()
_, _, err := lstm.forwardStep(tset, lstm.prevHidden, lstm.prevCell, 0)
if err != nil {
t.Fatal(err)
}
machine := G.NewTapeMachine(lstm.g)
// machine := G.NewLispMachine(lstm.g, G.ExecuteFwdOnly())
if err := machine.RunAll(); err != nil {
t.Fatal(err)
}
for _, computedVector := range tset.GetComputedVectors() {
t.Log(computedVector.Value().Data().([]float32))
}
}