layers
sorix.nn.layers ¶
Linear ¶
Bases: Module
Applies a linear transformation to the incoming data.
Attributes:
Examples:
Source code in sorix/nn/layers.py
ReLU ¶
LeakyReLU ¶
Bases: Module
Leaky Rectified Linear Unit activation function.
Attributes:
-
negative_slope(float) –Controls the angle of a negative slope. Default: 0.01
Source code in sorix/nn/layers.py
Sigmoid ¶
Tanh ¶
BatchNorm1d ¶
Bases: Module
Applies Batch Normalization over a 2D input.
Source code in sorix/nn/layers.py
Dropout ¶
Bases: Module
During training, randomly zeroes some of the elements of the input tensor with probability p using samples from a Bernoulli distribution.
This implementation uses Inverted Dropout, meaning that the output is scaled by 1/(1-p) during training. This ensures that the expected value of the activations remains constant, allowing the layer to act as an identity function during inference.
Parameters:
-
p(float, default:0.5) –Probability of an element to be zeroed. Default: 0.5
Source code in sorix/nn/layers.py
Embedding ¶
Bases: Module
A learnable lookup table that stores embeddings of a fixed dictionary and size.
This module is typically used to store word or categorical embeddings and
retrieve them using integer indices. Maps each index to a dense vector of
size embedding_dim.
Parameters:
-
num_embeddings(int) –Size of the dictionary of embeddings (vocabulary size).
-
embedding_dim(int) –The size of each embedding vector.
-
device(str, default:'cpu') –'cpu'or'cuda'. Default:'cpu'.
Attributes:
-
W(Tensor) –The embedding weight matrix of shape
(num_embeddings, embedding_dim).
Examples:
emb = nn.Embedding(num_embeddings=100, embedding_dim=16)
# Token IDs: batch of 2 sequences of length 5
indices = tensor(np.array([[1, 5, 3, 0, 7],
[2, 4, 1, 6, 8]])) # shape (2, 5)
out = emb(indices) # shape (2, 5, 16)