pub struct AdaptiveLogSoftmaxWithLoss { /* private fields */ }Expand description
Two-level output layer: a head linear scores the most frequent classes plus
one logit per tail cluster, while each tail cluster owns a projection and
output linear that rescore its classes conditioned on the head cluster
probability. Matches the nn.AdaptiveLogSoftmaxWithLoss contract: cutoffs
partition 0..n_classes into a head range 0..cutoffs[0] and one tail
cluster per cutoff, with tail i projecting in_features down to
round(in_features / div_value^(i+1)) before its output linear.
Implementations§
Source§impl AdaptiveLogSoftmaxWithLoss
impl AdaptiveLogSoftmaxWithLoss
Sourcepub fn new(
in_features: usize,
n_classes: usize,
cutoffs: &[usize],
) -> Result<Self>
pub fn new( in_features: usize, n_classes: usize, cutoffs: &[usize], ) -> Result<Self>
Construct on the current runtime with the thread-local seed source.
§Errors
Returns an error when the contract or initialization fails.
Sourcepub fn new_with_seed(
in_features: usize,
n_classes: usize,
cutoffs: &[usize],
seed: u64,
) -> Result<Self>
pub fn new_with_seed( in_features: usize, n_classes: usize, cutoffs: &[usize], seed: u64, ) -> Result<Self>
Construct on the current runtime with an explicit seed.
Uses div_value 4.0 and a bias-free head, matching the torch defaults.
§Errors
Returns an error when the contract or initialization fails.
Sourcepub fn new_with_seed_on(
runtime: &Runtime,
in_features: usize,
n_classes: usize,
cutoffs: &[usize],
div_value: f64,
head_bias: bool,
_tail_bias: bool,
seed: u64,
) -> Result<Self>
pub fn new_with_seed_on( runtime: &Runtime, in_features: usize, n_classes: usize, cutoffs: &[usize], div_value: f64, head_bias: bool, _tail_bias: bool, seed: u64, ) -> Result<Self>
Construct a deterministically initialized adaptive softmax layer.
cutoffs must be a nonempty strictly increasing list below n_classes;
each cutoff opens a tail cluster. div_value sets each tail’s
projection width and head_bias adds a bias to the head linear.
§Errors
Returns an error when the contract or initialization fails.
Sourcepub fn from_parts(
in_features: usize,
n_classes: usize,
cutoffs: &[usize],
head: Rc<Linear>,
tails: Vec<(Rc<Linear>, Rc<Linear>)>,
) -> Result<Self>
pub fn from_parts( in_features: usize, n_classes: usize, cutoffs: &[usize], head: Rc<Linear>, tails: Vec<(Rc<Linear>, Rc<Linear>)>, ) -> Result<Self>
Construct from explicit head and tail linears (deterministic tests and checkpoint assembly).
§Errors
Returns an error when the contract or any linear’s shape is invalid.
Sourcepub fn log_prob(&self, input: &Matrix) -> Result<Matrix>
pub fn log_prob(&self, input: &Matrix) -> Result<Matrix>
Return the assembled [N, V] log-probabilities for a rank-two FP32
input, matching AdaptiveLogSoftmaxWithLoss.log_prob.
§Errors
Returns an error when the input contract or runtime recording fails.
Sourcepub fn forward(
&self,
input: &Matrix,
target: &Matrix,
) -> Result<AdaptiveLogSoftmaxResult>
pub fn forward( &self, input: &Matrix, target: &Matrix, ) -> Result<AdaptiveLogSoftmaxResult>
Compute the assembled log-probabilities and the mean negative
log-likelihood for a rank-two FP32 input [N, I] and a rank-one
target [N] holding class indices as I32, U32, or FP32.
§Errors
Returns an error when the contract or runtime recording fails.
Sourcepub const fn in_features(&self) -> usize
pub const fn in_features(&self) -> usize
Return the input feature count.
Trait Implementations§
Source§impl Module for AdaptiveLogSoftmaxWithLoss
impl Module for AdaptiveLogSoftmaxWithLoss
Source§fn forward(&self, input: &Matrix) -> Result<Matrix>
fn forward(&self, input: &Matrix) -> Result<Matrix>
Source§fn registry(&self) -> &ModuleRegistry
fn registry(&self) -> &ModuleRegistry
Source§fn parameters(&self) -> Vec<Parameter>
fn parameters(&self) -> Vec<Parameter>
Source§fn named_parameters(&self) -> Vec<NamedParameter>
fn named_parameters(&self) -> Vec<NamedParameter>
Source§fn named_buffers(&self) -> Vec<NamedBuffer>
fn named_buffers(&self) -> Vec<NamedBuffer>
Source§fn all_parameters(&self) -> Result<Vec<Parameter>>
fn all_parameters(&self) -> Result<Vec<Parameter>>
Source§fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
Source§fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
Source§fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
u32 scalar state in
deterministic depth-first order. Read more