sklears-feature-extraction 0.2.0

Feature extraction from raw data (text, images)
Documentation
//! Word embedding implementations
//!
//! This module provides comprehensive implementations of word and document embedding algorithms
//! including Word2Vec, GloVe, Doc2Vec, sentence embeddings, and contextualized embeddings.
#![allow(dead_code)] // embedding struct fields retained as public configuration API for future training

use scirs2_core::ndarray::Array2;
use std::collections::HashMap;

// Word2Vec embeddings placeholder
#[derive(Debug, Clone)]
pub struct Word2Vec {
    vector_size: usize,
    window: usize,
    min_count: usize,
    workers: usize,
    sg: u8, // 0 for CBOW, 1 for skip-gram
    vocabulary: HashMap<String, usize>,
    embeddings: Option<Array2<f64>>,
}

impl Word2Vec {
    pub fn new() -> Self {
        Self {
            vector_size: 100,
            window: 5,
            min_count: 1,
            workers: 1,
            sg: 0,
            vocabulary: HashMap::new(),
            embeddings: None,
        }
    }

    pub fn vector_size(mut self, vector_size: usize) -> Self {
        self.vector_size = vector_size;
        self
    }

    pub fn window(mut self, window: usize) -> Self {
        self.window = window;
        self
    }

    pub fn sg(mut self, sg: u8) -> Self {
        self.sg = sg;
        self
    }
}

impl Default for Word2Vec {
    fn default() -> Self {
        Self::new()
    }
}

// GloVe embeddings placeholder
#[derive(Debug, Clone)]
pub struct GloVe {
    vector_size: usize,
    learning_rate: f64,
    max_iter: usize,
    vocabulary: HashMap<String, usize>,
    embeddings: Option<Array2<f64>>,
}

impl GloVe {
    pub fn new() -> Self {
        Self {
            vector_size: 100,
            learning_rate: 0.05,
            max_iter: 100,
            vocabulary: HashMap::new(),
            embeddings: None,
        }
    }

    pub fn vector_size(mut self, vector_size: usize) -> Self {
        self.vector_size = vector_size;
        self
    }

    pub fn learning_rate(mut self, learning_rate: f64) -> Self {
        self.learning_rate = learning_rate;
        self
    }
}

impl Default for GloVe {
    fn default() -> Self {
        Self::new()
    }
}

// Sentence embeddings placeholder
#[derive(Debug, Clone)]
pub struct SentenceEmbeddings {
    aggregation_method: AggregationMethod,
    vector_size: usize,
}

#[derive(Debug, Clone)]
pub enum AggregationMethod {
    /// Mean
    Mean,
    /// Max
    Max,
    /// TfIdfWeighted
    TfIdfWeighted,
}

impl SentenceEmbeddings {
    pub fn new() -> Self {
        Self {
            aggregation_method: AggregationMethod::Mean,
            vector_size: 100,
        }
    }

    pub fn aggregation_method(mut self, method: AggregationMethod) -> Self {
        self.aggregation_method = method;
        self
    }
}

impl Default for SentenceEmbeddings {
    fn default() -> Self {
        Self::new()
    }
}

// Doc2Vec placeholder
#[derive(Debug, Clone)]
pub struct Doc2Vec {
    vector_size: usize,
    learning_rate: f64,
    min_count: usize,
    epochs: usize,
}

impl Doc2Vec {
    pub fn new() -> Self {
        Self {
            vector_size: 100,
            learning_rate: 0.025,
            min_count: 1,
            epochs: 20,
        }
    }

    pub fn vector_size(mut self, vector_size: usize) -> Self {
        self.vector_size = vector_size;
        self
    }

    pub fn epochs(mut self, epochs: usize) -> Self {
        self.epochs = epochs;
        self
    }
}

impl Default for Doc2Vec {
    fn default() -> Self {
        Self::new()
    }
}