pub struct KnowledgeDistillation { /* private fields */ }Expand description
Knowledge Distillation (Hinton et al., 2015).
Transfers knowledge from a large teacher model to a smaller student model by training the student to match the teacher’s soft predictions.
§Variants
- Standard: Match soft logits with temperature scaling
- Feature: Match intermediate layer representations
- Attention: Match attention patterns
- Self: Use deeper layers to teach shallower layers
§Reference
- Hinton, G., et al. (2015). Distilling the Knowledge in a Neural Network.
Implementations§
Source§impl KnowledgeDistillation
impl KnowledgeDistillation
Sourcepub fn new(temperature: f32, alpha: f32) -> Self
pub fn new(temperature: f32, alpha: f32) -> Self
Create knowledge distillation with temperature and mixing weight.
§Arguments
temperature- Softmax temperature (higher = softer targets)alpha- Weight of distillation loss vs task loss (0-1)
Sourcepub fn distillation_loss(
&self,
student_logits: &[f32],
teacher_logits: &[f32],
) -> f32
pub fn distillation_loss( &self, student_logits: &[f32], teacher_logits: &[f32], ) -> f32
Compute soft cross-entropy loss between teacher and student logits.
Sourcepub fn combined_loss(
&self,
student_logits: &[f32],
teacher_logits: &[f32],
task_loss: f32,
) -> f32
pub fn combined_loss( &self, student_logits: &[f32], teacher_logits: &[f32], task_loss: f32, ) -> f32
Compute combined loss: alpha * distill_loss + (1-alpha) * task_loss.
pub fn temperature(&self) -> f32
pub fn alpha(&self) -> f32
Trait Implementations§
Source§impl Clone for KnowledgeDistillation
impl Clone for KnowledgeDistillation
Source§fn clone(&self) -> KnowledgeDistillation
fn clone(&self) -> KnowledgeDistillation
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for KnowledgeDistillation
impl RefUnwindSafe for KnowledgeDistillation
impl Send for KnowledgeDistillation
impl Sync for KnowledgeDistillation
impl Unpin for KnowledgeDistillation
impl UnwindSafe for KnowledgeDistillation
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)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