Skip to content

Text 0.4.0 tfidfvectorizer save

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.

TfidfVectorizer.Save

Write a fitted vectorizer out, vocabulary and document frequencies together.

public void Save(Stream destination)
public void Save(string path)

Parametersdestination is a writable stream, left open for the caller to dispose; path is a file to create or overwrite.

ExceptionsInvalidOperationException when nothing has been fitted yet. ArgumentNullException for a null stream or path. IOException from the stream or file system.

Example — saving and restoring, with the weights intact.

using Lodestar.Text.Vectorization;

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

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

TfidfVectorizer restored = TfidfVectorizer.Load(buffer);
string first = restored.GetFeatureNames()[0];  // => cat

Remarks — what is written is both halves of the fit: the vocabulary and the document frequencies. That second half is the reason saving matters more here than for CountVectorizer — frequencies are a property of the training corpus, and a corpus that is gone cannot be measured again.

The stream overload leaves destination open, so a vectorizer can be one entry in a larger archive.

Applies to — net10.0, netstandard2.0.

See alsoTfidfVectorizer.Load, TfidfVectorizer.SaveAsync.

Lodestar

Project

Clone this wiki locally