pub struct MultiModalEmbedding {Show 16 fields
pub config: CrossModalConfig,
pub model_id: Uuid,
pub text_embeddings: HashMap<String, Array1<f32>>,
pub kg_embeddings: HashMap<String, Array1<f32>>,
pub unified_embeddings: HashMap<String, Array1<f32>>,
pub text_kg_alignments: HashMap<String, String>,
pub entity_descriptions: HashMap<String, String>,
pub property_texts: HashMap<String, String>,
pub multilingual_mappings: HashMap<String, Vec<String>>,
pub cross_domain_mappings: HashMap<String, String>,
pub text_encoder: TextEncoder,
pub kg_encoder: KGEncoder,
pub alignment_network: AlignmentNetwork,
pub training_stats: TrainingStats,
pub model_stats: ModelStats,
pub is_trained: bool,
}Expand description
Multi-modal embedding model for unified representation learning
Fields§
§config: CrossModalConfig§model_id: Uuid§text_embeddings: HashMap<String, Array1<f32>>Text embeddings cache
kg_embeddings: HashMap<String, Array1<f32>>Knowledge graph embeddings cache
unified_embeddings: HashMap<String, Array1<f32>>Unified cross-modal embeddings
text_kg_alignments: HashMap<String, String>Cross-modal alignment mappings
entity_descriptions: HashMap<String, String>Entity descriptions for alignment
property_texts: HashMap<String, String>Property-text mappings
multilingual_mappings: HashMap<String, Vec<String>>Multi-language mappings
cross_domain_mappings: HashMap<String, String>Cross-domain mappings
text_encoder: TextEncoderTraining components
kg_encoder: KGEncoder§alignment_network: AlignmentNetwork§training_stats: TrainingStatsTraining statistics
model_stats: ModelStats§is_trained: boolImplementations§
Source§impl MultiModalEmbedding
impl MultiModalEmbedding
Sourcepub fn new(config: CrossModalConfig) -> Self
pub fn new(config: CrossModalConfig) -> Self
Create new multi-modal embedding model
Sourcepub fn add_text_kg_alignment(&mut self, text: &str, entity: &str)
pub fn add_text_kg_alignment(&mut self, text: &str, entity: &str)
Add text-KG alignment pair
Sourcepub fn add_entity_description(&mut self, entity: &str, description: &str)
pub fn add_entity_description(&mut self, entity: &str, description: &str)
Add entity description
Sourcepub fn add_property_text(&mut self, property: &str, text_description: &str)
pub fn add_property_text(&mut self, property: &str, text_description: &str)
Add property-text mapping
Sourcepub fn add_multilingual_mapping(
&mut self,
concept: &str,
translations: Vec<String>,
)
pub fn add_multilingual_mapping( &mut self, concept: &str, translations: Vec<String>, )
Add multilingual mapping
Sourcepub fn add_cross_domain_mapping(
&mut self,
source_concept: &str,
target_concept: &str,
)
pub fn add_cross_domain_mapping( &mut self, source_concept: &str, target_concept: &str, )
Add cross-domain mapping
Sourcepub async fn generate_unified_embedding(
&mut self,
text: &str,
entity: &str,
) -> Result<Array1<f32>>
pub async fn generate_unified_embedding( &mut self, text: &str, entity: &str, ) -> Result<Array1<f32>>
Generate unified embedding from text and KG
Sourcepub fn get_or_create_kg_embedding(&self, entity: &str) -> Result<Array1<f32>>
pub fn get_or_create_kg_embedding(&self, entity: &str) -> Result<Array1<f32>>
Get or create KG embedding for entity
Sourcepub fn contrastive_loss(
&self,
positive_pairs: &[(String, String)],
negative_pairs: &[(String, String)],
) -> Result<f32>
pub fn contrastive_loss( &self, positive_pairs: &[(String, String)], negative_pairs: &[(String, String)], ) -> Result<f32>
Perform contrastive learning
Sourcepub async fn zero_shot_prediction(
&self,
text: &str,
candidate_entities: &[String],
) -> Result<Vec<(String, f32)>>
pub async fn zero_shot_prediction( &self, text: &str, candidate_entities: &[String], ) -> Result<Vec<(String, f32)>>
Perform zero-shot learning
Sourcepub async fn cross_domain_transfer(
&mut self,
source_domain: &str,
target_domain: &str,
) -> Result<f32>
pub async fn cross_domain_transfer( &mut self, source_domain: &str, target_domain: &str, ) -> Result<f32>
Cross-domain transfer
Sourcepub async fn multilingual_alignment(
&self,
concept: &str,
) -> Result<Vec<(String, f32)>>
pub async fn multilingual_alignment( &self, concept: &str, ) -> Result<Vec<(String, f32)>>
Multi-language alignment
Sourcepub fn get_multimodal_stats(&self) -> MultiModalStats
pub fn get_multimodal_stats(&self) -> MultiModalStats
Get multi-modal statistics
Sourcepub fn with_few_shot_learning(self, _few_shot_config: FewShotLearning) -> Self
pub fn with_few_shot_learning(self, _few_shot_config: FewShotLearning) -> Self
Add few-shot learning capability
Sourcepub async fn few_shot_learn(
&self,
support_examples: &[(String, String, String)],
query_examples: &[(String, String)],
) -> Result<Vec<(String, f32)>>
pub async fn few_shot_learn( &self, support_examples: &[(String, String, String)], query_examples: &[(String, String)], ) -> Result<Vec<(String, f32)>>
Perform few-shot learning task
Sourcepub fn with_real_time_finetuning(self, _rt_config: RealTimeFinetuning) -> Self
pub fn with_real_time_finetuning(self, _rt_config: RealTimeFinetuning) -> Self
Add real-time fine-tuning capability
Trait Implementations§
Source§impl Clone for MultiModalEmbedding
impl Clone for MultiModalEmbedding
Source§fn clone(&self) -> MultiModalEmbedding
fn clone(&self) -> MultiModalEmbedding
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MultiModalEmbedding
impl Debug for MultiModalEmbedding
Source§impl<'de> Deserialize<'de> for MultiModalEmbedding
impl<'de> Deserialize<'de> for MultiModalEmbedding
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl EmbeddingModel for MultiModalEmbedding
impl EmbeddingModel for MultiModalEmbedding
fn config(&self) -> &ModelConfig
fn model_id(&self) -> &Uuid
fn model_type(&self) -> &'static str
fn add_triple(&mut self, triple: Triple) -> Result<()>
fn train<'life0, 'async_trait>(
&'life0 mut self,
epochs: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<TrainingStats>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_entity_embedding(&self, entity: &str) -> Result<Vector>
fn get_relation_embedding(&self, relation: &str) -> Result<Vector>
fn score_triple( &self, subject: &str, predicate: &str, object: &str, ) -> Result<f64>
fn predict_objects( &self, subject: &str, predicate: &str, k: usize, ) -> Result<Vec<(String, f64)>>
fn predict_subjects( &self, predicate: &str, object: &str, k: usize, ) -> Result<Vec<(String, f64)>>
fn predict_relations( &self, subject: &str, object: &str, k: usize, ) -> Result<Vec<(String, f64)>>
fn get_entities(&self) -> Vec<String>
fn get_relations(&self) -> Vec<String>
fn get_stats(&self) -> ModelStats
fn save(&self, _path: &str) -> Result<()>
fn load(&mut self, _path: &str) -> Result<()>
fn clear(&mut self)
fn is_trained(&self) -> bool
Auto Trait Implementations§
impl Freeze for MultiModalEmbedding
impl RefUnwindSafe for MultiModalEmbedding
impl Send for MultiModalEmbedding
impl Sync for MultiModalEmbedding
impl Unpin for MultiModalEmbedding
impl UnwindSafe for MultiModalEmbedding
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§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,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
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.