LSAVectorizer<T>
Models & Types · AiDotNet.Preprocessing.TextVectorizers
Converts text documents to latent semantic vectors using Latent Semantic Analysis (LSA/LSI).
Inheritance: TextVectorizerBase<T> → LSAVectorizer<T>
For Beginners
LSA discovers hidden topics in your text:
- “car” and “automobile” become similar because they appear in similar contexts
- Reduces thousands of word features to ~100-500 semantic concepts
- Great for document similarity, clustering, and information retrieval
- Can handle synonymy (different words, same meaning) and polysemy (same word, different meanings)
How It Works
LSA (Latent Semantic Analysis), also known as LSI (Latent Semantic Indexing), uses Singular Value Decomposition (SVD) to reduce the dimensionality of the term-document matrix while capturing latent semantic relationships between terms and documents.
The algorithm works by:
- Creating a TF-IDF weighted term-document matrix
- Applying truncated SVD to get a low-rank approximation
- Projecting documents into the reduced semantic space
Constructors
| Constructor | Summary |
|---|---|
LSAVectorizer(int nComponents, int nIterations, double tolerance, 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 LSAVectorizer. |
Properties
| Property | Summary |
|---|---|
bool IsFitted { get; } |
|
double[] Components { get; } |
Gets the components (topic-term matrix) from LSA. |
double[] ExplainedVarianceRatio { get; } |
Gets the explained variance ratio for each component. |
double[] SingularValues { get; } |
Gets the singular values from the SVD decomposition. |
int FeatureCount { get; } |
|
int NComponents { get; } |
Gets the number of components (latent dimensions). |
Methods
| Method | Summary |
|---|---|
Matrix<T> Transform(IEnumerable<string> documents) |
Transforms documents to LSA vectors. |
void Fit(IEnumerable<string> documents) |
Fits the LSA vectorizer to the corpus. |