pub struct NodeClassifier { /* private fields */ }Expand description
A small MLP that maps NodeFeatures to a content-probability.
Implementations§
Source§impl NodeClassifier
impl NodeClassifier
Sourcepub fn new(device: &Device, lr: f64) -> Result<Self>
pub fn new(device: &Device, lr: f64) -> Result<Self>
Create a new, randomly-initialized classifier.
Sourcepub fn score_batch(&self, features: &[NodeFeatures]) -> Result<Vec<f32>>
pub fn score_batch(&self, features: &[NodeFeatures]) -> Result<Vec<f32>>
Content probability in [0, 1] for each candidate.
Sourcepub fn select_best(&self, features: &[NodeFeatures]) -> Result<Option<usize>>
pub fn select_best(&self, features: &[NodeFeatures]) -> Result<Option<usize>>
Index of the candidate most likely to be the content root.
Sourcepub fn train_batch(
&mut self,
features: &[NodeFeatures],
labels: &[f32],
) -> Result<f32>
pub fn train_batch( &mut self, features: &[NodeFeatures], labels: &[f32], ) -> Result<f32>
One supervised gradient step over a batch of (features, label) pairs,
where label is 1.0 for the content node and 0.0 otherwise. Returns the
binary cross-entropy loss.
Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Number of trainable parameters (for logging / metadata).
Sourcepub fn save(&self, path: &Path) -> Result<()>
pub fn save(&self, path: &Path) -> Result<()>
Serialize the classifier weights to a .safetensors file.
Sourcepub fn load(path: &Path, device: &Device, lr: f64) -> Result<Self>
pub fn load(path: &Path, device: &Device, lr: f64) -> Result<Self>
Load a classifier previously written with Self::save.
The architecture is fixed (so new recreates the same variables) and the
stored tensors are copied into them; lr only affects subsequent
training and is irrelevant for inference.
Auto Trait Implementations§
impl !RefUnwindSafe for NodeClassifier
impl !UnwindSafe for NodeClassifier
impl Freeze for NodeClassifier
impl Send for NodeClassifier
impl Sync for NodeClassifier
impl Unpin for NodeClassifier
impl UnsafeUnpin for NodeClassifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more