Skip to main content

SerializableModel

Struct SerializableModel 

Source
pub struct SerializableModel {
Show 16 fields pub feature_weights: Vec<f64>, pub labels: Vec<String>, pub pos_info: Vec<String>, pub metadata: ModelMetadata, pub connection_matrix: BTreeMap<usize, BTreeMap<usize, f64>>, pub max_left_id: usize, pub max_right_id: usize, pub feature_sets: Vec<FeatureSetInfo>, pub unk_category_names: Vec<String>, pub unk_categories: BTreeMap<String, String>, pub char_def_content: String, pub feature_def_content: String, pub rewrite_def_content: String, pub cost_factor: i32, pub left_id_map: Vec<(u32, String)>, pub right_id_map: Vec<(u32, String)>,
}
Expand description

Trained model with weights and configuration.

Fields§

§feature_weights: Vec<f64>

Feature weights from CRF training

§labels: Vec<String>

Label information

§pos_info: Vec<String>

Part-of-speech information for each label

§metadata: ModelMetadata

Model metadata

§connection_matrix: BTreeMap<usize, BTreeMap<usize, f64>>

Connection cost matrix: (right_id, left_id) -> cost.

Ordered maps rather than hashed ones, at both levels. rkyv archives a HashMap as a SwissTable whose slot assignment resolves collisions in source iteration order, and HashMap iteration order is seeded per instance – so serializing the same trained model twice produced files of identical length with scattered byte differences (#974). A BTreeMap serializes from its key-ordered iterator into a tree whose shape depends only on the entry count, which makes model.dat byte-reproducible. No stored value changes: both levels are only ever filled key-by-key from Vec-ordered sources.

§max_left_id: usize

Maximum left connection ID

§max_right_id: usize

Maximum right connection ID

§feature_sets: Vec<FeatureSetInfo>

Feature set information (left_id, right_id, weight) for each label

§unk_category_names: Vec<String>

Unknown word category names (from char.def)

§unk_categories: BTreeMap<String, String>

Unknown word category features (from unk.def).

Ordered for the same reason as SerializableModel::connection_matrix: rkyv’s archived HashMap layout follows source iteration order (#974).

§char_def_content: String

Raw content of the character definition file (char.def)

§feature_def_content: String

Raw content of the feature definition file (feature.def)

§rewrite_def_content: String

Raw content of the rewrite rule definition file (rewrite.def)

§cost_factor: i32

Cost factor for weight-to-cost conversion (MeCab default: 700)

§left_id_map: Vec<(u32, String)>

Left context ID to feature string mapping (for left-id.def)

§right_id_map: Vec<(u32, String)>

Right context ID to feature string mapping (for right-id.def)

Implementations§

Source§

impl SerializableModel

Source

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

Write lexicon file with proper cost calculation

Source

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

Write dense connection cost matrix (MeCab-compatible)

Source

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

Update metadata.json with trained model values.

The emitted model_info section deliberately carries no timestamp, so exporting the same model twice produces byte-identical output (#981); serde_json’s map is ordered, so key order is stable too.

§引数
  • base_metadata_path - Path of the base metadata.json to update.
  • writer - Write sink for the updated JSON.
Source

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

Write unknown word definitions

Source

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

Writes the character definition file (char.def) content preserved from training.

Source

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

Writes the feature definition file (feature.def) content preserved from training.

Source

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

Writes the rewrite rule definition file (rewrite.def) content preserved from training.

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.

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.

Trait Implementations§

Source§

impl Archive for SerializableModel

Source§

const COPY_OPTIMIZATION: CopyOptimization<Self>

An optimization flag that allows the bytes of this type to be copied directly to a writer instead of calling serialize. Read more
Source§

type Archived = ArchivedSerializableModel

The archived representation of this type. Read more
Source§

type Resolver = SerializableModelResolver

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Source§

fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)

Creates the archived version of this value at the given position and writes it to the given output. Read more
Source§

impl<'de> Deserialize<'de> for SerializableModel

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<__D: Fallible + ?Sized> Deserialize<SerializableModel, __D> for Archived<SerializableModel>

Source§

fn deserialize( &self, deserializer: &mut __D, ) -> Result<SerializableModel, <__D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl Serialize for SerializableModel

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<__S: Fallible + ?Sized> Serialize<__S> for SerializableModel

Source§

fn serialize( &self, serializer: &mut __S, ) -> Result<<Self as Archive>::Resolver, <__S as Fallible>::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.

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> 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> ArchiveUnsized for T
where T: Archive,

Source§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
Source§

fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata

Creates the archived version of the metadata for this value.
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

Source§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Fallible + Writer + ?Sized,

Source§

fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
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