pub struct FeatureExtractor { /* private fields */ }Expand description
Feature extractor for logical expressions
Automatically converts TLExpr into numerical feature vectors suitable for kernel computation.
§Example
use tensorlogic_sklears_kernels::{FeatureExtractor, FeatureExtractionConfig};
use tensorlogic_ir::TLExpr;
let config = FeatureExtractionConfig::new()
.with_max_depth(3)
.with_encode_structure(true);
let extractor = FeatureExtractor::new(config);
let expr = TLExpr::and(
TLExpr::pred("tall", vec![]),
TLExpr::pred("smart", vec![]),
);
let features = extractor.extract(&expr).unwrap();
println!("Feature vector: {:?}", features);Implementations§
Source§impl FeatureExtractor
impl FeatureExtractor
Sourcepub fn new(config: FeatureExtractionConfig) -> Self
pub fn new(config: FeatureExtractionConfig) -> Self
Create a new feature extractor
Sourcepub fn extract(&self, expr: &TLExpr) -> Result<Vec<f64>>
pub fn extract(&self, expr: &TLExpr) -> Result<Vec<f64>>
Extract features from a logical expression
Sourcepub fn extract_batch(&self, exprs: &[TLExpr]) -> Result<Vec<Vec<f64>>>
pub fn extract_batch(&self, exprs: &[TLExpr]) -> Result<Vec<Vec<f64>>>
Extract features from multiple expressions
Sourcepub fn build_vocabulary(&mut self, exprs: &[TLExpr])
pub fn build_vocabulary(&mut self, exprs: &[TLExpr])
Build vocabulary from a set of expressions
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Get vocabulary size
Sourcepub fn vocabulary(&self) -> &HashMap<String, usize>
pub fn vocabulary(&self) -> &HashMap<String, usize>
Get vocabulary
Trait Implementations§
Source§impl Clone for FeatureExtractor
impl Clone for FeatureExtractor
Source§fn clone(&self) -> FeatureExtractor
fn clone(&self) -> FeatureExtractor
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FeatureExtractor
impl RefUnwindSafe for FeatureExtractor
impl Send for FeatureExtractor
impl Sync for FeatureExtractor
impl Unpin for FeatureExtractor
impl UnwindSafe for FeatureExtractor
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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