Skip to content

Embeddings precompilednormalizer fromcharsmap

github-actions[bot] edited this page Aug 22, 2026 · 23 revisions

PrecompiledNormalizer.FromCharsMap

Build one from a model's compiled trie.

public static PrecompiledNormalizer FromCharsMap(byte[] charsMap)

ParameterscharsMap is the precompiled_charsmap blob from a spiece.model or a tokenizer.json normalizer.

ReturnsPrecompiledNormalizer ready to Normalize.

ExceptionsInvalidDataException when the blob is not a usable charsmap: too short to carry its own trie size, or carrying an empty trie.

Example — the refusals, which are what a caller can actually reach without a model file.

using Lodestar.Embeddings.Tokenization;

string tooShort = "";
try { PrecompiledNormalizer.FromCharsMap([]); }
catch (InvalidDataException e) { tooShort = e.Message; }

string emptyTrie = "";
try { PrecompiledNormalizer.FromCharsMap([0, 0, 0, 0]); }
catch (InvalidDataException e) { emptyTrie = e.Message; }

bool bothRefused = tooShort.Length > 0 && emptyTrie.Length > 0;  // => True

Remarks — a charsmap cannot be synthesised, which is why the example above shows what happens when you try. Four zero bytes are a well-formed header declaring a trie of nothing, and that is refused separately from a blob too short to have a header at all — two different ways a file can be wrong, and the messages say which.

Refusing rather than accepting an empty trie matters: a normalizer that silently does nothing would leave text unfolded and the model would see input it was not trained on, with no error anywhere.

Applies to — net10.0, netstandard2.0.

See alsoPrecompiledNormalizer, PrecompiledNormalizer.Normalize.

Lodestar

Project

Clone this wiki locally