Skip to content

Embeddings 0.4.0 sentencepiecemodelloader load

github-actions[bot] edited this page Aug 21, 2026 · 1 revision

Lodestar.Embeddings 0.4.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

SentencePieceModelLoader.Load

Reads a spiece.model into a SentencePiece vocabulary.

public static SentencePieceVocabulary Load(Stream source, ArtifactLoadOptions options = null)
public static SentencePieceVocabulary Load(string path, ArtifactLoadOptions options = null)

Parameterssource is a readable stream, never disposed here; path is the file to read. options bounds what will be accepted and defaults to ArtifactLoadOptions's own defaults.

ReturnsSentencePieceVocabulary, carrying the pieces, their scores, their types and the model's special-token ids.

ExceptionsArgumentNullException for a null source or path. InvalidDataException when the content is not the format expected, declares a model this loader does not read, or exceeds a bound in options — the message names both the limit and the value.

Example — everything this tokenizer needs is in the one file.

using Lodestar.Embeddings.Persistence;
using Lodestar.Embeddings.Tokenization;

SentencePieceVocabulary vocab = SentencePieceModelLoader.Load("spiece.model");

RemarksNo settings parameters, because the file has them all. That is the difference from VocabTxtLoader.Load, and it is why this is the safer of the two routes where a model offers both: there is nothing left to get wrong.

The piece types are read rather than inferred. Control markers are marked as such in the protobuf, so the tokenizer does not have to guess from an id range — a guess that breaks on any model that lays its specials out differently.

The normalizer comes from the file too, as a compiled character map, and is never assumed to be identity. All four of the common families ship nmt_nfkc, and applying the model's own map is what makes the segmentation match Python's on the same string.

Applies to — net10.0, netstandard2.0.

See alsoSentencePieceModelLoader, SentencePieceModelLoader.LoadAsync, the persistence index.

Lodestar

Project

Clone this wiki locally