golgi

package module
v0.0.0-...-98938cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2020 License: MIT Imports: 11 Imported by: 0

README

golgi

Golgi is a package that makes creating neural networks with Gorgonia simpler. Common neural network patterns are supported. It is best used with the qol package (gorgonia.org/qol).

High Level Goals

The high-level goals of this package is to make simple things easy, and yet not sacrificing the options for customization.

Documentation

Overview

Example
package main

import (
	"fmt"

	. "gorgonia.org/golgi"
	"gorgonia.org/gorgonia"
	"gorgonia.org/tensor"
)

func softmax(a *gorgonia.Node) (*gorgonia.Node, error) { return gorgonia.SoftMax(a) }

func main() {
	n := 100
	of := tensor.Float64
	g := gorgonia.NewGraph()
	x := gorgonia.NewTensor(g, of, 4, gorgonia.WithName("X"), gorgonia.WithShape(n, 1, 28, 28), gorgonia.WithInit(gorgonia.GlorotU(1)))
	y := gorgonia.NewMatrix(g, of, gorgonia.WithName("Y"), gorgonia.WithShape(n, 10), gorgonia.WithInit(gorgonia.GlorotU(1)))
	nn, err := ComposeSeq(
		x,
		L(ConsReshape, ToShape(n, 784)),
		L(ConsFC, WithSize(50), WithName("l0"), AsBatched(true), WithActivation(gorgonia.Tanh), WithBias(true)),
		L(ConsDropout, WithProbability(0.5)),
		L(ConsFC, WithSize(150), WithName("l1"), AsBatched(true), WithActivation(gorgonia.Rectify)), // by default WithBias is true
		L(ConsLayerNorm, WithSize(20), WithName("Norm"), WithEps(0.001)),
		L(ConsFC, WithSize(10), WithName("l2"), AsBatched(true), WithActivation(softmax), WithBias(false)),
	)
	if err != nil {
		panic(err)
	}
	out := nn.Fwd(x)
	if err = gorgonia.CheckOne(out); err != nil {
		panic(err)
	}

	cost := gorgonia.Must(RMS(out, y))
	model := nn.Model()
	if _, err = gorgonia.Grad(cost, model...); err != nil {
		panic(err)
	}
	m := gorgonia.NewTapeMachine(g)
	if err := m.RunAll(); err != nil {
		panic(err)
	}

	fmt.Printf("Model: %v\n", model)
}
Output:

Model: [l0_W, l0_B, l1_W, l1_B, Norm_W, Norm_B, l2_W]
Example (Extension)
package main

import (
	"fmt"

	"github.com/pkg/errors"
	. "gorgonia.org/golgi"
	G "gorgonia.org/gorgonia"
	"gorgonia.org/tensor"
)

// myLayer is a layer with additional support for transformation for shapes.
//
// One may of course do this with a ComposeSeq(Reshape, FC), but this is just for demonstration purposes
type myLayer struct {
	// name is in FC
	FC

	// BE CAREFUL WITH EMBEDDINGS

	// size is in FC and in myLayer
	size int
}

// Model, Name, Type, Shape and Describe are all from the embedded FC

func (l *myLayer) Fwd(a G.Input) G.Result {
	if err := G.CheckOne(a); err != nil {
		return G.Err(errors.Wrapf(err, "Fwd of myLayer %v", l.FC.Name()))
	}
	x := a.Node()
	xShape := x.Shape()

	switch xShape.Dims() {
	case 0, 1:
		return G.Err(errors.Errorf("Unable to handle x of %v", xShape))
	case 2:
		return l.FC.Fwd(x)
	case 3, 4:
		return G.Err(errors.Errorf("NYI"))

	}
	panic("UNIMPLEMENTED")
}

func ConsMyLayer(x G.Input, opts ...ConsOpt) (retVal Layer, err error) {
	l := new(myLayer)
	for _, opt := range opts {
		var o Layer
		var ok bool
		if o, err = opt(l); err != nil {
			return nil, err
		}
		if l, ok = o.(*myLayer); !ok {
			return nil, errors.Errorf("Construction Option returned non *myLayer. Got %T instead", o)
		}
	}
	if err = l.Init(x.(*G.Node)); err != nil {
		return nil, err
	}
	return l, nil
}

