Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LSTM ¶
type LSTM struct { Model // contains filtered or unexported fields }
Example ¶
package main import ( "fmt" "github.com/itsubaki/autograd/model" ) func main() { m := model.NewLSTM(2, 3) for _, l := range m.Layers { fmt.Printf("%T\n", l) } }
Output: *layer.LSTMT *layer.LinearT
Example (Backward) ¶
package main import ( "fmt" "github.com/itsubaki/autograd/model" "github.com/itsubaki/autograd/rand" "github.com/itsubaki/autograd/variable" ) func main() { m := model.NewLSTM(1, 1, model.WithLSTMSource(rand.Const())) x := variable.New(1, 2) y := m.Forward(x) y.Backward() y = m.Forward(x) y.Backward() for _, l := range m.Layers { fmt.Printf("%T\n", l) for _, p := range l.Params() { fmt.Println(p.Name, p.Grad) } } }
Output: *layer.LSTMT w variable([-0.007097596643213066]) w variable([[0.013515028138341746] [0.027030056276683492]]) w variable([[0.04252623292012907] [0.08505246584025813]]) b variable([0.05279536845172966]) b variable([0.013515028138341746]) b variable([0.04252623292012907]) w variable([[0.05279536845172966] [0.10559073690345933]]) b variable([-0.00757230286787535]) w variable([[-0.00757230286787535] [-0.0151446057357507]]) w variable([-0.0062508612982463485]) w variable([-0.017558407475346018]) w variable([0.0016808382857761302]) *layer.LinearT b variable([2]) w variable([-1.1705639065492832])
func NewLSTM ¶
func NewLSTM(hiddenSize, outSize int, opts ...LSTMOptionFunc) *LSTM
func (*LSTM) ResetState ¶
func (m *LSTM) ResetState()
Example ¶
package main import ( "fmt" "github.com/itsubaki/autograd/model" "github.com/itsubaki/autograd/variable" ) func main() { m := model.NewLSTM(1, 1) x := variable.New(1, 2) m.Forward(x) m.ResetState() m.Forward(x) for _, p := range m.Params() { fmt.Println(p.Name, p.Grad) } }
Output: w <nil> b <nil> w <nil> b <nil> w <nil> b <nil> w <nil> b <nil> w <nil> b <nil> w <nil> w <nil> w <nil> w <nil>
type LSTMOptionFunc ¶
type LSTMOptionFunc func(*LSTM)
func WithLSTMSource ¶
func WithLSTMSource(s randv2.Source) LSTMOptionFunc
type MLP ¶
type MLP struct { Activation Activation Model // contains filtered or unexported fields }
Example ¶
package main import ( "fmt" "github.com/itsubaki/autograd/model" ) func main() { m := model.NewMLP([]int{1, 2, 3}) for _, l := range m.Layers { fmt.Printf("%T\n", l) } }
Output: *layer.LinearT *layer.LinearT *layer.LinearT
Example (Backward) ¶
package main import ( "fmt" F "github.com/itsubaki/autograd/function" "github.com/itsubaki/autograd/model" "github.com/itsubaki/autograd/rand" "github.com/itsubaki/autograd/variable" ) func main() { m := model.NewMLP([]int{5, 1}, model.WithMLPSource(rand.Const()), model.WithMLPActivation(F.ReLU), ) x := variable.New(1, 2) y := m.Forward(x) y.Backward() for _, p := range m.Params() { fmt.Println(p.Name, p.Grad) } }
Output: w variable([[0 0 -0.11785627150007956 -0.17275376822987032 -0.1452836777854009] [0 0 -0.23571254300015912 -0.34550753645974064 -0.2905673555708018]]) b variable([1]) w variable([[0] [0] [1.62887541989766] [0.7662326556923662] [1.9766127473463149]]) b variable([0 0 -0.11785627150007956 -0.17275376822987032 -0.1452836777854009])
Example (Cleargrads) ¶
package main import ( "fmt" F "github.com/itsubaki/autograd/function" "github.com/itsubaki/autograd/model" "github.com/itsubaki/autograd/rand" "github.com/itsubaki/autograd/variable" ) func main() { m := model.NewMLP([]int{5, 1}, model.WithMLPSource(rand.Const()), model.WithMLPActivation(F.ReLU), ) x := variable.New(1, 2) y := m.Forward(x) y.Backward() m.Cleargrads() for _, p := range m.Params() { fmt.Println(p.Name, p.Grad) } }
Output: b <nil> w <nil> b <nil> w <nil>
func NewMLP ¶
func NewMLP(outSize []int, opts ...MLPOptionFunc) *MLP
type MLPOptionFunc ¶
type MLPOptionFunc func(*MLP)
func WithMLPActivation ¶
func WithMLPActivation(activation Activation) MLPOptionFunc
func WithMLPSource ¶
func WithMLPSource(s randv2.Source) MLPOptionFunc
type MLPOpts ¶
type MLPOpts struct { Activation Activation Source randv2.Source }
Click to show internal directories.
Click to hide internal directories.