Welvet examples

21. layers/rnn · lstm

Open original example ↗Recorded results · not a live execution

Part: III · Layers
Package: github.com/openfluke/welvet/layers/lstm
Status: ok — ✅

When

Building or training a net that needs the layers/lstm Op (also usable as a Parallel cam).

Where

import "github.com/openfluke/welvet/layers/lstm"

cd 21-rnn-lstm && source ../env.sh && go run .

Why

Sequence models before transformers still need vanilla RNN and LSTM with BPTT on the shared MatVec stack.

What

IH/HH (and LSTM gates) via Dense; recurrence ALU host; device required for WebGPU path.

Sample output (captured)

64 64

Live capture from go run ./cmd/runall on local ../../welvet (exit 0).

Source

Copied from the Welvet feature book examples (openfluke.github.io/welvet/examples/21-rnn-lstm).

main.go

Download source ↓
package main

import (
	"fmt"

	"github.com/openfluke/welvet/core"
	"github.com/openfluke/welvet/layers/lstm"
	"github.com/openfluke/welvet/layers/rnn"
)

func main() {
	r, _ := rnn.New(rnn.Config{InputSize: 8, HiddenSize: 16, SeqLen: 4})
	l, _ := lstm.New(lstm.Config{InputSize: 8, HiddenSize: 16, SeqLen: 4})
	x := core.NewTensor[float32](1, 4, 8)
	_, yr, _ := rnn.Forward(r, x)
	_, yl, _ := lstm.Forward(l, x)
	fmt.Println(len(yr.Data), len(yl.Data))
}