Documentation
¶
Index ¶
- func Load(o any, r io.Reader) error
- func NormalInit(t *Tensor, mean, std float32)
- func Save(o any, w io.Writer) error
- func SetInferenceMode(enabled bool)
- type Adam
- type EmbeddingLayer
- type Layer
- type LinearLayer
- type Model
- type Optimizer
- type SGD
- type Sequential
- type Tensor
- func Abs(x *Tensor) *Tensor
- func Add(x0 *Tensor, x ...*Tensor) *Tensor
- func BCEWithLogits(target, prediction, weights *Tensor) *Tensor
- func BMM(x, y *Tensor, transpose1, transpose2 bool, jobs int) *Tensor
- func Broadcast(x *Tensor, shape ...int) *Tensor
- func Cos(x *Tensor) *Tensor
- func Div(x0, x1 *Tensor) *Tensor
- func Embedding(w, x *Tensor) *Tensor
- func Exp(x *Tensor) *Tensor
- func Flatten(x *Tensor) *Tensor
- func LinSpace(start, end float32, shape ...int) *Tensor
- func Log(x *Tensor) *Tensor
- func MatMul(x, y *Tensor, transpose1, transpose2 bool, jobs int) *Tensor
- func Mean(x *Tensor) *Tensor
- func MeanSquareError(x, y *Tensor) *Tensor
- func Mul(x0, x1 *Tensor) *Tensor
- func Neg(x *Tensor) *Tensor
- func NewScalar(data float32) *Tensor
- func NewTensor(data []float32, shape ...int) *Tensor
- func Normal(mean, std float32, shape ...int) *Tensor
- func Ones(shape ...int) *Tensor
- func Pow(x *Tensor, n *Tensor) *Tensor
- func Rand(shape ...int) *Tensor
- func ReLu(x *Tensor) *Tensor
- func Reshape(x *Tensor, shape ...int) *Tensor
- func Sigmoid(x *Tensor) *Tensor
- func Sin(x *Tensor) *Tensor
- func Softmax(x *Tensor, axis int) *Tensor
- func SoftmaxCrossEntropy(x, y *Tensor) *Tensor
- func Square(x *Tensor) *Tensor
- func Sub(x0, x1 *Tensor) *Tensor
- func Sum(x *Tensor, along ...int) *Tensor
- func Uniform(low, high float32, shape ...int) *Tensor
- func Zeros(shape ...int) *Tensor
- func (t *Tensor) Backward()
- func (t *Tensor) Data() []float32
- func (t *Tensor) Get(indices ...int) float32
- func (t *Tensor) Grad() *Tensor
- func (t *Tensor) IsScalar() bool
- func (t *Tensor) NoGrad() *Tensor
- func (t *Tensor) Shape() []int
- func (t *Tensor) Slice(start, end int) *Tensor
- func (t *Tensor) SliceIndices(indices ...int) *Tensor
- func (t *Tensor) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalInit ¶
func SetInferenceMode ¶
func SetInferenceMode(enabled bool)
SetInferenceMode enables or disables inference mode, which disables gradient computation to improve performance during model evaluation.
Types ¶
type Adam ¶
type Adam struct {
// contains filtered or unexported fields
}
func (*Adam) SetWeightDecay ¶
func (o *Adam) SetWeightDecay(wd float32)
type EmbeddingLayer ¶
type EmbeddingLayer struct {
W *Tensor
}
func (*EmbeddingLayer) Forward ¶
func (e *EmbeddingLayer) Forward(x *Tensor) *Tensor
func (*EmbeddingLayer) Parameters ¶
func (e *EmbeddingLayer) Parameters() []*Tensor
func (*EmbeddingLayer) SetJobs ¶
func (e *EmbeddingLayer) SetJobs(int)
type Layer ¶
func NewEmbedding ¶
func NewFlatten ¶
func NewFlatten() Layer
func NewSigmoid ¶
func NewSigmoid() Layer
type LinearLayer ¶
func (*LinearLayer) Forward ¶
func (l *LinearLayer) Forward(x *Tensor) *Tensor
func (*LinearLayer) Parameters ¶
func (l *LinearLayer) Parameters() []*Tensor
func (*LinearLayer) SetJobs ¶
func (l *LinearLayer) SetJobs(jobs int)
type SGD ¶
type SGD struct {
// contains filtered or unexported fields
}
func (*SGD) SetWeightDecay ¶
func (o *SGD) SetWeightDecay(wd float32)
type Sequential ¶
type Sequential struct {
Layers []Layer
}
func (*Sequential) Forward ¶
func (s *Sequential) Forward(x *Tensor) *Tensor
func (*Sequential) Parameters ¶
func (s *Sequential) Parameters() []*Tensor
func (*Sequential) SetJobs ¶
func (s *Sequential) SetJobs(jobs int)
type Tensor ¶
type Tensor struct {
// contains filtered or unexported fields
}
func Add ¶
Add returns the element-wise sum of two tensors. The shape of the second tensor must be a suffix sequence of the shape of the first tensor.
func BCEWithLogits ¶
BCEWithLogits calculates the binary cross-entropy loss between target and prediction with logits. This implementation is numerically stable. It is equivalent to the formula:
max(prediction, 0) - prediction*y + log(1 + exp(-|prediction|))
where y = (target + 1) / 2, target is -1 or 1.
func Div ¶
Div returns the element-wise division of two tensors. The shape of the second tensor must be a suffix sequence of the shape of the first tensor.
func MeanSquareError ¶
func Mul ¶
Mul returns the element-wise product of two tensors. The shape of the second tensor must be a suffix sequence of the shape of the first tensor.
func Pow ¶
Pow returns the element-wise power of a tensor. The shape of the second tensor must be a suffix sequence of the shape of the first tensor.
func SoftmaxCrossEntropy ¶
func Sub ¶
Sub returns the element-wise difference of two tensors. The shape of the second tensor must be a suffix sequence of the shape of the first tensor.