Skip to main content

IbmModel1

Struct IbmModel1 

Source
pub struct IbmModel1 {
    pub t_fe: Array2<f64>,
    pub t_0e: Array1<f64>,
}
Expand description

IBM Model 1.

Fields§

§t_fe: Array2<f64>

Translation probability from source word f to target word e. t_fe[(f, e)] = Pr(e|f) Shape: (|source_vocab|, |target_vocab|)

§t_0e: Array1<f64>

Translation probability from null word to target word e. t_e0[e] = Pr(e|NULL) Shape: (|target_vocab|,)

Implementations§

Source§

impl IbmModel1

Source

pub fn train(corpus: &Corpus, iteration: u32) -> Self

Trains IBM Model 1.

Trait Implementations§

Source§

impl Debug for IbmModel1

Source§

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

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

impl Model for IbmModel1

Source§

fn make_viterbi_alignment(&self, pair: &SentencePair) -> Alignment

Generates Viterbi alignment for given sentence pair.
Source§

impl Save for IbmModel1

Source§

fn save(&self, writer: &mut impl Write) -> Result<()>

§File format
  • f_size: u32
  • e_size: u32
  • t_fe: [f64; f_size * e_size]
  • t_0e: [f64; e_size]

All values are of little endian. t_fe and t_0e are stored in row-major ascending order.

  • t_fe: [(0, 0)], [(0, 1)]..., [(0, el-1)], [(1, 0)], ...
  • t_0e: [0], [1], ...
Source§

fn save_to_path(&self, path: impl AsRef<Path>) -> Result<()>

Saves things into file specified as a path.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.