func main() {
	of := tensor.Float64
	g := G.NewGraph()
	x := G.NewTensor(g, of, 4, G.WithName("X"), G.WithShape(100, 1, 28, 28), G.WithInit(G.GlorotU(1)))
	layer, err := ConsMyLayer(x, WithName("EXT"), WithSize(100))
	if err != nil {
		fmt.Printf("Uh oh. Error happened when constructing *myLayer: %v\n", err)
	}
	l := layer.(*myLayer)
	fmt.Printf("Name:  %q\n", l.Name())
	fmt.Printf("Model: %v\n", l.Model())
	fmt.Printf("BE CAREFUL\n======\nl.size is %v. But the models shapes are correct as follows:\n", l.size)
	for _, n := range l.Model() {
		fmt.Printf("\t%v - %v\n", n.Name(), n.Shape())
	}

}
Output:

Name:  "EXT"
Model: [EXT_W, EXT_B]
BE CAREFUL
======
l.size is 0. But the models shapes are correct as follows:
	EXT_W - (1, 100)
	EXT_B - (100, 100)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastAdd

func BroadcastAdd(a, b *G.Node, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastAdd performs a add. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastEq

func BroadcastEq(a, b *G.Node, retSame bool, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastEq performs a eq. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastGt

func BroadcastGt(a, b *G.Node, retSame bool, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastGt performs a gt. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastGte

func BroadcastGte(a, b *G.Node, retSame bool, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastGte performs a gte. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastHadamardDiv

func BroadcastHadamardDiv(a, b *G.Node, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastHadamardDiv performs a hadamarddiv. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastHadamardProd

func BroadcastHadamardProd(a, b *G.Node, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastHadamardProd performs a hadamardprod. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastLt

func BroadcastLt(a, b *G.Node, retSame bool, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastLt performs a lt. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastLte

func BroadcastLte(a, b *G.Node, retSame bool, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastLte performs a lte. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastNe

func BroadcastNe(a, b *G.Node, retSame bool, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastNe performs a ne. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastPow

func BroadcastPow(a, b *G.Node, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastPow performs a pow. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func BroadcastSub

func BroadcastSub(a, b *G.Node, leftPattern, rightPattern []byte) (*G.Node, error)

BroadcastSub performs a sub. The operation is precomposed with a broadcast such that the shapes matches before operations commence.

func ExtractMetadata

func ExtractMetadata(opts ...ConsOpt) (retVal Metadata, unused []ConsOpt, err error)

ExtractMetadata extracts common metadata from a list of ConsOpts. It returns the metadata. Any unused ConsOpt is also returned. This allows users to selectively use the metadata and/or ConsOpt options

func GeLUFn

func GeLUFn(a *G.Node) (*G.Node, error)

GeLUFn is an activation function. See https://arxiv.org/abs/1606.08415.

func RMS

func RMS(yHat, y G.Input) (retVal *G.Node, err error)

RMS represents a root mean equare error The root-mean-square deviation (RMSD) or root-mean-square error (RMSE) is a frequently used measure of the differences between values (sample or population values) predicted by a model or an estimator and the values observed.

Types

type Activation

type Activation int

Activation represents the types of ActivationFunctions that Golgi understands.

The Activation type is useful as it allows the models to be serialized (you cannot serialize ActivationFunction). Use ActivationMap() to get the relevant ActivationFunction.

const (
	Identity Activation = iota
	Sigmoid
	Tanh
	ReLU
	GeLU
	LeakyReLU
	ELU
	Cube
)

type ActivationFunction

type ActivationFunction func(*G.Node) (*G.Node, error)

ActivationFunction represents an activation function Note: This may become an interface once we've worked through all the linter errors

func ActivationMap

func ActivationMap(a Activation) ActivationFunction

ActivationMaps is a map from Activation to ActivationFunction. The mapping function is finite. If an invalid Activation is passed in, nil will be returned.

type ByNamer

type ByNamer interface {
	ByName(name string) Term
}

ByNamer is any type that allows a name to be found and returned.

If a name is not found, `nil` is to be returned

type Composition

type Composition struct {
	// contains filtered or unexported fields
}

Composition (∘) represents a composition of functions.

The semantics of ∘(a, b)(x) is b(a(x)).

func Compose

func Compose(a, b Term) (retVal *Composition)

Compose creates a composition of terms.

func ComposeSeq

func ComposeSeq(layers ...Term) (retVal *Composition, err error)

ComposeSeq creates a composition with the inputs written in left to right order

The equivalent in F# is |>. The equivalent in Haskell is (flip (.))

func (*Composition) ByName

func (l *Composition) ByName(name string) Term

ByName returns a Term by name

func (*Composition) Describe

func (l *Composition) Describe()

Describe will describe a composition

func (*Composition) Fwd

func (l *Composition) Fwd(a G.Input) (output G.Result)

Fwd runs the equation forwards

func (*Composition) Graph

func (l *Composition) Graph() *G.ExprGraph

func (*Composition) Model

func (l *Composition) Model() (retVal G.Nodes)

Model will return the gorgonia.Nodes associated with this composition

func (*Composition) Name

func (l *Composition) Name() string

Name will return the name of the composition

func (*Composition) Runners

func (l *Composition) Runners() []Runner

type ConsOpt

type ConsOpt func(Layer) (Layer, error)

ConsOpt is a construction option for layers

func AsBatched

func AsBatched(batched bool) ConsOpt

AsBatched defines a layer that performs batched operation or not. By default most layers in this package are batched.

func Of

func Of(dt tensor.Dtype) ConsOpt

func ToShape

func ToShape(shp ...int) ConsOpt

ToShape is a ConsOpt for Reshape only.

func WithActivation

func WithActivation(act ActivationFunction) ConsOpt

WithActivation sets the activation function of a layer

func WithBatchSize

func WithBatchSize(bs int) ConsOpt

WithBatchSize creates a layer with a given batch size.

func WithBias

func WithBias(withbias bool) ConsOpt

WithBias defines a layer with or without a bias

func WithClasses

func WithClasses(classes int) ConsOpt

WithClasses is a construction option that specifies how many classes are there in the embedding layer.

func WithConst

func WithConst(c *G.Node) ConsOpt

WithConst is a construction option for the skip Layer

func WithEps

func WithEps(eps float64) ConsOpt

WithEps is a ConsOpt for constructing Layer Norms only.

func WithName

func WithName(name string) ConsOpt

WithName creates a layer that is named.

If the layer is unnameable (i.e. trivial layers), then there is no effect.

func WithOneHotInput

func WithOneHotInput() ConsOpt

WithOneHotInput is a construction option for a *Embedding that specifiess the behaviour to accept one-hot-vector/matrix as input.

func WithProbability

func WithProbability(prob float64) ConsOpt

WithProbability is a ConsOpt for Dropout only.

func WithSize

func WithSize(size ...int) ConsOpt

WithSize automatically creates a layer of the given sizes.

func WithWB

func WithWB(w, b *G.Node) ConsOpt

WithWB is a FC specific construction option used to initialize a FC.

func WithWeights

func WithWeights(w *G.Node) ConsOpt

WithWeights constructs a layer with the given weights.

type Conv

type Conv struct{}

Conv represents a convolution layer

func (*Conv) Describe

func (l *Conv) Describe()

Describe will describe a convolution layer

func (*Conv) Fwd

func (l *Conv) Fwd(x G.Input) G.Result

Fwd runs the equation forwards

func (*Conv) Model

func (l *Conv) Model() G.Nodes

Model will return the gorgonia.Nodes associated with this convolution layer

func (*Conv) Name

func (l *Conv) Name() string

Name will return the name of the convolution layer

func (*Conv) Shape

func (l *Conv) Shape() tensor.Shape

Shape will return the tensor.Shape of the convolution layer

func (*Conv) Type

func (l *Conv) Type() hm.Type

Type will return the hm.Type of the convolution layer

type Data

type Data interface {
	Make(g *G.ExprGraph, name string) (Layer, error)
}

Data represents a layer's data. It is able to reconstruct a Layer and populating it.

type Embedding

type Embedding struct {
	// contains filtered or unexported fields
}

Embedding is a layer that represents an embedding layer.

An embedding layer is essentially a matrix of the shape (classes, dimensions). While the Embedding layer can be done by means of using FC, this provides some ease of use.

Specifically the Embedding layer supports forwarding of an input that is a slice of classes.

Let us look at a word-based example, consider the vocab size to be the number of classes. The classical word embedding then is simply a (vocab, dims) matrix. Let's set the dims to be 50. For simplicity, let's set the vocab to 10. So that the embedding matrix W is a (10, 50) matrix.

W := ⸢w1_1  ...  w1_50⸣
             ⋮
     ⸤w10_1 ... w10_50⸥

To select a word vector, we simply slice the matrix. For example, to get the vector of word ID 2, we slice W[2]. This gives us a 50-dimension vector:

W[2] = [w2_1 ... w2_50]

We can equally do this by multiplying the matrix with a one-hot vector. A vector O given as

O := [0 0 1 0 0 0 0 0 0 0]

when multiplied against W, will yield the same result as W[2].

The usual way of selecting from a embedding matrix with a one-hot vector is quite cumbersome. This struct makes it easy.

You can pass in a *tensor.Dense of qol.Class:

wv := tensor.New(tensor.WithBacking([]qol.Class{4, 10, 0, 0, 0, 0, 0, 0,0,0}))
words := gorgonia.NewVector(g, gorgonia.WithShape(10), gorgonia.WithValue(wv))
layer.Fwd(words)

The Embedding layer's Fwd function will automatically transform a slice of classes into a one-hot matrix to be multiplied with.

func NewEmbedding

func NewEmbedding(opts ...ConsOpt) *Embedding

NewEmbedding creates a new embedding layer.

func (*Embedding) Describe

func (l *Embedding) Describe()

func (*Embedding) Fwd

func (l *Embedding) Fwd(a G.Input) G.Result

func (*Embedding) Graph

func (l *Embedding) Graph() *G.ExprGraph

Graph returns the underlying computation graph. Embedding implements Grapher.

func (*Embedding) Init

func (l *Embedding) Init(xs ...*G.Node) (err error)

Init initializes the embedding layer.

func (*Embedding) IsInitialized

func (l *Embedding) IsInitialized() bool

func (*Embedding) Model

func (l *Embedding) Model() G.Nodes

Model returns the gorgonia.Nodes associated with the embedding layer.

func (*Embedding) Name

func (l *Embedding) Name() string

func (*Embedding) Run

func (l *Embedding) Run(input G.Input) (err error)

Run is a function that sets the internal one hot vector/matrix

func (*Embedding) Runners

func (l *Embedding) Runners() []Runner

Runners returns the embedding itself

type Env

type Env struct {
	// contains filtered or unexported fields
}

Env is a linked list representing an environment. Within the documentation, an environment is written as such:

e := (x ↦ X)

`x` is the name while `X` is the *gorgonia.Node

A longer environment may look like this:

e2 := (x ↦ X :: y ↦ Y)
                ^

Here, e2 is pointing to the *Env that contains (y ↦ Y).

When talking about Envs in general, it will often be written as a meta variable σ.

func NewEnv

func NewEnv(name string, node *G.Node) *Env

NewEnv creates a new Env.

func (*Env) ByName

func (e *Env) ByName(name string) (*G.Node, *Env)

ByName returns the first node that matches the given name. It also returns the parent

For example, if we have an Env as follows:

e := (x ↦ X1 :: w ↦ W :: x ↦ X2)
                         ^

The caret indicates the pointer of *Env. Now, if e.ByName("x") is called, then the result returned will be X2 and (x ↦ X1 :: w ↦ W)

func (*Env) Extend

func (e *Env) Extend(name string, node *G.Node) *Env

Extend allows users to extend the environment.

Given an environment as follows:

e := (x ↦ X)

if `e.Extend(y, Y)` is called, the following is returned

e2 := (x ↦ X :: y ↦ Y)
                ^

The pointer will be pointing to the *Env starting at y

func (*Env) HintedModel

func (e *Env) HintedModel(hint int) G.Nodes

HintedModel will return the gorgonia.Nodes hinted associated with this environment

func (*Env) Model

func (e *Env) Model() G.Nodes

Model will return the gorgonia.Nodes associated with this environment

func (*Env) Name

func (e *Env) Name() string

Name will return the name of the composition

type FC

type FC struct {
	// contains filtered or unexported fields
}

FC represents a fully connected layer

If batched is set to true, then the first dimension is assumed to be the batch dimension

func MakeFC

func MakeFC(w, b *G.Node, act ActivationFunction, name string, batched bool) FC

MakeFC creates a FC with the given parameters

func NewFC

func NewFC(opts ...ConsOpt) *FC

NewFC is the usual way to create a FC

func (*FC) ByName

func (l *FC) ByName(name string) Term

ByName returns a Term by name

func (*FC) Describe

func (l *FC) Describe()

Describe will describe a fully connected layer

func (*FC) Fwd

func (l *FC) Fwd(a G.Input) G.Result

Fwd runs the equation forwards

func (*FC) Graph

func (l *FC) Graph() *G.ExprGraph

func (*FC) Init

func (l *FC) Init(xs ...*G.Node) (err error)

Init will initialize the fully connected layer

func (*FC) IsInitialized

func (l *FC) IsInitialized() bool

IsInitialized returns true if it has been initialized. This allows lazy initialization to be supported

func (*FC) Model

func (l *FC) Model() G.Nodes

Model will return the gorgonia.Nodes associated with this fully connected layer

func (*FC) Name

func (l *FC) Name() string

Name will return the name of the fully connected layer

func (*FC) SetAct

func (l *FC) SetAct(act ActivationFunction) error

SetAct will set an activiation function of a fully connected layer

func (*FC) SetName

func (l *FC) SetName(a string) error

SetName will set the name of a fully connected layer

func (*FC) SetSize

func (l *FC) SetSize(a int) error

SetSize will set the size of a fully connected layer

func (*FC) Shape

func (l *FC) Shape() tensor.Shape

Shape will return the tensor.Shape of the fully connected layer

func (*FC) Type

func (l *FC) Type() hm.Type

Type will return the hm.Type of the fully connected layer

type Grapher

type Grapher interface {
	Graph() *G.ExprGraph
}

Grapher is any type that can return the underlying computational graph

type I

type I struct{}

func (I) Name

func (i I) Name() string

type Join

type Join struct {
	Composition
	// contains filtered or unexported fields
}

Joins are generalized compositions.

func Add

func Add(a, b Term) *Join

Add adds the results of two layers/terms.

func HadamardProd

func HadamardProd(a, b Term) *Join

HadamardProd performs a elementwise multiplicatoin on the results of two layers/terms.

func (*Join) Fwd

func (l *Join) Fwd(a G.Input) (output G.Result)

Fwd runs the equation forwards.

type LSTM

type LSTM struct {
	// contains filtered or unexported fields
}

LSTM represents an LSTM RNN

func FromLSTMData

func FromLSTMData(g *G.ExprGraph, layer *LSTMData, name string) *LSTM

FromLSTMData will initialize a new LSTM model

func (*LSTM) Describe

func (l *LSTM) Describe()

Describe will describe a LSTM

func (*LSTM) Fwd

func (l *LSTM) Fwd(x G.Input) G.Result

Fwd runs the equation forwards.

While a *LSTM can take any gorgonia.Input as an input, it returns a gorgonia.Result, of which the concrete type is a lstimIO.

The lstmIO type is not exported. Instead, to query the *Node of the gorgonia.Input or gorgonia.Result, use the Nodes() method.

The Result will always be organized as such: [previousHidden, previousCell]

e.g.

out := lstm.Fwd(x)
outNodes := out.Nodes()
prevHidden := outNodes[0]
prevCell := outNodes[1]

func (*LSTM) Init

func (l *LSTM) Init(xs ...*G.Node) (err error)

Init will initialize the fully connected layer

func (*LSTM) Model

func (l *LSTM) Model() G.Nodes

Model will return the gorgonia.Nodes associated with this LSTM

func (*LSTM) Name

func (l *LSTM) Name() string

Name will return the name of the LSTM

func (*LSTM) SetName

func (l *LSTM) SetName(a string) error

SetName will set the name of a fully connected layer

func (*LSTM) Shape

func (l *LSTM) Shape() tensor.Shape

Shape will return the tensor.Shape of the LSTM

func (*LSTM) Type

func (l *LSTM) Type() hm.Type

Type will return the hm.Type of the LSTM

type LSTMData

type LSTMData struct {
	// contains filtered or unexported fields
}

LSTMData represents a basic LSTM layer

func (*LSTMData) Make

func (l *LSTMData) Make(g *G.ExprGraph, name string) (Layer, error)

type Layer

type Layer interface {
	// σ - The weights are the "free variables" of a function
	Model() G.Nodes

	// Fwd represents the forward application of inputs
	// x.t
	Fwd(x G.Input) G.Result

	Term

	// Describe returns the protobuf definition of a Layer that conforms to the ONNX standard
	Describe() // some protobuf things TODO
}

Layer represents a neural network layer. λ

func ConsDropout

func ConsDropout(_ G.Input, opts ...ConsOpt) (l Layer, err error)

ConsDropout creates a dropout layer. It ignores the `x` input

func ConsEmbedding

func ConsEmbedding(in G.Input, opts ...ConsOpt) (retVal Layer, err error)

ConsEmbedding is a construction function to construct a *Embedding. This is typically used in a L() construction manner.

func ConsFC

func ConsFC(in G.Input, opts ...ConsOpt) (retVal Layer, err error)

ConsFC is a FC construction function. It takes a gorgonia.Input that has a *gorgonia.Node.

func ConsLSTM

func ConsLSTM(in G.Input, opts ...ConsOpt) (retVal Layer, err error)

ConsLSTM is a LSTM construction function. It takes a gorgonia.Input that has a *gorgonia.Node.

func ConsLayerNorm

func ConsLayerNorm(in G.Input, opts ...ConsOpt) (retVal Layer, err error)

ConsLayerNorm is a construction function for a layer normalization layer. `in` has to be at least a *gorgonia.Node

func ConsReshape

func ConsReshape(_ G.Input, opts ...ConsOpt) (l Layer, err error)

ConsReshape is a construction function for a reshaping layer. It ignores the `x` input.

func ConsSkip

func ConsSkip(_ G.Input, opts ...ConsOpt) (retVal Layer, err error)

func Redefine

func Redefine(l Layer, opts ...ConsOpt) (retVal Layer, err error)

Redefine redefines a layer with the given construction options. This is useful for re-initializing layers

type LayerCons

type LayerCons func(input G.Input, opts ...ConsOpt) (Layer, error)

LayerCons makes a layer

type Metadata

type Metadata struct {
	Size int

	ActivationFn ActivationFunction
	// contains filtered or unexported fields
}

Metadata is not a real Layer. Its main aims is to extract metadata such as name or size from ConsOpts. This is useful in cases where the metadata needs to be composed as well. Note that the fields may end up being all empty.

func (*Metadata) Describe

func (m *Metadata) Describe()

Describe will describe a metadata

func (*Metadata) Fwd

func (m *Metadata) Fwd(x G.Input) G.Result

Fwd runs the equation forwards

func (*Metadata) Model

func (m *Metadata) Model() G.Nodes

Model will return the gorgonia.Nodes associated with this metadata

func (*Metadata) Name

func (m *Metadata) Name() string

Name returns the name. Conveniently, this makes *Metadata fulfil the Layer interface, so we may use it to extract the desired metadata. Unfortunately this also means that the name is not an exported field. A little inconsistency there.

func (*Metadata) PassThru

func (m *Metadata) PassThru()

PassThru represents a passthru function

func (*Metadata) SetActivationFn

func (m *Metadata) SetActivationFn(act ActivationFunction) error

SetActivationFn allows the metadata to store activation function.

func (*Metadata) SetName

func (m *Metadata) SetName(name string) error

SetName allows for names to be set by a ConsOpt

func (*Metadata) SetSize

func (m *Metadata) SetSize(size int) error

SetSize allows for the metadata struct to be filled by a ConsOpt

func (*Metadata) Shape

func (m *Metadata) Shape() tensor.Shape

Shape will return the tensor.Shape of the metadata

func (*Metadata) Type

func (m *Metadata) Type() hm.Type

Type will return the hm.Type of the metadata

type Name

type Name string

Name is a variable by name

func (Name) Name

func (n Name) Name() string

Name will return itself as a string

type Pass

type Pass interface {
	PassThru()
}

Pass represents layers that are pass-thru - layers that have external effects that do not affect the expression graph.

type Runner

type Runner interface {
	Run(a G.Input) error

	// Runners should return themselves
	Runnerser
}

Runner is a kind of layer that requires outside-the-graph manipulation.

type Runnerser

type Runnerser interface {
	Runners() []Runner
}

Runnerser is any kind of layer that gets a slice of Runners.

For simplicity, all Runners should implement Runnerser

type Term

type Term interface {
	Name() string
}

Term represents a term that can be used in Golgi

func Apply

func Apply(a, b Term) (Term, error)

Apply will apply two terms and return the resulting term Apply(a, b) has the semantics of a(b).

func L

func L(cons LayerCons, opts ...ConsOpt) Term

L is a thunk of creation function

func Trace

func Trace(name, format, errFormat string, logger *log.Logger) Term

Trace creates a layer for debugging composed layers

The format string adds four things: "%s %v (%p) %v" - name (of trace), x, x, x.Shape()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL