pub struct BeamSearch { /* private fields */ }Expand description
Implementations§
Source§impl BeamSearch
impl BeamSearch
Sourcepub fn new(beam_size: usize) -> BeamSearch
pub fn new(beam_size: usize) -> BeamSearch
Sourcepub fn with_length_penalty(self, penalty: f32) -> BeamSearch
pub fn with_length_penalty(self, penalty: f32) -> BeamSearch
Set length penalty (>1 favors longer sequences).
Sourcepub fn with_early_stopping(self) -> BeamSearch
pub fn with_early_stopping(self) -> BeamSearch
Enable early stopping when all beams reach EOS.
Sourcepub fn with_eos_token_id(self, eos_token_id: usize) -> BeamSearch
pub fn with_eos_token_id(self, eos_token_id: usize) -> BeamSearch
Set EOS token ID.
Sourcepub fn step(
&self,
log_probs: &Tensor,
current_beams: &[BeamHypothesis],
) -> Vec<BeamHypothesis>
pub fn step( &self, log_probs: &Tensor, current_beams: &[BeamHypothesis], ) -> Vec<BeamHypothesis>
Sourcepub fn init(&self, start_token: usize) -> Vec<BeamHypothesis>
pub fn init(&self, start_token: usize) -> Vec<BeamHypothesis>
Initialize beam search with a start token.
Sourcepub fn all_done(&self, beams: &[BeamHypothesis]) -> bool
pub fn all_done(&self, beams: &[BeamHypothesis]) -> bool
Check if all beams are done.
Sourcepub fn best(&self, beams: &[BeamHypothesis]) -> Option<BeamHypothesis>
pub fn best(&self, beams: &[BeamHypothesis]) -> Option<BeamHypothesis>
Get the best hypothesis.
Sourcepub fn length_penalty(&self) -> f32
pub fn length_penalty(&self) -> f32
Get length_penalty.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BeamSearch
impl RefUnwindSafe for BeamSearch
impl Send for BeamSearch
impl Sync for BeamSearch
impl Unpin for BeamSearch
impl UnsafeUnpin for BeamSearch
impl UnwindSafe for BeamSearch
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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