pub struct BertEncoder {
pub hp: BertHparams,
pub tok_embd: WeightMatrix,
pub type_embd: Option<Vec<Vec<f32>>>,
pub pos_embd: WeightMatrix,
pub tok_norm_w: Vec<f32>,
pub tok_norm_b: Vec<f32>,
pub layers: Vec<BertLayer>,
}Fields§
§hp: BertHparams§tok_embd: WeightMatrix§type_embd: Option<Vec<Vec<f32>>>token_types.weight, every row: [n_token_types, n_embd].
Row 0 is “Sentence A” and row 1 “Sentence B”. None when the
checkpoint carries no table at all, which upstream allows
(TENSOR_NOT_REQUIRED) and which means no segment embedding is
added anywhere. Loading only row 0 — what this held before — is
what made a rerank pair score both halves as Sentence A.
pos_embd: WeightMatrix§tok_norm_w: Vec<f32>§tok_norm_b: Vec<f32>§layers: Vec<BertLayer>Implementations§
Source§impl BertEncoder
impl BertEncoder
pub fn vocab_size(&self) -> usize
Trait Implementations§
Source§impl TextEncoder for BertEncoder
impl TextEncoder for BertEncoder
Source§fn wrap_special(&self, pieces: &[u32]) -> Vec<u32>
fn wrap_special(&self, pieces: &[u32]) -> Vec<u32>
[CLS] … [SEP], which is what llama.cpp’s WPM branch adds when
add_special is set: it pushes special_bos_id before the
pieces and special_sep_id after, unconditionally — the
add_bos/add_eos flags are not consulted on that path
(llama-vocab.cpp, case LLAMA_VOCAB_TYPE_WPM).
Source§fn n_segments(&self) -> usize
fn n_segments(&self) -> usize
The height of token_types.weight, or 1 when the checkpoint
carries no table (nothing is added at any position, which is
what a one-row table would do anyway).
Source§fn wrap_special_pair(&self, a: &[u32], b: &[u32]) -> Option<PairSequence>
fn wrap_special_pair(&self, a: &[u32], b: &[u32]) -> Option<PairSequence>
[CLS] a [SEP] b [SEP] with segments 0…0 1…1 — what
HuggingFace’s tokenizer(query, document) builds for a BERT
cross-encoder, which is the input these checkpoints were
trained on.
The boundary is defined once, here, and both vectors are cut on
it: the first [SEP] closes segment 0 (HF counts it as part of
the first half) and everything after it is segment 1. Returning
the ids alone and letting the graph assume a segment is how the
document half came to be scored as “Sentence A”.
Source§fn n_ctx_train(&self) -> usize
fn n_ctx_train(&self) -> usize
Source§fn pooling_type(&self) -> PoolingType
fn pooling_type(&self) -> PoolingType
{arch}.pooling_type said.Source§fn encode(
&self,
tokens: &[u32],
segments: Option<&[u32]>,
) -> Result<Vec<f32>, EncodeError>
fn encode( &self, tokens: &[u32], segments: Option<&[u32]>, ) -> Result<Vec<f32>, EncodeError>
n_tokens × n_embd hidden states, in row order. Read moreSource§fn encode_tokens(&self, tokens: &[u32]) -> Result<Vec<f32>, EncodeError>
fn encode_tokens(&self, tokens: &[u32]) -> Result<Vec<f32>, EncodeError>
Self::encode for a single sequence: every position is
segment 0.Source§fn embed_tokens(&self, tokens: &[u32]) -> Result<Vec<f32>, EncodeError>
fn embed_tokens(&self, tokens: &[u32]) -> Result<Vec<f32>, EncodeError>
Self::encode_tokens followed by the checkpoint’s own pooling.
Not L2-normalized — see crate::pooling::pool.Auto Trait Implementations§
impl Freeze for BertEncoder
impl RefUnwindSafe for BertEncoder
impl Send for BertEncoder
impl Sync for BertEncoder
impl Unpin for BertEncoder
impl UnsafeUnpin for BertEncoder
impl UnwindSafe for BertEncoder
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> 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 more