NMFVectorizer<T>

Models & Types · AiDotNet.Preprocessing.TextVectorizers

Converts text documents to topic vectors using Non-negative Matrix Factorization (NMF).

Inheritance: TextVectorizerBase<T> → NMFVectorizer<T>

For Beginners

NMF is like LSA but with only positive values:

  • Topics are “built from” words (additive combinations)
  • Results are often more interpretable than LSA
  • Works well for topic modeling when you want to “see” what makes up each topic
  • Each document is a combination of topics with positive weights

How It Works

NMF factorizes the term-document matrix V into two non-negative matrices W and H such that V ≈ W × H.

  • W: document-topic matrix (n_docs × n_topics)
  • H: topic-term matrix (n_topics × n_terms)

Unlike LSA which can have negative values, NMF produces purely additive, parts-based representations that are often more interpretable. Topics are combinations of words with positive weights.

Constructors

Constructor Summary
NMFVectorizer(int nComponents, int maxIterations, double tolerance, NMFInitialization init, int minDf, double maxDf, int? maxFeatures, ValueTuple<int, int>? nGramRange, bool lowercase, int? randomState, Func<string, IEnumerable<string>> tokenizer, HashSet<string> stopWords, ITokenizer advancedTokenizer) Creates a new instance of NMFVectorizer.

Properties

Property Summary
bool IsFitted { get; }
double[] Components { get; } Gets the topic-term matrix (H) from NMF.
int FeatureCount { get; }
int NComponents { get; } Gets the number of components (topics).

Methods

Method Summary
Matrix<T> Transform(IEnumerable<string> documents) Transforms documents to NMF topic vectors.
string[][] GetTopWordsPerTopic(int nWords) Gets the top words for each topic.
void Fit(IEnumerable<string> documents) Fits the NMF model to the corpus using multiplicative update rules.