Skip to content

Text 0.4.0 countvectorizer load

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

Lodestar.Text 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.

CountVectorizer.Load

Read a fitted vectorizer back.

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

Parameterssource is a readable stream, left open; path is a file to read. options bounds what will be accepted — sizes, counts and depths — and defaults to ArtifactLoadOptions's own defaults.

ReturnsCountVectorizer, fitted and ready to Transform.

ExceptionsArgumentNullException for a null source. InvalidDataException when the content is not a saved vectorizer, or when it exceeds a bound in options.

Example — restoring, and counting with the vocabulary that was saved.

using Lodestar.Text.Vectorization;

var original = new CountVectorizer();
original.Fit(["the cat eats", "the dog eats"]);

using var buffer = new MemoryStream();
original.Save(buffer);
buffer.Position = 0;

CountVectorizer restored = CountVectorizer.Load(buffer);
IReadOnlyList<string> names = restored.GetFeatureNames();

string first = names[0];  // => cat

Remarksoptions is the reason this is not a one-line deserialization. A saved vectorizer is a file, a file can come from anywhere, and a vocabulary declaring a hundred million entries would otherwise be allocated before anything noticed. The bounds are refused rather than truncated, so a file that exceeds one is an error rather than a quietly smaller model.

The vocabulary comes back in the order it was saved, so a matrix produced after loading has the same column meanings as one produced before.

Applies to — net10.0, netstandard2.0.

See alsoCountVectorizer.Save, CountVectorizer.LoadAsync, ArtifactLoadOptions.

Lodestar

Project

Clone this wiki locally