pub struct RDrop { /* private fields */ }Expand description
R-Drop regularization (Liang et al., 2021).
Forces consistency between two forward passes with different dropout masks. Adds bidirectional KL divergence loss between the two outputs.
Loss = CE(p1, y) + CE(p2, y) + α * (KL(p1||p2) + KL(p2||p1)) / 2
§Reference
Liang, X., et al. (2021). R-Drop: Regularized Dropout for Neural Networks.
Implementations§
Source§impl RDrop
impl RDrop
pub fn alpha(&self) -> f32
Sourcepub fn kl_divergence(&self, p: &[f32], q: &[f32]) -> f32
pub fn kl_divergence(&self, p: &[f32], q: &[f32]) -> f32
Compute KL divergence: KL(p || q) = Σ p * log(p / q)
Sourcepub fn symmetric_kl(&self, p: &[f32], q: &[f32]) -> f32
pub fn symmetric_kl(&self, p: &[f32], q: &[f32]) -> f32
Compute bidirectional KL divergence (symmetric).
Sourcepub fn compute_loss(&self, logits1: &[f32], logits2: &[f32]) -> f32
pub fn compute_loss(&self, logits1: &[f32], logits2: &[f32]) -> f32
Compute R-Drop regularization loss between two forward passes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RDrop
impl RefUnwindSafe for RDrop
impl Send for RDrop
impl Sync for RDrop
impl Unpin for RDrop
impl UnwindSafe for RDrop
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