TensorInitializers

scalation.modeling.autograd.TensorInitializers

The TensorInitializers utility object for tensor initializations commonly used in neural networks. Provides methods to create tensors filled with zeros, ones, random values, and standardized initialization schemes like He and Xavier initialization. All returned tensors have batch-first shape: (batch, rows, cols).

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def fromMatrices(mats: IndexedSeq[MatrixD]): TensorD

Stack a sequence of matrices into a TensorD with batch dimension. Each matrix becomes one slice: resulting shape = (batch, rows, cols).

Stack a sequence of matrices into a TensorD with batch dimension. Each matrix becomes one slice: resulting shape = (batch, rows, cols).

Attributes

Convert a MatrixD to a TensorD with shape (1, rows, cols).

Convert a MatrixD to a TensorD with shape (1, rows, cols).

Attributes

def heInit(batch: Int = ..., rows: Int, cols: Int): TensorD

He initialization (Kaiming initialization). Standard deviation: sqrt(2 / fanIn), where fanIn = number of input features.

He initialization (Kaiming initialization). Standard deviation: sqrt(2 / fanIn), where fanIn = number of input features.

Attributes

def lecunUniform(batch: Int = ..., fanOut: Int, fanIn: Int): TensorD

LeCun uniform initialization. Samples from U(± sqrt(3 / fanIn)). Suitable for tanh activations.

LeCun uniform initialization. Samples from U(± sqrt(3 / fanIn)). Suitable for tanh activations.

Value parameters

batch

the number of tensor slices (default 1)

fanIn

the number of input features (cols)

fanOut

the number of output features (rows)

Attributes

Returns

a TensorD initialized using LeCun uniform initialization

def ones(batch: Int = ..., rows: Int, cols: Int): TensorD

Create a tensor of ones with shape (batch, rows, cols).

Create a tensor of ones with shape (batch, rows, cols).

Attributes

def rand(batch: Int = ..., rows: Int, cols: Int): TensorD

Create a tensor with random values from a uniform distribution N(0, 1).

Create a tensor with random values from a uniform distribution N(0, 1).

Attributes

def randn(batch: Int = ..., rows: Int, cols: Int, stdDev: Double = ...): TensorD

Create a tensor with random values from a normal distribution N(0, stdDev^2).

Create a tensor with random values from a normal distribution N(0, stdDev^2).

Attributes

def rnnUniform(batch: Int = ..., hiddenSize: Int, rows: Int, cols: Int): TensorD

PyTorch-style RNN parameter initialization. Samples from U(± 1/sqrt(hiddenSize)) for all recurrent parameters.

PyTorch-style RNN parameter initialization. Samples from U(± 1/sqrt(hiddenSize)) for all recurrent parameters.

Value parameters

batch

the number of tensor slices (default 1)

cols

the number of columns per slice

hiddenSize

size of the hidden state used to compute bound

rows

the number of rows per slice

Attributes

Returns

a TensorD initialized using RNN uniform initialization

def uniform(batch: Int = ..., rows: Int, cols: Int, bound: Double): TensorD

Uniform initializer: samples values from U(-bound, bound).

Uniform initializer: samples values from U(-bound, bound).

Value parameters

batch

number of tensor slices

bound

half-width of uniform interval

cols

number of columns per slice

rows

number of rows per slice

Attributes

Returns

a TensorD with uniform random values in [-bound, bound]

def xavierInit(batch: Int = ..., rows: Int, cols: Int): TensorD

Xavier initialization (Glorot initialization). Standard deviation: sqrt(2 / (fanIn + fanOut)).

Xavier initialization (Glorot initialization). Standard deviation: sqrt(2 / (fanIn + fanOut)).

Attributes

def xavierUniform(batch: Int = ..., fanOut: Int, fanIn: Int): TensorD

Xavier/Glorot uniform initialization. Samples from U(± sqrt(6 / (fanIn + fanOut))).

Xavier/Glorot uniform initialization. Samples from U(± sqrt(6 / (fanIn + fanOut))).

Value parameters

batch

the number of tensor slices (default 1)

fanIn

the number of input features (cols)

fanOut

the number of output features (rows)

Attributes

Returns

a TensorD initialized using Xavier uniform initialization

def zeros(batch: Int = ..., rows: Int, cols: Int): TensorD

Create a tensor of zeros with shape (batch, rows, cols).

Create a tensor of zeros with shape (batch, rows, cols).

Attributes