pub struct StructuredPerceptron {
pub n_labels: usize,
pub n_features: usize,
pub emissions: Vec<f64>,
pub transitions: Vec<f64>,
}Expand description
A linear-chain structured perceptron tagger.
Parameter layout (identical to LinearChainCrf):
emissions[label*n_features + k]— weight for featurekunderlabel.transitions[prev*n_labels + cur]— score of theprev → curbigram.
Fields§
§n_labels: usizeNumber of output labels.
n_features: usizeNumber of (real-valued) emission features per position.
emissions: Vec<f64>Emission weights, length n_labels * n_features.
transitions: Vec<f64>Transition weights, length n_labels * n_labels.
Implementations§
Source§impl StructuredPerceptron
impl StructuredPerceptron
Sourcepub fn zeros(n_labels: usize, n_features: usize) -> SeqResult<Self>
pub fn zeros(n_labels: usize, n_features: usize) -> SeqResult<Self>
Create a zero-initialised perceptron.
§Errors
SeqError::InvalidConfiguration if n_labels == 0 or n_features == 0.
Sourcepub fn param_count(&self) -> usize
pub fn param_count(&self) -> usize
Total number of parameters.
Sourcepub fn decode(&self, x: &[f64]) -> SeqResult<Vec<usize>>
pub fn decode(&self, x: &[f64]) -> SeqResult<Vec<usize>>
Viterbi decode the highest-scoring label sequence for feature matrix
x (T × n_features, row-major).
§Errors
SeqError::EmptyInput— ifxis empty.SeqError::ShapeMismatch— ifx.len()is not a multiple ofn_features.
Sourcepub fn sequence_score(&self, x: &[f64], y: &[usize]) -> SeqResult<f64>
pub fn sequence_score(&self, x: &[f64], y: &[usize]) -> SeqResult<f64>
Total linear score of a full label sequence y under x.
§Errors
SeqError::EmptyInput— ifyis empty.SeqError::ShapeMismatch— ifx.len() ≠ y.len() * n_features.SeqError::IndexOutOfBounds— if any label≥ n_labels.
Sourcepub fn update(
&mut self,
x: &[f64],
gold: &[usize],
pred: &[usize],
) -> SeqResult<usize>
pub fn update( &mut self, x: &[f64], gold: &[usize], pred: &[usize], ) -> SeqResult<usize>
Apply the perceptron correction θ ← θ + φ(gold) − φ(pred) in place,
returning the number of positions where gold and pred differ.
Both label sequences must have length T = x.len() / n_features.
§Errors
SeqError::LengthMismatch— ifgold.len() ≠ pred.len().SeqError::ShapeMismatch— if shapes are inconsistent.SeqError::IndexOutOfBounds— if any label is out of range.
Trait Implementations§
Source§impl Clone for StructuredPerceptron
impl Clone for StructuredPerceptron
Source§fn clone(&self) -> StructuredPerceptron
fn clone(&self) -> StructuredPerceptron
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 StructuredPerceptron
impl RefUnwindSafe for StructuredPerceptron
impl Send for StructuredPerceptron
impl Sync for StructuredPerceptron
impl Unpin for StructuredPerceptron
impl UnsafeUnpin for StructuredPerceptron
impl UnwindSafe for StructuredPerceptron
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