pub struct FineTuner { /* private fields */ }Expand description
Embedding fine-tuner using contrastive learning losses.
Implementations§
Source§impl FineTuner
impl FineTuner
Sourcepub fn new(config: FinetuneConfig) -> Self
pub fn new(config: FinetuneConfig) -> Self
Create a fine-tuner with the given configuration.
Sourcepub fn compute_triplet_loss(
&self,
anchor: &[f32],
positive: &[f32],
negative: &[f32],
) -> f32
pub fn compute_triplet_loss( &self, anchor: &[f32], positive: &[f32], negative: &[f32], ) -> f32
Compute triplet margin loss.
loss = max(0, d(a,p) - d(a,n) + margin)
Sourcepub fn compute_contrastive_loss(&self, a: &[f32], b: &[f32], label: f32) -> f32
pub fn compute_contrastive_loss(&self, a: &[f32], b: &[f32], label: f32) -> f32
Compute contrastive loss for a pair.
label = 1.0(similar): loss = d²label = 0.0(dissimilar): loss = max(0, margin − d)²
Sourcepub fn compute_cosine_loss(&self, a: &[f32], b: &[f32], target: f32) -> f32
pub fn compute_cosine_loss(&self, a: &[f32], b: &[f32], target: f32) -> f32
Compute cosine similarity loss: MSE between cosine_sim(a,b) and target.
Sourcepub fn step(&mut self, pairs: &[EmbeddingPair]) -> f32
pub fn step(&mut self, pairs: &[EmbeddingPair]) -> f32
Simulate one gradient step over the given pairs and return the mean loss.
Sourcepub fn train(&mut self, pairs: &[EmbeddingPair]) -> Vec<f32>
pub fn train(&mut self, pairs: &[EmbeddingPair]) -> Vec<f32>
Run full training for config.epochs epochs and return the mean loss per epoch.
Sourcepub fn training_history(&self) -> &[TrainingStep]
pub fn training_history(&self) -> &[TrainingStep]
Access the full training history.
Sourcepub fn total_steps(&self) -> usize
pub fn total_steps(&self) -> usize
Total number of gradient steps recorded.
Auto Trait Implementations§
impl Freeze for FineTuner
impl RefUnwindSafe for FineTuner
impl Send for FineTuner
impl Sync for FineTuner
impl Unpin for FineTuner
impl UnsafeUnpin for FineTuner
impl UnwindSafe for FineTuner
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.