pub struct SentenceEmbeddingsModel { /* private fields */ }
Expand description
§SentenceEmbeddingsModel to perform sentence embeddings
It is made of the following blocks:
transformer
: Base transformer modelpooling
: Pooling layerdense
(optional): Linear (feed forward) layernormalization
(optional): Embeddings normalization
Implementations§
Source§impl SentenceEmbeddingsModel
impl SentenceEmbeddingsModel
Sourcepub fn new(config: SentenceEmbeddingsConfig) -> Result<Self, RustBertError>
pub fn new(config: SentenceEmbeddingsConfig) -> Result<Self, RustBertError>
Build a new SentenceEmbeddingsModel
§Arguments
config
-SentenceEmbeddingsConfig
object containing the resource references (model, vocabulary, configuration) and device placement (CPU/GPU)
Sourcepub fn new_with_tokenizer(
config: SentenceEmbeddingsConfig,
tokenizer: TokenizerOption,
) -> Result<Self, RustBertError>
pub fn new_with_tokenizer( config: SentenceEmbeddingsConfig, tokenizer: TokenizerOption, ) -> Result<Self, RustBertError>
Build a new ONNXCausalGenerator
from a GenerateConfig
and TokenizerOption
.
A tokenizer must be provided by the user and can be customized to use non-default settings.
§Arguments
config
-SentenceEmbeddingsConfig
object containing the resource references (model, vocabulary, configuration) and device placement (CPU/GPU)tokenizer
-TokenizerOption
tokenizer to use for question answering.
Sourcepub fn get_tokenizer(&self) -> &TokenizerOption
pub fn get_tokenizer(&self) -> &TokenizerOption
Get a reference to the model tokenizer.
Sourcepub fn get_tokenizer_mut(&mut self) -> &mut TokenizerOption
pub fn get_tokenizer_mut(&mut self) -> &mut TokenizerOption
Get a mutable reference to the model tokenizer.
Sourcepub fn set_tokenizer_truncation(
&mut self,
truncation_strategy: TruncationStrategy,
)
pub fn set_tokenizer_truncation( &mut self, truncation_strategy: TruncationStrategy, )
Sets the tokenizer’s truncation strategy
Sourcepub fn get_embedding_dim(&self) -> Result<i64, RustBertError>
pub fn get_embedding_dim(&self) -> Result<i64, RustBertError>
Return the embedding output dimension
Sourcepub fn tokenize<S>(&self, inputs: &[S]) -> SentenceEmbeddingsTokenizerOutput
pub fn tokenize<S>(&self, inputs: &[S]) -> SentenceEmbeddingsTokenizerOutput
Tokenizes the inputs
Sourcepub fn encode_as_tensor<S>(
&self,
inputs: &[S],
) -> Result<SentenceEmbeddingsModelOutput, RustBertError>
pub fn encode_as_tensor<S>( &self, inputs: &[S], ) -> Result<SentenceEmbeddingsModelOutput, RustBertError>
Computes sentence embeddings, outputs Tensor
.
Sourcepub fn encode<S>(&self, inputs: &[S]) -> Result<Vec<Embedding>, RustBertError>
pub fn encode<S>(&self, inputs: &[S]) -> Result<Vec<Embedding>, RustBertError>
Computes sentence embeddings.
Sourcepub fn encode_with_attention<S>(
&self,
inputs: &[S],
) -> Result<(Vec<Embedding>, Vec<AttentionOutput>), RustBertError>
pub fn encode_with_attention<S>( &self, inputs: &[S], ) -> Result<(Vec<Embedding>, Vec<AttentionOutput>), RustBertError>
Computes sentence embeddings, also outputs AttentionOutput
s.
Auto Trait Implementations§
impl !Freeze for SentenceEmbeddingsModel
impl RefUnwindSafe for SentenceEmbeddingsModel
impl Send for SentenceEmbeddingsModel
impl !Sync for SentenceEmbeddingsModel
impl Unpin for SentenceEmbeddingsModel
impl UnwindSafe for SentenceEmbeddingsModel
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> 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 more