Skip to main content

AlignChain

Struct AlignChain 

Source
pub struct AlignChain { /* private fields */ }
Expand description

A reference to align: the phones in order, and what each one costs to give up.

Phones are columns of the acoustic matrix, not labels. Which label a column sits on matters only to to_fst, because only an FST has labels; align never forms one.

Implementations§

Source§

impl AlignChain

Source

pub const HOLD_BLANK: u8 = 0

The transition that stays put and says nothing: silence, or a phone that has not started.

Source

pub const HOLD_PHONE: u8 = 1

The transition that stays put sounding the phone it is on.

Source

pub const COMMIT: u8 = 2

The transition that moves to the next phone and sounds it.

Source

pub const SKIP: u8 = 3

The transition that moves to the next phone without sounding it.

Source

pub fn new(phones: impl Into<Vec<u32>>) -> Self

A reference every phone of which has to be given frames.

Skipping is forbidden until a caller asks for it, because a skip cost is a claim about the phone; see with_skip_costs. Column 0 is the blank, which is where a CTC model puts it; with_blank moves it.

Source

pub fn with_skip_costs(self, costs: &[f32]) -> Result<Self, OpenFstError>

The cost of giving up each position, one per phone.

An infinite cost forbids the skip, and new leaves one everywhere. A finite cost is a threshold: the phone is dropped only when keeping it costs strictly more, so the number that matters is how much acoustic evidence the phone is worth.

Skip costs belong to individual phones rather than to the utterance as a whole, so callers can make only the appropriate positions optional.

§Errors

A count that is not the number of phones, or a cost below zero or not a number. A negative cost would pay the alignment to throw the reference away.

Source

pub fn with_uniform_skip_cost(self, cost: f32) -> Result<Self, OpenFstError>

The same cost for every position.

§Errors

A cost below zero or not a number, as with_skip_costs.

Source

pub fn with_blank(self, column: u32) -> Self

The column meaning “no phone is sounding”. Column 0 by default.

Source

pub fn num_phones(&self) -> usize

The number of phones in the reference.

Source

pub fn is_empty(&self) -> bool

Whether the reference is empty, in which case every frame is blank.

Source

pub fn phones(&self) -> &[u32]

The columns the reference sounds, in order.

Source

pub fn skip_costs(&self) -> &[f32]

The cost of giving up each position, in order.

Source

pub fn blank(&self) -> u32

The column that means silence.

Source

pub fn against<'a, A>( &'a self, dense: &'a DenseFst<'a, A>, ) -> Result<ChainTrellis<'a, A>, OpenFstError>
where A: Arc, A::Weight: FromScore,

The chain against a matrix of scores, ready to be solved.

align is this plus best_path plus reading the answer back into phones. Call it directly to get at the Path, whose codes are the four below and whose positions are reference positions, or to run posteriors with an accumulator of your own.

§Errors

A phone, or the blank, naming a column the acoustic model does not have. Checked once here so that solving never has to.

Source

pub const fn sounds(code: u8) -> bool

Whether a transition sounds the phone of the position it lands in.

The four codes are listed best-first, which is the tie-break; see ChainTrellis::steps_into.

§Panics

On a code this chain has no transition for.

Source

pub fn to_fst<A: Arc>( &self, label_offset: i64, ) -> Result<VectorFst<A>, OpenFstError>
where A::Weight: FromScore,

The chain as an ordinary FST, so it can go through the decoders in this crate or be composed like anything else.

label_offset has to be the one the DenseFst was built with. It is 1 by default, because label 0 is epsilon to every FST algorithm and a blank is not one. Input labels are the columns, offset.

Output labels name what the frame sounded: p + 1 for position p, and N + 1 for a frame that sounded nothing. Every arc carries one, so a decoded path’s output labels are one per frame and are the alignment itself, which Alignment::from_output_labels reads back. That is what makes lattice_decode and n_best over this FST produce alternative alignments, which the exact aligner, returning one answer, does not.

align is what to use to align. This exists to put the chain in front of the rest of the library, and it is also the oracle the exact aligner is tested against, since the two share no code.

§Errors

A label that does not fit the arc’s label type, or an offset below 1, which would put a column on epsilon and so on an arc consuming no frame.

Trait Implementations§

Source§

impl Clone for AlignChain

Source§

fn clone(&self) -> AlignChain

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AlignChain

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for AlignChain

Source§

fn eq(&self, other: &AlignChain) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AlignChain

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.