CountVectorizer<T>
Models & Types · AiDotNet.Preprocessing.TextVectorizers
Converts a collection of text documents to a matrix of token counts.
Inheritance: TextVectorizerBase<T> → CountVectorizer<T>
For Beginners
CountVectorizer turns text into numbers:
- Each unique word becomes a column
- Each document becomes a row
- Values are word counts
Example: [“I like cats”, “I like dogs”] becomes: | I | like | cats | dogs | Doc 1: | 1 | 1 | 1 | 0 | Doc 2: | 1 | 1 | 0 | 1 |
How It Works
CountVectorizer tokenizes text documents and builds a vocabulary, then encodes each document as a count vector (bag of words representation).
Features include:
- Customizable tokenization
- N-gram support (unigrams, bigrams, etc.)
- Minimum and maximum document frequency thresholds
- Maximum vocabulary size
Constructors
| Constructor | Summary |
|---|---|
CountVectorizer(int minDf, double maxDf, int? maxFeatures, ValueTuple<int, int>? nGramRange, bool lowercase, bool binary, Func<string, IEnumerable<string>> tokenizer, HashSet<string> stopWords, ITokenizer advancedTokenizer) |
Creates a new instance of CountVectorizer. |
Methods
| Method | Summary |
|---|---|
Matrix<T> Transform(IEnumerable<string> documents) |
Transforms documents to count vectors. |
void Fit(IEnumerable<string> documents) |
Fits the vectorizer to the corpus. |