Word2VecVectorizer<T>

Models & Types · AiDotNet.Preprocessing.TextVectorizers

Converts text documents to dense vectors using Word2Vec-style word embeddings.

Inheritance: TextVectorizerBase<T> → Word2VecVectorizer<T>

For Beginners

Word2Vec captures word meaning in numbers:

  • “king” - “man” + “woman” ≈ “queen” (famous example)
  • Similar words have similar vectors
  • Documents become the average of their word vectors
  • Much smaller dimensions than bag-of-words (typically 100-300)

How It Works

Word2Vec learns dense vector representations of words where semantically similar words have similar vectors. This vectorizer trains word embeddings and represents documents as the average (or weighted average) of their word vectors.

Two architectures are supported:

  • CBOW (Continuous Bag of Words): Predicts target word from context
  • Skip-gram: Predicts context words from target word

Constructors

Constructor Summary
Word2VecVectorizer(int vectorSize, int windowSize, int minCount, int epochs, double learningRate, int negativeSamples, Word2VecArchitecture architecture, Word2VecAggregation aggregation, bool lowercase, int? randomState, Func<string, IEnumerable<string>> tokenizer, HashSet<string> stopWords, ITokenizer advancedTokenizer) Creates a new instance of Word2VecVectorizer.

Properties

Property Summary
Dictionary<string, double[]> WordVectors { get; } Gets the learned word vectors.
bool IsFitted { get; }
int FeatureCount { get; }
int VectorSize { get; } Gets the vector dimensionality.

Methods

Method Summary
List<ValueTuple<string, double>> MostSimilar(string word, int topN) Finds the most similar words to a given word.
Matrix<T> Transform(IEnumerable<string> documents) Transforms documents to dense vectors by aggregating word vectors.
double[] GetWordVector(string word) Gets the vector for a specific word.
void Fit(IEnumerable<string> documents) Trains Word2Vec embeddings on the corpus.