pub struct BertModelWrapper { /* private fields */ }Expand description
BERT model wrapper for embeddings
Implementations§
Source§impl BertModelWrapper
impl BertModelWrapper
Sourcepub fn from_varbuilder(
vb: VarBuilder<'_>,
config: &ModelDefinition,
device: CandleDevice,
dtype: DType,
) -> Result<Self>
pub fn from_varbuilder( vb: VarBuilder<'_>, config: &ModelDefinition, device: CandleDevice, dtype: DType, ) -> Result<Self>
Create from VarBuilder and config
Sourcepub fn from_config_json(
vb: VarBuilder<'_>,
config_path: &Path,
device: CandleDevice,
dtype: DType,
) -> Result<Self>
pub fn from_config_json( vb: VarBuilder<'_>, config_path: &Path, device: CandleDevice, dtype: DType, ) -> Result<Self>
Load from config.json path
Sourcepub fn forward(
&self,
input_ids: &Tensor,
token_type_ids: &Tensor,
) -> Result<Tensor>
pub fn forward( &self, input_ids: &Tensor, token_type_ids: &Tensor, ) -> Result<Tensor>
Forward pass to get embeddings Returns the pooled output (CLS token representation) for sentence embeddings
Sourcepub fn get_sentence_embedding(
&self,
input_ids: &Tensor,
token_type_ids: &Tensor,
attention_mask: Option<&Tensor>,
) -> Result<Tensor>
pub fn get_sentence_embedding( &self, input_ids: &Tensor, token_type_ids: &Tensor, attention_mask: Option<&Tensor>, ) -> Result<Tensor>
Get sentence embedding (mean pooling over sequence)
Sourcepub fn get_cls_embedding(
&self,
input_ids: &Tensor,
token_type_ids: &Tensor,
) -> Result<Tensor>
pub fn get_cls_embedding( &self, input_ids: &Tensor, token_type_ids: &Tensor, ) -> Result<Tensor>
Get CLS token embedding
Sourcepub fn config(&self) -> &BertConfig
pub fn config(&self) -> &BertConfig
Get config reference
Sourcepub fn device(&self) -> &CandleDevice
pub fn device(&self) -> &CandleDevice
Get device
Get hidden size
Auto Trait Implementations§
impl !Freeze for BertModelWrapper
impl !RefUnwindSafe for BertModelWrapper
impl Send for BertModelWrapper
impl Sync for BertModelWrapper
impl Unpin for BertModelWrapper
impl UnsafeUnpin for BertModelWrapper
impl !UnwindSafe for BertModelWrapper
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