Skip to main content

ParserModel

Struct ParserModel 

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

The model of the parser, in memory.

It holds the weights of the classifier, and with them what makes the feature strings they are for: the schema of the dictionary and the feature set. It is what training gives. To keep it, put it into a model file with ModelBuilder.

It is a Classifier itself, and scores a decision as the parser part of a model file written without quantization does, to the last bit.

Implementations§

Source§

impl ParserModel

Source

pub fn new( schema: Schema, feature_set: FeatureSet, bias: f64, features: Vec<(String, f32)>, pairs: PairWeights, ) -> Result<Self>

Makes a model.

§Arguments
  • schema - The schema of the dictionary the model is for.
  • feature_set - The groups of features the weights are for.
  • bias - The bias.
  • features - The feature strings with their weights, sorted by the bytes of the strings, each once. The number of a feature is its index.
  • pairs - The weights of the pairs.
§Returns

The model, or Error::Parser for a weight that is not finite, feature strings that are not sorted, pairs that are not sorted with the smaller number first or that name a feature that is not there, or a hashed table that has not 2^bits weights with 1 to 30 bits.

Source

pub fn with_unit(self, unit: f64) -> Result<Self>

Gives the weights a unit: what their sum is multiplied by before the bias is added. The bias is not in the unit.

The unit of a model is 1, and training gives such a model. A unit is for weights that come as whole numbers of a step: a model converted from CaboCha keeps the whole numbers CaboCha adds up, so that a score has the sign CaboCha gives it, and has CaboCha’s step as its unit.

§Arguments
  • unit - The unit, greater than 0.
§Returns

The model, or Error::Parser for a unit that is not a finite number greater than 0.

Source

pub fn compact(self) -> Self

The model without what has no weight: the pairs of an exact table whose weight is 0, and the features whose weight is 0 and that are in no pair that is kept. With a hashed table, a feature whose weight is 0 is taken out: training gives a feature the weight 0 only when no decision with it moved the weights.

§Returns

The smaller model.

Source

pub fn schema(&self) -> &Schema

The schema of the dictionary the model is for.

§Returns

The schema.

Source

pub fn feature_set(&self) -> &FeatureSet

The groups of features the weights are for.

§Returns

The feature set.

Source

pub fn bias(&self) -> f64

The bias.

§Returns

The bias.

Source

pub fn unit(&self) -> f64

The unit of the weights: what their sum is multiplied by before the bias is added. See ParserModel::with_unit.

§Returns

The unit; 1 unless one was given.

Source

pub fn feature_count(&self) -> usize

The number of features of the model.

§Returns

The number of feature strings.

Source

pub fn pairs(&self) -> &PairWeights

The weights of the pairs.

§Returns

The weights.

Source

pub fn pair_count(&self) -> usize

The number of weights of pairs that are not 0.

§Returns

The number of weights: of pairs for an exact table, of places for a hashed one.

Trait Implementations§

Source§

impl Classifier for ParserModel

Source§

fn id(&self, feature: &str) -> Option<u32>

The number of a feature. Read more
Source§

fn score(&self, features: &[u32]) -> f64

The score of a decision. Read more
Source§

impl Clone for ParserModel

Source§

fn clone(&self) -> Self

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 ParserModel

Source§

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

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

impl PartialEq for ParserModel

Source§

fn eq(&self, other: &Self) -> 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 ParserModel

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> 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.