Documentation ¶
Overview ¶
Package model provides an interface for machine learning models.
Index ¶
- Variables
- func AsBatch(size int) func(*Input)
- func AsType(dtype t.Dtype) func(*Input)
- func NameAsBatch(name string) string
- func WithBatchSize(size int) func(Model)
- func WithGraphLogger(log *golog.Logger) func(Model)
- func WithLogger(logger *log.Logger) func(Model)
- func WithLoss(loss Loss) func(Model)
- func WithMetrics(metrics ...Metric) func(Model)
- func WithOptimizer(optimizer g.Solver) func(Model)
- func WithTracker(tracker *track.Tracker) func(Model)
- func WithoutTracker() func(Model)
- type CloneOpt
- type CrossEntropyLoss
- type Input
- func (i *Input) AsBatch(size int) *Input
- func (i *Input) AsLayer() l.Layer
- func (i *Input) Check(value g.Value) error
- func (i *Input) Clone(opts ...CloneOpt) *Input
- func (i *Input) CloneTo(graph *g.ExprGraph, opts ...CloneOpt) *Input
- func (i *Input) Compile(graph *g.ExprGraph, opts ...InputOpt) *g.Node
- func (i *Input) DType() t.Dtype
- func (i *Input) EnsureBatch() *Input
- func (i *Input) Input() *Input
- func (i *Input) Inputs() Inputs
- func (i *Input) Name() string
- func (i *Input) Node() *g.Node
- func (i *Input) OneOfMany() (err error)
- func (i *Input) Set(value g.Value) error
- func (i *Input) Shape() t.Shape
- func (i *Input) Squeeze() t.Shape
- func (i *Input) Validate() error
- type InputLayer
- type InputOpt
- type InputOr
- type Inputs
- type Loss
- type MSELoss
- type Metric
- type Metrics
- type Model
- type Opt
- type Opts
- type PseudoCrossEntropyLoss
- type PseudoHuberLoss
- type Sequential
- func (s *Sequential) AddLayer(layer layer.Config)
- func (s *Sequential) AddLayers(layers ...layer.Config)
- func (s *Sequential) CloneLearnablesTo(to *Sequential) error
- func (s *Sequential) Compile(x InputOr, y *Input, opts ...Opt) error
- func (s *Sequential) Fit(x ValueOr, y g.Value) error
- func (s *Sequential) FitBatch(x ValueOr, y g.Value) (err error)
- func (s *Sequential) Fwd(x *Input)
- func (s *Sequential) Graphs() map[string]*g.ExprGraph
- func (s *Sequential) Learnables() g.Nodes
- func (s *Sequential) Predict(x g.Value) (prediction g.Value, err error)
- func (s *Sequential) PredictBatch(x g.Value) (prediction g.Value, err error)
- func (s *Sequential) ResizeBatch(n int) (err error)
- func (s *Sequential) SetLearnables(desired g.Nodes) error
- func (s *Sequential) Visualize(name string)
- func (s *Sequential) X() InputOr
- func (s *Sequential) Y() *Input
- type ValueOr
- type Values
Constants ¶
This section is empty.
Variables ¶
var AllMetrics = Metrics{TrainLossMetric, TrainBatchLossMetric}
AllMetrics are all metrics.
var CrossEntropy = &CrossEntropyLoss{}
CrossEntropy loss.
var MSE = &MSELoss{}
MSE is standard mean squared error loss.
var PseudoCrossEntropy = &PseudoCrossEntropyLoss{}
PseudoCrossEntropy loss.
var PseudoHuber = &PseudoHuberLoss{
Delta: 1.0,
}
PseudoHuber is the Huber loss function.
Functions ¶
func NameAsBatch ¶
NameAsBatch takes an input name and converts it to its batch name.
func WithBatchSize ¶
WithBatchSize sets the batch size for the model. Defaults to 32.
func WithGraphLogger ¶
WithGraphLogger adds a logger to the model which will print out the graph operations as they occur.
func WithLogger ¶
WithLogger adds a logger to the model.
func WithMetrics ¶
WithMetrics sets the metrics that the model should track. Defaults to AllMetrics.
func WithOptimizer ¶
WithOptimizer uses a specific optimizer function. Defaults to Adam.
func WithTracker ¶
WithTracker adds a tracker to the model, if not provided one will be created.
func WithoutTracker ¶
func WithoutTracker() func(Model)
WithoutTracker uses no tracking with the model.
Types ¶
type CrossEntropyLoss ¶
type CrossEntropyLoss struct{}
CrossEntropyLoss is standard cross entropy loss.
func (*CrossEntropyLoss) CloneTo ¶
func (c *CrossEntropyLoss) CloneTo(graph *g.ExprGraph, opts ...CloneOpt) Loss
CloneTo another graph.
func (*CrossEntropyLoss) Inputs ¶
func (c *CrossEntropyLoss) Inputs() Inputs
Inputs returns any inputs the loss function utilizes.
type Input ¶
type Input struct {
// contains filtered or unexported fields
}
Input into the model.
func (*Input) Check ¶
Check that the dimensions and type of the given value are congruent with the expected input.
func (*Input) EnsureBatch ¶
EnsureBatch checks that the first dimension is 1 or reshapes it to be so.
func (*Input) OneOfMany ¶
OneOfMany normalizes the input shape to be one of many. Any incoming singular input will also be normalized to this shape.
type InputLayer ¶
type InputLayer struct {
// contains filtered or unexported fields
}
InputLayer is an input layer to be used in a chain.
func (*InputLayer) Compile ¶
func (i *InputLayer) Compile(graph *g.ExprGraph, opts ...l.CompileOpt)
Compile the layer.
func (*InputLayer) Graph ¶
func (i *InputLayer) Graph() *g.ExprGraph
Graph returns the graph for this layer.
func (*InputLayer) Learnables ¶
func (i *InputLayer) Learnables() g.Nodes
Learnables returns all learnable nodes within this layer.
type Inputs ¶
type Inputs []*Input
Inputs is a slice of input.
type Loss ¶
type Loss interface { // Comput the loss. Compute(yHat, y *g.Node) (loss *g.Node, err error) // Clone the loss to another graph. CloneTo(graph *g.ExprGraph, opts ...CloneOpt) Loss // Inputs return any inputs the loss function utilizes. Inputs() Inputs }
Loss is the loss of a model.
type MSELoss ¶
type MSELoss struct{}
MSELoss is mean squared error loss.
type Model ¶
type Model interface { // Compile the model. Compile(x InputOr, y *Input, opts ...Opt) error // Predict x. Predict(x g.Value) (prediction g.Value, err error) // Fit x to y. Fit(x ValueOr, y g.Value) error // FitBatch fits x to y as batches. FitBatch(x ValueOr, y g.Value) error // PredictBatch predicts x as a batch PredictBatch(x g.Value) (prediction g.Value, err error) // ResizeBatch resizes the batch graphs. ResizeBatch(n int) error // Visualize the model by graph name. Visualize(name string) // Graph returns the expression graph for the model. Graphs() map[string]*g.ExprGraph // X is the inputs to the model. X() InputOr // Y is the expected output of the model. Y() *Input // Learnables for the model. Learnables() g.Nodes }
Model is a prediction model.
type Opts ¶
type Opts struct {
// contains filtered or unexported fields
}
Opts are optsion for a model
type PseudoCrossEntropyLoss ¶
type PseudoCrossEntropyLoss struct{}
PseudoCrossEntropyLoss is standard cross entropy loss.
func (*PseudoCrossEntropyLoss) CloneTo ¶
func (c *PseudoCrossEntropyLoss) CloneTo(graph *g.ExprGraph, opts ...CloneOpt) Loss
CloneTo another graph.
func (*PseudoCrossEntropyLoss) Inputs ¶
func (c *PseudoCrossEntropyLoss) Inputs() Inputs
Inputs returns any inputs the loss function utilizes.
type PseudoHuberLoss ¶
type PseudoHuberLoss struct { // Delta determines where the function switches behavior. Delta float32 }
PseudoHuberLoss is a loss that is less sensetive to outliers. Can be thought of as absolute error when large, and quadratic when small. The larger the Delta param the steeper the loss.
!blocked on https://github.com/gorgonia/gorgonia/issues/373
func NewPseudoHuberLoss ¶
func NewPseudoHuberLoss(delta float32) *PseudoHuberLoss
NewPseudoHuberLoss return a new huber loss.
func (*PseudoHuberLoss) CloneTo ¶
func (h *PseudoHuberLoss) CloneTo(graph *g.ExprGraph, opts ...CloneOpt) Loss
CloneTo another graph.
func (*PseudoHuberLoss) Inputs ¶
func (h *PseudoHuberLoss) Inputs() Inputs
Inputs returns any inputs the loss function utilizes.
type Sequential ¶
type Sequential struct { // Chain of layers in the model. Chain *layer.Chain // Tracker of values. Tracker *track.Tracker // contains filtered or unexported fields }
Sequential model.
func NewSequential ¶
func NewSequential(name string) (*Sequential, error)
NewSequential returns a new sequential model.
func (*Sequential) AddLayer ¶
func (s *Sequential) AddLayer(layer layer.Config)
AddLayer adds a layer.
func (*Sequential) AddLayers ¶
func (s *Sequential) AddLayers(layers ...layer.Config)
AddLayers adds a number of layer.
func (*Sequential) CloneLearnablesTo ¶
func (s *Sequential) CloneLearnablesTo(to *Sequential) error
CloneLearnablesTo another model.
func (*Sequential) Compile ¶
func (s *Sequential) Compile(x InputOr, y *Input, opts ...Opt) error
Compile the model.
func (*Sequential) FitBatch ¶
func (s *Sequential) FitBatch(x ValueOr, y g.Value) (err error)
FitBatch fits x to y as a batch.
func (*Sequential) Fwd ¶
func (s *Sequential) Fwd(x *Input)
Fwd tells the model which input should be sent through the layer. If not provided, the first input will be used.
func (*Sequential) Graphs ¶
func (s *Sequential) Graphs() map[string]*g.ExprGraph
Graphs returns the expression graphs for the model.
func (*Sequential) Learnables ¶
func (s *Sequential) Learnables() g.Nodes
Learnables are the model learnables.
func (*Sequential) PredictBatch ¶
PredictBatch predicts x as a batch.
func (*Sequential) ResizeBatch ¶
func (s *Sequential) ResizeBatch(n int) (err error)
ResizeBatch will resize the batch graph. Note: this is expensive as it recompiles the graph.
func (*Sequential) SetLearnables ¶
func (s *Sequential) SetLearnables(desired g.Nodes) error
SetLearnables sets learnables to model
func (*Sequential) Visualize ¶
func (s *Sequential) Visualize(name string)
Visualize the model by graph name.