pub struct MultilingualEmbeddingAligner {
pub config: MeaAlignerConfig,
pub language_spaces: HashMap<LangId, LanguageSpace>,
pub alignment_matrices: HashMap<(LangId, LangId), AlignmentMatrix>,
pub alignment_history: VecDeque<AlignmentRecord>,
/* private fields */
}Expand description
Multilingual embedding aligner: maps embeddings from different language spaces to a shared cross-lingual embedding space.
Fields§
§config: MeaAlignerConfig§language_spaces: HashMap<LangId, LanguageSpace>§alignment_matrices: HashMap<(LangId, LangId), AlignmentMatrix>§alignment_history: VecDeque<AlignmentRecord>Implementations§
Source§impl MultilingualEmbeddingAligner
impl MultilingualEmbeddingAligner
Sourcepub fn new(config: MeaAlignerConfig) -> Self
pub fn new(config: MeaAlignerConfig) -> Self
Create a new aligner with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create an aligner with default config.
Sourcepub fn add_language(&mut self, id: LangId, name: String, dim: usize)
pub fn add_language(&mut self, id: LangId, name: String, dim: usize)
Register a new language space.
Sourcepub fn remove_language(&mut self, id: LangId)
pub fn remove_language(&mut self, id: LangId)
Remove a language space and all alignment matrices involving it.
Sourcepub fn add_embedding(
&mut self,
lang_id: LangId,
emb_id: u64,
vector: Vec<f64>,
) -> Result<(), MeaError>
pub fn add_embedding( &mut self, lang_id: LangId, emb_id: u64, vector: Vec<f64>, ) -> Result<(), MeaError>
Add an embedding to a language space.
Sourcepub fn remove_embedding(
&mut self,
lang_id: LangId,
emb_id: u64,
) -> Result<(), MeaError>
pub fn remove_embedding( &mut self, lang_id: LangId, emb_id: u64, ) -> Result<(), MeaError>
Remove an embedding from a language space.
Sourcepub fn compute_alignment(
&mut self,
src: LangId,
tgt: LangId,
anchors: &[(u64, u64)],
) -> Result<(), MeaError>
pub fn compute_alignment( &mut self, src: LangId, tgt: LangId, anchors: &[(u64, u64)], ) -> Result<(), MeaError>
Compute and store an alignment matrix from src → tgt.
anchors is a list of (src_emb_id, tgt_emb_id) pairs that are
known to be translation equivalents.
Sourcepub fn align_embedding(
&self,
src: LangId,
tgt: LangId,
vector: &[f64],
) -> Result<Vec<f64>, MeaError>
pub fn align_embedding( &self, src: LangId, tgt: LangId, vector: &[f64], ) -> Result<Vec<f64>, MeaError>
Apply the stored alignment matrix to transform vector from src space to tgt space.
Sourcepub fn cross_lingual_search(
&self,
query_lang: LangId,
query: &[f64],
target_lang: LangId,
top_k: usize,
) -> Result<Vec<(u64, f64)>, MeaError>
pub fn cross_lingual_search( &self, query_lang: LangId, query: &[f64], target_lang: LangId, top_k: usize, ) -> Result<Vec<(u64, f64)>, MeaError>
Search in target_lang’s embedding space using a query from query_lang.
Returns top-k (emb_id, cosine_score) pairs, sorted by descending score.
Sourcepub fn alignment_quality(&self, src: LangId, tgt: LangId) -> Option<f64>
pub fn alignment_quality(&self, src: LangId, tgt: LangId) -> Option<f64>
Return the stored alignment quality for a (src, tgt) pair.
Sourcepub fn compute_centroid(
&mut self,
lang_id: LangId,
) -> Result<Vec<f64>, MeaError>
pub fn compute_centroid( &mut self, lang_id: LangId, ) -> Result<Vec<f64>, MeaError>
Compute and cache the centroid of a language space.
Sourcepub fn aligner_stats(&self) -> MeaAlignerStats
pub fn aligner_stats(&self) -> MeaAlignerStats
Aggregate statistics about the aligner state.
Sourcepub fn embedding_count(&self, lang_id: LangId) -> Option<usize>
pub fn embedding_count(&self, lang_id: LangId) -> Option<usize>
Number of embeddings in a language space.
Sourcepub fn get_alignment_matrix(
&self,
src: LangId,
tgt: LangId,
) -> Option<&AlignmentMatrix>
pub fn get_alignment_matrix( &self, src: LangId, tgt: LangId, ) -> Option<&AlignmentMatrix>
Retrieve a stored alignment matrix (immutable borrow).
Sourcepub fn language_ids(&self) -> Vec<LangId> ⓘ
pub fn language_ids(&self) -> Vec<LangId> ⓘ
List all registered language IDs.
Sourcepub fn has_alignment(&self, src: LangId, tgt: LangId) -> bool
pub fn has_alignment(&self, src: LangId, tgt: LangId) -> bool
Check whether an alignment exists for the given pair.
Sourcepub fn centroid(&self, lang_id: LangId) -> Option<&Vec<f64>>
pub fn centroid(&self, lang_id: LangId) -> Option<&Vec<f64>>
Retrieve the centroid of a language space without recomputing.
Sourcepub fn history(&self, limit: usize) -> Vec<&AlignmentRecord>
pub fn history(&self, limit: usize) -> Vec<&AlignmentRecord>
Recent alignment history entries (newest first).
Auto Trait Implementations§
impl Freeze for MultilingualEmbeddingAligner
impl RefUnwindSafe for MultilingualEmbeddingAligner
impl Send for MultilingualEmbeddingAligner
impl Sync for MultilingualEmbeddingAligner
impl Unpin for MultilingualEmbeddingAligner
impl UnsafeUnpin for MultilingualEmbeddingAligner
impl UnwindSafe for MultilingualEmbeddingAligner
Blanket Implementations§
impl<T> Allocation for T
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
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>
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>
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
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.