Skip to content

Text hashingvectorizer load

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

HashingVectorizer.Load

Read the options back.

public static HashingVectorizer Load(Stream source, ArtifactLoadOptions options = null)
public static HashingVectorizer 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.

ReturnsHashingVectorizer, ready to Transform immediately.

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

Example — restored, and hashing identically to the original.

using Lodestar.Text.Vectorization;

var original = new HashingVectorizer(new HashingVectorizerOptions { NumFeatures = 16 });

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

HashingVectorizer restored = HashingVectorizer.Load(buffer);
CsrMatrix before = original.Transform(["the cat eats"]);
CsrMatrix after = restored.Transform(["the cat eats"]);

bool sameShape = before.NonZeroCount == after.NonZeroCount;  // => True
bool sameLength = before.RowL2Norm(0) == after.RowL2Norm(0);  // => True

Remarks — a restored vectorizer produces the same columns as the original, because hashing depends only on the term and the settings. That is the property that makes this type useful across machines: shipping the options is enough, where the other two must ship a vocabulary.

Applies to — net10.0, netstandard2.0.

See alsoHashingVectorizer.Save, ArtifactLoadOptions.

Lodestar

Project

Clone this wiki locally