Skip to main content

Model

Struct Model 

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

Trained model.

Implementations§

Source§

impl Model

Source

pub fn read_user_lexicon<R: Read>(&mut self, rdr: R) -> Result<()>

Reads the user-defined lexicon file.

If you want to assign parameters to the user-defined lexicon file, you need to call this function before exporting the dictionary. The model overwrites the parameter only when it is 0,0,0. Otherwise, the parameter is used as is.

§Arguments
  • rdr - Read sink of the user-defined lexicon file.
Source

pub fn write_model<W: Write>(&self, writer: &mut W) -> Result<()>

Writes the model to a writer.

Source

pub fn read_model<R: Read>(reader: R) -> Result<SerializableModel>

Reads a trained model from a reader.

Accepts the current rkyv binary format and, for backward compatibility, the legacy JSON format.

§Arguments
  • reader - Reader containing the serialized model data
§Returns

The deserialized model.

§Errors

Returns an error naming the format that failed. A model written by a build with a different SerializableModel layout is reported as such, with the instruction to re-train – it used to fall through to the legacy JSON reader and surface as an unrelated UTF-8 error (#974).

Source

pub fn write_dictionary<W1, W2, W3, W4>( &self, lexicon_wtr: &mut W1, connector_wtr: &mut W2, unk_handler_wtr: &mut W3, user_lexicon_wtr: &mut W4, ) -> Result<()>
where W1: Write, W2: Write, W3: Write, W4: Write,

Writes the dictionary files in Lindera format.

Source

pub fn write_lexicon<W: Write>(&self, writer: &mut W) -> Result<()>

Source

pub fn write_connection_costs<W: Write>(&self, writer: &mut W) -> Result<()>

Source

pub fn write_unknown_dictionary<W: Write>(&self, writer: &mut W) -> Result<()>

Source

pub fn get_unknown_word_cost(&self, category: usize) -> i32

Calculate unknown word cost based on trained feature weights using dynamic calculation

Source

pub fn num_features(&self) -> usize

Gets the number of features in the model.

Source

pub fn num_labels(&self) -> usize

Gets the number of labels in the model.

Source

pub fn raw_model(&self) -> &RawModel

Gets the raw CRF model for advanced operations.

Source

pub fn write_bigram_details<L, R, C>( &self, left_wtr: L, right_wtr: R, cost_wtr: C, ) -> Result<()>
where L: Write, R: Write, C: Write,

Writes the bigram details in three separate files.

This method outputs:

  • Left features: per left connection id, the quoted right-side (%R) feature strings it groups, * for absent slots
  • Right features: per right connection id, the quoted left-side (%L) feature strings it groups
  • Costs: one {left}/{right}\t{cost} line per raw bigram feature pair, where id 0 renders as BOS / EOS and names come from the feature extractor

All three files are byte-reproducible for the same model: the loops run over vectors or key-sorted map entries, never over raw map iteration order (#981).

§引数
  • left_wtr - Write sink for the left-feature file.
  • right_wtr - Write sink for the right-feature file.
  • cost_wtr - Write sink for the feature-pair cost file.
§戻り値

Ok(()) on success.

Source

pub fn evaluate(&self, _test_lattices: &[Lattice]) -> f64

Evaluates the model on test data. Returns a simple evaluation score based on feature weights.

Source

pub fn write_dictionary_buffers( &self, lexicon: &mut Vec<u8>, connector: &mut Vec<u8>, unk_handler: &mut Vec<u8>, user_lexicon: &mut Vec<u8>, ) -> Result<()>

Write dictionary components to separate buffers using optimized serialization

Source§

impl Model

Source

pub fn write_left_id_def<W: Write>(&self, writer: &mut W) -> Result<()>

Writes left-id.def: maps left context IDs to their feature strings.

Format: id feature_string (one per line), with BOS/EOS at id=0.

Source

pub fn write_right_id_def<W: Write>(&self, writer: &mut W) -> Result<()>

Writes right-id.def: maps right context IDs to their feature strings.

Format: id feature_string (one per line), with BOS/EOS at id=0.

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

§

impl UnwindSafe for Model

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> SendAlias for T

Source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,

Source§

impl<T> SyncAlias for T

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V