pub struct RankHead { /* private fields */ }Expand description
The classification head a reranker checkpoint carries on top of the encoder.
Implementations§
Source§impl RankHead
impl RankHead
Sourcepub fn n_cls_out(&self) -> usize
pub fn n_cls_out(&self) -> usize
How many floats Self::apply returns.
Sourcepub fn labels(&self) -> &[String]
pub fn labels(&self) -> &[String]
{arch}.classifier.output_labels, in output order. Empty for a
single-output head that named none.
Sourcepub fn apply(&self, pooled: &[f32]) -> Vec<f32>
pub fn apply(&self, pooled: &[f32]) -> Vec<f32>
Every output of the head, for pooled — which must already be
the CLS row, not the whole hidden-state matrix.
Sourcepub fn score(&self, pooled: &[f32]) -> f32
pub fn score(&self, pooled: &[f32]) -> f32
The single relevance score /v1/rerank reports: output 0, which
is what upstream’s send_rerank sends (res->score = embd[0]).
Sourcepub fn has_pooler(&self) -> bool
pub fn has_pooler(&self) -> bool
Whether cls — HuggingFace’s bert.pooler.dense — is in this
checkpoint, and therefore in every score this head produces.
The one bit that decides which of the two score scales in the module docs a caller is reading. Everything else that reports the regime is derived from it, so nothing can disagree with the weights that are actually loaded.
Sourcepub fn graph(&self) -> String
pub fn graph(&self) -> String
The composition Self::apply runs, as a formula over the CLS
row: classifier(tanh(pooler(cls))) for a head with its pooler,
classifier(cls) for one without.
Built from the same three Options Self::apply branches on,
in the same order, rather than restated as a table of the four
shapes — two structures that must agree about one thing is this
repo’s dominant bug shape, and a description that has drifted
from the graph is worse than none. The test
the_graph_names_a_tanh_exactly_when_a_tanh_is_applied closes
the loop by checking the label against the arithmetic.
Auto Trait Implementations§
impl Freeze for RankHead
impl RefUnwindSafe for RankHead
impl Send for RankHead
impl Sync for RankHead
impl Unpin for RankHead
impl UnsafeUnpin for RankHead
impl UnwindSafe for RankHead
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