pub struct DiverseBeam {
pub cfg: DiverseBeamConfig,
}Expand description
Diverse beam search decoder.
Fields§
§cfg: DiverseBeamConfigImplementations§
Source§impl DiverseBeam
impl DiverseBeam
Sourcepub fn new(cfg: DiverseBeamConfig) -> SeqResult<Self>
pub fn new(cfg: DiverseBeamConfig) -> SeqResult<Self>
Validate configuration and create a new DiverseBeam.
Sourcepub fn search<F>(&self, score_fn: F) -> SeqResult<Vec<Vec<usize>>>
pub fn search<F>(&self, score_fn: F) -> SeqResult<Vec<Vec<usize>>>
Run diverse beam search.
Groups decode sequentially at each time step. Group g receives a Hamming diversity penalty based on the tokens that groups 0..g-1 committed to at the current step.
Returns beam_width sequences (all groups concatenated), each a
vector of token IDs.
Sourcepub fn hamming_penalty(
token: usize,
prev_group_tokens: &[usize],
strength: f32,
) -> f32
pub fn hamming_penalty( token: usize, prev_group_tokens: &[usize], strength: f32, ) -> f32
Hamming diversity penalty for token.
Counts how many elements of prev_group_tokens equal token, then
multiplies by strength. This penalises tokens already chosen by
earlier groups at the current decoding step.
Trait Implementations§
Source§impl Clone for DiverseBeam
impl Clone for DiverseBeam
Source§fn clone(&self) -> DiverseBeam
fn clone(&self) -> DiverseBeam
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for DiverseBeam
impl RefUnwindSafe for DiverseBeam
impl Send for DiverseBeam
impl Sync for DiverseBeam
impl Unpin for DiverseBeam
impl UnsafeUnpin for DiverseBeam
impl UnwindSafe for DiverseBeam
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