pub struct Model { /* private fields */ }Expand description
Trained model.
Implementations§
Source§impl Model
impl Model
Sourcepub fn read_user_lexicon<R: Read>(&mut self, rdr: R) -> Result<()>
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.
Sourcepub fn write_model<W: Write>(&self, writer: &mut W) -> Result<()>
pub fn write_model<W: Write>(&self, writer: &mut W) -> Result<()>
Writes the model to a writer.
Sourcepub fn read_model<R: Read>(reader: R) -> Result<SerializableModel>
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).
Sourcepub 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<()>
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<()>
Writes the dictionary files in Lindera format.
pub fn write_lexicon<W: Write>(&self, writer: &mut W) -> Result<()>
pub fn write_connection_costs<W: Write>(&self, writer: &mut W) -> Result<()>
pub fn write_unknown_dictionary<W: Write>(&self, writer: &mut W) -> Result<()>
Sourcepub fn get_unknown_word_cost(&self, category: usize) -> i32
pub fn get_unknown_word_cost(&self, category: usize) -> i32
Calculate unknown word cost based on trained feature weights using dynamic calculation
Sourcepub fn num_features(&self) -> usize
pub fn num_features(&self) -> usize
Gets the number of features in the model.
Sourcepub fn num_labels(&self) -> usize
pub fn num_labels(&self) -> usize
Gets the number of labels in the model.
Sourcepub fn write_bigram_details<L, R, C>(
&self,
left_wtr: L,
right_wtr: R,
cost_wtr: C,
) -> Result<()>
pub fn write_bigram_details<L, R, C>( &self, left_wtr: L, right_wtr: R, cost_wtr: C, ) -> Result<()>
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 asBOS/EOSand 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.
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.