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
impl ParserModel
Sourcepub fn new(
schema: Schema,
feature_set: FeatureSet,
bias: f64,
features: Vec<(String, f32)>,
pairs: PairWeights,
) -> Result<Self>
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.
Sourcepub fn with_unit(self, unit: f64) -> Result<Self>
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.
Sourcepub fn compact(self) -> Self
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.
Sourcepub fn feature_set(&self) -> &FeatureSet
pub fn feature_set(&self) -> &FeatureSet
Sourcepub fn unit(&self) -> f64
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.
Sourcepub fn feature_count(&self) -> usize
pub fn feature_count(&self) -> usize
Sourcepub fn pairs(&self) -> &PairWeights
pub fn pairs(&self) -> &PairWeights
Sourcepub fn pair_count(&self) -> usize
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.